Reputation: 194
I have a project which is the following:
project/
├── apps
│ ├── app_a
│ ├── app_b
│ ├── app_c
│ ├── CMakeLists.txt
├── CMakeLists.txt
├── common
│ ├── some_data.cpp
│ ├── some_data.h
│ ├── some_data_a
│ ├── some_data_b
│ ├── some_data_c
└── └── CMakeLists.txt
I would like to include directory common
which contains some_data.h(cpp) and directories some_data_* which named targets some_data_a
, some_data_b
, some_data_c
.
In root CMakeLists.txt I tried to add:
include_directories(${PROJECT_SOURCE_DIR})
So, it works. For example in my app_a/src/app_a.h
I can write include like this:
#include "common/some_data_a/some_data_a.h"
The problem is that I don't understand how to rewrite include_directories
from main CMakeLists.txt
to common/CMakeLists.txt
using target_include_directories
? (not just include_directories, I want to delete that string from main CMakeLists.txt).
It is important that I can still able to include the full path. For example in file apps/app_a/app_a.h
:
#include "common/some_data_a/some_data_a.h"
not just:
#include "some_data_a/some_data_a.h"
I also tried to write it like this:
target_include_directories(common INTERFACE ${PROJECT_SOURCE_DIR})
But it doesn't work
Upvotes: 0
Views: 186
Reputation: 194
Solution. Just put this in common/CMakeLists.txt:
target_include_directories(common INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/..)
And add common
to target_link_libraries
in some_data_a/CMakeLists.txt
Upvotes: 0