0
votes

Upon reading about CMake policy 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.

Does this mean <PackageName>_ROOT need not be included in the find_* paths explicitly? Does this mean <PackageName>_ROOT will be checked automatically?

1

1 Answers

1
votes

Yes, but this only applies to CMake 3.12 and greater, as stated in the policy 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.

This also only applies to find_* commands within find modules and config packages.

This behavior is stated explicitly in the documentation for all of the find_* commands. For example, here is a snippet from the find_library() documentation (important section bolded):

If NO_DEFAULT_PATH is not specified, the search process is as follows:

  1. 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.

Also note, the <PackageName>_ROOT variable will not be used for the search if the find module is called with NO_DEFAULT_PATH or NO_PACKAGE_ROOT_PATH.