cpm-cmake / CPM.cmake

📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Any idea about how to resolve target name clash?

MrJia1997 opened this issue · comments

Hi there,

I'm using CPM as the dependency manager of my project so far, and it works pretty well. However, I'm facing a problem about target name clashing right now.

My projects uses Abseil-cpp (from Google) as a basic C++ library and Gperftools (also from Google) as the profiler. The problem is that they both have a target named "stacktrace" introduced by add_library. As CPM using add_subdirectory under the hood, this will cause the CMake to complain about target naming conflict.

Any idea about how to resolve the issue without patching those third-parties? Thank you!

Hey, that's a tough one as I don't think CMake allows scoping targets from subdirectory imports. In the special case that the targets are add_custom_target() targets and you only care about Makefile generators, there exists a CMake property ALLOW_DUPLICATE_CUSTOM_TARGETS which could help.

Unfortunately otherwise all I can think of would be to fork one of the dependency repos and rename the target to add a project specific prefix, e.g. stacktrace -> abseil_stacktrace, to allow subdirectory usage. I can imagine they would also be happy to accept a PR with this change.

@MrJia1997 I think this one needs to go onto the CMake issue tracker. I would expect this may already be in discussion somewhere though. It would be good if the project(...) scope were somehow involved in the name resolution under this circumstance.

@CraigHutchinson Actually there is one, see https://gitlab.kitware.com/cmake/cmake/-/issues/16414. Considering that this issue was addressed more than 6 yrs ago, I assume there will be no progress in CMake anytime soon...