CMake - shivamvats/notes GitHub Wiki

find_package

This has two modes:

  1. module: This is useful when you have the FindFoo.cmake file for the target package and is the default mode. Most popular libraries have this file. In fact, CMake itself ships with cmake files for some packages. Append (or set) CMAKE_MODULE_PATH to modify the list of places where cmake looks for this file.
  2. config: CMake looks for foo-config.cmake or fooConfig.cmake file for the required package. It looks into places specified by CMAKE_PREFIX_PATH for this file.

Note that both these modes set a bunch of useful variables as well (Foo_INCLUDE_DIRS etc.) if they are correctly written. Hence, it is advisable to use one of these modes instead of hardcoding the absolute address.

Important Variables

  1. CMAKE_PREFIX_PATH: Append to this to modify the directories cmake look into while executing find_package. Note This prefix is prefixed to all the paths that are searched. Hence, to ensure that the root directories are searched as well, you need to ensure that there is a root: / path in this list as well.
  2. CMAKE_INSTALL_PATH: Set this while running cmake -DCMAKE_INSTALL_PATH=/what/ever ../ to set where the current library will be installed (if it has an install definition.)
  3. CMAKE_MODULE_PATH: See above.
  4. RPATH: https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling

Work-flow

To link with a locally compiled library, it is advisable to not install it in /usr/local. I have created a separate ~/bin folder for this purpose. Use

⚠️ **GitHub.com Fallback** ⚠️