summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2024-04-22 12:41:59 (GMT)
committerKitware Robot <kwrobot@kitware.com>2024-04-22 12:42:12 (GMT)
commit8f44e1a07b16aba866cc28d635e41aca3744d8c4 (patch)
tree5636d9119d53c97ed7f720f41fbe05e4598d74b6 /Tests
parent58157d92936b4736977805d0f2251f9c0e843fb9 (diff)
parent8ac7958e3a2d24258cc4ebf0d6c44eccfb8a849a (diff)
downloadCMake-8f44e1a07b16aba866cc28d635e41aca3744d8c4.zip
CMake-8f44e1a07b16aba866cc28d635e41aca3744d8c4.tar.gz
CMake-8f44e1a07b16aba866cc28d635e41aca3744d8c4.tar.bz2
Merge topic 'save-restore-PACKAGE_PREFIX_DIR' into release-3.29
8ac7958e3a generate_apple_*_selection_file: Save/restore PACKAGE_PREFIX_DIR bf88879f1f generate_apple_architecture_selection_file: Avoid early returns a4ac2c92f4 Help: Add missing section heading for apple architecture selection b7fcc44be9 Help: Fix CMakePackageConfigHelpers typos, grammar and formatting f1cacaa830 Tests/RunCMake/CMakePackage: Define variable closer to where it is used Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !9430
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir-stdout.txt3
-rw-r--r--Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir.cmake50
-rw-r--r--Tests/RunCMake/CMakePackage/RunCMakeTest.cmake14
3 files changed, 64 insertions, 3 deletions
diff --git a/Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir-stdout.txt b/Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir-stdout.txt
new file mode 100644
index 0000000..8821dad
--- /dev/null
+++ b/Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir-stdout.txt
@@ -0,0 +1,3 @@
+(-- )?Hello from platform switch
+(-- )?Hello from arch switch
+(-- )?Hello from pkg_a
diff --git a/Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir.cmake b/Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir.cmake
new file mode 100644
index 0000000..e472665
--- /dev/null
+++ b/Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir.cmake
@@ -0,0 +1,50 @@
+set(CMAKE_INSTALL_DATADIR share)
+set(SWITCH_DIR platform/cmake)
+
+include(CMakePackageConfigHelpers)
+
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/pkg_a-config.cmake.in [[
+@PACKAGE_INIT@
+include("@PACKAGE_SWITCH_DIR@/platform-switch.cmake")
+include("@PACKAGE_CMAKE_INSTALL_DATADIR@/pkg_a_included.cmake")
+]])
+configure_package_config_file(
+ ${CMAKE_CURRENT_BINARY_DIR}/pkg_a-config.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/install/pkg_a-config.cmake
+ INSTALL_DESTINATION .
+ PATH_VARS CMAKE_INSTALL_DATADIR SWITCH_DIR
+)
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/install/${CMAKE_INSTALL_DATADIR}/pkg_a_included.cmake
+ [[message(STATUS "Hello from pkg_a")]]
+)
+
+# To expose re-using the same package prefix variable, we need to use a
+# different install prefix. This is really contrived and not representative of
+# what a package should do.
+generate_apple_platform_selection_file(
+ ${CMAKE_CURRENT_BINARY_DIR}/install/platform/cmake/platform-switch.cmake
+ INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/platform
+ INSTALL_DESTINATION cmake
+ MACOS_INCLUDE_FILE cmake/switch_included.cmake # relative to install prefix
+)
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/install/platform/cmake/switch_included.cmake
+[[
+message(STATUS "Hello from platform switch")
+include("${CMAKE_CURRENT_LIST_DIR}/../arch/cmake/arch-switch.cmake")
+]]
+)
+
+generate_apple_architecture_selection_file(
+ ${CMAKE_CURRENT_BINARY_DIR}/install/platform/arch/cmake/arch-switch.cmake
+ INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/platform/arch
+ INSTALL_DESTINATION cmake
+ UNIVERSAL_ARCHITECTURES i386 x86_64 arm64 $(ARCHS_STANDARD)
+ UNIVERSAL_INCLUDE_FILE cmake/switch_included.cmake # relative to install prefix
+)
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/install/platform/arch/cmake/switch_included.cmake
+ [[message(STATUS "Hello from arch switch")]]
+)
+
+find_package(pkg_a REQUIRED NO_DEFAULT_PATH
+ PATHS ${CMAKE_CURRENT_BINARY_DIR}/install
+)
diff --git a/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake b/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake
index 1551b55..3b4bef5 100644
--- a/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake
@@ -48,9 +48,6 @@ if(APPLE)
endif()
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(tvos_sim_archs "x86_64;arm64")
@@ -78,6 +75,17 @@ if(APPLE AND CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
set(enable_visionos 1)
endif()
+ string(REPLACE ";" "\\;" macos_archs_for_cmd "${macos_archs}")
+ run_cmake_with_options(ApplePlatformGenSubdir
+ "-DCMAKE_OSX_ARCHITECTURES=${macos_archs_for_cmd}"
+ ${maybe_CMAKE_BUILD_TYPE}
+ )
+ unset(macos_archs_for_cmd)
+
+ # Place all export/import steps in a single install prefix.
+ set(apple_install ${RunCMake_BINARY_DIR}/apple-install)
+ file(REMOVE_RECURSE "${apple_install}")
+
apple_export(macos Darwin "${macos_archs}" macosx)
apple_export(ios iOS "arm64" iphoneos)
apple_export(tvos tvOS "arm64" appletvos)