Skip to content

Commit

Permalink
Deny 'settings.build_type' in conf 'tools.cmake.cmake_layout:build_fo…
Browse files Browse the repository at this point in the history
…lder_vars' (#11470)
  • Loading branch information
lasote committed Jun 16, 2022
1 parent 7415932 commit c6fa869
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions conan/tools/cmake/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ def get_build_folder_custom_vars(conanfile):
tmp = None
if s.startswith("settings."):
_, var = s.split("settings.", 1)
if var == "build_type":
raise ConanException("Error, don't include 'settings.build_type' in the "
"'tools.cmake.cmake_layout:build_folder_vars' conf. It is "
"managed by default because 'CMakeToolchain' and 'CMakeDeps' "
"are multi-config generators.`")
tmp = conanfile.settings.get_safe(var)
elif s.startswith("options."):
_, var = s.split("options.", 1)
Expand Down
11 changes: 11 additions & 0 deletions conans/test/functional/toolchains/cmake/test_cmake_toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,3 +907,14 @@ def test_cmake_presets_with_conanfile_txt():
c.run_command("build\\Release\\foo")

assert "Hello World Release!" in c.out


def test_cmake_presets_forbidden_build_type():
client = TestClient(path_with_spaces=False)
client.run("new hello/0.1 --template cmake_exe")
# client.run("new cmake_exe -d name=hello -d version=0.1")
settings_layout = '-c tools.cmake.cmake_layout:build_folder_vars=' \
'\'["options.missing", "settings.build_type"]\''
client.run("install . {}".format(settings_layout), assert_error=True)
assert "Error, don't include 'settings.build_type' in the " \
"'tools.cmake.cmake_layout:build_folder_vars' conf" in client.out

0 comments on commit c6fa869

Please sign in to comment.