15

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

1 Answer 1

55

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.