Search code examples
cmakeconan

Conan + cmake + boost python


I have just started using conan from my cmake files to download and build dependencies - very convenient. I have tried using it also for Boost, but the default conanfile for boost does not seem to build boost python which I need. My current setup looks like:

conan_cmake_configure(REQUIRES
  fmt/8.0.1
  boost/1.75.0
  eigen/3.4.0
  GENERATORS cmake_find_package)

conan_cmake_autodetect(settings)

conan_cmake_install(PATH_OR_REFERENCE .
  BUILD missing
  REMOTE conancenter
  SETTINGS ${settings})

find_package(Eigen3 REQUIRED)
find_package(Boost COMPONENTS Python) // Approx syntax
...

and this fails because the Boost python package is not available. I guess I can edit the conan_make_configures() command to make sure boost Python is built?


Solution

  • you can use the OPTIONS variable of conan_cmake_configure:

    conan_cmake_configure(REQUIRES
      fmt/8.0.1
      boost/1.75.0
      eigen/3.4.0
      GENERATORS cmake_find_package
      OPTIONS boost:without_python=False
    )
    

    See: https://github.com/conan-io/conan_cmake_configure

    You can find all available options for boost package at: boost C/C++ Package - JFrog ConanCenter

    [Edit 1]: Use of a conanfile with cmake-conan

    You can also create a conanfile.txt to manage your dependencies:

    [requires]
    fmt/8.0.1
    boost/1.75.0
    eigen/3.4.0
    
    [options]
    boost:without_python=False
    
    [generators]
    cmake_find_package
    cmake_paths
    

    And call conan_cmake_run as follows:

    conan_cmake_autodetect(settings)
    
    conan_cmake_run(
            CONANFILE conanfile.txt
            BASIC_SETUP CMAKE_TARGETS
            BUILD missing
            SETTINGS ${settings}
    )