Conan is a package manager for C++. It has a concept of profiles where different settings are specified, including OS, compiler and compiler version.
[settings] os=linux compiler=clang version=16
I was under an (incorrect) impression that Conan would then tell CMake to use CLang version 16. In reality, it was not happening. Regardless of what I would write in Conan file, CMake would use /usr/bin/c++
, which pointed to GCC.
Then I realized, this is by design. Conan has no say in what compiler CMake will use. The profile simply informs Conan what the compiler is going to be, so Conan could find compatible packages in its respositories. This is probably trivial for Conan authors, so it is not mentioned in the documentation.
In fact, even CMakeList.txt files don’t encode which compiler to use. It is recommended to specify the compiler path on CMake command line, like this:
cmake -GNinja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ /path/to/source
See this stack overflow article for details on why it is so.
CMake tries to avoid encoding things like binary output path or compiler path into the project, contrary to make or Visual Studio. CMake defers these decisions to the command line or environment variables. So, one needs and IDE or a shell script to invoke CMake, if they don’t want to use the defaults, and don’t want to type this information every time.