cmake : 详解find_package
https://blog.csdn.net/LaineGates/article/details/108247128
参考cmake官方文档find_package()有两种用法:Basic Signature and Module Mode和Full Signature and Config Mode。
前者在cmake自带的Modules目录下查找Find<PackageName>.cmake
后者在所有搜索目录里找<PackageName>Config.cmake或者<PackageName>-config.cmake。
Basic Mode
1 | find_package(<PackageName> # package名,如Boost |
Config Mode
1 | find_package(<PackageName> |
与basic mode类似,此处只讲不同的。
CONFIG模式之前没用过,记录原文。Config mode search attempts to locate a configuration file provided by the package to be found. A cache entry called _DIR is created to hold the directory containing the file. By default the command searches for a package with the name . If the NAMES option is given the names following it are used instead of . The command searches for a file called Config.cmake or -config.cmake for each name specified. A replacement set of possible configuration file names may be given using the CONFIGS option. The search procedure is specified below. Once found, the configuration file is read and processed by CMake. Since the file is provided by the package it already knows the location of package contents. The full path to the configuration file is stored in the cmake variable _CONFIG.
获取版本信息
cmake会在<config-file>.cmake目录,查找<config-file>-version.cmake 或 <config-file>Version.cmake。
如果查找失败,任何版本检查都会失败。
如果查找成功,以下变量会被设置:<PackageName>_VERSION<PackageName>_VERSION_MAJOR<PackageName>_VERSION_MINOR<PackageName>_VERSION_PATCH<PackageName>_VERSION_TWEAK<PackageName>_VERSION_COUNT