From 722382d3c91987a56cf78fff51f967568707ca04 Mon Sep 17 00:00:00 2001 From: "Klein, Thorsten (GDE-EDS9)" Date: Mon, 18 Sep 2023 21:32:39 +0200 Subject: [PATCH] accept empty build_type in case of CMake single configuration --- conan/tools/cmake/cmake.py | 11 ++--- .../toolchains/cmake/test_cmake.py | 49 +++++++++++++++++++ 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/conan/tools/cmake/cmake.py b/conan/tools/cmake/cmake.py index 55ddbd116be..e56572d2456 100644 --- a/conan/tools/cmake/cmake.py +++ b/conan/tools/cmake/cmake.py @@ -118,11 +118,10 @@ def _build(self, build_type=None, target=None, cli_args=None, build_tool_args=No bf = self._conanfile.build_folder is_multi = is_multi_configuration(self._generator) if build_type and not is_multi: - self._conanfile.output.error("Don't specify 'build_type' at build time for " - "single-config build systems") - + self._conanfile.output.warning("Specifying 'build_type' does not have " + "any effect for single-config build systems") bt = build_type or self._conanfile.settings.get_safe("build_type") - if not bt: + if not bt and is_multi: raise ConanException("build_type setting should be defined.") build_config = "--config {}".format(bt) if bt and is_multi else "" @@ -180,9 +179,9 @@ def install(self, build_type=None, component=None, cli_args=None): mkdir(self._conanfile, self._conanfile.package_folder) bt = build_type or self._conanfile.settings.get_safe("build_type") - if not bt: - raise ConanException("build_type setting should be defined.") is_multi = is_multi_configuration(self._generator) + if not bt and is_multi: + raise ConanException("build_type setting should be defined.") build_config = "--config {}".format(bt) if bt and is_multi else "" pkg_folder = '"{}"'.format(self._conanfile.package_folder.replace("\\", "/")) diff --git a/conans/test/integration/toolchains/cmake/test_cmake.py b/conans/test/integration/toolchains/cmake/test_cmake.py index 86ae90d270d..7f819257fa4 100644 --- a/conans/test/integration/toolchains/cmake/test_cmake.py +++ b/conans/test/integration/toolchains/cmake/test_cmake.py @@ -31,3 +31,52 @@ def run(self, *args, **kwargs): assert "-something" in client.out assert "--testverbose" in client.out assert "-testok" in client.out + +def test_build_type_single_config_warn(): + client = TestClient() + + conanfile = textwrap.dedent(""" + from conan import ConanFile + from conan.tools.cmake import CMake + class Pkg(ConanFile): + name = "pkg" + version = "0.1" + settings = "os", "compiler", "arch" + generators = "CMakeToolchain" + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build(build_type="Release") + + def run(self, *args, **kwargs): + self.output.info("MYRUN: {}".format(*args)) + """) + client.save({"conanfile.py": conanfile}) + client.run("create . ") + assert "Specifying 'build_type' does not have " + \ + "any effect for single-config build systems" in client.out + assert "Created package" in client.out + +def test_build_type_empty(): + client = TestClient() + + conanfile = textwrap.dedent(""" + from conan import ConanFile + from conan.tools.cmake import CMake + class Pkg(ConanFile): + name = "pkg" + version = "0.1" + settings = "os", "compiler", "arch" + generators = "CMakeToolchain" + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + cmake.install() + + def run(self, *args, **kwargs): + self.output.info("MYRUN: {}".format(*args)) + """) + client.save({"conanfile.py": conanfile}) + client.run("create . ") + assert "Created package" in client.out