官方文档:
cmake-modules(7) — Ccmake-modules(7) — C
1. 系统预定义模块
可以查看上述链接,存在CURL,则
find_package(CURL)
2. 非系统预定义模块
依赖于cmake编译的库
find_package(YOUR_LIB)
回顾
find_package从上述两个例子有一个疑问,他是如何找到对应路径的?
find_package — CMake 3.21.3 Documentation
Module模式(即上述1引用CURL):
In Module mode, CMake searches for a file called Find<PackageName>.cmake
. The file is first searched in the CMAKE_MODULE_PATH, then among the Find Modules provided by the CMake installation. If the file is found, it is read and processed by CMake
Config模式(即上述1引用YOUR_LIB)::
Config mode search attempts to locate a configuration file provided by the package to be found. A cache entry called <PackageName>_DIR
is created to hold the directory containing the file. By default the command searches for a package with the name <PackageName>
. If the NAMES
option is given the names following it are used instead of <PackageName>
. The command searches for a file called <PackageName>Config.cmake
or <lower-case-package-name>-config.cmake
for each name specified.
交叉编译环境
cmake .. -DCMAKE_TOOLCHAIN_FILE