diff options
author | Brad King <brad.king@kitware.com> | 2023-12-18 15:56:29 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2023-12-18 15:56:43 (GMT) |
commit | edb10c53256a4c308548af298eafc9ddf90b3bda (patch) | |
tree | 38e1287241f8329880119ee5872b8b39a35e4a73 | |
parent | 43e6d30061f96d4bf7e1f0304d038f56b93b8ee3 (diff) | |
parent | 1dd4a9baff389f2f62142c38f76d6383290c6ed6 (diff) | |
download | CMake-edb10c53256a4c308548af298eafc9ddf90b3bda.zip CMake-edb10c53256a4c308548af298eafc9ddf90b3bda.tar.gz CMake-edb10c53256a4c308548af298eafc9ddf90b3bda.tar.bz2 |
Merge topic 'package-dispatch-apple'
1dd4a9baff Tests: Cover generate_apple_platform_selection_file on all platforms
3148db4533 CMakePackageConfigHelpers: Fix Apple platform selection for tvOS
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9077
28 files changed, 182 insertions, 2 deletions
diff --git a/Modules/Internal/PlatformSelectionFile.cmake.in b/Modules/Internal/PlatformSelectionFile.cmake.in index 3f80f4b..493d650 100644 --- a/Modules/Internal/PlatformSelectionFile.cmake.in +++ b/Modules/Internal/PlatformSelectionFile.cmake.in @@ -5,9 +5,9 @@ if(_CMAKE_OSX_SYSROOT_LOWER MATCHES "(^|/)iphonesimulator") @_branch_IOS_SIMULATOR_CONFIG_FILE@ elseif(_CMAKE_OSX_SYSROOT_LOWER MATCHES "(^|/)iphoneos") @_branch_IOS_CONFIG_FILE@ -elseif(_CMAKE_OSX_SYSROOT_LOWER MATCHES "(^|/)tvsimulator") +elseif(_CMAKE_OSX_SYSROOT_LOWER MATCHES "(^|/)appletvsimulator") @_branch_TVOS_SIMULATOR_CONFIG_FILE@ -elseif(_CMAKE_OSX_SYSROOT_LOWER MATCHES "(^|/)tvos") +elseif(_CMAKE_OSX_SYSROOT_LOWER MATCHES "(^|/)appletvos") @_branch_TVOS_CONFIG_FILE@ elseif(_CMAKE_OSX_SYSROOT_LOWER MATCHES "(^|/)watchsimulator") @_branch_WATCHOS_SIMULATOR_CONFIG_FILE@ diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 7e1b0e4..dbcb94e 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -325,6 +325,13 @@ if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja") add_RunCMake_test(Byproducts) endif() add_RunCMake_test(CMakeDependentOption) +if(APPLE # Remove these conditions when the test has non-Apple cases + AND CMAKE_C_COMPILER_ID STREQUAL "AppleClang") + add_RunCMake_test(CMakePackage + -DCMake_TEST_XCODE_VERSION=${CMake_TEST_XCODE_VERSION} + -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID} + ) +endif() add_RunCMake_test(CMakeRoleGlobalProperty) add_RunCMake_test(CMakeRelease -DCMake_TEST_JQ=${CMake_TEST_JQ}) if(CMAKE_GENERATOR MATCHES "Make|Ninja") diff --git a/Tests/RunCMake/CMakePackage/CMakeLists.txt b/Tests/RunCMake/CMakePackage/CMakeLists.txt new file mode 100644 index 0000000..6a9ce76 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.28) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake b/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake new file mode 100644 index 0000000..9fef792 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake @@ -0,0 +1,86 @@ +include(RunCMake) + +if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG) + set(maybe_CMAKE_BUILD_TYPE -DCMAKE_BUILD_TYPE=Release) +endif() + +function(apple_export platform system_name archs sysroot) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/apple-export-${platform}-build) + string(REPLACE ";" "\\;" archs "${archs}") + run_cmake_with_options(apple-export-${platform} + "-DCMAKE_SYSTEM_NAME=${system_name}" + "-DCMAKE_OSX_ARCHITECTURES=${archs}" + "-DCMAKE_OSX_SYSROOT=${sysroot}" + "-DCMAKE_INSTALL_PREFIX=${apple_install}" + ${maybe_CMAKE_BUILD_TYPE} + ) + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake_command(apple-export-${platform}-build ${CMAKE_COMMAND} --build . --config Release) + run_cmake_command(apple-export-${platform}-install ${CMAKE_COMMAND} --install . --config Release) +endfunction() + +function(apple_import platform system_name archs sysroot) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/apple-import-${platform}-build) + string(REPLACE ";" "\\;" archs "${archs}") + run_cmake_with_options(apple-import-${platform} + "-DCMAKE_SYSTEM_NAME=${system_name}" + "-DCMAKE_OSX_ARCHITECTURES=${archs}" + "-DCMAKE_OSX_SYSROOT=${sysroot}" + "-DCMAKE_PREFIX_PATH=${apple_install}" + ${maybe_CMAKE_BUILD_TYPE} + ) + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake_command(apple-import-${platform}-build ${CMAKE_COMMAND} --build . --config Release) +endfunction() + +if(APPLE AND CMAKE_C_COMPILER_ID STREQUAL "AppleClang") + set(apple_install ${RunCMake_BINARY_DIR}/apple-install) + file(REMOVE_RECURSE "${apple_install}") + + if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 12) + set(macos_archs "x86_64;arm64") + set(watch_sim_archs "x86_64") + else() + set(macos_archs "x86_64") + set(watch_sim_archs "i386") + endif() + + if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 9) + set(watch_archs "armv7k;arm64_32") + else() + set(watch_archs "armv7k") + endif() + + #FIXME(#25266): Xcode 15.0 does not have visionOS. Improve this condition. + #if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 15) + # set(enable_visionos 1) + #endif() + + apple_export(macos Darwin "${macos_archs}" macosx) + apple_export(ios iOS "arm64" iphoneos) + apple_export(tvos tvOS "arm64" appletvos) + if(enable_visionos) + apple_export(visionos visionOS "arm64" xros) + endif() + apple_export(watchos watchOS "${watch_archs}" watchos) + apple_export(ios-simulator iOS "${macos_archs}" iphonesimulator) + apple_export(tvos-simulator tvOS "${macos_archs}" appletvsimulator) + if(enable_visionos) + apple_export(visionos-simulator visionOS "${macos_archs}" xrsimulator) + endif() + apple_export(watchos-simulator watchOS "${watch_sim_archs}" watchsimulator) + + apple_import(macos Darwin "${macos_archs}" macosx) + apple_import(ios iOS "arm64" iphoneos) + apple_import(tvos tvOS "arm64" appletvos) + if(enable_visionos) + apple_import(visionos visionOS "arm64" xros) + endif() + apple_import(watchos watchOS "${watch_archs}" watchos) + apple_import(ios-simulator iOS "${macos_archs}" iphonesimulator) + apple_import(tvos-simulator tvOS "${macos_archs}" appletvsimulator) + if(enable_visionos) + apple_import(visionos-simulator visionOS "${macos_archs}" xrsimulator) + endif() + apple_import(watchos-simulator watchOS "${watch_sim_archs}" watchsimulator) +endif() diff --git a/Tests/RunCMake/CMakePackage/apple-common.cmake b/Tests/RunCMake/CMakePackage/apple-common.cmake new file mode 100644 index 0000000..f854f34 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-common.cmake @@ -0,0 +1,15 @@ +enable_language(C) + +if(CMAKE_SYSTEM_NAME MATCHES "^(iOS)$") + set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO") + set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO") + set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "") + set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO") +endif() + +if(CMAKE_SYSTEM_NAME MATCHES "^(tvOS|watchOS|visionOS)$") + set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO") + set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO") + set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "") + set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "YES") +endif() diff --git a/Tests/RunCMake/CMakePackage/apple-export-common.cmake b/Tests/RunCMake/CMakePackage/apple-export-common.cmake new file mode 100644 index 0000000..1381f59 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-export-common.cmake @@ -0,0 +1,22 @@ +include(apple-common.cmake) + +add_library(mylib STATIC src/mylib.c) +target_sources(mylib PUBLIC FILE_SET HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include FILES include/mylib.h) +install(TARGETS mylib EXPORT mylib-targets FILE_SET HEADERS ARCHIVE DESTINATION lib/${platform_name}) + +install(EXPORT mylib-targets DESTINATION lib/${platform_name}/cmake/mylib) + +include(CMakePackageConfigHelpers) +generate_apple_platform_selection_file(mylib-config-install.cmake + INSTALL_DESTINATION lib/cmake/mylib + MACOS_CONFIG_FILE lib/macos/cmake/mylib/mylib-targets.cmake + IOS_CONFIG_FILE lib/ios/cmake/mylib/mylib-targets.cmake + IOS_SIMULATOR_CONFIG_FILE lib/ios-simulator/cmake/mylib/mylib-targets.cmake + TVOS_CONFIG_FILE lib/tvos/cmake/mylib/mylib-targets.cmake + TVOS_SIMULATOR_CONFIG_FILE lib/tvos-simulator/cmake/mylib/mylib-targets.cmake + VISIONOS_CONFIG_FILE lib/watchos/cmake/mylib/mylib-targets.cmake + VISIONOS_SIMULATOR_CONFIG_FILE lib/watchos-simulator/cmake/mylib/mylib-targets.cmake + WATCHOS_CONFIG_FILE lib/watchos/cmake/mylib/mylib-targets.cmake + WATCHOS_SIMULATOR_CONFIG_FILE lib/watchos-simulator/cmake/mylib/mylib-targets.cmake + ) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mylib-config-install.cmake DESTINATION lib/cmake/mylib RENAME mylib-config.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-export-ios-simulator.cmake b/Tests/RunCMake/CMakePackage/apple-export-ios-simulator.cmake new file mode 100644 index 0000000..dd545bb --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-export-ios-simulator.cmake @@ -0,0 +1,2 @@ +set(platform_name ios-simulator) +include(apple-export-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-export-ios.cmake b/Tests/RunCMake/CMakePackage/apple-export-ios.cmake new file mode 100644 index 0000000..33daa40 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-export-ios.cmake @@ -0,0 +1,2 @@ +set(platform_name ios) +include(apple-export-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-export-macos.cmake b/Tests/RunCMake/CMakePackage/apple-export-macos.cmake new file mode 100644 index 0000000..d845d5c --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-export-macos.cmake @@ -0,0 +1,2 @@ +set(platform_name macos) +include(apple-export-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-export-tvos-simulator.cmake b/Tests/RunCMake/CMakePackage/apple-export-tvos-simulator.cmake new file mode 100644 index 0000000..d44d663 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-export-tvos-simulator.cmake @@ -0,0 +1,2 @@ +set(platform_name tvos-simulator) +include(apple-export-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-export-tvos.cmake b/Tests/RunCMake/CMakePackage/apple-export-tvos.cmake new file mode 100644 index 0000000..c58144b --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-export-tvos.cmake @@ -0,0 +1,2 @@ +set(platform_name tvos) +include(apple-export-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-export-visionos-simulator.cmake b/Tests/RunCMake/CMakePackage/apple-export-visionos-simulator.cmake new file mode 100644 index 0000000..e783d80 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-export-visionos-simulator.cmake @@ -0,0 +1,2 @@ +set(platform_name visionos-simulator) +include(apple-export-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-export-visionos.cmake b/Tests/RunCMake/CMakePackage/apple-export-visionos.cmake new file mode 100644 index 0000000..73e1b2e --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-export-visionos.cmake @@ -0,0 +1,2 @@ +set(platform_name visionos) +include(apple-export-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-export-watchos-simulator.cmake b/Tests/RunCMake/CMakePackage/apple-export-watchos-simulator.cmake new file mode 100644 index 0000000..f4f95a6 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-export-watchos-simulator.cmake @@ -0,0 +1,2 @@ +set(platform_name watchos-simulator) +include(apple-export-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-export-watchos.cmake b/Tests/RunCMake/CMakePackage/apple-export-watchos.cmake new file mode 100644 index 0000000..59fc572 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-export-watchos.cmake @@ -0,0 +1,2 @@ +set(platform_name watchos) +include(apple-export-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-import-common.cmake b/Tests/RunCMake/CMakePackage/apple-import-common.cmake new file mode 100644 index 0000000..ce79541 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-import-common.cmake @@ -0,0 +1,7 @@ +include(apple-common.cmake) + +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER) +find_package(mylib CONFIG REQUIRED) + +add_executable(myexe src/myexe.c) +target_link_libraries(myexe PRIVATE mylib) diff --git a/Tests/RunCMake/CMakePackage/apple-import-ios-simulator.cmake b/Tests/RunCMake/CMakePackage/apple-import-ios-simulator.cmake new file mode 100644 index 0000000..fa7ba53 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-import-ios-simulator.cmake @@ -0,0 +1 @@ +include(apple-import-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-import-ios.cmake b/Tests/RunCMake/CMakePackage/apple-import-ios.cmake new file mode 100644 index 0000000..fa7ba53 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-import-ios.cmake @@ -0,0 +1 @@ +include(apple-import-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-import-macos.cmake b/Tests/RunCMake/CMakePackage/apple-import-macos.cmake new file mode 100644 index 0000000..fa7ba53 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-import-macos.cmake @@ -0,0 +1 @@ +include(apple-import-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-import-tvos-simulator.cmake b/Tests/RunCMake/CMakePackage/apple-import-tvos-simulator.cmake new file mode 100644 index 0000000..fa7ba53 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-import-tvos-simulator.cmake @@ -0,0 +1 @@ +include(apple-import-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-import-tvos.cmake b/Tests/RunCMake/CMakePackage/apple-import-tvos.cmake new file mode 100644 index 0000000..fa7ba53 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-import-tvos.cmake @@ -0,0 +1 @@ +include(apple-import-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-import-visionos-simulator.cmake b/Tests/RunCMake/CMakePackage/apple-import-visionos-simulator.cmake new file mode 100644 index 0000000..fa7ba53 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-import-visionos-simulator.cmake @@ -0,0 +1 @@ +include(apple-import-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-import-visionos.cmake b/Tests/RunCMake/CMakePackage/apple-import-visionos.cmake new file mode 100644 index 0000000..fa7ba53 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-import-visionos.cmake @@ -0,0 +1 @@ +include(apple-import-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-import-watchos-simulator.cmake b/Tests/RunCMake/CMakePackage/apple-import-watchos-simulator.cmake new file mode 100644 index 0000000..fa7ba53 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-import-watchos-simulator.cmake @@ -0,0 +1 @@ +include(apple-import-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/apple-import-watchos.cmake b/Tests/RunCMake/CMakePackage/apple-import-watchos.cmake new file mode 100644 index 0000000..fa7ba53 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/apple-import-watchos.cmake @@ -0,0 +1 @@ +include(apple-import-common.cmake) diff --git a/Tests/RunCMake/CMakePackage/include/mylib.h b/Tests/RunCMake/CMakePackage/include/mylib.h new file mode 100644 index 0000000..4955e74 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/include/mylib.h @@ -0,0 +1,3 @@ +#pragma once + +extern int mylib(void); diff --git a/Tests/RunCMake/CMakePackage/src/myexe.c b/Tests/RunCMake/CMakePackage/src/myexe.c new file mode 100644 index 0000000..c1182a2 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/src/myexe.c @@ -0,0 +1,6 @@ +#include <mylib.h> /* include by angle-bracket to find installed copy */ + +int main(void) +{ + return mylib(); +} diff --git a/Tests/RunCMake/CMakePackage/src/mylib.c b/Tests/RunCMake/CMakePackage/src/mylib.c new file mode 100644 index 0000000..f4c047e --- /dev/null +++ b/Tests/RunCMake/CMakePackage/src/mylib.c @@ -0,0 +1,4 @@ +int mylib(void) +{ + return 0; +} |