I'm trying to include external libraries to a cmake project through ExternalProject_Add
. To try out this feature I've created a minimal working example that involves adding pugixml to the project with ExternalProject_Add
. However, I'm having problems finding a way to add the library's header files from the external project's local installation (i.e., pugixml's headers) in the project's include path.
The project tree of the minimal working example is organized as follows:
.
├── build
├── CMakeLists.txt
└── src
├── CMakeLists.txt
└── main.cpp
In this project tree, build
refers to the build directory and the path where cmake is called to generate the build.
The contents of ./CMakeLists.txt
are as follows:
cmake_minimum_required(VERSION 3.0)
include(ExternalProject)
ExternalProject_Add(pugixml
GIT_REPOSITORY https://github.com/zeux/pugixml.git
INSTALL_DIR ${PROJECT_BINARY_DIR}/extern_install/pugixml
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
)
add_subdirectory(src)
In the above example I've added pugixml as an external project that is to be installed within the project's binary dir, whose file will be used by an executable stored in ./src
. Thus, the contents of ./src/CMakeLists.txt
are:
project(foo)
add_executable(foo main.cpp)
target_link_libraries(foo ${pugixml_LIBRARIES})
include_directories(${pugixml_INCLUDE_DIR}) # this part doesn't work
This is precisely the part I'm having problems. I've assumed that once the external project was added and installed that ExternalProject_Add
would have defined some convenience libraries to help refer to library files and include directories. However, that doesn't work. Does anyone know what's the right way of using ExternalProject_Add
to include external libraries?