RunCMakeTest.cmake 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. include(RunCMake)
  2. # Build dependencies that the other tests will use and treat as external.
  3. # Always build in the Debug configuration so that the path to the framework
  4. # is predictable.
  5. function(ExternalDependencies)
  6. set(RunCMake_TEST_NO_CLEAN 1)
  7. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ExternalDependencies-build)
  8. set(externalFramework ${RunCMake_TEST_BINARY_DIR}/Debug/sharedFrameworkExt.framework PARENT_SCOPE)
  9. set(externalDylib ${RunCMake_TEST_BINARY_DIR}/Debug/libsharedDylibExt.dylib PARENT_SCOPE)
  10. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  11. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  12. run_cmake(ExternalDependencies)
  13. run_cmake_command(ExternalDependencies-build
  14. ${CMAKE_COMMAND} --build ${RunCMake_TEST_BINARY_DIR}
  15. --config Debug
  16. --target sharedFrameworkExt sharedDylibExt
  17. )
  18. endfunction()
  19. ExternalDependencies()
  20. function(TestFlagsOn testName dependencyName)
  21. set(RunCMake_TEST_NO_CLEAN 1)
  22. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-${dependencyName}-build)
  23. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  24. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  25. run_cmake(${testName})
  26. run_cmake_command(${testName}-${dependencyName}-build
  27. ${CMAKE_COMMAND} --build ${RunCMake_TEST_BINARY_DIR}
  28. --config Debug
  29. --target app
  30. )
  31. endfunction()
  32. foreach(dependency ${externalFramework} ${externalDylib})
  33. cmake_path(GET dependency FILENAME dependencyName)
  34. set(RunCMake_TEST_OPTIONS -DEXTERNAL_DEPENDENCY=${dependency} -DEXTERNAL_DEPENDENCY_NAME=${dependencyName})
  35. run_cmake(EmbedFrameworksFlagsOff)
  36. TestFlagsOn(EmbedFrameworksFlagsOnNoSubdir ${dependencyName})
  37. TestFlagsOn(EmbedFrameworksFlagsOnWithSubdir ${dependencyName})
  38. endforeach()
  39. unset(RunCMake_TEST_OPTIONS)
  40. function(TestAppExtension platform)
  41. set(testName EmbedAppExtensions-${platform})
  42. if(NOT platform STREQUAL "macOS")
  43. set(RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=${platform})
  44. endif()
  45. set(RunCMake_TEST_NO_CLEAN 1)
  46. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build)
  47. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  48. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  49. run_cmake(${testName})
  50. run_cmake_command(${testName}-build
  51. ${CMAKE_COMMAND} --build ${RunCMake_TEST_BINARY_DIR}
  52. --config Debug
  53. --target app
  54. )
  55. endfunction()
  56. function(TestExtensionKitExtension platform)
  57. set(testName EmbedExtensionKitExtensions-${platform})
  58. if(NOT platform STREQUAL "macOS")
  59. set(RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=${platform})
  60. endif()
  61. set(RunCMake_TEST_NO_CLEAN 1)
  62. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build)
  63. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  64. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  65. run_cmake(${testName})
  66. run_cmake_command(${testName}-build
  67. ${CMAKE_COMMAND} --build ${RunCMake_TEST_BINARY_DIR}
  68. --config Debug
  69. --target app
  70. )
  71. endfunction()
  72. function(TestEmbedCommon what platform)
  73. set(testName Embed${what}-${platform})
  74. if(NOT platform STREQUAL "macOS")
  75. set(RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=${platform})
  76. endif()
  77. set(RunCMake_TEST_NO_CLEAN 1)
  78. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build)
  79. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  80. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  81. run_cmake(${testName})
  82. run_cmake_command(${testName}-build
  83. ${CMAKE_COMMAND} --build ${RunCMake_TEST_BINARY_DIR}
  84. --config Debug
  85. --target app
  86. )
  87. endfunction()
  88. # Isolate device tests from host architecture selection.
  89. unset(ENV{CMAKE_OSX_ARCHITECTURES})
  90. if(XCODE_VERSION VERSION_GREATER_EQUAL 8)
  91. # The various flag on/off combinations are tested by the EmbedFrameworks...
  92. # tests, so we don't duplicate all the combinations here. We only verify the
  93. # defaults, which is to remove headers on copy, but not code sign.
  94. TestAppExtension(macOS)
  95. TestAppExtension(iOS)
  96. endif()
  97. if(XCODE_VERSION VERSION_GREATER_EQUAL 14.1)
  98. # The various flag on/off combinations are tested by the EmbedFrameworks...
  99. # tests, so we don't duplicate all the combinations here. We only verify the
  100. # defaults, which is to remove headers on copy, but not code sign.
  101. TestAppExtension(macOS)
  102. TestAppExtension(iOS)
  103. TestEmbedCommon(Resources macOS)
  104. TestEmbedCommon(Resources iOS)
  105. TestEmbedCommon(PlugIns macOS)
  106. TestEmbedCommon(XPCServices macOS)
  107. endif()