Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake: pass include directories to external project

Tags:

cmake

I'm using cmake and external project module via ExternalProject_Add.

I'd like to specify custom header location for external project (just exactly as if I use include_directories in that project, but I am not able to modify its CMakeLists.txt and don't want to apply patch).

Is there any possibility to pass some include path to my external project?

I tried CMAKE_ARGS -DCMAKE_INCLUDE_PATH=<required path> without success.

like image 526
avtomaton Avatar asked Feb 25 '16 15:02

avtomaton


People also ask

What is the difference between Include_directories and Target_include_directories?

1, include_directories() is accessible for all the files in the source-tree 2, target_include_directories() is-only accessible for a specific target when compile.

Where does CMake look for include files?

cmake is searched first in CMAKE_MODULE_PATH , then in the CMake module directory. There is one exception to this: if the file which calls include() is located itself in the CMake builtin module directory, then first the CMake builtin module directory is searched and CMAKE_MODULE_PATH afterwards.

Where do I put CMakeLists txt?

CMakeLists. txt is placed at the root of the source tree of any application, library it will work for. If there are multiple modules, and each module can be compiled and built separately, CMakeLists. txt can be inserted into the sub folder.


1 Answers

You may execute additional CMake script for external project by assigning path to this script to variable CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE (documentation).

Let external project uses CMake command

project(e_cool)

and you want to execute

include_directories(/path/to/additional/include)

at that moment.

For doing that, you need to prepare cmake script with corresponded content:

fix_e_cool.cmake:

include_directories(/path/to/additional/include)

And pass this script via CMAKE_ARGS option of ExternalProject_Add in the main project:

CMakeLists.txt:

...
ExternalProject_Add(<name>
    ...
    CMAKE_ARGS -DCMAKE_PROJECT_e_cool_INCLUDE=${CMAKE_SOURCE_DIR}/fix_e_cool.cmake
)
like image 178
Tsyvarev Avatar answered Oct 11 '22 00:10

Tsyvarev