![]() # This will trigger an error and stop if used with a cmake version Tip : It's often way easier to install a newer CMake release than wasting time learning and using legacy tricks. Imposing your choice will make you save hundreds, if not thousands, of unmaintainable lines, and thus days of hard but avoidable work. This prevents use of deprecated CMake releases. Use cmake_minimum_required as first instruction. This only fact should be self-explanatory enough. See policy CMP0083 related to PIE support for instance.Īlso, CMake releases prior to 3.0 are not referenced anymore in the documentation. Basically, the user can explicitly select an NEW or OLD behavior for each policy. These are mecanismes introduced to ensure backward compatibilities. However, considering technical constraints may interfere in that choice, as mentioned in section 1.Įven if CMake is greatly backward compatible, the CMake 3.x.x series introduced some breaking changes.įor more information, you may have a look to cmake policies. Opting for modern CMake seems like a pretty straight-forward decision to make. Modern CMake is a nice way to replace unreadable & unmaintainable "2k-lines-long" CMakelists.txt files with clean, short bunches of instructions. Just like C++, CMake has a paradigm gap between so-called legacy and modern releases. In short, modern CMake starts from CMake 3.1. This popular saying best reflects the requested mindset here. "Hope for the best, be prepared for the worst" Most projects are likely to build on different systems, involving different OS, compilers, generators, and of course cmake releases. What works perfectly fine locally may be a total mess on another system. This matters a lot, as a single CMakelist.txt may result in different behaviors when processed across multiple release. On MS Windows 10 with Ms Visual Studio 2019, CMake 3.10 or greater. Especially the lowest.įor instance, if you work with Ubuntu 14.04 LTS Docker containers, you are more likely to use GCC 4.8.4 and CMake 2.8. Make sure to read until the end, I'll show you a pattern I use to create CMake modules for targets importation ! 1 - Know your CMake version(s)įirst, know which CMake release are your targets. I strongly encourage you to read the documentation and make your own experience. Googling for advises was more a source of frustration than answers.ĭisclaimer : I still do not know if I use CMake the right way.Especially because of the lack of standard practices in CMake usage, and in particular the insufficient adoption of modern design patterns. It is these tips & tricks that I'm willing to share with you across this article. Thus, I spent the last past months writing CMake scripts, experimenting and learning new tricks along the way. However, being always ready for new challenges, and eager to learn, I accepted the request. Indeed, I used to work in teams where someone's job was dedicated to CI/CD tools, including build scripts, Git, Jenkins, Gitlab CI, Dockers, etc. Since about a year, I work for a famous French telecoms company.Īccording to the company size, I was pretty surprised when I was requested to create CMake scripts. Thus, I spend most of my time improving codebases quality, increasing softwares performances, as well as training teams to modern C++.īeside, migrating existing code from legacy to modern C++ is such a rewarding work, as it usually both increase quality and performances, while greatly decreasing the amount of code. I daily deal with template metaprogramming, modern design patterns implementation, and new concepts experimentation. Replace is used with back substitution to output only that one group.Requirement : A first experience with CMake IntroĪs a modern C++ specialist, my job is to focus on software development, from a performance and quality perspective. If you want to avoid replacing existing $)Ībove, file(STRINGS file_name variable_name REGEX regex) picks lines that match a regex and the same regex is used to then pick out the parentheses capture group with the version part. in) from one place to another, substituting all CMake variables it finds. This command copies a file (traditionally ending in. Communication with your code Configure FileĬMake allows you to access CMake variables from your code using configure_file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |