Skip to content
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

fix: quote template CMake variables #17156

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conan/internal/api/profile/profile_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""


Expand Down
6 changes: 3 additions & 3 deletions conan/tools/cmake/toolchain/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
45 changes: 45 additions & 0 deletions test/functional/toolchains/cmake/test_cmake_toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2112,3 +2112,48 @@ 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,
)

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