CMAKE

How To Make Your Library Support find_package()

Article by:
Date Published:
Last Modified:

Overview

As a code library maintainer, if you want your users to be able to use find_package(MyPackage) in CMake files, you need to now how to create a CMake package.

Annoyingly, this is not a simple task!

If the user performs a local install, they may call cmake as:

1
build$ cmake -DCMAKE_INSTALL_PREFIX=../install ..

Referencing Your Package From Downstream Build

Once you have created your package, you will be wanting to be able to use find_package() in a downstream package.

The CMake variable CMAKE_PREFIX_PATH can be used to specify local install locations for your dependent packages.

External Resources

A great resource on creating a CMake package can be found at https://cmake.org/cmake/help/git-master/manual/cmake-packages.7.html#creating-packages.

An working GitHub example repo which uses the CMake packaging system can be found at https://github.com/forexample/package-example.


Authors

Geoffrey Hunter

Dude making stuff.

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License .

Tags

    comments powered by Disqus