Phantom
Phantom

Reputation: 875

CMake get sources files list in parent directory

I have a project which is organized like this:

<path_to_project>
  |_ build
  |_ exe1
  | |_ src
  | |_ includes
  |_ exe2
  | |_ src
  | |_ includes
  |_ libs
    |_ src
    |_ includes

I want to manage all different compilation parts of it with CMake (I'm new to it).

For this I created a CMakeLists.txt at the root directory, in it I added the line:
add_executable(exe1 ${EXE1_SOURCES})

Where EXE1_SOURCES is defined, in a CMakeLists.txt in the exe1/src directory, with all exe1 sources files.

When I go in the build directory, and I make cmake .., it says add_executable called with incorrect number of arguments, which means it cannot find the EXE1_SOURCES variable.

I tried two things:

But both failed.

What is the simplest way to achieve what I want to do ?

Upvotes: 1

Views: 1674

Answers (1)

Phantom
Phantom

Reputation: 875

In order to make all variable defined in a subdirectory CMakeLists.txt, I had to add add_subdirectory(${PROJECT_SOURCE_DIR}/exe1/src) in the main CMakeLists.txt.

Upvotes: 2

Related Questions