From bcdac84961698264edb25f391cfa95e00c2d7d63 Mon Sep 17 00:00:00 2001 From: makise-homura Date: Fri, 1 Jul 2022 19:22:59 +0300 Subject: Tests/FindPkgConfig: correctly handle broken pkg-config Older versions of pkg-config (e.g. 0.21 and 0.22) do not handle correctly spaces in paths specified in .pc files. It breaks RunCMake.FindPkgConfig test, if CMake is built inside path containing spaces. In this case, we check if we're inside such path, and if pkg-config is broken; and if both are true, test is to be skipped. --- Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake index f479dcf..661ae3f 100644 --- a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake +++ b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake @@ -24,6 +24,27 @@ endif() # We need a real pkg-config to run the test for get_variable. find_package(PkgConfig) if (PKG_CONFIG_FOUND) + string(FIND "${CMAKE_CURRENT_BINARY_DIR}" " " IS_SPACES_IN_PATH) + if(IS_SPACES_IN_PATH GREATER -1) + string(REPLACE " " "\\ " ESCAPED_ROOT "${CMAKE_CURRENT_BINARY_DIR}") + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_spaces.pc" " +libdir=${ESCAPED_ROOT} +Name: test_spaces.pc +Version: 0.0 +Description: test spaces +Libs: -L\${libdir} +") + set(PKG_CONFIG_PATH_SAVED "$ENV{PKG_CONFIG_PATH}") + set(ENV{PKG_CONFIG_PATH} "${CMAKE_CURRENT_BINARY_DIR}") + execute_process(COMMAND "${PKG_CONFIG_EXECUTABLE}" --libs test_spaces + ERROR_QUIET COMMAND_ERROR_IS_FATAL ANY + OUTPUT_VARIABLE test_spaces_LIBS) + set(ENV{PKG_CONFIG_PATH} "${PKG_CONFIG_PATH_SAVED}") + string(STRIP "${test_spaces_LIBS}" test_spaces_LIBS_STRIPPED) + if(NOT "${test_spaces_LIBS_STRIPPED}" STREQUAL "-L${ESCAPED_ROOT}") + set(PKG_CONFIG_DONT_SUPPORT_SPACES_IN_PATH TRUE) + endif() + endif() run_cmake(FindPkgConfig_GET_VARIABLE) run_cmake(FindPkgConfig_GET_VARIABLE_PREFIX_PATH) run_cmake(FindPkgConfig_GET_VARIABLE_PKGCONFIG_PATH) @@ -32,5 +53,7 @@ if (PKG_CONFIG_FOUND) run_cmake(FindPkgConfig_VERSION_OPERATORS) run_cmake(FindPkgConfig_GET_MATCHING_MODULE_NAME) run_cmake(FindPkgConfig_empty_target) - run_cmake(FindPkgConfig_LIBRARY_PATH) + if(NOT PKG_CONFIG_DONT_SUPPORT_SPACES_IN_PATH) + run_cmake(FindPkgConfig_LIBRARY_PATH) + endif() endif () -- cgit v0.12