In CMake, how do I create objects with the same names?

I have a question regarding CMake and I need help solving the following error that I am getting:

CMake Error at :::: (add_custom_target):
  add_custom_target cannot create target "generate" because another target
  with the same name already exists.  The existing target is a custom target
  created in source directory :::::.

      

Here the target names of the two same levels are the CMakeLists.txt

same and I want them to be identical without any conflicts. Can anyone help me?

+3


source to share


1 answer


As per CMake policy CMP0002

(introduced by CMake 2.6, emphasis mine):

Target names created with add_executable, add_library, or add_custom_target are the target names of the logical assembly. Target logical names must be globally unique [...]

The following note deserves a mention and can probably help you anyway:

Custom targets should just have globally unique names (unless using a global property ALLOW_DUPLICATE_CUSTOM_TARGETS

with the Makefiles generator).

This means that there is a named global property ALLOW_DUPLICATE_CUSTOM_TARGETS

, which is probably what you are looking for. It has limited use and you should read the documentation carefully, but it's worth a try.
The most important part:



Makefile generators can maintain duplicate custom target names. [...] However, setting this property will cause generators without a Makefile to generate an error and refuse to generate the project.

To be able to use repeating custom targets, enter the following line in CMakeLists.txt

:

set(ALLOW_DUPLICATE_CUSTOM_TARGETS TRUE)

      

If it solves your problem, it mostly depends on the real problem, so I can't tell.

+4


source







All Articles