diff options
author | Brad King <brad.king@kitware.com> | 2021-08-19 14:27:14 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-08-19 14:27:23 (GMT) |
commit | 30dd9b33a048ec76fd48665f3793cf282cd75f12 (patch) | |
tree | dbf4fc68b294f6ef3cdb7787be5352a565633400 | |
parent | daeb4f0f5070d70e0bae9e966099f64b4c4671e9 (diff) | |
parent | 17e4934dbfa6df048e201bf0f0b46ad8d0e279ef (diff) | |
download | CMake-30dd9b33a048ec76fd48665f3793cf282cd75f12.zip CMake-30dd9b33a048ec76fd48665f3793cf282cd75f12.tar.gz CMake-30dd9b33a048ec76fd48665f3793cf282cd75f12.tar.bz2 |
Merge topic 'FindPkgConfig-restore-legacy-behavior' into release-3.21
17e4934dbf FindPkgConfig: Restore legacy behavior when CMP0126 is set to NEW
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6461
-rw-r--r-- | Modules/FindPkgConfig.cmake | 8 | ||||
-rw-r--r-- | Tests/RunCMake/FindPkgConfig/FindPkgConfig_CMP0126_NEW.cmake | 64 | ||||
-rw-r--r-- | Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake | 1 |
3 files changed, 73 insertions, 0 deletions
diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake index 3bc9dba..01ad5ac 100644 --- a/Modules/FindPkgConfig.cmake +++ b/Modules/FindPkgConfig.cmake @@ -79,10 +79,18 @@ set(PKG_CONFIG_FOUND "${PKGCONFIG_FOUND}") # Unsets the given variables macro(_pkgconfig_unset var) + # Clear normal variable (possibly set by project code). + unset(${var}) + # Store as cache variable. + # FIXME: Add a policy to switch to a normal variable. set(${var} "" CACHE INTERNAL "") endmacro() macro(_pkgconfig_set var value) + # Clear normal variable (possibly set by project code). + unset(${var}) + # Store as cache variable. + # FIXME: Add a policy to switch to a normal variable. set(${var} ${value} CACHE INTERNAL "") endmacro() diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_CMP0126_NEW.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_CMP0126_NEW.cmake new file mode 100644 index 0000000..a419ab3 --- /dev/null +++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_CMP0126_NEW.cmake @@ -0,0 +1,64 @@ + +cmake_policy(SET CMP0126 NEW) + +# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE, FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS +enable_language(C) + +# Prepare environment and variables +set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH TRUE) +set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/pc-foo") +if(WIN32) + set(PKG_CONFIG_EXECUTABLE "${CMAKE_CURRENT_SOURCE_DIR}\\dummy-pkg-config.bat") + set(ENV{CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}\\pc-bar;X:\\this\\directory\\should\\not\\exist\\in\\the\\filesystem") + set(ENV{PKG_CONFIG_PATH} "C:\\baz") +else() + set(PKG_CONFIG_EXECUTABLE "${CMAKE_CURRENT_SOURCE_DIR}/dummy-pkg-config.sh") + set(ENV{CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/pc-bar:/this/directory/should/not/exist/in/the/filesystem") + set(ENV{PKG_CONFIG_PATH} "/baz") +endif() + + +find_package(PkgConfig) + + +if(NOT DEFINED CMAKE_SYSTEM_NAME + OR (CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU)$" + AND NOT CMAKE_CROSSCOMPILING)) + if(EXISTS "/etc/debian_version") # is this a debian system ? + if(CMAKE_LIBRARY_ARCHITECTURE MATCHES "^(i386-linux-gnu|x86_64-linux-gnu)$") + # Cannot create directories for all the existing architectures... + set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") + else() + set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") + endif() + else() + # not debian, check the FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS properties + get_property(uselibx32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIBX32_PATHS) + get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS) + get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS) + if(uselibx32 AND CMAKE_INTERNAL_PLATFORM_ABI STREQUAL "ELF X32") + set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/libx32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/libx32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") + elseif(uselib32 AND CMAKE_SIZEOF_VOID_P EQUAL 4) + set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") + elseif(uselib64 AND CMAKE_SIZEOF_VOID_P EQUAL 8) + set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") + else() + set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") + endif() + endif() +else() + if(WIN32) + set(expected_path "C:\\baz;${CMAKE_CURRENT_SOURCE_DIR}\\pc-foo\\lib\\pkgconfig;${CMAKE_CURRENT_SOURCE_DIR}\\pc-bar\\lib\\pkgconfig") + else() + set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") + endif() +endif() + + +set(FOO_FOUND FALSE) + +pkg_check_modules(FOO "${expected_path}") + +if(NOT FOO_FOUND) + message(FATAL_ERROR "Expected FOO_FOUND == 1.") +endif() diff --git a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake index e7f008c..78ccd96 100644 --- a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake +++ b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake @@ -7,6 +7,7 @@ set(ENV{CMAKE_FRAMEWORK_PATH} "") run_cmake(PkgConfigDoesNotExist) +run_cmake(FindPkgConfig_CMP0126_NEW) run_cmake(FindPkgConfig_NO_PKGCONFIG_PATH) run_cmake(FindPkgConfig_PKGCONFIG_PATH) run_cmake(FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_PATH) |