Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake add_executable target name is reserved

Tags:

c++

cmake

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

like image 487
ellen6a Avatar asked Jan 07 '15 05:01

ellen6a


1 Answers

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

like image 136
steveire Avatar answered Sep 21 '22 18:09

steveire