Hello everyone,

Last Tuesday (September 17, 2024), we gathered for the 66th meeting of The San Diego C++ Meetup.

The topic was CMake. Yes, CMake can be fun sometimes! šŸ˜Š

The inspiration for this session came from the relatively new 2nd edition of ā€œModern CMake for C++ā€ by Rafal Swidzinski.

First off, the book is fantastic! Itā€™s packed with valuable material that can make your life easier if your build system is CMake. Despite considering myself quite knowledgeable about CMake, I learned a lot from it.

This wasnā€™t my first time giving a talk on CMake. Iā€™ve had several opportunities in the past, ranging from one-hour to multi-hour sessions. It always feels like thereā€™s so much to cover that even 1, 2, or 4 hours isnā€™t enough to touch on every aspect of CMake. CMake is extensive, and itā€™s crucial to understand and use it well. Otherwise, your build system can become difficult to improve, extend, and maintain, leading to a lot of frustration.

When discussing CMake (or any topic in a C++ session), my goal is for everyone to learn something newā€”at least one thing!

The meetup page link: here

And the recording:

San Diego C++ Meetup recording

BTW – We had an excellent session on July 11, 2023, with Alex Reinking, titled ā€œModern CMake Best Practices for Library Authorsā€ at the San Diego C++ Meetup. Itā€™s definitely worth watching!

Summary of our discussion:

  • Introduction to the book.
  • CMakeā€™s popularity (based on 2023 surveys).
  • Overview of CMake: its purpose and stages (configuration, generation, and build).
  • Simple CMake files and FetchContent.
  • Generators: what they are and how to write agnostic command lines that work with any generator.
  • CMake Cache file (CMakeCache.txt): using the --force option, cache variables, and debugging/tracing CMake build generation with options like --trace, --log-context, --trace-expand, and --debug-output.
  • Cleaning with the --clean-first option.
  • Targets: what they are and how to build them.
  • Installation: a high-level overview (thereā€™s much more to explore here).
  • Running CMake as a script with the -P option.
  • Brief mentions of CTest/CPack and other tools in the CMake suite.
  • CMakeConfigureLog.yaml (introduced in version 3.26) for advanced debugging of the configure stage.
  • Utility modules included with the CMake package, and projects like cmake-awesome and cmake-modules.
  • Find modules.
  • A slide on important elements of the CMake language (the book has an excellent chapter on this).
  • CLion and CMake: debugging CMake with CLion.

Additional topics covered in the book:

  • Generator expressions
  • Dependency graph and how to print it
  • CMake presets
  • Program analysis tools
  • C++20 modules
  • Testing frameworks
  • Generating documentation

Many thanks to Packtpub for their support providing me the material to review!

Thatā€™s it for this session!

Happy CMake-ing!

Kobi

Leave a Reply