Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate Find Cmake automatically and install it for importing

Tags:

c++

cmake

Is there any way to create a FindXXX.cmake automatically where XXX is my Cmake project? I see many projects that they created their FindXXX.cmake manually but I believe it's possible to create it automatically.

And, where I should install my project on Linux?

Thanks!

like image 931
Manuel Ignacio López Quintero Avatar asked Mar 17 '14 09:03

Manuel Ignacio López Quintero


2 Answers

CMake supports templating with configure_file() command.

Standard dirs where CMake searches for FindXXX.cmake modules are listed in the documentation of find_package() command.

like image 29
arrowd Avatar answered Nov 15 '22 22:11

arrowd


Take a look at CMake's project config file mechanism (along with the CMakePackageConfigHelper module; you might also want to take a look at this wiki page).

Find scripts are most useful for locating dependencies that are not aware of CMake themselves. If on the other hand the dependency was also built using CMake, you can let CMake auto-generate a project config file for you as part of that project's build process. This config file will allow you to refer to the targets of that project from an enclosing project as if they were being built as part of the enclosing project's CMake run. This is even more powerful than using find scripts, as it allows for example distinct handling of configurations beyond the debug/optimized options available to traditional find scripts.

On Windows, projects generating config files this way will register themselves with CMake, so that depending projects building on the same machine can find them automatically without any additional configuration. If you are building on non-Windows platforms (or you are building the two libraries on different machines) you will have to place the config file in a default directory (the docs for find_package describe which directories are searched) or explicitly point CMake to the location using CMAKE_MODULE_PATH.

Modern CMake-aware libraries should always prefer this approach over traditional find scripts. A prominent example of a library that does this already is Qt5.

like image 157
ComicSansMS Avatar answered Nov 16 '22 00:11

ComicSansMS