在CMake中如何创建具有相同名称的目标? [英] In CMake how to create targets with identical names?
问题描述
我对 CMake 有疑问,我需要帮助来解决以下错误:
I have a question regarding CMake and I need help to solve the following error I'm 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 :::::.
这里是两个相同级别的目标名称 CMakeLists.txt
是相同的,我想保持它们相同,没有任何冲突。有人可以帮我吗?
Here the target names of the two same level CMakeLists.txt
are the same and I want to keep them identical, without any conflict. Can anyone help me out?
推荐答案
根据CMake政策 CMP0002
(由CMake 2.6引入,重点是我的):
According with CMake policy CMP0002
(introduced by CMake 2.6, emphasis mine):
使用 add_executable,add_library或 add_custom_target 创建的目标名称是逻辑构建目标名称。逻辑目标名称必须是全局唯一的 [...]
Targets names created with add_executable, add_library, or add_custom_target are logical build target names. Logical target names must be globally unique [...]
以下注释值得一提,并且可以可能仍然可以帮助您:
The following note deserves a mention and could probably help you anyway:
自定义目标必须简单地具有全局唯一名称(除非有人使用全局属性
ALLOW_DUPLICATE_CUSTOM_TARGETS
和Makefiles生成器。)
Custom targets must simply have globally unique names (unless one uses the global property
ALLOW_DUPLICATE_CUSTOM_TARGETS
with a Makefiles generator).
这意味着存在一个名为 ALLOW_DUPLICATE_CUSTOM_TARGETS
正在找。它用途有限,您应该仔细阅读文档,但是值得一试。
最相关的部分如下:
It means that there exists a global property named ALLOW_DUPLICATE_CUSTOM_TARGETS
that is probably what you are looking for. It has a limited use and you should read carefully the documentation, but it's worth a try.
The most relevant part follows:
Makefile生成器能够支持重复的自定义目标名称。 [...]但是,设置此属性将导致非Makefile生成器产生错误并拒绝生成项目。
Makefile generators are capable of supporting duplicate custom target names. [...] However, setting this property will cause non-Makefile generators to produce an error and refuse to generate the project.
为了能够使用重复的自定义目标,请将以下行放入您的 CMakeLists.txt
:
To be able to use duplicate custom targets put the following line in your CMakeLists.txt
:
set(ALLOW_DUPLICATE_CUSTOM_TARGETS TRUE)
如果能解决您的问题,主要取决于实际问题,所以我不能说。
If it solves your issue mainly depends on the actual problem, so I cannot say.
这篇关于在CMake中如何创建具有相同名称的目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!