Reputation: 1839
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
Upvotes: 1
Views: 1246
Reputation: 66061
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:
<PackageName>_ROOT
CMake and environment variables could be omitted by setting CMAKE_FIND_USE_PACKAGE_ROOT_PATH
variable.CMAKE_FIND_USE_CMAKE_PATH
variable.CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH
variable.CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH
variable.CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY
variable.CMAKE_FIND_USE_CMAKE_SYSTEM_PATH
variable. CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY
variable.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.
Upvotes: 3
Reputation: 13708
When you need to modify some standard behavior of the command you might use functions or macros to hide some details. In this case you need a macro which might look like this:
macro(find_package_restricted)
find_package(${ARGN} NO_DEFAULT_PATH)
endmacro()
And you use it just like you would use find_package
:
find_package_restricted(Boost REQUIRED)
Upvotes: 1