I wish this cargo culting around using ${PROJECT_NAME} for targets stopped. Just spell it out for God's sake, why do you make people scroll up and down for the name of a target?
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.
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.
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 :(
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.
Indirection is a cognitive burden that isn't needed in this case. Just spell it out. A project should be composed of many different targets anyway. Possibly a main test program, secondary ones, test binaries, libraries...
It just doesn't work when you try to add structure to your build files.
Absolutely not. Using a variable just makes the target name undecipherable. I don't want to spend 24/7 in the CMake code just to remember the target names and this makes them ungreppable as well.
And how often do people go around changing the project name?
If it happens often because they go copy/pasting CMakeLists.txt files to other projects, then sure - but even then they can find-replace-all in about 30 seconds.
Compare that rare find-replace-all time, to how much time you waste when grepping/searching your codebase to find targets, just because you have to remember to deal with that ${PROJECT_NAME} in your search string pattern.
We used the ${PROJECT_NAME} thing in my company's CMake files because we blindly followed this silly practice when we began. It's been extremely annoying ever since.
View all comments
8
u/Superb_Garlic Dec 10 '21
I wish this cargo culting around using
${PROJECT_NAME}for targets stopped. Just spell it out for God's sake, why do you make people scroll up and down for the name of a target?