conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.14k stars 970 forks source link

[bug] conan 2.7.1 profile unable to set tools.cmake.cmaketoolchain:user_toolchain #17029

Open dzonerzy opened 19 hours ago

dzonerzy commented 19 hours ago

Describe the bug

I've modified my default profile to inject a cmake which clear all the compiler flags for Debug and Release builds like as follows:

[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.version=194
os=Windows

[conf]
tools.cmake.cmaketoolchain:user_toolchain=["C:\Users\user\Desktop\test\base.cmake"]

when I run

conan install --requires=zlib/1.3.1 -r=local-repo --build=zlib/1.3.1 -s build_type=Release -c tools.build:cxxflags="['/O1']" -c tools.compilation:verbosity=verbose

To force compilation with /O1 everytime I get the following error:

PS C:\Users\user\Desktop\test> conan install --requires=zlib/1.3.1 -r=local-repo  --build=zlib/1.3.1 -s build_type=Release -c tools.build:cxxflags="['/O1']" -c tools.compilation:verbosity=verbose

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=194
os=Windows
[conf]
tools.build:cxxflags=['/O1']
tools.cmake.cmaketoolchain:user_toolchain=["C:\Users\user\Desktop\test\base.cmake"]
tools.compilation:verbosity=verbose

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=194
os=Windows
[conf]
tools.cmake.cmaketoolchain:user_toolchain=["C:\Users\user\Desktop\test\base.cmake"]

======== Computing dependency graph ========
Graph root
    cli
Requirements
    zlib/1.3.1#f52e03ae3d251dec704634230cd806a2 - Cache

======== Computing necessary packages ========
zlib/1.3.1: Forced build from source
Requirements
    zlib/1.3.1#f52e03ae3d251dec704634230cd806a2:0d6dd492a7d31822b2f2686ec67bbaef586416a3 - Build

======== Installing packages ========

-------- Installing package zlib/1.3.1 (1 of 1) --------
zlib/1.3.1: Building from source
zlib/1.3.1: Package zlib/1.3.1:0d6dd492a7d31822b2f2686ec67bbaef586416a3
zlib/1.3.1: Copying sources to build folder
zlib/1.3.1: Building your package in C:\Users\user\.conan2\p\b\zlibcaa05e814eba2\b
zlib/1.3.1: Calling generate()
zlib/1.3.1: Generators folder: C:\Users\user\.conan2\p\b\zlibcaa05e814eba2\b\build\generators
ERROR: zlib/1.3.1: Error in generate() method, line 64
        tc.generate()
        ConanException: [conf] tools.cmake.cmaketoolchain:user_toolchain must be a list-like object. The value '["C:\Users\user\Desktop\test\base.cmake"]' introduced is a str object

I've tried both with the square brackets and without but the error still persist.

This is the content of my base.cmake

SET(CMAKE_CXX_FLAGS "")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "")
SET(CMAKE_CXX_FLAGS_RELEASE "")
SET(CMAKE_CXX_FLAGS_DEBUG  "")

How to reproduce it

1 - Modify a profile to inject the attached user toolchain 2 - Build from source a receips

base.zip

memsharded commented 13 hours ago

Thanks for the report @dzonerzy

I am trying to reproduce with a simple test like:

def test_cross_build_user_toolchain_defined_quotes():
    # https://github.com/conan-io/conan/issues/17029
    rpi_profile = textwrap.dedent("""
        [settings]
        os=Linux
        compiler=gcc
        compiler.version=6
        compiler.libcxx=libstdc++11
        arch=armv8
        build_type=Release
        [conf]
        tools.cmake.cmaketoolchain:user_toolchain=["rpi_toolchain.cmake"]
        """)

    client = TestClient(path_with_spaces=False)

    conanfile = GenConanfile().with_settings("os", "arch", "compiler", "build_type")\
        .with_generator("CMakeToolchain")
    client.save({"conanfile.py": conanfile,
                "rpi": rpi_profile})
    client.run("install . --profile:host=rpi")
    toolchain = client.load("conan_toolchain.cmake")
    print(toolchain)
    assert 'include("rpi_toolchain.cmake")' in toolchain

And this seems to work so far. I will keep investigating, are you using the standard zlib recipe from ConanCenter?

dzonerzy commented 11 hours ago

Thanks for looking at this @memsharded, yes I'm using the official zlib recipe, I cloned the ConanCenter repo locally and added it to conan using:

conan remote add <repo_folder>

then I installed the package with:

conan install --requires=zlib/1.3.1 -r=local-repo --build=zlib/1.3.1 -s build_type=Release -c tools.build:cxxflags="['/O1']" -c tools.compilation:verbosity=verbose

AbrilRBS commented 10 hours ago

Hi @dzonerzy. Turns out this has nothing to do with the recipe, it's an evaluation issue in Python's side.

As a workaround for now, you can replace the backslashes in the toolchain path in your profile with either forward ones, or double them, like =["C:\\Users\\user\\Desktop\\test\\base.cmake"], and that should solve the current issue.

It's quite annoying, but currently backslash paths can't be used in conf lists and have them behave as such, we'll try to take a look into this, see if we can address it for 2.8.0, but no guarantee