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

Fix/cmakedeps tool no build type #13267

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
11 changes: 2 additions & 9 deletions conan/tools/cmake/cmakedeps/templates/__init__.py
Expand Up @@ -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):
Expand Down
Expand Up @@ -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
Expand All @@ -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()
Expand Down
Expand Up @@ -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