CMake Package Registry

by Oleksandr Senkovych

It's Time To Do CMake Right

How do we add a library dependency to CMake project?

find_package(Example 1.0.0 REQUIRED)
add_executable(hello_world main.cpp)
target_link_libraries(
    hello_world Example::example
)

A lot of times you also are developer of a library

Library has to be installed somewhere

  • Manually specify prefix path every time

  • Or has to be installed system-wise
    • Permissions
    • May affect other software
  • Re-installation after each edit

Problems:

CMake Package Registry!

  • Adds project build tree to search path

  • Can be imported via find_package()

  • Has to be enabled manually by library developer

Usage:

export(PACKAGE Example)

* Package name is case sensitive

Challenges

Problem:

Different paths after installation

Solution:

Generator expressions:

target_include_directories(example
  PUBLIC
  $<INSTALL_INTERFACE:include>
  $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
)

Problem:

Multiple candidates

Solution:

  • Versioning

  • Manually specifying search path

cmake -DCMAKE_MODULE_PATH=libexample/build
cmake -DExample_DIR=libexample/build

Version support:

  • Package registry: 2.8.0

  • "Usable" version: 2.8.11

Example code:

Useful links

CMake Package Registry

By blackjack

CMake Package Registry

  • 72