I have been learning Conan for a personal project, and I have a question that I haven't been able to answer from looking at the docs and examples.
There seems to be an awkward lack of interaction between Conan's "profiles" and CMake. What I mean is: There are a number of different build parameters that must be manually kept in sync - running CMake with different parameters than the ones that were chosen during conan install
will result in build errors.
To give a more concrete example, here are two of my configs and how I would use them to build:
$ cat ~/.conan/profiles/gcc_debug
[settings]
os=Linux
os_build=Linux
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=10
compiler.libcxx=libstdc++11
build_type=Debug
[options]
[build_requires]
[env]
$ export CC=/usr/bin/gcc
$ export CXX=/usr/bin/g++
$ conan install ../src --profile gcc_debug
$ cmake ../src -GNinja -DCMAKE_BUILD_TYPE=Debug
$ cmake --build .
$ cat ~/.conan/profiles/clang_cl_release
[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=Visual Studio
compiler.version=16
compiler.toolset=ClangCL
build_type=Release
[options]
[build_requires]
[env]
$ conan install ../src --profile clang_cl_release
$ cmake ../src -G"Visual Studio 16 2019" -TClangCL
$ cmake --build . --config=Release
In the first example, I have to repeat gcc
and Debug
.
In the second one, I have to repeat Visual Studio
, 16
, ClangCL
, and Release
.
Having to repeat myself so many times feels smelly, especially when these options are spread out across multiple long-running commands, and forgetting one just option can result in non-obvious error messages. It also seems weird to me that Conan doesn't just enforce (override) the appropriate CMake vars when you call cmake_basic_setup()
; it already knows what values it expects, and blows up if they don't match.
What is the recommended way to handle this?
I just started looking into conan build
, which seems promising. I had originally skipped over this because it looked like it only applied to people who were publishing a Conan package, but now I'm thinking it is meant for consumers as well. In fact, this page even explicitly mentions my problem statement:
This
conan build
will use the settings used in theconan install
which have been cached in the localconaninfo.txt
and file in your build folder. This simplifies the process and reduces the errors of mismatches between the installed packages and the current project configuration. [...] Implementing and using the conanfile.pybuild()
method ensures that we always use the same settings both in the installation of requirements and the build of the project, and simplifies calling the build system.