CMake Find<LIB>.cmake files

Hello,

I'm currently learning CMake and something I don't fully understand is, how CMake knows where to find the Find<LIB>.cmake files. (Windows)

For example, I download the Eigen library which comes with its own FindEigen.cmake file.

Do I have to move it to my CMake/Modules directory and set up the EIGEN3_ROOT environment variable, or is there another way to set this up with CMake?

Thanks
make files typically have a bunch of hard coded partial paths, eg ./foo means 'where I am now, go into sub-folder foo, which was presumably put there when you unzipped this project'.

so when you get something, it should just compile from running its make file in the folder it was in when you got it. Then that resulting library, you have to put somewhere your other code will find it (or tie that code back to where you built it, whatever) so it can find it.

This can get exotic between the window's path, the current path, and the makefile's path(s) that it defines. Some makefiles are cleaner than others.

if the current one depends on others, you have to tie that path(s) in if it is not in some default place that works.

is something not working, or are you just wanting to know generally how it works?

https://www.cs.swarthmore.edu/~adanner/tips/cmake.php may help

in there you see a couple of examples like I am saying:
cumin[w01-cpp]$ ./oglfirst
cumin[w01-cpp]$ ./test_geometry

Make syntax is cryptic by design. I would try to avoid it and let your IDE to the dirty work of using make under the hood, if you can. Fooling with makefiles by hand is … 1980s approach IMHO and only to be done in the most extreme emergencies.
Last edited on
How does CMake know where to find the Find<LIB>.cmake files.

CMake maintains a known search path.
https://cmake.org/cmake/help/v3.2/command/find_package.html#command:find_package

Do I have to move it to my CMake/Modules directory

No. When you install Eigen, it will become available for use in other projects. Part of its installation process should involve placing FindEigen.cmake in the search path.
Last edited on
Registered users can post here. Sign in or register to post.