The target name is reserved or not valid for certain CMake features...

I am not sure why this library alias is causing this error. Using double colon :: seems to be permitted with import and alias targets. See double-colon in target name .

error:

  The target name "zeromq::zeromq" is reserved or not valid for certain CMake
  features, such as generator expressions, and may result in undefined
  behavior.

code:

include(FetchContent)
FetchContent_Declare(
    ZeroMQ
    GIT_REPOSITORY https://github.com/zeromq/libzmq
    GIT_TAG v4.3.4
    GIT_SHALLOW TRUE
    GIT_PROGRESS TRUE
    OVERRIDE_FIND_PACKAGE
)
message("ZEROMQ_LIBRARY is ${ZEROMQ_LIBRARY}")
add_library(zeromq::zeromq alias ${ZEROMQ_LIBRARY})

The ALIAS keyword needs to be in uppercase:

add_library(zeromq::zeromq ALIAS ${ZEROMQ_LIBRARY})

It looks like you are missing a FetchContent_MakeAvailable(ZeroMQ) there though. I’d also recommend a check that the target doesn’t already exist before you call add_library() to create the alias target. There are scenarios in which that target might already have been created (e.g. by a dependency provider, or an earlier call that already populated the ZeroMQ dependency).

1 Like

Ah of course. Embarrassing for me. I was experimenting while debugging something else. I had the makeavailable call but it was after the attempt to create the library alias.

Thank you