summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/FindPkgConfig
diff options
context:
space:
mode:
authormakise-homura <akemi_homura@kurisa.ch>2022-07-01 16:22:59 (GMT)
committermakise-homura <akemi_homura@kurisa.ch>2022-07-01 16:22:59 (GMT)
commitbcdac84961698264edb25f391cfa95e00c2d7d63 (patch)
treed809c8d935ac25d1caaefae8a78dabc062450661 /Tests/RunCMake/FindPkgConfig
parentf41b2b25a6951212e7745383ca808cb3ff701fd7 (diff)
downloadCMake-bcdac84961698264edb25f391cfa95e00c2d7d63.zip
CMake-bcdac84961698264edb25f391cfa95e00c2d7d63.tar.gz
CMake-bcdac84961698264edb25f391cfa95e00c2d7d63.tar.bz2
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.
Diffstat (limited to 'Tests/RunCMake/FindPkgConfig')
-rw-r--r--Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake25
1 files changed, 24 insertions, 1 deletions
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 ()