xaav
xaav

Reputation: 7916

How to use CMAKE_MODULE_PATH correctly on windows

What is the proper way to modify this variable so that CMake can find the appropriate modules that projects specify as requirements? It seems to be autogenerated and I cannot find environment variables that would modify this path in any way. I also am hard pressed to find documentation that explains this well; only instructions to "install" CMake packages with no details on how exactly that can be accomplished.

Upvotes: 7

Views: 16855

Answers (2)

adam.hendry
adam.hendry

Reputation: 5605

@xaav Expanding upon @utopia'S answer:

"CMake will look for modules in the directories specified by CMAKE_MODULE_PATH; if it cannot find it there, it will look in the Modules subdirectory."

-Master CMake, by K. Matrin & B. Hoffman, pg. 38

The book doesn't do too a good job of explaining where this directory is though.

On Windows, you'll find it in:

C:\Program Files\CMake\share\cmake-3.21\Modules\

(for x64-bit CMake vers. 3.21 on Windows 10, e.g.). In general on Windows, it will be in

<your_cmake_install_directory>\share\cmake-<your_version>\Modules\

Furthermore, modules are files ending in .cmake and can be run directly from the command line by

cmake -P module.cmake

You can find a copy of the book here. Its a fair starting point, but it's 500 pages long and should be read kind of like a novel. To really understand CMake, I'd dive through the online documentation examples and projects others have posted on GitHub.

Upvotes: 0

utopia
utopia

Reputation: 1535

You can extend or set the module path like so:

list(APPEND CMAKE_MODULE_PATH "some path to modules")

or:

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "path")

Just like you can any other (list) variable.

Upvotes: 7

Related Questions