Issue
I want to modularize my project and use find_package
to control 3rdparty inclusions and i also have a strict requirement to control all my packages. I don't want cmake to include something on the side and debug what is going on, i need to limit its search path to CMAKE_MODULE_PATH
.
The single explicit approach i found is NO_DEFAULT_PATH
in find_package
calls but i don't want to repeat these arguments over and over again. Is there a variable that can control it for me? I found a family of variables CMAKE_FIND_USE_*_PATH
but there is no clear documentation on them
Solution
CMake documentation describes the algorithm of constructing installation prefixes. By following that algorithm it should be easy to collect all CMAKE_FIND_USE_*_PATH
variables, setting which to FALSE will disable corresponding prefixes:
- Search paths specified in the
<PackageName>_ROOT
CMake and environment variables could be omitted by settingCMAKE_FIND_USE_PACKAGE_ROOT_PATH
variable. - Search paths specified in cmake-specific cache variables could be omitted by setting
CMAKE_FIND_USE_CMAKE_PATH
variable. - Search paths specified in cmake-specific environment variables could be omitted by setting
CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH
variable. - Search paths specified by the HINTS option cannot be disabled.
- Search the standard system environment variables could be omitted by setting
CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH
variable. - Search paths stored in the CMake User Package Registry could be omitted by setting
CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY
variable. - Search cmake variables defined in the Platform files for the current system could be omitted by setting
CMAKE_FIND_USE_CMAKE_SYSTEM_PATH
variable. - Search paths stored in the CMake System Package Registry could be omitted by setting
CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY
variable. - Search paths specified by the PATHS option cannot be disabled.
In total, setting
set(CMAKE_FIND_USE_PACKAGE_ROOT_PATH FALSE)
set(CMAKE_FIND_USE_CMAKE_PATH FALSE)
set(CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH FALSE)
set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH FALSE)
set(CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY FALSE)
set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE)
set(CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY FALSE)
is equivalent to NO_DEFAULT_PATH option in every find_package
call.
Answered By - Tsyvarev Answer Checked By - Katrina (WPSolving Volunteer)