Conan 1.50: New CMakeToolchain.cache_variables, improving XCodeDeps support for components, fixes in CMake, MSBuild, XCode, many backports, minor changes, new tools, towards providing a 2.0 compatible recipe syntax and new Conan 2.0 beta docs
We are pleased to announce that Conan 1.50 has been released and brings some significant
new features and bug fixes. We have added the CMakeToolchain.cache_variables
to
apply them via -D
arguments in the build helper. Also, we have improved the XCodeDeps
support for components. Finally, we continue fixing things and porting tools so that the
recipe syntax is compatible with Conan 2.0.
New CMakeToolchain.cache_variables
Since this version, the CMakeToolchain
generator
provides an attribute to define CMake cache-variables. This variables will be stored in
the CMakePresets.json file (at the cacheVariables in the configurePreset) and will
be applied with -D
arguments when calling cmake.configure
using the Conan CMake
build
helper.
Let’s see an example:
...
class MylibConan(ConanFile):
...
def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["foo"] = True
tc.cache_variables["foo2"] = False
tc.cache_variables["var"] = "23"
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
When cmake.configure()
is invoked, it will pass the following arguments to CMake:
cmake -G ... -DCMAKE_TOOLCHAIN_FILE="/pathto/conan_toolchain.cmake" ... -Dfoo="ON" -Dfoo2="OFF" -Dvar="23" ...
As you can see, the booleans in the recipe are automatically translated to ON
and
OFF
values in CMake.
Improvements in XCodeDeps
Since we introduced XcodeDeps in Conan
1.42, we have been
gradually improving this generator. Since Conan 1.49 this generator creates separate
.xcconfig files for packages that have components, now this release adds some internal
optimizations that make it more efficient to consume these type of packages. The
components support makes it possible to select just specific components instead of adding
the whole package. For example, if you are depending directly on a package that has
components such as boost but you just want to use the
boost filesystem and chrono components, you can easily do this in your recipe
in the generate()
method. Let’s see an example:
import textwrap
from conan import ConanFile
from conan.tools.apple import XcodeDeps
from conan.tools.files import save
class MyappConan(ConanFile):
name = "myapp"
version = "1.0"
...
def generate(self):
deps = XcodeDeps(self)
deps.generate()
# overwrite the generated conandeps.xcconfig
# with just the components
# we want to use instead the whole package
component_deps = textwrap.dedent("""
#include "conan_boost_filesystem.xcconfig"
#include "conan_boost_chrono.xcconfig"
""")
save(self, "conandeps.xcconfig", component_deps)
Advances in providing a 2.0 compatible recipe syntax
We continue improving the syntax compatibility with Conan 2.0, some relevant changes are:
- Create
self.info.clear()
as an alias ofself.info.header_only()
that will disappear in Conan 2.0. - Allow options having
["ANY"]
as a list - Ported all C++ standard related tools from 2.0 to 1.50
For more detailed information on how to migrate your recipes to be compatible with Conan 2.0, please check the migration guide.
Advances in the documentation for Conan 2.0
We would like to talk a bit about Conan 2.0. As you may know, the first Conan 2.0 beta is already out. You can install it using pip:
$ pip install conan --pre
We have done an effort lately to complete the documentation for the new Conan major version. Although the documentation for 2.0 is still in “draft” state, some sections are practically complete. There are some differences in how the Conan 1.X and Conan 2.0 documentation is structured. Let’s see the most relevant sections of the documentation for Conan 2.0:
The tutorial section
This new section gives a practical hands-on introduction to the most important Conan features. The objective is to learn these features step by step. This section is divided into three sub-sections:
-
Consuming packages: this part, that is already completed shows how to build your projects using Conan to manage your dependencies starting from a simple project that uses the Zlib library. In this section, you will learn things like using tool_requires, what Conan settings and options are, how to consume using a conanfile.py, and how you can cross-compile your applications with Conan using the dual profile approach.
-
Creating packages: this section is half finished and shows how to create Conan packages using a Conan recipe. We begin by creating a basic Conan recipe to package a simple C++ library that you can scaffold using the conan new command and then we begin adding features to it explaining how the different methods of the Conan recipe work. Topics such as how to retrieve the source code from external repositories and apply patches, customise the toolchain, how binary compatibility works and how to package the files of your Conan packages. The last part of the tutorial is about the peculiarities of different types of Conan packages like header-only packages, packages for pre-built binaries or tool requires packages.
-
Versioning and Continuous Integration: this section is not written yet. We will provide some “best practices” for using Conan in your CI here.
The examples section
This section collects examples of some relevant use cases for Conan features, things like:
- Creating custom Conan commands
- Using CMakePresets to build your project.
- Best practices for patching the source code
- How to cross-build for Android and integrate Conan in Android Studio.
The reference section
This section will collect the reference of public classes and methods you can use in your Conan recipes. One significant section of the reference is the one documenting the Conan API. Although the development of this API is still in progress and is not stable yet, we plan to document the whole Conan API for Conan 2.0 so that you can use that in your projects. One relevant example, regarding this, is the one that creates a Conan custom command to clean the Conan cache and uses some methods of this API.
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.