RunCMakeTest.cmake 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. include(RunCMake)
  2. function(create_library type platform system_name archs)
  3. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/create-${type}-${platform}-build)
  4. run_cmake_with_options(create-${type}-${platform} -DCMAKE_SYSTEM_NAME=${system_name} -DCMAKE_OSX_ARCHITECTURES=${archs} -DCMAKE_INSTALL_PREFIX=${RunCMake_TEST_BINARY_DIR}/install)
  5. set(RunCMake_TEST_NO_CLEAN 1)
  6. run_cmake_command(create-${type}-${platform}-build ${CMAKE_COMMAND} --build . --config Release)
  7. run_cmake_command(create-${type}-${platform}-install ${CMAKE_COMMAND} --install . --config Release)
  8. endfunction()
  9. function(create_libraries type)
  10. create_library(${type} macos Darwin "${macos_archs_2}")
  11. create_library(${type} ios iOS "arm64")
  12. create_library(${type} tvos tvOS "arm64")
  13. create_library(${type} watchos watchOS "armv7k\\\\;arm64_32")
  14. if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
  15. create_library(${type} visionos visionOS "arm64")
  16. endif()
  17. endfunction()
  18. function(create_xcframework name type platforms)
  19. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/create-xcframework-${name}-build)
  20. set(args)
  21. foreach(platform IN LISTS platforms)
  22. if(type STREQUAL "framework")
  23. list(APPEND args -framework ${RunCMake_BINARY_DIR}/create-${type}-${platform}-build/install/lib/mylib.framework)
  24. else()
  25. list(APPEND args -library ${RunCMake_BINARY_DIR}/create-${type}-${platform}-build/install/lib/libmylib.a -headers ${RunCMake_SOURCE_DIR}/mylib/include)
  26. endif()
  27. endforeach()
  28. run_cmake_command(create-xcframework-${name} xcodebuild -create-xcframework ${args} -output ${RunCMake_TEST_BINARY_DIR}/mylib.xcframework)
  29. endfunction()
  30. function(create_executable name xcfname system_name archs)
  31. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/create-executable-${name}-build)
  32. run_cmake_with_options(create-executable-${name} -DCMAKE_SYSTEM_NAME=${system_name} -DCMAKE_OSX_ARCHITECTURES=${archs} -DMYLIB_LIBRARY=${RunCMake_BINARY_DIR}/create-xcframework-${xcfname}-build/mylib.xcframework)
  33. set(RunCMake_TEST_NO_CLEAN 1)
  34. run_cmake_command(create-executable-${name}-build ${CMAKE_COMMAND} --build . --config Release)
  35. endfunction()
  36. function(create_executables name type)
  37. create_executable(${name}-macos ${type} Darwin "${macos_archs_2}")
  38. create_executable(${name}-ios ${type} iOS "arm64")
  39. create_executable(${name}-tvos ${type} tvOS "arm64")
  40. create_executable(${name}-watchos ${type} watchOS "armv7k\\\\;arm64_32")
  41. if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
  42. create_executable(${name}-visionos ${type} visionOS "arm64")
  43. endif()
  44. endfunction()
  45. set(xcframework_platforms macos ios tvos watchos)
  46. if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
  47. list(APPEND xcframework_platforms visionos)
  48. endif()
  49. if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12)
  50. set(macos_archs_1 "x86_64\\;arm64")
  51. set(macos_archs_2 "x86_64\\\\;arm64")
  52. else()
  53. set(macos_archs_1 "x86_64")
  54. set(macos_archs_2 "x86_64")
  55. endif()
  56. create_libraries(library)
  57. create_libraries(framework)
  58. create_xcframework(library library "${xcframework_platforms}")
  59. create_xcframework(framework framework "${xcframework_platforms}")
  60. create_xcframework(incomplete framework "tvos;watchos")
  61. create_executables(library library)
  62. create_executables(framework framework)
  63. run_cmake_with_options(create-executable-incomplete -DCMAKE_SYSTEM_NAME=Darwin "-DCMAKE_OSX_ARCHITECTURES=${macos_archs_1}" -DMYLIB_LIBRARY=${RunCMake_BINARY_DIR}/create-xcframework-incomplete-build/mylib.xcframework)
  64. create_executables(target-library library)
  65. create_executables(target-framework framework)
  66. run_cmake_with_options(create-executable-target-incomplete -DCMAKE_SYSTEM_NAME=Darwin "-DCMAKE_OSX_ARCHITECTURES=${macos_archs_1}" -DMYLIB_LIBRARY=${RunCMake_BINARY_DIR}/create-xcframework-incomplete-build/mylib.xcframework)
  67. if(RunCMake_GENERATOR STREQUAL "Xcode" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12)
  68. create_executables(library-link-phase library)
  69. create_executables(framework-link-phase framework)
  70. run_cmake_with_options(create-executable-incomplete-link-phase -DCMAKE_SYSTEM_NAME=Darwin "-DCMAKE_OSX_ARCHITECTURES=${macos_archs_1}" -DMYLIB_LIBRARY=${RunCMake_BINARY_DIR}/create-xcframework-incomplete-build/mylib.xcframework)
  71. create_executables(target-library-link-phase library)
  72. create_executables(target-framework-link-phase framework)
  73. run_cmake_with_options(create-executable-target-incomplete-link-phase -DCMAKE_SYSTEM_NAME=Darwin "-DCMAKE_OSX_ARCHITECTURES=${macos_archs_1}" -DMYLIB_LIBRARY=${RunCMake_BINARY_DIR}/create-xcframework-incomplete-build/mylib.xcframework)
  74. endif()