ellen6a
ellen6a

Reputation: 657

CMake add_executable target name is reserved

I have following CMakeLists.txt file:

CMAKE_MINIMUM_REQUIRED(VERSION 3.1)

PROJECT(MyProject)

FILE(GLOB_RECURSE sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
FILE(GLOB_RECURSE headers RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h)

ADD_EXECUTABLE(AnyNameHere, ${sources})

When I use "Configure" in CMake I get this error:

CMake Error at CMakeLists.txt:8 (ADD_EXECUTABLE): The target name "AnyNameHere," is reserved or not valid for certain CMake features, such as generator expressions, and may result in undefined behavior.

I changed the name, but I get same error no matter what name I choose. I checked the documentation and all the characters I used for the name seem to be valid and I assume the actual error is somewhere else.

Can you please guide me to fix this?

EDIT:

I further simplified the script to have only:

CMAKE_MINIMUM_REQUIRED(VERSION 3.1)

PROJECT(MyProject)

ADD_EXECUTABLE(AnyNameHere, HelloWorld.cpp)

with the same error. I'm using CMake GUI, version 3.1

Upvotes: 15

Views: 18715

Answers (1)

steveire
steveire

Reputation: 11084

Remove the comma. CMake command parameters are separated by whitespace, not commas.

Upvotes: 53

Related Questions