diff --git a/conan/tools/cmake/cmakedeps/templates/__init__.py b/conan/tools/cmake/cmakedeps/templates/__init__.py index dbf9c0dc668..fb785c59ef0 100644 --- a/conan/tools/cmake/cmakedeps/templates/__init__.py +++ b/conan/tools/cmake/cmakedeps/templates/__init__.py @@ -60,18 +60,11 @@ def filename(self): @property def configuration(self): - if not self.require.build: - return self.cmakedeps.configuration \ - if self.cmakedeps.configuration else None - else: - return self.conanfile.settings_build.get_safe("build_type") + return self.cmakedeps.configuration @property def arch(self): - if not self.require.build: - return self.cmakedeps.arch if self.cmakedeps.arch else None - else: - return self.conanfile.settings_build.get_safe("arch") + return self.cmakedeps.arch @property def config_suffix(self): diff --git a/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py b/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py index ba6729e74da..d3001e94a3d 100644 --- a/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py +++ b/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py @@ -341,7 +341,7 @@ def build(self): def test_custom_configuration(client): - """ The configuration may differ from the build context and the host context""" + """ The configuration in the build context is still the same than the host context""" conanfile = textwrap.dedent(""" from conan import ConanFile from conan.tools.cmake import CMakeDeps @@ -366,12 +366,12 @@ def generate(self): client.run("install . -pr:h default -s:b build_type=RelWithDebInfo" " -pr:b default -s:b arch=x86 --build missing") curdir = client.current_folder - data_name_context_build = "liba_build-relwithdebinfo-x86-data.cmake" + data_name_context_build = f"liba_build-debug-{host_arch}-data.cmake" data_name_context_host = f"liba-debug-{host_arch}-data.cmake" assert os.path.exists(os.path.join(curdir, data_name_context_build)) assert os.path.exists(os.path.join(curdir, data_name_context_host)) - assert "set(liba_build_INCLUDE_DIRS_RELWITHDEBINFO" in \ + assert "set(liba_build_INCLUDE_DIRS_DEBUG" in \ open(os.path.join(curdir, data_name_context_build)).read() assert "set(liba_INCLUDE_DIRS_DEBUG" in \ open(os.path.join(curdir, data_name_context_host)).read() diff --git a/conans/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py b/conans/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py index 333b7d2a2b7..45add87f6ce 100644 --- a/conans/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py +++ b/conans/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py @@ -468,6 +468,38 @@ def build(self): # The debug binaries are missing, so adding --build=missing c.run("create example -pr:b=default -pr:h=default -s:h build_type=Debug --build=missing " "--build=example") + # listed as both requires and build_requires c.assert_listed_require({"example/1.0": "Cache"}) c.assert_listed_require({"example/1.0": "Cache"}, build=True) + + +def test_using_package_module(): + """ + This crashed, because the profile "build" didn't have "build_type" + https://github.com/conan-io/conan/issues/13209 + """ + c = TestClient() + c.save({"conanfile.py": GenConanfile("tool", "0.1")}) + c.run("create .") + + consumer = textwrap.dedent(""" + from conan import ConanFile + from conan.tools.cmake import CMakeDeps + class Pkg(ConanFile): + name = "pkg" + version = "0.1" + settings = "os", "compiler", "build_type", "arch" + tool_requires = "tool/0.1" + + def generate(self): + deps = CMakeDeps(self) + deps.build_context_activated = ["tool"] + deps.build_context_build_modules = ["tool"] + deps.generate() + """) + c.save({"conanfile.py": consumer, + "profile_build": "[settings]\nos=Windows"}, clean_first=True) + c.run("create . -pr:b=profile_build") + # it doesn't crash anymore, it used to crash + assert "pkg/0.1: Created package" in c.out