conan icon indicating copy to clipboard operation
conan copied to clipboard

[question] Check example examples2/examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets

Open kostprof21 opened this issue 4 months ago • 5 comments

What is your question?

Hi! In example https://github.com/conan-io/examples2/tree/main/examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets using ConanPreset.json. Can you check the functionality? What's the problem: after calling conan install .I'm checkingcmake --list-presets and I get the error Invalid preset: "conan-debug" As I found out, the problem is in the ConanPresets file.json and a stub for the buildPresets/conan-debug field.

"buildPresets": [
        {
            "name": "conan-debug"
        }
    ],

If I add a configurePreset

"buildPresets": [
        {
            "name": "conan-debug",
            "configurePreset": "conan-debug"
        }
    ]

then `cmake --list-presets' works:

$ cmake --list-presets
Available configure presets:

  "default"       - multi config
  "release"       - release single config
  "debug"         - debug single config
  "conan-default"
  "conan-debug"
  "conan-release" - 'conan-release' config

Macos Sequoia 15.7 cmake version 3.28.3 conan version 2.17.0

I also checked in the docker container CentOS Linux 8 cmake version 3.31.9 Conan version 2.21.0

Have you read the CONTRIBUTING guide?

  • [x] I've read the CONTRIBUTING guide

kostprof21 avatar Oct 31 '25 12:10 kostprof21

Hi @kostprof21

Thanks for the feedback.

What's the problem: after calling conan install .I'm checkingcmake --list-presets and I get the error Invalid preset: "conan-debug"

When using a multi-config generator with this approach, it is necessary to install both the Debug and Release configurations, as described in https://docs.conan.io/2/examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets.html, it is necessary to do:

conan install .
conan install . -s build_type=Debug

That way both Release and Debug expected information will be filled and the presets will work.

Can you please try that?

memsharded avatar Nov 08 '25 21:11 memsharded

I'm usnig generator "Unix Makefiles" or "Ninja". The problem is the generation of stubs in ConanPreset.json for buildPresets. It looks like this is a cmake problem, as I did not find the mandatory availability of additional field configurePreset inbuildPresets/. But since there is a problem (maybe only I have) it is worth correcting if it manifests itself in others. For this reason, I ask you to try to reproduce it.

kostprof21 avatar Nov 09 '25 06:11 kostprof21

Hi @memsharded,

Any news?

kostprof21 avatar Nov 12 '25 15:11 kostprof21

Hi @kostprof21

I am afraid that I a missing details and information to reproduce. If you are using the Ninja generator, then the command line must be something like:

conan install .... -c tools.cmake.cmaketoolchaing:generator=Ninja

because if not, Conan will use by default the default Visual Studio generator that is multi-config and requires both Debug and Release configurations and dependencies to be installed. This is why I was suggesting above:

conan install .
conan install . -s build_type=Debug

which is the documented way, because in the docs that you are linking Ninja is not being used, so you are doing some different steps than the docs, but those details were missing in the report above.

memsharded avatar Nov 14 '25 11:11 memsharded

@memsharded okay, let's start in order, I hope I'm not missing anything. My system macOS Sequoia 15.7.1, default profile

[settings]
arch=x86_64
build_type=Release
compiler=apple-clang
compiler.cppstd=gnu17
compiler.libcxx=libc++
compiler.version=16
os=Macos
  1. In examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets calling
conan install .  --build=missing

In build/Release/generators/CMakePresets.json in fields configurePresets for conan-release using "generator": "Unix Makefiles".

  1. Calling
cmake --list-presets

I get error:

CMake Error: Could not read presets from examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets:
Invalid preset: "conan-debug"
  1. Open the generated examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets/ConanPresets.json and add "configurePreset": "conan-debug" in "buildPresets"for "conan-debug" like this
"buildPresets": [
        {
            "name": "conan-debug",
            "configurePreset": "conan-debug"
        }
    ]
  1. Check cmake --list-presets. It's OK:
> cmake --list-presets
Available configure presets:

  "default"       - multi config
  "release"       - release single config
  "debug"         - debug single config
  "conan-default"
  "conan-debug"
  "conan-release" - 'conan-release' config

The same behavior if I use Ninja

kostprof21 avatar Nov 14 '25 13:11 kostprof21