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

let CMakeToolchain not crash if build_type not defined #9984

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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