0

Is there a way to make an external dependency depend of two others external dependencies of a project ?

Here is my situation

  • core depdends on boost_program_options and on quetzal
  • quetzal depends on gdal and boost_filesystem and boost_unit_test_framework

How to orchestrate these dependencies ? I have been trying the following approach:

The root CMakelist.txt contains:

list(APPEND BOOST_COMPONENTS_REQUIRED program_options)
add_subdirectory(external/upstream)
    ExternalProject_Add(
      ${PROJECT_NAME}_core
      DEPENDS
        boost_external
        gdal_external
        quetzal_external
      SOURCE_DIR
        ${CMAKE_CURRENT_LIST_DIR}/FTD_core
      CMAKE_ARGS
        -DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
        -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
        -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
        -DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS}
        -DCMAKE_CXX_STANDARD_REQUIRED=${CMAKE_CXX_STANDARD_REQUIRED}
      CMAKE_CACHE_ARGS
        -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
        -DCMAKE_LIBRARY_PATH:PATH=${STAGED_INSTALL_PREFIX}
        # Forward externals to the core project
        -DCMAKE_INCLUDE_PATH:PATH=${BOOST_INCLUDEDIR}
        -DCMAKE_LIBRARY_PATH:PATH=${BOOST_LIBRARYDIR}
        -DCMAKE_INCLUDE_PATH:PATH=${GDAL_INCLUDE_DIR}
        -DCMAKE_LIBRARY_PATH:PATH=${GDAL_LIBRARY}
        -DCMAKE_INCLUDE_PATH:PATH=${QUETZAL_INCLUDE_DIR}
      BUILD_ALWAYS
        1
      INSTALL_COMMAND
        ""
      )

The external/upstream/quetzal/CMakeLists.txt contains:

list(APPEND BOOST_COMPONENTS_REQUIRED unit_test_framework filesystem)
      include(ExternalProject)
      ExternalProject_Add(quetzal_external
        DEPENDS
          boost_external
          gdal_external
        GIT_REPOSITORY https://github.com/Becheler/quetzal.git
        GIT_TAG        master
        CMAKE_ARGS
          -DCMAKE_LIBRARY_PATH:PATH=${STAGED_INSTALL_PREFIX}
          -DCMAKE_INCLUDE_PATH:PATH=${BOOST_INCLUDEDIR}
          -DCMAKE_LIBRARY_PATH:PATH=${BOOST_LIBRARYDIR}
          -DCMAKE_INCLUDE_PATH:PATH=${GDAL_INCLUDE_DIR}
          -DCMAKE_LIBRARY_PATH:PATH=${GDAL_LIBRARY}
              -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}
              -DCMAKE_PREFIX_PATH=${CMAKE_CURRENT_BINARY_DIR}
              -DBUILD_TESTS=Off
          UPDATE_COMMAND ""
        )

external/upstream/boost/CMakeLists.txt and external/upstream/gdal/CMakeLists.txt seem to behave adequately. But for some reason external/upstream/quetzal/CMakeLists.txt finds the system boost installation (1.71), when I want it to find the locally built boost installation (1.65).

I think something is wrong with my way to forward the boost dependency to the quetzal dependency, but I don't even know if the general approach is correct or not.

WaterFox
  • 850
  • 6
  • 18
  • 1
    "But for some reason `external/upstream/quetzal/CMakeLists.txt` finds the system boost installation (1.71), when I want it to find the locally built boost installation (1.65)." - So you need to pass parameters to `quetzal` project so it would find your Boost installation. It can be done either via `-D` parameters to CMake or by setting environment variables. Variable `CMAKE_PREFIX_PATH` looks good for this purpose, but have you actually installed Boost, passing `${CMAKE_CURRENT_BINARY_DIR}` as **installation prefix**? – Tsyvarev Jul 24 '20 at 07:39
  • @Tsyvarev you are saying that the CMAKE_PREFIX_PATH i'm giving is wrong ? I just don't know what I'm supposed to write instead :/ – WaterFox Jul 24 '20 at 17:16
  • 1
    "I just don't know what I'm supposed to write instead" - As I said, you need to write Boost **installation prefix** to the CMAKE_PREFIX_PATH. If you have Boost installed via `ExternalProject_Add`, then its installation prefix is specified by `CMAKE_INSTALL_PREFIX` parameter. – Tsyvarev Jul 24 '20 at 17:27
  • But in this recipe https://github.com/dev-cafe/cmake-cookbook/tree/master/chapter-08/recipe-02/cxx-example that I'm reusing they don't seem to use CMAKE_PREFIX_PATH. It seems that they pass the boost location through the option DCMAKE_INCLUDE_PATH:PATH=${BOOST_INCLUDEDIR} and -DCMAKE_LIBRARY_PATH:PATH=${BOOST_LIBRARYDIR} that they define in the external/upstream/boost/CMakeLists.txt ? – WaterFox Jul 28 '20 at 03:04
  • According to that [CMakeLists.txt](https://github.com/dev-cafe/cmake-cookbook/blob/master/chapter-08/recipe-02/cxx-example/external/upstream/boost/CMakeLists.txt), they don't expect Boost to be already installed. Otherwise existed Boost installation will be used, and branch with `ExternalProject_Add` would never be executed. – Tsyvarev Jul 28 '20 at 07:34

0 Answers0