How to use CMAKE_MODULE_PATH correctly on windows

Viewed 12160

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.

2 Answers

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

Related