summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake
diff options
context:
space:
mode:
authorChristophe Giboudeaux <christophe@krop.fr>2019-08-27 22:52:13 (GMT)
committerChristophe Giboudeaux <christophe@krop.fr>2019-08-29 19:50:49 (GMT)
commitfe683876952ee6172e46fe770b4f3e48c69646d1 (patch)
tree54ed9a4a123e207c6712d5b32880f854e75ac8a8 /Tests/RunCMake
parent843ab7544e319597306a6d9cea4ab8be3296e6c4 (diff)
downloadCMake-fe683876952ee6172e46fe770b4f3e48c69646d1.zip
CMake-fe683876952ee6172e46fe770b4f3e48c69646d1.tar.gz
CMake-fe683876952ee6172e46fe770b4f3e48c69646d1.tar.bz2
FindPkgConfig: return the module found by pkg_search_module
When running `pkg_search_module`, it may be useful to get the matching module name in order to run `pkg_get_variable`. `pkg_search_module` now defines `<prefix>_MODULE_NAME` which contains the first matching module name. Fixes: #19648
Diffstat (limited to 'Tests/RunCMake')
-rw-r--r--Tests/RunCMake/FindPkgConfig/FindPkgConfig_GET_MATCHING_MODULE_NAME.cmake28
-rw-r--r--Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake1
2 files changed, 29 insertions, 0 deletions
diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_GET_MATCHING_MODULE_NAME.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_GET_MATCHING_MODULE_NAME.cmake
new file mode 100644
index 0000000..fc3a766
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_GET_MATCHING_MODULE_NAME.cmake
@@ -0,0 +1,28 @@
+# Prepare environment to reuse bletch.pc
+file(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/pc-bletch/lib/pkgconfig" PC_PATH)
+if(UNIX)
+ string(REPLACE "\\ " " " PC_PATH "${PC_PATH}")
+endif()
+set(ENV{PKG_CONFIG_PATH} "${PC_PATH}")
+
+find_package(PkgConfig REQUIRED)
+pkg_search_module(FOO REQUIRED foo bletch bar)
+
+if(NOT FOO_MODULE_NAME STREQUAL "bletch")
+ message(FATAL_ERROR "Wrong value for FOO_MODULE_NAME. Expected: bletch, got: ${FOO_MODULE_NAME}")
+endif()
+
+pkg_get_variable(FOO_JACKPOT ${FOO_MODULE_NAME} jackpot)
+
+if(NOT FOO_JACKPOT STREQUAL "bletch-lives")
+ message(FATAL_ERROR "Wrong value for FOO_JACKPOT. Expected: bletch-lives, got: ${FOO_JACKPOT}")
+endif()
+
+unset(FOO_MODULE_NAME)
+
+# verify variable get's also set on subsequent run
+pkg_search_module(FOO REQUIRED foo bletch bar)
+
+if(NOT FOO_MODULE_NAME STREQUAL "bletch")
+ message(FATAL_ERROR "Wrong value for FOO_MODULE_NAME on second run. Expected: bletch, got: ${FOO_MODULE_NAME}")
+endif()
diff --git a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake
index 414d9b6..b77bb54 100644
--- a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake
+++ b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake
@@ -19,4 +19,5 @@ if (PKG_CONFIG_FOUND)
run_cmake(FindPkgConfig_cache_variables)
run_cmake(FindPkgConfig_IMPORTED_TARGET)
run_cmake(FindPkgConfig_VERSION_OPERATORS)
+ run_cmake(FindPkgConfig_GET_MATCHING_MODULE_NAME)
endif ()