0

I have the following project structure:

root/
   CMakeLists.txt
   src/
      CMakeLists.txt
      engine/
         CMakeLists.txt
         *.h
         *.cpp
      console/
         CMakeLists.txt
         *.h
         *.cpp

Now in src/engine/CMakeLists.txt I call add_library(engine ${SOURCES}) and it works out fine, compiles and everything. Now over in console, I would like my includes to the engine be #include "engine/foo.h" and not just #include "foo.h".

Now the question is, are there any elegant way to add the includes so I have to prepend engine to my includes in the console project?

Currently what I do is have the following in src/console/CMakeLists.txt:

add_executable(console ${SOURCES})

target_include_directories(console PUBLIC ${lib_incl_path})
target_link_libraries(console PRIVATE engine)

and then define set(lib_incl_path ${CMAKE_CURRENT_SOURCE_DIR}) in src/CMakeLists.txt. But that seems overkill (and hacky), to add the entire src folder to the includes.

Sheph
  • 625
  • 1
  • 6
  • 19

1 Answers1

0

The answer is to use

target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..)

See CMake how to correctly create dependencies between targets

Community
  • 1
  • 1
Sheph
  • 625
  • 1
  • 6
  • 19