diff options
author | Craig Scott <craig.scott@crascit.com> | 2024-04-19 06:10:47 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2024-04-19 15:41:12 (GMT) |
commit | 8ac7958e3a2d24258cc4ebf0d6c44eccfb8a849a (patch) | |
tree | 57cc8c3c114b17ca2b38d29d9995f1c7b7a54a1b | |
parent | bf88879f1f3dff188a2520abe9b2dfb71d92be5e (diff) | |
download | CMake-8ac7958e3a2d24258cc4ebf0d6c44eccfb8a849a.zip CMake-8ac7958e3a2d24258cc4ebf0d6c44eccfb8a849a.tar.gz CMake-8ac7958e3a2d24258cc4ebf0d6c44eccfb8a849a.tar.bz2 |
generate_apple_*_selection_file: Save/restore PACKAGE_PREFIX_DIR
Issue: #25827
5 files changed, 102 insertions, 0 deletions
diff --git a/Modules/Internal/AppleArchitectureSelection.cmake.in b/Modules/Internal/AppleArchitectureSelection.cmake.in index b7315b6..0c3a3a2 100644 --- a/Modules/Internal/AppleArchitectureSelection.cmake.in +++ b/Modules/Internal/AppleArchitectureSelection.cmake.in @@ -1,2 +1,23 @@ +# Save this now so we can restore it before returning +if(NOT DEFINED PACKAGE_PREFIX_DIR) + list(APPEND _gasf_PACKAGE_PREFIX_DIR "<__CMAKE_UNDEFINED__>") +elseif("${PACKAGE_PREFIX_DIR}" STREQUAL "") + list(APPEND _gasf_PACKAGE_PREFIX_DIR "<__CMAKE_EMPTY__>") +else() + list(APPEND _gasf_PACKAGE_PREFIX_DIR "${PACKAGE_PREFIX_DIR}") +endif() + @PACKAGE_INIT@ @_branch_code@ + +# Restore PACKAGE_PREFIX_DIR +list(LENGTH _gasf_PACKAGE_PREFIX_DIR _gasf_tmp) +math(EXPR _gasf_tmp "${_gasf_tmp} - 1") +list(GET _gasf_PACKAGE_PREFIX_DIR ${_gasf_tmp} PACKAGE_PREFIX_DIR) +list(REMOVE_AT _gasf_PACKAGE_PREFIX_DIR ${_gasf_tmp}) +unset(_gasf_tmp) +if("${PACKAGE_PREFIX_DIR}" STREQUAL "<__CMAKE_UNDEFINED__>") + unset(PACKAGE_PREFIX_DIR) +elseif("${PACKAGE_PREFIX_DIR}" STREQUAL "<__CMAKE_EMPTY__>") + set(PACKAGE_PREFIX_DIR "") +endif() diff --git a/Modules/Internal/ApplePlatformSelection.cmake.in b/Modules/Internal/ApplePlatformSelection.cmake.in index 6c03ab6..c07f139 100644 --- a/Modules/Internal/ApplePlatformSelection.cmake.in +++ b/Modules/Internal/ApplePlatformSelection.cmake.in @@ -1,3 +1,12 @@ +# Save this now so we can restore it before returning +if(NOT DEFINED PACKAGE_PREFIX_DIR) + list(APPEND _gpsf_PACKAGE_PREFIX_DIR "<__CMAKE_UNDEFINED__>") +elseif("${PACKAGE_PREFIX_DIR}" STREQUAL "") + list(APPEND _gpsf_PACKAGE_PREFIX_DIR "<__CMAKE_EMPTY__>") +else() + list(APPEND _gpsf_PACKAGE_PREFIX_DIR "${PACKAGE_PREFIX_DIR}") +endif() + @PACKAGE_INIT@ string(TOLOWER "${CMAKE_OSX_SYSROOT}" _CMAKE_OSX_SYSROOT_LOWER) @@ -23,3 +32,15 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") else() @_branch_ELSE@ endif() + +# Restore PACKAGE_PREFIX_DIR +list(LENGTH _gpsf_PACKAGE_PREFIX_DIR _gpsf_tmp) +math(EXPR _gpsf_tmp "${_gpsf_tmp} - 1") +list(GET _gpsf_PACKAGE_PREFIX_DIR ${_gpsf_tmp} PACKAGE_PREFIX_DIR) +list(REMOVE_AT _gpsf_PACKAGE_PREFIX_DIR ${_gpsf_tmp}) +unset(_gpsf_tmp) +if("${PACKAGE_PREFIX_DIR}" STREQUAL "<__CMAKE_UNDEFINED__>") + unset(PACKAGE_PREFIX_DIR) +elseif("${PACKAGE_PREFIX_DIR}" STREQUAL "<__CMAKE_EMPTY__>") + set(PACKAGE_PREFIX_DIR "") +endif() 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 848c36d..3b4bef5 100644 --- a/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake @@ -75,6 +75,13 @@ 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}") |