c++cmakemongo-c-driver

cmake include_directories passed to externaproject_add


I need to use mangrove (mongo ODM lib over mongo-c-driver and mongo-cxx-driver) and included this into my project as CMake ExternalProject_Add command, with a dependencies as mongo-c-driver/mongo-cxx-driver

# mongo-c-driver
ExternalProject_Add(mongo-c-driver
        GIT_REPOSITORY https://github.com/mongodb/mongo-c-driver.git
        GIT_TAG r1.12
        CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF
#        CMAKE_ARGS -DINCLUDE_DIRECTORIES=${EXTERNAL_INSTALL_LOCATION}/include/libbson-1.0 ${EXTERNAL_INSTALL_LOCATION}/include/libmongoc-1.0
        )

#include_directories(${EXTERNAL_INSTALL_LOCATION}/include/libbson-1.0
#        ${EXTERNAL_INSTALL_LOCATION}/include/libmongoc-1.0)
#link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)

include_directories command here is not really required because cmake configuration file of mongoc makes this work. However, for sure, I also checked with uncommented too.

So includes from mongo-c-driver are required by next-included external project - mangrove.

Which fails due the c++ error not found some include files, which are exist in include paths of the current project. So it seems that included external project doesn't use current CMake includes, which are previously added by another external project

# mangrove
ExternalProject_Add(mangrove
        GIT_REPOSITORY https://github.com/aospan/mangrove.git
        CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} -DCMAKE_INCLUDE_DIRECTORIES_BEFORE=${EXTERNAL_INSTALL_LOCATION}/include/libbson-1.0
        )

ExternalProject_Add_StepDependencies(mangrove build mongo-c-driver mongo-cxx-driver)

include_directories(${EXTERNAL_INSTALL_LOCATION}/include/libbson-1.0
        ${EXTERNAL_INSTALL_LOCATION}/include/libmongoc-1.0)
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)

It seems that include_directories inside the script doesn't affect CMake-based project included by ExternalProject_Add.

Is there a technique to pass those include paths to external project?


Solution

  • You are using the wrong macro. CMAKE_INCLUDE_DIRECTORIES_BEFORE only indicates how include-directories work and is a flag.

    There is no other option as to set the proper variables so that the external CMakeLists.txt uses find_path to populate the path to bson.h. If it doesn't, then I suggest you patch CMakeLists.txt to use find_path and make a pull request.

    Edit:

    It seems that the mangrove project has a way of setting all this with ENABLE_BSON. You can then set BSON_VERSION, BSON_INCLUDE_DIRS and BSON_LIBRARIES manually if the default AUTO doesn't work.