Namespaces for targets?

I’m experimenting with putting my projects into a monorepo. I have a root CMakeLists.txt with some global config and then a bunch of add_subdirectory calls. An executable target somewhere in the tree builds in a similar folder hierarchy. That’s nice. For example:

> cmake --build build-debug --target hello
> ./build-debug/MyUI/Samples/HelloWorldMac/hello 
Hello world.

That target named hello was defined in a CMakeLists.txt in MyUI/Samples/HelloWorldMac.


But now I can’t have another ‘hello’ target in some other branch of the tree, and the argument to --target is bare, like a global variable.

How do you name targets like this, to keep their names from conflicting when you have a big hierarchy of folders and CMakeLists.txt files?

The projects would need to name their targets in a namespaced way. They can un-namespace the actual binary names using the OUTPUT_NAME target property.

1 Like

It won’t help you right now, but this proposal for supporting project-level namespaces will probably be of interest to you.