Best practice for project / target naming

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 :smiley:

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

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

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).

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.