Professional CMake:

A Practical Guide

Learn to use CMake effectively with practical advice from a CMake co-maintainer. You can also have the author work directly with your team!

CppCon 2019: Deep CMake For Library Authors

This talk presents a road map for C++ library authors grappling with cross-platform aspects of library development and deployment. It highlights key CMake features that every cross-platform library project should be using and digs deeper into the platform-specific quirks and conventions behind them. The material presented will give library authors more robust control over their API, smoother integration with major platforms and packaging systems, and more convenient inclusion by other projects.

The presentation will firstly examine how symbol visibility, library versioning and API evolution can be handled coherently across all major platforms and compilers. CMake provides dedicated features for these that are easy to use, but with the deeper understanding provided by this talk, library authors will be able to make these areas work together more seamlessly and avoid future maintenance and compatibility issues.

We will then explore how platform and vendor differences affect the installed directory layout for projects with libraries. CMake features for transparently handling the different conventions and policies will be presented, including recent CMake improvements which simplify this task. The importance of RPATH/RUNPATH functionality for improved runtime robustness and ease of use will also be explained, along with some associated support CMake provides.

Along the way, the talk will mention a number of specific things that CMake library projects should do or avoid to make themselves easy for other projects to consume. This will include versioning support for CMake config package files, guidance on defining install components and accounting for the different ways that projects may incorporate yours into their build.

The slides from the talk can be downloaded as a PDF and they include bonus material at the end, as mentioned in the talk.

NOTE: One question near the end was muted when the mic cut out (around the 59 minute mark), so a switch to a hand-held mic for the last question was necessary.


Have a CMake maintainer work on your project

Get the book for more CMake content

2 thoughts on “CppCon 2019: Deep CMake For Library Authors”

  1. Concerning the RPATH stuff , according to my test it depends on binutils version for having the “recursive magic” working.
    see https://github.com/Mizux/SecondaryDependency for examples and current distro limitation.

    ps: You should also note that RPATH separator differ between Apple (‘;’) and Linux (‘:’)
    e.g.

    if(UNIX AND NOT APPLE)
    INSTALL_RPATH "$ORIGIN:$ORIGIN/../lib")
    else()
    INSTALL_RPATH "@loader_path;@loader_path/../lib")
    endif()

    Reply
  2. Concerning the RPATH stuff , according to my test it depends on binutils version for having the “recursive magic” working.

    It’s not that simple. The following stackoverflow answer gives a clearer picture: https://stackoverflow.com/a/55283740/1938798 You will likely see different decisions about defaults made at different times by different distributions, so it really is a case-by-case basis.

    You should also note that RPATH separator differ between Apple (‘;’) and Linux (‘:’)

    You should just be able to specify the value for RPATH as a list in CMake and it should do the right thing for the platform. For example, the following works just fine on Linux:

    set(CMAKE_INSTALL_RPATH "$ORIGIN" "$ORIGIN/../lib")
    
    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.