FindPkgConfig----CMake的pkg-config模塊


FindPkgConfig

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或以后的版本這個行為缺省是啟用的,否則禁用。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM