From dccf0e8e27dd40691c8e0a48391a8f1292bf0e40 Mon Sep 17 00:00:00 2001 From: Manuel Leonhardt Date: Sun, 13 Oct 2024 22:00:15 +0200 Subject: [PATCH 1/3] fix: quote template CMake variables This fix addresses an issue where "cppstd" is undefined for pure C recipes. Consequently, "set" sometimes leaves the "conan_watched_std_variable" unset, leading to an error in the subsequent string comparison: ``` CMake Error at .../conan_toolchain.cmake:64 (if): if given arguments: "READ_ACCESS" "STREQUAL" "MODIFIED_ACCESS" "AND" "NOT" "11" "STREQUAL" Unknown arguments specified ``` --- conan/tools/cmake/toolchain/blocks.py | 6 +-- .../toolchains/cmake/test_cmake_toolchain.py | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/conan/tools/cmake/toolchain/blocks.py b/conan/tools/cmake/toolchain/blocks.py index 74aa1c2f0c0..8f9a2c85236 100644 --- a/conan/tools/cmake/toolchain/blocks.py +++ b/conan/tools/cmake/toolchain/blocks.py @@ -274,11 +274,11 @@ class CppStdBlock(Block): # Define the C++ and C standards from 'compiler.cppstd' and 'compiler.cstd' function(conan_modify_std_watch variable access value current_list_file stack) - set(conan_watched_std_variable {{ cppstd }}) + set(conan_watched_std_variable "{{ cppstd }}") if (${variable} STREQUAL "CMAKE_C_STANDARD") - set(conan_watched_std_variable {{ cstd }}) + set(conan_watched_std_variable "{{ cstd }}") endif() - if (${access} STREQUAL "MODIFIED_ACCESS" AND NOT ${value} STREQUAL ${conan_watched_std_variable}) + if ("${access}" STREQUAL "MODIFIED_ACCESS" AND NOT "${value}" STREQUAL "${conan_watched_std_variable}") message(STATUS "Warning: Standard ${variable} value defined in conan_toolchain.cmake to ${conan_watched_std_variable} has been modified to ${value} by ${current_list_file}") endif() unset(conan_watched_std_variable) diff --git a/test/functional/toolchains/cmake/test_cmake_toolchain.py b/test/functional/toolchains/cmake/test_cmake_toolchain.py index b3173091bb9..6a0960fb911 100644 --- a/test/functional/toolchains/cmake/test_cmake_toolchain.py +++ b/test/functional/toolchains/cmake/test_cmake_toolchain.py @@ -2112,3 +2112,42 @@ def build(self): c.run('build . --profile:host=android') assert 'VERSION ".0" format invalid.' not in c.out assert 'sdk: 1.0.0' in c.out + + +@pytest.mark.tool("cmake") +def test_cmake_toolchain_language_c(): + client = TestClient() + + conanfile = textwrap.dedent(r""" + from conan import ConanFile + from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout + + class Pkg(ConanFile): + settings = "os", "compiler", "arch", "build_type" + generators = "CMakeToolchain" + languages = "C" + + def layout(self): + cmake_layout(self) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + """) + + cmakelists = textwrap.dedent(""" + cmake_minimum_required(VERSION 3.15) + project(pkg C) + """) + + client.save( + { + "conanfile.py": conanfile, + "CMakeLists.txt": cmakelists, + }, + clean_first=True, + ) + + client.run("install . -s compiler.cstd=11") + client.run("build . -s compiler.cstd=11") From 56100cd8619f010c4fb8d668437466b6558638dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Mon, 14 Oct 2024 08:54:42 +0200 Subject: [PATCH 2/3] Fix error reporting for cstd --- conan/internal/api/profile/profile_loader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conan/internal/api/profile/profile_loader.py b/conan/internal/api/profile/profile_loader.py index 3ea76a37946..0ab7b0d822b 100644 --- a/conan/internal/api/profile/profile_loader.py +++ b/conan/internal/api/profile/profile_loader.py @@ -107,7 +107,7 @@ def _error(compiler, cstd, min_version, version): mver = {"17": "192", "11": "192"}.get(cstd) if mver and version < mver: - _error(compiler, cppstd, mver, version) + _error(compiler, cstd, mver, version) """ From 6b50ed6d5056f9f13aabee348f2cee35ac3064e9 Mon Sep 17 00:00:00 2001 From: memsharded Date: Mon, 14 Oct 2024 10:08:50 +0200 Subject: [PATCH 3/3] fix Windows test --- .../toolchains/cmake/test_cmake_toolchain.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/functional/toolchains/cmake/test_cmake_toolchain.py b/test/functional/toolchains/cmake/test_cmake_toolchain.py index 6a0960fb911..5be9ffa6fcf 100644 --- a/test/functional/toolchains/cmake/test_cmake_toolchain.py +++ b/test/functional/toolchains/cmake/test_cmake_toolchain.py @@ -2137,9 +2137,9 @@ def build(self): """) cmakelists = textwrap.dedent(""" - cmake_minimum_required(VERSION 3.15) - project(pkg C) - """) + cmake_minimum_required(VERSION 3.15) + project(pkg C) + """) client.save( { @@ -2149,5 +2149,11 @@ def build(self): clean_first=True, ) - client.run("install . -s compiler.cstd=11") - client.run("build . -s compiler.cstd=11") + if platform.system() == "Windows": + # compiler.version=191 is already the default now + client.run("build . -s compiler.cstd=11 -s compiler.version=191", assert_error=True) + assert "The provided compiler.cstd=11 requires at least msvc>=192 but version 191 provided" \ + in client.out + else: + client.run("build . -s compiler.cppstd=11") + # It doesn't fail