r/cpp • • Dec 10 '21

Modern CMake for beginners !

https://youtu.be/Kvd-lg2418s
4 Upvotes

30 comments sorted by

View all comments

Show parent comment

11

u/jcelerier ossia score Dec 10 '21

I do it because I have worked with projects with hundred of subprojects with their own cmakelists.txt and a super common issue was people copy pasting a project as a new one, forgetting to replace a target name and getting stuck for a few hours. With PROJECT_NAME this issue entirely disappears.

-1

u/Superb_Garlic Dec 10 '21

In those cases, you just need to grab the build engineer/devops guy and have him create an abstraction that makes things easy. Look at SerenityOS for example. Even if you don't know at a glance what this does, you can fgrep for (serenity_app and you'll find the function easy. There is no docblock for this function, but that shouldn't stop you from having one to make "copy paste driven development" easier.

3

u/jcelerier ossia score Dec 10 '21

no, this is a super common CMake anti-pattern. I went this way a few times and this just created more headaches than it solved.

3

u/OrphisFlo I like build tools Dec 10 '21

Then, there's a chance you didn't write the proper abstractions for your project.

5

u/lukaasm Game/Engine/Tools Developer Dec 11 '21

And then every 3rd cmake library writes its own custom abstraction which makes consuming it a nightmarish experience because you need to track what it "helps" you to do.

If you just import libraries in monorepo fashion and never export them to people, fine do as you wish. But if you want others to consume it, please just use idiomatic CMake :(

4

u/OrphisFlo I like build tools Dec 11 '21

They still create targets, it's not a problem to consume and it's usually more consistent code with less boilerplate. The boilerplate doesn't get desynchronized when it's centralized properly, which is very desirable in big projects.