4

I have very simple CMakeLists.txt file.

cmake_minimum_required (VERSION 2.6)
project (test_proj)

set(TEST_INCLUDE_DIR
    "${PROJECT_SOURCE_DIR}/src")

set(TEST_CPP "${PROJECT_SOURCE_DIR}/src/source_file.cpp"
             "${PROJECT_SOURCE_DIR}/src/main.cpp")

set(TEST_HEADERS
    "${PROJECT_SOURCE_DIR}/src/header.h")

#include_directories(${TEST_INCLUDE_DIR})


add_executable(testproj "${TEST_CPP}" "${TEST_HEADERS}")

And when I run it like that:

mkdir build
cd build
cmake ..

I get next output:

...
-- Configuring done
CMake Error at CMakeLists.txt:16 (add_executable):
  Cannot find source file:

    /home/me/test_proj/src/source_file.cpp;/home/me/test_proj/src/main.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
  .hxx .in .txx

But those files:

/home/me/test_proj/src/source_file.cpp
/home/me/test_proj/src/main.cpp

Are there. Exactly under that path. Why it can't find them? If I remove any one of them, so TEST_CPP contains just one source file, project generates well. But why it can't if I have more then one source?

I tried CR LF and just LF as end symbols, result is the same.

cmake version 2.8.12.2

Arkady
  • 2,084
  • 3
  • 27
  • 48

1 Answers1

4

Don't put quotes around ${TEST_CPP}:

add_executable(testproj ${TEST_CPP} ${TEST_HEADERS})

Otherwise it will add the sources as ; separated list.

And just a hint: you don't need to prefix everything with ${PROJECT_SOURCE_DIR} (it's done automatically by CMake).

Reference

Community
  • 1
  • 1
Florian
  • 39,996
  • 9
  • 133
  • 149