3 # Extends CMake's PkgConfig module with commands:
5 # pkg_check_modules_for_option(_option_name _option_description _prefix _module0)
7 # which calls `pkg_check_modules(_prefix _module0)` and if <_prefix>_FOUND is False,
8 # then prints an error with a hint to disaable the _option_name if needed.
10 # pkg_check_exists(_output_name _pkg)
12 # calls pkg-config --exists for _pkg and stores the result to _output_name.
14 # pkg_check_at_least_version(_output_name _pkg _version)
16 # calls pkg-config --at-least-version=_version for _pkg and stores the result to _output_name.
18 # pkg_check_exact_version(_output_name _pkg _version)
20 # calls pkg-config --exact-version=_version for _pkg and stores the result to _output_name.
22 # pkg_check_variable(_output_name _pkg _name)
24 # gets a variable named _name from package _pkg and stores the result into _output_name
26 find_package(PkgConfig REQUIRED)
28 macro(pkg_check_modules_for_option _option_name _option_description _prefix _module0)
29 pkg_check_modules(${_prefix} ${_module0} ${ARGN})
31 if(NOT ${_prefix}_FOUND)
32 message(FATAL_ERROR "Necessary libraries not found or not enough version. If you want to disable ${_option_description}, please use -D${_option_name}=OFF argument to cmake command.")
33 endif(NOT ${_prefix}_FOUND)
36 macro(pkg_check_exists _output_name _pkg)
37 execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --exists ${_pkg}
38 RESULT_VARIABLE ${_output_name})
40 # Negate the result, because 0 means 'found'
42 set(${_output_name} OFF)
44 set(${_output_name} ON)
45 endif(${_output_name})
48 macro(pkg_check_at_least_version _output_name _pkg _version)
49 execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --atleast-version=${_version} ${_pkg}
50 RESULT_VARIABLE ${_output_name})
52 # Negate the result, because 0 means 'found'
54 set(${_output_name} OFF)
56 set(${_output_name} ON)
57 endif(${_output_name})
60 macro(pkg_check_exact_version _output_name _pkg _version)
61 execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --exact-version=${_version} ${_pkg}
62 RESULT_VARIABLE ${_output_name})
64 # Negate the result, because 0 means 'found'
66 set(${_output_name} OFF)
68 set(${_output_name} ON)
69 endif(${_output_name})
72 function(pkg_check_variable _output_name _pkg _name)
73 execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=${_name} ${_pkg}
74 OUTPUT_VARIABLE _pkg_result
75 OUTPUT_STRIP_TRAILING_WHITESPACE)
77 set("${_output_name}" "${_pkg_result}" CACHE STRING "pkg-config variable ${_name} of ${_pkg}")
80 macro(add_pkgconfig_file _input _output)
82 ${CMAKE_CURRENT_SOURCE_DIR}/${_input}
83 ${CMAKE_CURRENT_BINARY_DIR}/${_output}
87 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${_output}
88 DESTINATION ${LIB_INSTALL_DIR}/pkgconfig