summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2024-04-11 13:06:41 (GMT)
committerBrad King <brad.king@kitware.com>2024-04-11 13:23:46 (GMT)
commit0e4db177647e29b5f4a99ec220e38b5dbbf01361 (patch)
tree51cc15ef6f9c3b0391e66f94d00f7192dd13c5d3
parent85f501ed59cb3df68bffc713cd3cfc62ad878f55 (diff)
downloadCMake-0e4db177647e29b5f4a99ec220e38b5dbbf01361.zip
CMake-0e4db177647e29b5f4a99ec220e38b5dbbf01361.tar.gz
CMake-0e4db177647e29b5f4a99ec220e38b5dbbf01361.tar.bz2
CMakePackageConfigHelpers: Restore undocumented PACKAGE_PREFIX_DIR variable
Revert commit 6ddf8712cd (CMakePackageConfigHelpers: Use unique variable name for pkg prefix, 2024-03-30, v3.29.1~8^2). It regressed existing projects that rely on the undocumented `PACKAGE_PREFIX_DIR` variable in package configuration files generated by `CMakePackageConfigHelpers`. Fixes: #25873 Fixes: #25885 Issue: #25827
-rw-r--r--Modules/CMakePackageConfigHelpers.cmake42
-rw-r--r--Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir-stdout.txt3
-rw-r--r--Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir.cmake50
-rw-r--r--Tests/RunCMake/CMakePackage/NestedConfigFile-stdout.txt2
-rw-r--r--Tests/RunCMake/CMakePackage/NestedConfigFile.cmake39
-rw-r--r--Tests/RunCMake/CMakePackage/RunCMakeTest.cmake8
6 files changed, 7 insertions, 137 deletions
diff --git a/Modules/CMakePackageConfigHelpers.cmake b/Modules/CMakePackageConfigHelpers.cmake
index 8bd643e..dfe1ec7 100644
--- a/Modules/CMakePackageConfigHelpers.cmake
+++ b/Modules/CMakePackageConfigHelpers.cmake
@@ -377,24 +377,6 @@ macro(WRITE_BASIC_PACKAGE_VERSION_FILE)
write_basic_config_version_file(${ARGN})
endmacro()
-function(__CMAKE_get_config_file_package_prefix outvar)
- get_property(counter GLOBAL PROPERTY CMAKE_CONFIGURE_PACKAGE_CONFIG_FILE_COUNTER)
- if(NOT counter)
- set(counter 1)
- set_property(GLOBAL PROPERTY CMAKE_CONFIGURE_PACKAGE_CONFIG_FILE_COUNTER ${counter})
- endif()
- set(${outvar} "PACKAGE_\${CMAKE_FIND_PACKAGE_NAME}_COUNTER_${counter}" PARENT_SCOPE)
-endfunction()
-
-function(__CMAKE_increment_config_file_counter)
- get_property(counter GLOBAL PROPERTY CMAKE_CONFIGURE_PACKAGE_CONFIG_FILE_COUNTER)
- if(NOT counter)
- message(FATAL_ERROR "Internal error: global counter unexpectedly not set")
- endif()
- math(EXPR counter "${counter} + 1")
- set_property(GLOBAL PROPERTY CMAKE_CONFIGURE_PACKAGE_CONFIG_FILE_COUNTER ${counter})
-endfunction()
-
function(CONFIGURE_PACKAGE_CONFIG_FILE _inputFile _outputFile)
set(options NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO)
set(oneValueArgs INSTALL_DESTINATION INSTALL_PREFIX)
@@ -430,17 +412,15 @@ function(CONFIGURE_PACKAGE_CONFIG_FILE _inputFile _outputFile)
file(RELATIVE_PATH PACKAGE_RELATIVE_PATH "${absInstallDir}" "${installPrefix}" )
- __CMAKE_get_config_file_package_prefix(prefix_dir)
-
foreach(var ${CCF_PATH_VARS})
if(NOT DEFINED ${var})
message(FATAL_ERROR "Variable ${var} does not exist")
else()
if(IS_ABSOLUTE "${${var}}")
- string(REPLACE "${installPrefix}" "\${${prefix_dir}}"
+ string(REPLACE "${installPrefix}" "\${PACKAGE_PREFIX_DIR}"
PACKAGE_${var} "${${var}}")
else()
- set(PACKAGE_${var} "\${${prefix_dir}}/${${var}}")
+ set(PACKAGE_${var} "\${PACKAGE_PREFIX_DIR}/${${var}}")
endif()
endif()
endforeach()
@@ -452,7 +432,7 @@ function(CONFIGURE_PACKAGE_CONFIG_FILE _inputFile _outputFile)
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was ${inputFileName} ########
-get_filename_component(${prefix_dir} \"\${CMAKE_CURRENT_LIST_DIR}/${PACKAGE_RELATIVE_PATH}\" ABSOLUTE)
+get_filename_component(PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/${PACKAGE_RELATIVE_PATH}\" ABSOLUTE)
")
if("${absInstallDir}" MATCHES "^(/usr)?/lib(64)?/.+")
@@ -463,7 +443,7 @@ get_filename_component(${prefix_dir} \"\${CMAKE_CURRENT_LIST_DIR}/${PACKAGE_RELA
get_filename_component(_realCurr \"\${CMAKE_CURRENT_LIST_DIR}\" REALPATH)
get_filename_component(_realOrig \"${absInstallDir}\" REALPATH)
if(_realCurr STREQUAL _realOrig)
- set(${prefix_dir} \"${installPrefix}\")
+ set(PACKAGE_PREFIX_DIR \"${installPrefix}\")
endif()
unset(_realOrig)
unset(_realCurr)
@@ -501,10 +481,6 @@ endmacro()
configure_file("${_inputFile}" "${_outputFile}" @ONLY)
- # We're done writing the file. Make sure the next one has a unique prefix dir
- # variable name (we may have multiple config files for the one package)
- __CMAKE_increment_config_file_counter()
-
endfunction()
function(generate_apple_platform_selection_file _output_file)
@@ -545,14 +521,12 @@ function(generate_apple_platform_selection_file _output_file)
set(_branch_INIT "")
endif()
- __CMAKE_get_config_file_package_prefix(prefix_dir)
-
set(_else ELSE)
foreach(_opt IN LISTS _config_file_options _else)
if(_gpsf_${_opt})
set(_config_file "${_gpsf_${_opt}}")
if(NOT IS_ABSOLUTE "${_config_file}")
- string(PREPEND _config_file "\${${prefix_dir}}/")
+ string(PREPEND _config_file [[${PACKAGE_PREFIX_DIR}/]])
endif()
set(_branch_${_opt} "include(\"${_config_file}\")")
elseif(_gpsf_ERROR_VARIABLE)
@@ -626,13 +600,11 @@ function(generate_apple_architecture_selection_file _output_file)
"endif()\n"
)
- __CMAKE_get_config_file_package_prefix(prefix_dir)
-
foreach(pair IN ZIP_LISTS _gasf_SINGLE_ARCHITECTURES _gasf_SINGLE_ARCHITECTURE_INCLUDE_FILES)
set(arch "${pair_0}")
set(config_file "${pair_1}")
if(NOT IS_ABSOLUTE "${config_file}")
- string(PREPEND config_file "\${${prefix_dir}}/")
+ string(PREPEND config_file [[${PACKAGE_PREFIX_DIR}/]])
endif()
string(APPEND _branch_code
"\n"
@@ -647,7 +619,7 @@ function(generate_apple_architecture_selection_file _output_file)
string(JOIN " " universal_archs "${_gasf_UNIVERSAL_ARCHITECTURES}")
set(config_file "${_gasf_UNIVERSAL_INCLUDE_FILE}")
if(NOT IS_ABSOLUTE "${config_file}")
- string(PREPEND config_file "\${${prefix_dir}}/")
+ string(PREPEND config_file [[${PACKAGE_PREFIX_DIR}/]])
endif()
string(APPEND _branch_code
"\n"
diff --git a/Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir-stdout.txt b/Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir-stdout.txt
deleted file mode 100644
index 8821dad..0000000
--- a/Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir-stdout.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-(-- )?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
deleted file mode 100644
index a8a3168..0000000
--- a/Tests/RunCMake/CMakePackage/ApplePlatformGenSubdir.cmake
+++ /dev/null
@@ -1,50 +0,0 @@
-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 but still with the same package name. 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
deleted file mode 100644
index a95ef87..0000000
--- a/Tests/RunCMake/CMakePackage/NestedConfigFile-stdout.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-(-- )?Hello from pkg_a
-(-- )?Hello from pkg_b
diff --git a/Tests/RunCMake/CMakePackage/NestedConfigFile.cmake b/Tests/RunCMake/CMakePackage/NestedConfigFile.cmake
deleted file mode 100644
index e62c46b..0000000
--- a/Tests/RunCMake/CMakePackage/NestedConfigFile.cmake
+++ /dev/null
@@ -1,39 +0,0 @@
-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")
-]])
-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)
-find_dependency(pkg_a NO_DEFAULT_PATH
- PATHS "@CMAKE_CURRENT_BINARY_DIR@/install_pkg_a"
-)
-include("@PACKAGE_CMAKE_INSTALL_DATADIR@/pkg_b_included.cmake")
-]])
-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 6663f38..1551b55 100644
--- a/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CMakePackage/RunCMakeTest.cmake
@@ -4,8 +4,6 @@ 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}")
@@ -80,12 +78,6 @@ 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}
- )
-
apple_export(macos Darwin "${macos_archs}" macosx)
apple_export(ios iOS "arm64" iphoneos)
apple_export(tvos tvOS "arm64" appletvos)