A pkg-config module for CMake.
CMake的pkg-config模块。
Finds the pkg-config executable and add the pkg_check_modules() and pkg_search_module() commands.
查找 pkg-config 执行档并且添加 pkg_check_modules() 和 pkg_search_module() 命令。
In order to find the pkg-config executable, it uses the PKG_CONFIG_EXECUTABLE variable or the PKG_CONFIG environment variable first.
为了找到 pkg-config 执行档,首先使用 PKG_CONFIG_EXECUTABLE 变量或者 PKG_CONFIG 环境变量。
pkg_check_modules
Checks for all the given modules.
检查所有给出的模块。
pkg_check_modules(<PREFIX> [REQUIRED] [QUIET]
[NO_CMAKE_PATH] [NO_CMAKE_ENVIRONMENT_PATH]
<MODULE> [<MODULE>]*)
When the REQUIRED argument was set, macros will fail with an error when module(s) could not be found.
如果设置了 REQUIRED 参数,未找到模块时宏将错误并失败。
When the QUIET argument is set, no status messages will be printed.
如果设置了 QUIET 参数,将不打印状态信息。
By default, if CMAKE_MINIMUM_REQUIRED_VERSION is 3.1 or later, 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 pkg-config search path. The NO_CMAKE_PATH and NO_CMAKE_ENVIRONMENT_PATH arguments disable this behavior for the cache variables and the environment variables, respectively.
默认的,如果 CMAKE_MINIMUM_REQUIRED_VERSION 是3.1或之后的版本,或者设置了 PKG_CONFIG_USE_CMAKE_PREFIX_PATH,如下的缓存和环境变量将被添加到 pkg-config 查找路径:CMAKE_PREFIX_PATH,CMAKE_FRAMEWORK_PATH 和 CMAKE_APPBUNDLE_PATH 。 NO_CMAKE_PATH 和 NO_CMAKE_ENVIRONMENT_PATH 参数分别禁用上述的关于缓存变量和环境变量的行为。
It sets the following variables:
设置了如下的变量:
PKG_CONFIG_FOUND ... if pkg-config executable was found
PKG_CONFIG_EXECUTABLE ... pathname of the pkg-config program
PKG_CONFIG_VERSION_STRING ... the version of the pkg-config program found
(since CMake 2.8.8)
For the following variables two sets of values exist; first one is the common one and has the given PREFIX. The second set contains flags which are given out when pkg-config was called with the --static option.
存在下列的2个系列值;第一个系列是常用的并且以给出的 PREFIX 开始。第二个系列在当 pkg-config 被调用时带有 --static 选项时,包含给出的符号。
<XPREFIX>_FOUND ... set to 1 if module(s) exist
<XPREFIX>_LIBRARIES ... only the libraries (w/o the '-l')
<XPREFIX>_LIBRARY_DIRS ... the paths of the libraries (w/o the '-L')
<XPREFIX>_LDFLAGS ... all required linker flags
<XPREFIX>_LDFLAGS_OTHER ... all other linker flags
<XPREFIX>_INCLUDE_DIRS ... the '-I' preprocessor flags (w/o the '-I')
<XPREFIX>_CFLAGS ... all required cflags
<XPREFIX>_CFLAGS_OTHER ... the other compiler flags
<XPREFIX> = <PREFIX> for common case
<XPREFIX> = <PREFIX>_STATIC for static linking
There are some special variables whose prefix depends on the count of given modules. When there is only one module, <PREFIX> stays unchanged. When there are multiple modules, the prefix will be changed to <PREFIX>_<MODNAME>:
有一些特殊的变量前缀依赖给出的模块数。当仅有一个模块给出时,<PREFIX> 保持不变。当有多个模块时,前缀将变为 <PREFIX>_<MODNAME> :
<XPREFIX>_VERSION ... version of the module
<XPREFIX>_PREFIX ... prefix-directory of the module
<XPREFIX>_INCLUDEDIR ... include-dir of the module
<XPREFIX>_LIBDIR ... lib-dir of the module
<XPREFIX> = <PREFIX> when |MODULES| == 1, else
<XPREFIX> = <PREFIX>_<MODNAME>
A <MODULE> parameter can have the following formats:
<MODULE> 参数可以是如下的格式:
{MODNAME} ... matches any version
{MODNAME}>={VERSION} ... at least version <VERSION> is required
{MODNAME}={VERSION} ... exactly version <VERSION> is required
{MODNAME}<={VERSION} ... modules must not be newer than <VERSION>
Examples
pkg_check_modules (GLIB2 glib-2.0)
pkg_check_modules (GLIB2 glib-2.0>=2.10)
Requires at least version 2.10 of glib2 and defines e.g. GLIB2_VERSION=2.10.3
需要 glib2 的版本至少是2.10并且定义项如 GLIB2_VERSION=2.10.3
pkg_check_modules (FOO glib-2.0>=2.10 gtk+-2.0)
Requires both glib2 and gtk2, and defines e.g. FOO_glib-2.0_VERSION=2.10.3 and FOO_gtk+-2.0_VERSION=2.8.20
请求 glib2 和 gtk2,并且定义如 FOO_glib-2.0_VERSION=2.10.3 和 FOO_gtk+-2.0_VERSION=2.8.20
pkg_check_modules (XRENDER REQUIRED xrender)
Defines for example:
定义例子:
XRENDER_LIBRARIES=Xrender;X11``
XRENDER_STATIC_LIBRARIES=Xrender;X11;pthread;Xau;Xdmcp
pkg_search_module
Same as pkg_check_modules(), but instead it checks for given modules and uses the first working one.
如同 pkg_check_modules(),但是代替它检查给定的模块并使用第一个工作的。
pkg_search_module(<PREFIX> [REQUIRED] [QUIET]
[NO_CMAKE_PATH] [NO_CMAKE_ENVIRONMENT_PATH]
<MODULE> [<MODULE>]*)
Examples
pkg_search_module (BAR libxml-2.0 libxml2 libxml>=2)
PKG_CONFIG_EXECUTABLE
Path to the pkg-config executable.
pkg-config 执行档的路径。
PKG_CONFIG_USE_CMAKE_PREFIX_PATH
Whether pkg_check_modules() and pkg_search_module() should add the paths in CMAKE_PREFIX_PATH, CMAKE_FRAMEWORK_PATH, and CMAKE_APPBUNDLE_PATH cache and environment variables to pkg-config search path.
pkg_check_modules() 和 pkg_search_module() 是否应该添加路径到 CMAKE_PREFIX_PATH, CMAKE_FRAMEWORK_PATH 和 CMAKE_APPBUNDLE_PATH 缓存和环境变量到 pkg-config 的搜索路径。
If this variable is not set, this behavior is enabled by default if CMAKE_MINIMUM_REQUIRED_VERSION is 3.1 or later, disabled otherwise.
如果变量没设置,在 CMAKE_MINIMUM_REQUIRED_VERSION 为3.1或以后的版本这个行为缺省是启用的,否则禁用。
转载于:https://www.cnblogs.com/the-capricornus/p/5619884.html
FindPkgConfigA pkg-config module for CMake.CMake的pkg-config模块。Finds the pkg-config executable and add the pkg_check_modules() and pkg_search_module() commands.查找 pkg-config 执行档并且添加 pkg_check_m...
在安装开源软件的过程中, 经常会碰到提示配置PKG_CONFIG_PATH路径, 或者直接提示没有安装某某库, 但是我们已经安装了啊。
其实造成这种情况的原因很简单, 就是安装的目录不能被依赖程序找到。
具体的原理可以网上搜索 configure, pkg-config , PKG_CONFIG_PATH这三者直接的关系。此处不再赘述。
解决方法就是让依赖库能找到我们的安装目录...
Ubuntu编译clamav时报如下错误:
CMake Error at /usr/local/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Libcheck (missing: LIBCHECK_INCLUDE_DIR LIBCHECK_LIBRARY)
Call Stack (most recent call first):
/usr/local/share/..
这个是用来寻找代码依赖的模块。如果找到的话,库,头文件的位置以及链接符号都会添加到预定义的变量里面.先看一个简单的 dbus代码:$ cat dbus.c
#include <dbus/dbus.h>
int main(void)
DBusError err;
dbus_error_init(&err);
DBusConnection *connection...
find_package(GTK2 REQUIRED )
message(STATUS "----- GTK2_INCLUDE_DIRS: ${GTK2_INCLUDE_DIRS}")
message(STATUS "----- GKT3_LIBRARIES: ${GTK2_LIBRARIES}")
message(STATUS "----- GTK2_LINK_LIBRARIES:
编译一测试工具时,遇到Makefile里面有一行:
gcc `pkg-config --libs --cflags libva libva-x11` -I/usr/include subpic.c -o subpic
编译出现了错误,找不到libva库。搜索得知,
C知道:pkg-config 是一个用于管理编译时依赖关系的工具,它可以帮助我们在编译时自动链接所需的库文件。在 CMake 中使用 pkg-config,需要在 CMakeLists.txt 文件中添加以下代码:
find_package(PkgConfig REQUIRED)
pkg_check_modules(PKG_CONFIG REQUIRED <package>)
include_directories(${PKG_CONFIG_INCLUDE_DIRS})
link_directories(${PKG_CONFIG_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME} ${PKG_CONFIG_LIBRARIES})
其中,<package> 是需要链接的库文件名,例如要链接 libcurl 库,可以写成:
pkg_check_modules(PKG_CONFIG REQUIRED libcurl)
这样,CMake 就会自动查找并链接 libcurl 库。需要注意的是,如果库文件不在系统默认路径中,需要在 PKG_CONFIG_LIBRARY_DIRS 中添加库文件所在的路径。
希望这个回答能够帮到你。