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

More friendly cmake_layout #11391

Merged
merged 7 commits into from Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
18 changes: 9 additions & 9 deletions conan/tools/cmake/layout.py
Expand Up @@ -20,17 +20,17 @@ def cmake_layout(conanfile, generator=None, src_folder="."):
except ConanException:
raise ConanException("'build_type' setting not defined, it is necessary for cmake_layout()")

suffix = get_build_folder_vars_suffix(conanfile)
build_folder = "build"
custom_conf = get_build_folder_custom_vars(conanfile)
if custom_conf:
build_folder = "{}/{}".format(build_folder, custom_conf)

if multi:
conanfile.folders.build = "build"
conanfile.folders.build = build_folder
else:
conanfile.folders.build = "cmake-build-{}".format(str(build_type).lower())

if suffix:
conanfile.folders.build += "-{}".format(suffix)
conanfile.folders.build = "{}/{}".format(build_folder, build_type)

conanfile.folders.generators = os.path.join("build" if not suffix else "build-{}".format(suffix),
"generators")
conanfile.folders.generators = "{}/{}".format(build_folder, "generators")

conanfile.cpp.source.includedirs = ["include"]

Expand All @@ -42,7 +42,7 @@ def cmake_layout(conanfile, generator=None, src_folder="."):
conanfile.cpp.build.bindirs = ["."]


def get_build_folder_vars_suffix(conanfile):
def get_build_folder_custom_vars(conanfile):

build_vars = conanfile.conf.get("tools.cmake.cmake_layout:build_folder_vars",
default=[], check_type=list)
Expand Down
22 changes: 11 additions & 11 deletions conan/tools/cmake/presets.py
Expand Up @@ -2,7 +2,7 @@
import os
import platform

from conan.tools.cmake.layout import get_build_folder_vars_suffix
from conan.tools.cmake.layout import get_build_folder_custom_vars
from conan.tools.cmake.utils import is_multi_configuration
from conans.errors import ConanException
from conans.util.files import save, load
Expand All @@ -20,22 +20,22 @@ def _add_build_preset(conanfile, multiconfig):

def _build_preset_name(conanfile):
build_type = conanfile.settings.get_safe("build_type")
suffix = get_build_folder_vars_suffix(conanfile)
if suffix:
custom_conf = get_build_folder_custom_vars(conanfile)
if custom_conf:
if build_type:
return "{}-{}".format(build_type, suffix)
return "{}-{}".format(custom_conf, build_type.lower())
else:
return suffix
return build_type or "default"
return custom_conf
return build_type.lower() if build_type else "default"


def _configure_preset_name(conanfile, multiconfig):
build_type = conanfile.settings.get_safe("build_type")
suffix = get_build_folder_vars_suffix(conanfile)
base = "default" if multiconfig or not build_type else build_type
if suffix:
return "{}-{}".format(base, suffix)
return base
custom_conf = get_build_folder_custom_vars(conanfile)
suffix = "default" if multiconfig or not build_type else str(build_type).lower()
if custom_conf:
return "{}-{}".format(custom_conf, suffix)
lasote marked this conversation as resolved.
Show resolved Hide resolved
return suffix


def _add_configure_preset(conanfile, generator, cache_variables, toolchain_file, multiconfig):
Expand Down
Expand Up @@ -172,7 +172,7 @@ def package(self):
client.run("source .")
assert os.path.exists(os.path.join(client.current_folder, "src", "source.txt"))
client.run("build .")
contents = load(os.path.join(client.current_folder, "cmake-build-release", "build.txt"))
contents = load(os.path.join(client.current_folder, "build", "Release", "build.txt"))
assert contents == "fooexported_contents"
client.run("export-pkg . foo/1.0@ --force")
assert "Packaged 1 '.txt' file: build.txt" in client.out
Expand Down
6 changes: 2 additions & 4 deletions conans/test/functional/layout/test_editable_cmake.py
Expand Up @@ -11,8 +11,6 @@


def editable_cmake(generator, build_folder=None):
multi = (generator is None and platform.system() == "Windows") or \
generator in ("Ninja Multi-Config", "Xcode")
c = TestClient()
if generator is not None:
c.save({"global.conf": "tools.cmake.cmaketoolchain:generator={}".format(generator)},
Expand All @@ -36,12 +34,12 @@ def build_dep():

def build_pkg(msg):
c.run("build . -if=install_release")
folder = os.path.join("build", "Release") if multi else "cmake-build-release"
folder = os.path.join("build", "Release")
c.run_command(os.sep.join([".", folder, "pkg"]))
assert "main: Release!" in c.out
assert "{}: Release!".format(msg) in c.out
c.run("build . -if=install_debug")
folder = os.path.join("build", "Debug") if multi else "cmake-build-debug"
folder = os.path.join("build", "Debug")
c.run_command(os.sep.join([".", folder, "pkg"]))
assert "main: Debug!" in c.out
assert "{}: Debug!".format(msg) in c.out
Expand Down