Ediolot
Ediolot

Reputation: 531

Understanding CMake find_package vs add_submodule (with boost)

I'm having some issues understand what would be the correct protocol to follow here. Let's say in my use case I have a CMake C++ project with the colmap dependency that itself depends on boost.

- project
  - dependencies
    - colmap (git submodule)
    - boost (git submodule)
    - CMakeLists.txt
  - src
    - ...
    - CMakeLists.txt
  - CMakeLists.txt

My initial thought was to set the cmake configuration as follows:

# project/CMakeLists.txt
cmake_minimum_required(VERSION 3.29)
project(myproject)
set(CMAKE_CXX_STANDARD 17)
add_subdirectory(dependencies)
add_subdirectory(src)

# project/dependencies/CMakeLists.txt
add_subdirectory(boost)
add_subdirectory(colmap)

However, when configuring the project, colmap complains it can not find boost:

CMake Error at C:/Program Files (x86)/.../cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Boost (missing: Boost_INCLUDE_DIR graph program_options
  system)

I thought I could just set the variable Boost_INCLUDE_DIR to point to the correct directory, but that will make it complain it doesnt find version.hpp which I believe is part of the boost config lib:

CMake Error at C:/Program Files (x86)/.../cmake-3.29/Modules/FindBoost.cmake:1842 (file):
  file STRINGS file
  "C:/Users/.../myproject/dependencies/boost/boost/version.hpp"
  cannot be read.

As I have read online, both this error and my confusion seem to arise from the point that colmap is using find_package(Boost ${COLMAP_FIND_TYPE} COMPONENTS graph program_options system) which requires an already compiled and installed version of boost and I'm trying to just use the configuration variables with add_submodule and these two approaches are not compatible.

The solutions I have came up with are:

  1. Have a different project folder for boost. However I would like to keep this dependency as a git submodule inside my project so it's easier for future me and users to just clone the project and use it directly
  2. Modify the colmap CMakeLists.txt to make use of the boost configuration instead of using find_package, but this looks "dirty"
  3. Use vcpkg to handle boost dependency, however I would like to know if there is better solution that only uses cmake

Are there any other approaches that would be good in this case ?

Upvotes: 2

Views: 84

Answers (0)

Related Questions