FindPkgConfig: Extend PKG_CONFIG_PATH using CMake variables (#12926)
Use CMAKE_PREFIX_PATH, CMAKE_FRAMEWORK_PATH, and CMAKE_APPBUNDLE_PATH
cache and environment variables to extend PKG_CONFIG_PATH before calling
pkg-config.
In each of the path in these variables it searches for lib/pkgconfig.
Then, depending on the system, it searches for
lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig (debian) or for
lib64/pkgconfig (other 64 bit unixes). If any of these path is found,
it is appended to the PKG_CONFIG_PATH enviromnent variable.
Add two new arguments to the pkg_check_module and pkg_search_module
macro, NO_CMAKE_PATH and NO_CMAKE_ENVIRONMENT_PATH. The new signature
are therefore:
pkg_check_modules(<PREFIX> [REQUIRED] [QUIET]
[NO_CMAKE_PATH] [NO_CMAKE_ENVIRONMENT_PATH]
<MODULE> [<MODULE>]*)
pkg_search_module(<PREFIX> [REQUIRED] [QUIET]
[NO_CMAKE_PATH] [NO_CMAKE_ENVIRONMENT_PATH]
<MODULE> [<MODULE>]*)
By default, if CMAKE_MINIMUM_REQUIRED_VERSION is 3.1 or later (in
order to keep compatibility with the previous behavior), or if
PKG_CONFIG_USE_CMAKE_PREFIX_PATH is set, the CMAKE_PREFIX_PATH,
CMAKE_FRAMEWORK_PATH, and CMAKE_APPBUNDLE_PATH cache and environment
variables will be added to pkgconfig search path.
The NO_CMAKE_PATH and NO_CMAKE_ENVIRONMENT_PATH arguments disable this
behavior for the cache variables and the environment variables,
respectively, similarly to the find_package() command.
2014-03-06 21:55:04 +04:00
|
|
|
# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE 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, chech the FIND_LIBRARY_USE_LIB64_PATHS property
|
|
|
|
get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
|
|
|
|
if(uselib64)
|
|
|
|
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")
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
2014-03-17 21:09:54 +04:00
|
|
|
pkg_check_modules(FOO "${expected_path}")
|
FindPkgConfig: Extend PKG_CONFIG_PATH using CMake variables (#12926)
Use CMAKE_PREFIX_PATH, CMAKE_FRAMEWORK_PATH, and CMAKE_APPBUNDLE_PATH
cache and environment variables to extend PKG_CONFIG_PATH before calling
pkg-config.
In each of the path in these variables it searches for lib/pkgconfig.
Then, depending on the system, it searches for
lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig (debian) or for
lib64/pkgconfig (other 64 bit unixes). If any of these path is found,
it is appended to the PKG_CONFIG_PATH enviromnent variable.
Add two new arguments to the pkg_check_module and pkg_search_module
macro, NO_CMAKE_PATH and NO_CMAKE_ENVIRONMENT_PATH. The new signature
are therefore:
pkg_check_modules(<PREFIX> [REQUIRED] [QUIET]
[NO_CMAKE_PATH] [NO_CMAKE_ENVIRONMENT_PATH]
<MODULE> [<MODULE>]*)
pkg_search_module(<PREFIX> [REQUIRED] [QUIET]
[NO_CMAKE_PATH] [NO_CMAKE_ENVIRONMENT_PATH]
<MODULE> [<MODULE>]*)
By default, if CMAKE_MINIMUM_REQUIRED_VERSION is 3.1 or later (in
order to keep compatibility with the previous behavior), or if
PKG_CONFIG_USE_CMAKE_PREFIX_PATH is set, the CMAKE_PREFIX_PATH,
CMAKE_FRAMEWORK_PATH, and CMAKE_APPBUNDLE_PATH cache and environment
variables will be added to pkgconfig search path.
The NO_CMAKE_PATH and NO_CMAKE_ENVIRONMENT_PATH arguments disable this
behavior for the cache variables and the environment variables,
respectively, similarly to the find_package() command.
2014-03-06 21:55:04 +04:00
|
|
|
|
|
|
|
if(NOT "FOO_FOUND")
|
|
|
|
message(FATAL_ERROR "Expected PKG_CONFIG_PATH: \"${expected_path}\".")
|
|
|
|
endif()
|