Skip to content

Commit

Permalink
accept empty build_type in case of CMake single configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten-klein committed Sep 18, 2023
1 parent c21df11 commit 722382d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
11 changes: 5 additions & 6 deletions conan/tools/cmake/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""

Expand Down Expand Up @@ -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("\\", "/"))
Expand Down
49 changes: 49 additions & 0 deletions conans/test/integration/toolchains/cmake/test_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 722382d

Please sign in to comment.