Search code examples
c++cmakeconan

Using `conan.cmake` with `conan_multi` generator, missing build_type argument?


I am attempting to get a multi-config cmake build working using conan.cmake. I am also following along with the cmake_multi docs.

It seems that in the docs for cmake_multi, they require that you both pass -g cmake_multi and -s build_type={type} ({type} being Release/Debug/...).

However, in conan.cmake it does not look like the current build_type is passed on when calling conan install -g cmake_multi ....

I am hitting a situation now where if I run with the configurations "Release;Debug" conan reports that a bunch of packages are missing

Requirements
    boost/1.71.0@conan/stable from 'my_repo' - Cache
    libconfig/1.6@internal/custom from 'my_repo' - Cache
    ...
Packages
    boost/1.71.0@conan/stable:5b939a5d59f5432d9263459d17f2acb1535629bd - Missing
    libconfig/1.6@internal/custom:ef44119b64b51a15f7b334090b2ff53fddcc38df - Missing
    ...

However if I edit conan.cmake to also pass "-sbuild_type=${CMAKE_BUILD_TYPE}" at the end of conan_args, it is able to find my packages for both Release and Debug.

Could anyone see what I may be doing wrong here? I do not specify a build_type in my conan profile, nor is one already set as part of my settings.


Solution

  • After reading the source code for conan.cmake a few more times I discovered that it is possible to have it propagate the build type, you just need to use the PROFILE_AUTO argument to conan_cmake_run.

    conan_cmake_run(
       PROFILE ${CONAN_PROFILE}
       CONFIGURATION_TYPES ${CONFIGURATION_TYPES}
       PROFILE_AUTO build_type  # Use build_type as detected by CMake, override any values in the profile
       BUILD outdated
    )