# Best practice for project / target naming

**URL:** <https://discourse.cmake.org/t/best-practice-for-project-target-naming/7608>\
**Category:** Code\
**Created:** [March 6, 2023, 12:03pm UTC](https://discourse.cmake.org/t/best-practice-for-project-target-naming/7608 "2023-03-06T12:03:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)\
**Post date:** [March 6, 2023, 12:03pm UTC](https://discourse.cmake.org/t/best-practice-for-project-target-naming/7608/1 "2023-03-06T12:03:59Z")

</div>

Hi,

I do have some problems with naming my targets / project. I do have a project / group called `my_project` and then multiple seperate repos, which mostly all define one library.  
Currently my projects therefore have the project name `my_project_my_library_name` and targets with the same name `my_project_my_library_name`. And the exported / alias name is then: `my_project_my_library_name::my_project_my_library_name`. Which doesn’t feel quite right.

I would prefer my alias targets to be `my_project::my_library_name`. But it seems kind of best practice that the alias target name always include the project name (this is also enforced by some cmake function in ROS2, which I’m using). So in order to get that I would need to set the project name to `my_project` only. But this seems bad to me, because then multiple repositories would have the same project name.

I also thought about something like:

- project name: `my_project_my_library_name`
- target name: `my_project_my_library_name_lib` or `my_project_my_library_name_main`
- Export / Alias: `my_project_my_library_name_lib::lib` (Because I know it is possible and common to remove the project name of the target name in this alias notation).

But yeah I’ve never seen someone doing it like this. In fact I see it quite often thar project / target names are the same and thus it is just `name::name`. But usually the name then is short, so it’s not that bad. But still it feels weird.

I wonder what some best practices might be in this case. Other people must have the same problems 😃

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [March 7, 2023, 7:03pm UTC](https://discourse.cmake.org/t/best-practice-for-project-target-naming/7608/2 "2023-03-07T19:03:43Z")

</div>

You can use the `EXPORT_NAME` property to change the part after `::` in exported target names.

---

<div class="post-metadata">

**Author:** ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)\
**Post date:** [March 7, 2023, 7:13pm UTC](https://discourse.cmake.org/t/best-practice-for-project-target-naming/7608/3 "2023-03-07T19:13:52Z")

</div>

Yeah I know that. This is what I indicated with my last sample.

But as said usually my project and target names are completly the same. Something like `my_company_common_components:my_company_common_components` or `my_company_some_service::my_company_some_service`.

Obviously, my preferred choice would `my_company::some_service`. So the namespace would just be my\_company. But it seems common practice that the namespace is always the project name. Some frameworks such as ROS2 (which I am using) are even enforcing this. See [ament\_cmake/ament\_cmake\_export\_targets\_package\_hook.cmake at rolling · ament/ament\_cmake · GitHub](https://github.com/ament/ament_cmake/blob/rolling/ament_cmake_export_targets/cmake/ament_cmake_export_targets_package_hook.cmake#L31)

Using `my_company` as a project name doesn’t sound really suitable though. I’m not quite sure, but I suppose project names should be rather unique.

So that’s why I was asking for some better way to name things somehow. So that the project name is either entirely different from the target name or at least only a true subset of the target name (in which case I could change the `EXPORT_NAME` as you explained).

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [March 7, 2023, 10:19pm UTC](https://discourse.cmake.org/t/best-practice-for-project-target-naming/7608/4 "2023-03-07T22:19:57Z")

</div>

Ah. I usually try to use the package name before `::` and the “target” afterwards. It’s useful to avoid stuttering though even there. Within a project some unique target name is fine but I prefer to add an `ALIAS` target to match what will be installed so that everything uses the same target name.
