We are pleased to announce that Conan 1.48 has been released and brings some significant new features and bug fixes. We have improved the CMakePresets integration. Also, we have added new “conan new” Autotools templates. We added CMakeToolchain configuration for bitcode, arc and visibility flags on Apple platforms. This release also adds support to generate env .ps1 instead of .bat in Windows.

Improvements in CMakePresets integration

Since Conan 1.47 we started to provide support for CMakePresets. This file is used internally in Conan to pass information like the generator and toolchain file location from the CMakeToolchain to the CMake build helper. Besides this, using this file also improves the developer flow experience, when working locally with Conan and CMake. Let’s see an example of how to use this file with Visual Studio Code with the CMake Tools installed.

Starting with a simple consumer project with this structure that uses the Zlib library:

├── CMakeLists.txt
├── conanfile.txt
└── src
    └── main.cpp

Where the conanfile.txt requires zlib/1.2.11 and adds the CMakeDeps and CMakeToolchain generators:

[requires]
zlib/1.2.12

[generators]
CMakeDeps
CMakeToolchain

And the CMakeLists.txt is as simple as:

cmake_minimum_required(VERSION 3.15)
project(compressor CXX)

find_package(ZLIB REQUIRED)

add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} ZLIB::ZLIB)

The main.cpp code will just show whether we are using Debug or Release configuration and the version of zlib.

#include <iostream>

#include <zlib.h>

int main(void) {
    #ifdef NDEBUG
    std::cout << "Release!" << std::endl;
    #else
    std::cout << "Debug!" << std::endl;
    #endif
    std::cout << "Zlib version: " << zlibVersion() << std::endl;
    return 0;
}

Run the conan install command to install the Zlib dependency for Release and Debug configurations:

conan install . --build=missing
conan install . -s build_type=Debug --build=missing

After running this, Conan will generate a CMakePresets.json file. This file stores different presets that you can select in Visual Studio Code. Select Release as the configure preset:

Configure CMake

And run the build:

Build the project

Now it’s easy to change between presets to launch different build configurations.

New Autotools templates for the conan new command

As you know, the conan new command is a practical way to create a template for a C++ project using Conan. Until Conan 1.48 there were templates for CMake, Meson, Bazel and MSBuild. Now you can also use new templates to create a project example for both a library and an executable with Conan using Autotools.

You try it using:

conan new hello/1.0 -m=autotools_lib 
conan new app/1.0 -m=autotools_exe

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.

CMakeToolchain configuration support for bitcode, arc and visibility flags on Apple platforms

This version adds support in CMakeToolchain for the following conf properties:

  • tools.build:tools.apple:enable_bitcode boolean value to enable/disable Bitcode Apple. This will set the CMAKE_XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE and CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE CMake variables when using the CMake Xcode generator. If other generator is used, it adds the -fembed-bitcode flag to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS.

  • tools.build:tools.apple:enable_arc boolean value to enable/disable ARC Apple Clang flags. This will set the CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC CMake variable when using the CMake Xcode generator. If other generator is used, it adds the -fobjc-arc or -fno-objc-arc flag to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS .

  • tools.build:tools.apple:enable_visibility This will set the CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN CMake variable when using the CMake Xcode generator. If other generator is used, it adds the -fvisibility flag to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS.

Configuration to choose between Batch or PowerShell scripts in Windows

This version brings a new configuration option to choose between Batch or PowerShell script generation. As you know, the Conan Environment class saves the information in a .bat Batch file by default in Windows. Now, setting the tools.env.virtualenv:powershell to True, you can generate .ps1 PowerShell scripts instead. This will also apply to the VirtualBuildEnv and VirtualRunEnv generators as they use the Environment class internally.



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.