diff options
author | Craig Scott <craig.scott@crascit.com> | 2017-12-16 08:21:24 (GMT) |
---|---|---|
committer | Craig Scott <craig.scott@crascit.com> | 2017-12-16 11:38:56 (GMT) |
commit | b0ff528adc3ec53c06bcead3845f9c2f7251c4d3 (patch) | |
tree | ab0d82db2705c5daa17b313ec93c8db3a680d1ef /Tests/RunCMake/FindPkgConfig | |
parent | d4fb3136d5b32ac17ce6bc00d9f62163ba5bd800 (diff) | |
download | CMake-b0ff528adc3ec53c06bcead3845f9c2f7251c4d3.zip CMake-b0ff528adc3ec53c06bcead3845f9c2f7251c4d3.tar.gz CMake-b0ff528adc3ec53c06bcead3845f9c2f7251c4d3.tar.bz2 |
FindPkgConfig: Make IMPORTED_TARGET test verify NO...PATH properly
Diffstat (limited to 'Tests/RunCMake/FindPkgConfig')
-rw-r--r-- | Tests/RunCMake/FindPkgConfig/FindPkgConfig_IMPORTED_TARGET.cmake | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_IMPORTED_TARGET.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_IMPORTED_TARGET.cmake index 00cbb7b..606b1df 100644 --- a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_IMPORTED_TARGET.cmake +++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_IMPORTED_TARGET.cmake @@ -24,3 +24,64 @@ if (NCURSES_FOUND) else () message(STATUS "skipping test; ncurses not found") endif () + + +# Setup for the remaining package tests below +set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH) +set(fakePkgDir ${CMAKE_CURRENT_BINARY_DIR}/pc-fakepackage) +foreach(i 1 2) + set(pname cmakeinternalfakepackage${i}) + file(WRITE ${fakePkgDir}/lib/lib${pname}.a "") + file(WRITE ${fakePkgDir}/lib/${pname}.lib "") + file(WRITE ${fakePkgDir}/lib/pkgconfig/${pname}.pc +"Name: CMakeInternalFakePackage${i} +Description: Dummy package (${i}) for FindPkgConfig IMPORTED_TARGET test +Version: 1.2.3 +Libs: -l${pname} +") +endforeach() + +# Always find the .pc file in the calls further below so that we can test that +# the import target find_library() calls handle the NO...PATH options correctly +set(ENV{PKG_CONFIG_PATH} ${fakePkgDir}/lib/pkgconfig) + +# Confirm correct behavior of NO_CMAKE_PATH, ensuring we only find the library +# for the imported target if we have both set CMAKE_PREFIX_PATH and have not +# given the NO_CMAKE_PATH option +unset(CMAKE_PREFIX_PATH) +unset(ENV{CMAKE_PREFIX_PATH}) +pkg_check_modules(FakePackage1 QUIET IMPORTED_TARGET cmakeinternalfakepackage1) +if (TARGET PkgConfig::FakePackage1) + message(FATAL_ERROR "Have import target for fake package 1 with no path prefix") +endif() + +set(CMAKE_PREFIX_PATH ${fakePkgDir}) +pkg_check_modules(FakePackage1 QUIET IMPORTED_TARGET NO_CMAKE_PATH cmakeinternalfakepackage1) +if (TARGET PkgConfig::FakePackage1) + message(FATAL_ERROR "Have import target for fake package 1 with ignored cmake path") +endif() + +pkg_check_modules(FakePackage1 REQUIRED QUIET IMPORTED_TARGET cmakeinternalfakepackage1) +if (NOT TARGET PkgConfig::FakePackage1) + message(FATAL_ERROR "No import target for fake package 1 with prefix path") +endif() + +# And now do the same for the NO_CMAKE_ENVIRONMENT_PATH - ENV{CMAKE_PREFIX_PATH} +# combination +unset(CMAKE_PREFIX_PATH) +unset(ENV{CMAKE_PREFIX_PATH}) +pkg_check_modules(FakePackage2 QUIET IMPORTED_TARGET cmakeinternalfakepackage2) +if (TARGET PkgConfig::FakePackage2) + message(FATAL_ERROR "Have import target for fake package 2 with no path prefix") +endif() + +set(ENV{CMAKE_PREFIX_PATH} ${fakePkgDir}) +pkg_check_modules(FakePackage2 QUIET IMPORTED_TARGET NO_CMAKE_ENVIRONMENT_PATH cmakeinternalfakepackage2) +if (TARGET PkgConfig::FakePackage2) + message(FATAL_ERROR "Have import target for fake package 2 with ignored cmake path") +endif() + +pkg_check_modules(FakePackage2 REQUIRED QUIET IMPORTED_TARGET cmakeinternalfakepackage2) +if (NOT TARGET PkgConfig::FakePackage2) + message(FATAL_ERROR "No import target for fake package 2 with prefix path") +endif() |