[CMake] Support for multiple targets with the same name

Ken Martin ken.martin at kitware.com
Tue Jun 14 15:27:54 EDT 2005


I'm implementing support for having an executable and library with the same
name. A few projects do this and currently CMake does not support it. There
is a design question to address in how CMake should work with two targets
with the same name. Specifically...

# build the foo library and link it against math
ADD_LIBRARY(foo foo.c)
TARGET_LINK_LIBRARIES(foo math)

# build the foo executable and link it against the spanish lib
ADD_EXECUTABLE(foo main.c)
TARGET_LINK_LIBRARIES(foo spanish)


Clearly the second TARGET_LINK_LIBRARIES call is ambiguous.  There are a few
options on how to address this and I'm looking for feedback. Here are a few
different options for disambiguating the targets...  

TARGET_LINK_LIBRARIES(foo_EXE Spanish)

TARGET_LINK_LIBRARIES(foo:EXE Spanish)

EXECUTABLE_TARGET_LINK_LIBRARIES(foo Spanish)

TARGET_LINK_LIBRARIES(foo EXECUTABLE Spanish)

TARGET_LINK_LIBRARIES(EXECUTABLE foo Spanish)

TARGET_LINK_LIBRARIES(foo Spanish)


Any preferences or other ideas... I am working from the assumption that if
TARGET_LINK_LIBRARIES is called without any of these special signatures the
default behavior will be to operate on the named target and if there are
more than one target with that name (which is impossible in the current
CMake so this will be 100% backwards compatible) default to a library
target. The same issue will happen with SET_TARGET_PROPERTIES etc.

Another option is that CMake simply should not support having an executable
and library with the same name although it seems reasonable to me.

Thanks
Ken




More information about the CMake mailing list