diff options
author | Brad King <brad.king@kitware.com> | 2024-04-22 12:41:59 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2024-04-22 12:42:13 (GMT) |
commit | 8b3d48ab9484e6f40e4dc28420ffcb1da757c8e5 (patch) | |
tree | 4763eee4060ea5a3a20866618323b27029be0b8b /Tests | |
parent | ad98b352baab962c28fae88296b1558ffb6b2879 (diff) | |
parent | 41f4e1c45761c107a0a59cf7c16d34ef569301fc (diff) | |
download | CMake-8b3d48ab9484e6f40e4dc28420ffcb1da757c8e5.zip CMake-8b3d48ab9484e6f40e4dc28420ffcb1da757c8e5.tar.gz CMake-8b3d48ab9484e6f40e4dc28420ffcb1da757c8e5.tar.bz2 |
Merge topic 'save-restore-PACKAGE_PREFIX_DIR'
41f4e1c457 CMakePackageConfigHelpers: Document PACKAGE_PREFIX_DIR for public use
c5231ba29e find_package: Save/restore PACKAGE_PREFIX_DIR
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')
5 files changed, 115 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/NestedConfigFile-stdout.txt b/Tests/RunCMake/CMakePackage/NestedConfigFile-stdout.txt new file mode 100644 index 0000000..cdb3384 --- /dev/null +++ b/Tests/RunCMake/CMakePackage/NestedConfigFile-stdout.txt @@ -0,0 +1,6 @@ +(-- )?Before find_dependency: PACKAGE_PREFIX_DIR = .*/Tests/RunCMake/CMakePackage/NestedConfigFile-build/install_pkg_b +(-- )?Hello from pkg_a +(-- )?Leaving pkg_a-config\.cmake with PACKAGE_PREFIX_DIR = .*/Tests/RunCMake/CMakePackage/NestedConfigFile-build/install_pkg_a +(-- )?After find_dependency: PACKAGE_PREFIX_DIR = .*/Tests/RunCMake/CMakePackage/NestedConfigFile-build/install_pkg_b +(-- )?Hello from pkg_b +(-- )?Leaving pkg_b-config\.cmake with PACKAGE_PREFIX_DIR = .*/Tests/RunCMake/CMakePackage/NestedConfigFile-build/install_pkg_b diff --git a/Tests/RunCMake/CMakePackage/NestedConfigFile.cmake b/Tests/RunCMake/CMakePackage/NestedConfigFile.cmake new file mode 100644 index 0000000..2eeaebb --- /dev/null +++ b/Tests/RunCMake/CMakePackage/NestedConfigFile.cmake @@ -0,0 +1,43 @@ +set(CMAKE_INSTALL_DATADIR share) + +include(CMakePackageConfigHelpers) + +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/pkg_a-config.cmake.in [[ +@PACKAGE_INIT@ +include("@PACKAGE_CMAKE_INSTALL_DATADIR@/pkg_a_included.cmake") +message(STATUS "Leaving pkg_a-config.cmake with PACKAGE_PREFIX_DIR = ${PACKAGE_PREFIX_DIR}") +]]) +configure_package_config_file( + ${CMAKE_CURRENT_BINARY_DIR}/pkg_a-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/install_pkg_a/pkg_a-config.cmake + INSTALL_DESTINATION . + PATH_VARS CMAKE_INSTALL_DATADIR +) +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/install_pkg_a/share/pkg_a_included.cmake + [[message(STATUS "Hello from pkg_a")]] +) + +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/pkg_b-config.cmake.in [[ +@PACKAGE_INIT@ +include(CMakeFindDependencyMacro) +message(STATUS "Before find_dependency: PACKAGE_PREFIX_DIR = ${PACKAGE_PREFIX_DIR}") +find_dependency(pkg_a NO_DEFAULT_PATH + PATHS "@CMAKE_CURRENT_BINARY_DIR@/install_pkg_a" +) +message(STATUS "After find_dependency: PACKAGE_PREFIX_DIR = ${PACKAGE_PREFIX_DIR}") +include("@PACKAGE_CMAKE_INSTALL_DATADIR@/pkg_b_included.cmake") +message(STATUS "Leaving pkg_b-config.cmake with PACKAGE_PREFIX_DIR = ${PACKAGE_PREFIX_DIR}") +]]) +configure_package_config_file( + ${CMAKE_CURRENT_BINARY_DIR}/pkg_b-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/install_pkg_b/pkg_b-config.cmake + INSTALL_DESTINATION . + PATH_VARS CMAKE_INSTALL_DATADIR +) +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/install_pkg_b/share/pkg_b_included.cmake + [[message(STATUS "Hello from pkg_b")]] +) + +find_package(pkg_b REQUIRED NO_DEFAULT_PATH + PATHS ${CMAKE_CURRENT_BINARY_DIR}/install_pkg_b +) diff --git a/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake b/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake index 1551b55..c4a05e3 100644 --- a/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake @@ -4,6 +4,8 @@ if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG) set(maybe_CMAKE_BUILD_TYPE -DCMAKE_BUILD_TYPE=Release) endif() +run_cmake_with_options(NestedConfigFile ${maybe_CMAKE_BUILD_TYPE}) + function(apple_export platform system_name archs sysroot) set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/apple-export-${platform}-build) string(REPLACE ";" "\\;" archs "${archs}") @@ -48,9 +50,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 +77,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) |