CMake find_path / find_library 默认搜索 <PackageName>_ROOT 吗?
Does CMake find_path / find_library search for <PackageName>_ROOT by default?
阅读 CMake 政策 74 - https://cmake.org/cmake/help/latest/policy/CMP0074.html
[...] now searches prefixes specified by the _ROOT CMake variable and the ROOT environment variable. Package roots are maintained as a stack so nested calls to all find* commands inside find modules and config packages also search the roots as prefixes.
这是否意味着 <PackageName>_ROOT
不需要明确包含在 find_*
路径中?
这是否意味着 <PackageName>_ROOT
将被自动检查?
是的,但这仅适用于 CMake 3.12 及更高版本,如政策中所述 documentation:
In CMake 3.12 and above the find_package(<PackageName>)
command now searches prefixes specified by the <PackageName>_ROOT
CMake variable and the <PackageName>_ROOT
environment variable.
此也仅适用于查找模块和配置包中的find_*
命令。
此行为在 find_*
命令的 all 的文档中明确说明。例如,这里是 find_library()
文档中的一个片段(重要部分以粗体显示):
If NO_DEFAULT_PATH
is not specified, the search process is as follows:
- If called from within a find module or any other script loaded by a call to
find_package(<PackageName>)
, search prefixes unique to the current package being found. Specifically, look in the <PackageName>_ROOT
CMake variable and the <PackageName>_ROOT
environment variable. The package root variables are maintained as a stack, so if called from nested find modules or config packages, root paths from the parent’s find module or config package will be searched after paths from the current module or package. In other words, the search order would be <CurrentPackage>_ROOT
, ENV{<CurrentPackage>_ROOT}
, <ParentPackage>_ROOT
, ENV{<ParentPackage>_ROOT}
, etc. This can be skipped if NO_PACKAGE_ROOT_PATH
is passed or by setting the CMAKE_FIND_USE_PACKAGE_ROOT_PATH
to FALSE
.
另请注意,如果使用 NO_DEFAULT_PATH
或 NO_PACKAGE_ROOT_PATH
调用查找模块,<PackageName>_ROOT
变量将 不会 用于搜索.
阅读 CMake 政策 74 - https://cmake.org/cmake/help/latest/policy/CMP0074.html
[...] now searches prefixes specified by the _ROOT CMake variable and the ROOT environment variable. Package roots are maintained as a stack so nested calls to all find* commands inside find modules and config packages also search the roots as prefixes.
这是否意味着 <PackageName>_ROOT
不需要明确包含在 find_*
路径中?
这是否意味着 <PackageName>_ROOT
将被自动检查?
是的,但这仅适用于 CMake 3.12 及更高版本,如政策中所述 documentation:
In CMake 3.12 and above the
find_package(<PackageName>)
command now searches prefixes specified by the<PackageName>_ROOT
CMake variable and the<PackageName>_ROOT
environment variable.
此也仅适用于查找模块和配置包中的find_*
命令。
此行为在 find_*
命令的 all 的文档中明确说明。例如,这里是 find_library()
文档中的一个片段(重要部分以粗体显示):
If
NO_DEFAULT_PATH
is not specified, the search process is as follows:
- If called from within a find module or any other script loaded by a call to
find_package(<PackageName>)
, search prefixes unique to the current package being found. Specifically, look in the<PackageName>_ROOT
CMake variable and the<PackageName>_ROOT
environment variable. The package root variables are maintained as a stack, so if called from nested find modules or config packages, root paths from the parent’s find module or config package will be searched after paths from the current module or package. In other words, the search order would be<CurrentPackage>_ROOT
,ENV{<CurrentPackage>_ROOT}
,<ParentPackage>_ROOT
,ENV{<ParentPackage>_ROOT}
, etc. This can be skipped ifNO_PACKAGE_ROOT_PATH
is passed or by setting theCMAKE_FIND_USE_PACKAGE_ROOT_PATH
toFALSE
.
另请注意,如果使用 NO_DEFAULT_PATH
或 NO_PACKAGE_ROOT_PATH
调用查找模块,<PackageName>_ROOT
变量将 不会 用于搜索.