Reputation: 744
I'm having trouble getting CMake's include()
statement to recognize CMAKE_MODULE_PATH
. I'm hoping to do something like this:
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(Foo.cmake)
with this style of directory tree:
.
├── cmake
│ └── Foo.cmake
├── CMakeLists.txt
However, I get the error:
include could not find load file:
Foo.cmake
Based on the docs for include()
and CMAKE_MODULE_PATH
, I thought that this should be possible.
If I keep the same tree but modify the include
, it loads fine:
include(cmake/Foo.cmake)
Am I mistaken or doing something wrong?
Thanks!
Upvotes: 5
Views: 2517
Reputation: 65860
It should be a module name - without .cmake
extension - for apply CMAKE_MODULE_PATH
variable when search the file with include
command:
# This searches a *module* and uses 'CMAKE_MODULE_PATH' variable
include(Foo)
# This searches a *file* and doesn't use 'CMAKE_MODULE_PATH' variable
include(Foo.cmake)
The signature of include
function
include(<file|module> [OPTIONAL] [RESULT_VARIABLE ] [NO_POLICY_SCOPE])
means that its first argument could be either a file or a module.
And CMAKE_MODULE_PATH
variable is applied only when search a module:
If a module is specified instead of a file, the file with name
<modulename>.cmake
is searched first inCMAKE_MODULE_PATH
, then in the CMake module directory.
The name of the file - <modulename>.cmake
- suggests that module name shouldn't have .cmake
suffix.
Upvotes: 6