Skip to content

Commit

Permalink
let CMakeToolchain not crash if build_type not defined (#9984)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded committed Nov 30, 2021
1 parent fc164d5 commit 14d01da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion conan/tools/cmake/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from conan.tools._check_build_profile import check_using_build_profile
from conan.tools._compilers import architecture_flag, use_win_mingw
from conan.tools.cmake.utils import is_multi_configuration, get_file_name
from conan.tools.cmake.utils import is_multi_configuration
from conan.tools.files import save_toolchain_args
from conan.tools.intel import IntelCC
from conan.tools.microsoft import VCVars
Expand Down Expand Up @@ -117,6 +117,8 @@ def context(self):
config_dict = dict(matches)

build_type = settings.get_safe("build_type") # FIXME: change for configuration
if build_type is None:
return None
runtime = settings.get_safe("compiler.runtime")
if compiler == "Visual Studio":
config_dict[build_type] = {"MT": "MultiThreaded",
Expand Down
14 changes: 14 additions & 0 deletions conans/test/functional/toolchains/cmake/test_cmake_toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,17 @@ def build(self):
"CMakeLists.txt": gen_cmakelists()}, clean_first=True)
client.run("create . pkg/0.1@")
assert "mytoolchain.cmake !!!running!!!" in client.out


def test_cmake_toolchain_without_build_type():
# If "build_type" is not defined, toolchain will still be generated, it will not crash
# Main effect is CMAKE_MSVC_RUNTIME_LIBRARY not being defined
client = TestClient(path_with_spaces=False)
conanfile = GenConanfile().with_settings("os", "compiler", "arch").\
with_generator("CMakeToolchain")

client.save({"conanfile.py": conanfile})
client.run("install .")
toolchain = client.load("conan_toolchain.cmake")
assert "CMAKE_MSVC_RUNTIME_LIBRARY" not in toolchain
assert "CMAKE_BUILD_TYPE" not in toolchain

0 comments on commit 14d01da

Please sign in to comment.