We are pleased to announce that Conan 1.47 is out and comes with some significant new features and bug fixes. We added new [conf] values to inject C/C++ flags and preprocessor definitions to packages. There is also preliminary support for CMakePresets.json in CMakeToolchain to generate necessary information for the CMake build helper. We also added new templates in the conan new command to create examples of an application and a library, one for the Bazel build system and another for MSBuild. It’s also worth noting significant improvements in Meson support, including Android cross-build.

New [conf] to inject arbitrary C++ flags to packages

We added some new [conf] values to inject extra C/C++ flags and preprocessor definitions to the build system (currently supported by CMakeToolchain, AutotoolsToolchain, MesonToolchain, and XCodeToolchain). The values you can set are:

  • tools.build:cxxflags: List of extra CXX flags.
  • tools.build:cflags: List of extra C flags.
  • tools.build:defines: List of extra preprocessor definitions.
  • tools.build:sharedlinkflags: List of flags that will be used by the linker when creating a shared library.
  • tools.build:exelinkflags: List of flags that will be used by the linker when creating an executable.

As with other configuration items, their values can be set in the global.conf file, in recipes, in your profiles or using the --conf argument in the command line. In this case, the injection of values composing profiles could be an interesting example. Imagine you create a “sanitized” profile that adds some sanitizer flags to the builds to track the execution at runtime and report execution errors. That profile could look like this:

include(default)
[conf]
tools.build:cxxflags=["-fsanitize=address", "-fno-omit-frame-pointer"]

Then invoking Conan commands with that profile would inject these flags in every build:

conan create . -pr=./sanitized

Preliminar support for CMakePresets.json

Now Conan uses a CMakePresets.json file to pass certain information from the CMakeToolchain to the CMake build helper. When the CMake build helper calls the configure() method, it will read this information from that file:

  • The generator to be used.
  • The path to the conan_toolchain.cmake toolchain toolchain file.
  • Some cache variables corresponding to the specified settings cannot work if specified in the toolchain.

It’s also important to note that some IDEs like Visual Studio and Visual Studio Code and CLion have built-in support for this file, so putting it next to your CMakeList.txt they will read it automatically and know what generator and toolchain to use for building.

New Bazel and MSBuild templates for conan new

The conan new command is practical to create a template for a C++ project using Conan. Until Conan 1.47 there were templates for CMake and Meson. Now you can also use new templates to scaffold projects using the Microsoft Build Engine and Bazel.

You can give them a try using:

# MSBuild
conan new hello/1.0 -m=msbuild_lib 
conan new app/1.0 -m=msbuild_lib 

# Bazel
conan new hello/1.0 -m=bazel_lib 
conan new app/1.0 -m=bazel_lib 

To build the project, just run:

conan create .

If you want more built-in templates available in Conan, please do not hesitate to contribute them to the GitHub repository. Also, remember that you can always use your own defined templates. Please check the documentation for more information.

Improvements in Meson support

There are a few significant improvements in Meson integration. The most important one is adding support for cross-compilation for Android in the MesonToolchain.

Please note that you should provide the location for your Android NDK path using the tools.android:ndk_path configuration option. This path is used by the ‘MesonToolchain* to point to the correct compiler and linker executables inside the Android NDK. Conan will define the following variables for Meson:

  • c, cpp, ar: The Android NDK compiler executables under the [binaries] section.
  • system, cpu_family, cpu, endian: to define the host and build systems under the [build_machine] and [host_machine] sections.


Besides the items listed above, there were some minor bug fixes you may wish to read about. If so, please refer to the changelog for the complete list.

We hope you enjoy this release, and look forward to your feedback.