3
votes

I am trying to build a big project with CMake but I struggle on how to write the CMakeList.txt file. My project is separated in different folders each containing a set of .hpp and .cpp files more or less related together as follows:

root 

   - memory
   -- Memory.cpp
   -- Memory.hpp
   -- MemoryManager.hpp
   -- MemoryManager.cpp
   -- CMakeLists.txt

   - tools
   -- Array.cpp
   -- Array.hpp
   -- CMakeLists.txt

   - main.cpp
   - CMakeLists.txt

I would like to build all the files together to an executable. I don't want to build libraries in each subfolder as I don't see any good reason to do it. I would like also to avoid putting a single big list of all source files in the ADD_EXECUTABLE command of the CMakeLists.txt file located at the root of the project.

Do you have any idea of how to set this up correctly ?

Cheers,

M.

1

1 Answers

4
votes

You can use the GLOB function, such as:

file (GLOB _my_sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  memory/*.cpp tools/*.cpp main.cpp)
add_executable (myprogbin ${_my_sources})
set_target_properties (myprogbin PROPERTIES OUTPUT_NAME myprog)

See http://cmake.org/cmake/help/cmake-2-8-docs.html#command:file for reference