Skip to content

Using Host and Build Profile from CMakePresets #678

@ibis-hdl

Description

@ibis-hdl

I like to start with the positive things: it works as intended, but if you have other ideas, problems rises as usually :)
Anyway, I use CMakePresets.json in that way:

{
    ...
    "configurePresets": [
        {
            "name": "conan-provider",
            "hidden": true,
            "cacheVariables": {
                "CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "${sourceDir}/cmake/cmake-conan/conan_provider.cmake"
            }
        },

where I clone the git repo cmake-conan into ${sourceDir}/cmake/cmake-conan and inherits to all my presets, which works as expected.
To support macOS users with clang and libc++ on my Linux box, I have a special target clang-libc++ (since I don't own a Mac).

My intention is to use cmake-conan with this CMake preset.

The first step was to write a default profile for conan:

$ cat ~/.conan2/profiles/default 
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=gnu17
compiler.libcxx=libc++
compiler.version=18
os=Linux

[buildenv]
CC=clang
CXX=clang++

[conf]
tools.build:compiler_executables={ "c": "/usr/bin/clang", "cpp": "/usr/bin/clang++" }

The conan provider should take this into account for host and build profile, but doesn't.

Second try, I wrote a CMake cache file clang-libc++-cachevars.cmake:

# pre-fill
set(CONAN_HOST_PROFILE:STRING  "clang-libc++")
set(CONAN_BUILD_PROFILE:STRING "clang-libc++")

to inject this into the CMake cache as it is done with the CMakePresets.json from above, and call it:

$ cmake -C clang-libc++-cachevars.cmake --preset clang-libc++-release
loading initial cache file clang-libc++-cachevars.cmake
Preset CMake variables:

  CMAKE_BUILD_TYPE="Release"
  CMAKE_CONFIGURATION_TYPES="Debug;Release;RelWithDebInfo"
  CMAKE_CXX_COMPILER="clang++"
  CMAKE_C_COMPILER="clang"
  CMAKE_DEFAULT_BUILD_TYPE="Release"
...
-- CMake-Conan: Checking if a default profile exists
/home/vscode/.conan2/profiles/default
-- CMake-Conan: cmake_system_name=Linux
-- CMake-Conan: cmake_system_processor=x86_64
-- CMake-Conan: CMake compiler=Clang
-- CMake-Conan: CMake compiler version=18.1.3
-- CMake-Conan: [settings] compiler=clang
-- CMake-Conan: [settings] compiler.version=18
-- Performing Test _conan_is_libcxx
-- Performing Test _conan_is_libcxx - Failed
-- Performing Test _conan_is_gnu_libstdcxx
-- Performing Test _conan_is_gnu_libstdcxx - Success
...
-- CMake-Conan: Creating profile /workspaces/gh-actions-test/build/conan_host_profile
-- CMake-Conan: Profile: 
[settings]
arch=x86_64
os=Linux
compiler=clang
compiler.version=18
compiler.cppstd=20
compiler.libcxx=libstdc++11
[conf]
tools.cmake.cmaketoolchain:generator=Ninja Multi-Config
tools.build:compiler_executables={"c":"clang","cpp":"/usr/bin/clang++"}

-- CMake-Conan: Installing both Debug and Release
-- CMake-Conan: conan install /workspaces/gh-actions-test -of=/workspaces/gh-actions-test/build/conan --profile:host=default;--profile:host=/workspaces/gh-actions-test/build/conan_host_profile;--profile:build=default;-s;build_type=Release;--build=missing

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=20
compiler.libcxx=libstdc++11
compiler.version=18
os=Linux
[conf]
tools.build:compiler_executables={'c': 'clang', 'cpp': '/usr/bin/clang++'}
tools.cmake.cmaketoolchain:generator=Ninja Multi-Config
[buildenv]
CC=clang
CXX=clang++

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=gnu17
compiler.libcxx=libc++
compiler.version=18
os=Linux
[conf]
tools.build:compiler_executables={'c': '/usr/bin/clang', 'cpp': '/usr/bin/clang++'}
[buildenv]
CC=clang
CXX=clang++
...
$ cmake -C clang-libc++-cachevars.cmake --build --preset clang-libc++-release
...

Finally, the provider is always creating the build profile:

-- CMake-Conan: Creating profile /home/runner/work/gh-actions-test/gh-actions-test/build/conan_host_profile
-- CMake-Conan: Profile: 
[settings]
arch=x86_64
os=Linux
compiler=clang
compiler.version=18
compiler.cppstd=20
compiler.libcxx=libstdc++11
[conf]
tools.cmake.cmaketoolchain:generator=Ninja Multi-Config
tools.build:compiler_executables={"c":"clang","cpp":"/usr/bin/clang++"}

-- CMake-Conan: Installing both Debug and Release
-- CMake-Conan: conan install /home/runner/work/gh-actions-test/gh-actions-test -of=/home/runner/work/gh-actions-test/gh-actions-test/build/conan --profile:host=default;--profile:host=/home/runner/work/gh-actions-test/gh-actions-test/build/conan_host_profile;--profile:build=default;-s;build_type=Release;--build=missing

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=20
compiler.libcxx=libstdc++11
compiler.version=18
os=Linux
[conf]
tools.build:compiler_executables={'c': 'clang', 'cpp': '/usr/bin/clang++'}
tools.cmake.cmaketoolchain:generator=Ninja Multi-Config

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=20
compiler.libcxx=libc++
compiler.version=18
os=Linux

and the CMakeCache.txt contains always:

...
//Conan build profile
CONAN_BUILD_PROFILE:STRING=default
...

//Conan host profile
CONAN_HOST_PROFILE:STRING=default;auto-cmake

//Command line arguments for conan install
CONAN_INSTALL_ARGS:STRING=--build=missing
...

To me, it looks as the variables CONAN_BUILD_PROFILEand CONAN_HOST_PROFILEaren't honored as described in the docs, isn't it or do I use it not in the right way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions