Does this look familiar to you?įind_package (Boost 1. Daniel, I am your prophet.Įnough preambles. ![]() Daniel has practically become the Messiah of the modern CMake church, preaching best practices and guidelines in a time when the only standard is to not have one. ![]() Many of the concepts presented here find their roots in Daniel Pfeifer’s masterpiece Effective CMake. My intention is to show how “new” (>= 3.0.0) features can be employed to reshape your CMake system into a more maintainable and intuitive alternative that actually makes sense. This post explores the concepts of what is known as modern CMake, which advocates for abandoning a traditional variable-based approach for a more structured model based on so-called targets. My excitement was soon shattered after discovering the lack of standard practices in CMake usage and specially the insufficient adoption of modern design patterns. Most people I know would have avoided such enterprise at all costs, but there is something about writing find modules that makes my brain release endorphins. The idea was to evaluate existing components, dependencies, but most importantly, to establish a superior design by making use of modern CMake features and paradigms. This is based on convention, but will help you: Easily read other projects following the same patterns, Avoid a pattern that causes conflicts, Keep from muddling and complicating your build. 3.17/3.Not so long ago I got the task of rethinking our build system. I'm going to tell you how to structure the directories in your project.3.16: Unity builds / precompiled headers, CUDA meta features.3.12: C++20, cmake -build build -j N, SHELL:, FindPython.3.11: IMPORTED INTERFACE setting, faster, FetchContent, COMPILE_LANGUAGE in IDEs.3.8: C++ meta features, CUDA, lots more.Modularize and reuse CMake code across projects. This book covers the following exciting features: Get to grips with architecting a well-structured CMake project. latest: pip/conda-forge/homebew/chocolaty, etc. It shows you how to integrate various development tools into your CMake workflow and covers field-proven best practices for using CMake effectively even in large, complex settings.3.11: CentOS 8 (use EPEL or AppSteams, though).CMake should always beĪt least as new as your compiler. Never select a minimum version older than the oldest compiler version you support. For support, there are two ways to pick minimums: based onįeatures added (which is what a developer cares about), or on common pre-installed CMakes (which is what a What minimum CMake should you run locally, and what minimum should you support for people using yourĬode? Since you are reading this, you should be able to get a release in the last few versions of CMake ĭo that, it will make your development easier. Only piecemeal set OLD policies if you have to. Use cmake_policy and/or range of versions: Policies change for a reason.Use lowercase function names: CMake functions and macros can be called lower or upper case.Combine common functionality into clearly documented functions or macros: Functions are better usually.Make ALIAS targets to keep usage consistent: Using add_subdirectory and find_package should provide the same targets and namespaces.Write a Config.cmake file: This is what a library author should do to support clients.Export your interface: You should be able to run from build or install. ![]() Make an (IMPORTED) INTERFACE target for anything that should stay together and link to that.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |