Skip to content

[bug] Inconsistent build_type with user_presets_path #18090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AlexandrePTJ opened this issue Apr 7, 2025 · 6 comments
Open

[bug] Inconsistent build_type with user_presets_path #18090

AlexandrePTJ opened this issue Apr 7, 2025 · 6 comments

Comments

@AlexandrePTJ
Copy link

AlexandrePTJ commented Apr 7, 2025

Describe the bug

When setting user_presets_path as in example, resulting ConanPresets.json file is inconsistent.
When build_type=Debug, it creates presets with release and vice versa in addition to include expected CMakePreset.

Then it cannot build as presets are invalid.

How to reproduce it

Follow instructions from https://docs.conan.io/2/examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets.html

From a fresh debian docker (docker run --rm -it debian) :

# Install minimal tools
$ apt update
$ apt install -y build-essential python3-venv git

# Get example
$ git clone https://github.com/conan-io/examples2.git
$ cd examples2/examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets

# Install conan and cmake
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install conan cmake

# Configure conan
$ conan profile detect

Detected profile:
...
build_type=Release
...

# Configure project
$ conan install .

# Here the bug : generated preset are invalid
$ cmake --preset conan-default

CMake Error: Could not read presets from /root/examples2/examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets:
Invalid preset: "conan-debug"

Observation

I run conan install with either build_type=Debug and build_type=Release. Presets are ok.

@memsharded memsharded self-assigned this Apr 7, 2025
@memsharded
Copy link
Member

Hi @AlexandrePTJ

Thanks for your feedback.

Could you please provide a bit more details to be able to reproduce? Something like:

  • A minimal conanfile to reproduce
  • Making sure starting from a clean folder
  • The exact command you are using
  • The full output of the command, and the resulting (relevant) contents (the ConanPresets.json should be barely some includes), so if necessary provide the internal xxxx/generators/CMakePresets.json
  • The details of the current platform, like conan version

Thanks!

@AlexandrePTJ
Copy link
Author

Hi @memsharded , I updated the description.

@memsharded
Copy link
Member

I see, the problem is:

# Configure project
$ conan install .

# Here the bug : generated preset are invalid
$ cmake --preset conan-default

You are missing the installation of the Debug configuration, the docs in https://docs.conan.io/2/examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets.html instruct to do:

$ conan install .
$ conan install . -s build_type=Debug

It is necessary to install both Release and Debug, configurations, as the defined user presets depend on both configurations.
CMake presets need the presets to be defined, the CMakePresets.json described in the docs, "inherits": "conan-debug", and this is validated when presets are loaded even if the debug preset is not being used at that point.

I run conan install with either build_type=Debug and build_type=Release. Presets are ok.

Yes, exactly this, this is needed, CMake needs all inherited presets to exist.

So this doesn't seem a bug then, but expected behavior.

@aiyolo
Copy link

aiyolo commented Apr 16, 2025

I think it would be preferable not to generate CMakeUserPreset.json by default, as generating a conan_toolchain.cmake is sufficient for most scenarios.

@memsharded
Copy link
Member

I think it would be preferable not to generate CMakeUserPreset.json by default, as generating a conan_toolchain.cmake is sufficient for most scenarios.

This cannot be changed, it would be breaking behavior to many users that depend on this creation by default.

@memsharded
Copy link
Member

@AlexandrePTJ did my above comment clarified the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants