PageRenderTime 21ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/subprojects/platform-native/src/testFixtures/groovy/org/gradle/nativeplatform/fixtures/app/CCallingMixedCAndCppHelloWorldApp.groovy

https://github.com/andrewhj-mn/gradle
Groovy | 85 lines | 63 code | 7 blank | 15 comment | 0 complexity | 57ca3e6f3863060b0c8e23cf58d1cea0 MD5 | raw file
  1. /*
  2. * Copyright 2013 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.gradle.nativeplatform.fixtures.app
  17. import org.gradle.integtests.fixtures.SourceFile;
  18. public class CCallingMixedCAndCppHelloWorldApp extends HelloWorldApp {
  19. @Override
  20. List<String> getPluginList() {
  21. return ['c', 'cpp']
  22. }
  23. @Override
  24. SourceFile getMainSource() {
  25. sourceFile("c", "main.c", """
  26. #include <stdio.h>
  27. #include "hello.h"
  28. int main () {
  29. sayHello();
  30. printf("%d", sum(5, 7));
  31. return 0;
  32. }
  33. """)
  34. }
  35. @Override
  36. SourceFile getLibraryHeader() {
  37. sourceFile("headers", "hello.h", """
  38. #ifdef _WIN32
  39. #define DLL_FUNC __declspec(dllexport)
  40. #else
  41. #define DLL_FUNC
  42. #endif
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. void DLL_FUNC sayHello();
  47. int DLL_FUNC sum(int a, int b);
  48. #ifdef __cplusplus
  49. }
  50. #endif
  51. """)
  52. }
  53. List<SourceFile> librarySources = [
  54. sourceFile("cpp", "hello.cpp", """
  55. #include <iostream>
  56. #include "hello.h"
  57. void DLL_FUNC sayHello() {
  58. #ifdef FRENCH
  59. std::cout << "${HELLO_WORLD_FRENCH}" << std::endl;
  60. #else
  61. std::cout << "${HELLO_WORLD}" << std::endl;
  62. #endif
  63. }
  64. """),
  65. sourceFile("c", "sum.c", """
  66. #include "hello.h"
  67. int DLL_FUNC sum(int a, int b) {
  68. return a + b;
  69. }
  70. """)
  71. ]
  72. }