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

allow gnuinstall dirs local flow #16214

Merged
merged 2 commits into from
May 17, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions conan/tools/cmake/toolchain/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,11 +969,10 @@ class OutputDirsBlock(Block):

@property
def template(self):
if not self._conanfile.package_folder:
return ""

return textwrap.dedent("""
{% if package_folder %}
set(CMAKE_INSTALL_PREFIX "{{package_folder}}")
{% endif %}
{% if default_bin %}
set(CMAKE_INSTALL_BINDIR "{{default_bin}}")
set(CMAKE_INSTALL_SBINDIR "{{default_bin}}")
Expand All @@ -998,9 +997,8 @@ def _get_cpp_info_value(self, name):
return elements[0] if elements else None

def context(self):
if not self._conanfile.package_folder:
return {}
return {"package_folder": self._conanfile.package_folder.replace("\\", "/"),
pf = self._conanfile.package_folder
return {"package_folder": pf.replace("\\", "/") if pf else None,
"default_bin": self._get_cpp_info_value("bindirs"),
"default_lib": self._get_cpp_info_value("libdirs"),
"default_include": self._get_cpp_info_value("includedirs"),
Expand Down
75 changes: 75 additions & 0 deletions conans/test/integration/toolchains/cmake/test_cmaketoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1438,3 +1438,78 @@ def layout(self):
assert os.path.isabs(user_presets["include"][0])
presets = json.loads(c.load(user_presets["include"][0]))
assert os.path.isabs(presets["configurePresets"][0]["toolchainFile"])


def test_output_dirs_gnudirs_local_default():
# https://github.com/conan-io/conan/issues/14733
c = TestClient()
conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.cmake import cmake_layout
from conan.tools.files import load

class Conan(ConanFile):
name = "pkg"
version = "0.1"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain"
def build(self):
tc = load(self, "conan_toolchain.cmake")
self.output.info(tc)
""")
c.save({"conanfile.py": conanfile})
c.run("create .")

def _assert_install(out):
assert 'set(CMAKE_INSTALL_BINDIR "bin")' in out
assert 'set(CMAKE_INSTALL_SBINDIR "bin")' in out
assert 'set(CMAKE_INSTALL_LIBEXECDIR "bin")' in out
assert 'set(CMAKE_INSTALL_LIBDIR "lib")' in out
assert 'set(CMAKE_INSTALL_INCLUDEDIR "include")' in out

_assert_install(c.out)
assert "CMAKE_INSTALL_PREFIX" in c.out

c.run("build .")
_assert_install(c.out)
assert "CMAKE_INSTALL_PREFIX" not in c.out


def test_output_dirs_gnudirs_local_custom():
# https://github.com/conan-io/conan/issues/14733
c = TestClient()
conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.cmake import cmake_layout
from conan.tools.files import load

class Conan(ConanFile):
name = "pkg"
version = "0.1"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain"
def layout(self):
self.cpp.package.bindirs = ["mybindir"]
self.cpp.package.includedirs = ["myincludedir"]
self.cpp.package.libdirs = ["mylibdir"]

def build(self):
tc = load(self, "conan_toolchain.cmake")
self.output.info(tc)
""")
c.save({"conanfile.py": conanfile})
c.run("create .")

def _assert_install(out):
assert 'set(CMAKE_INSTALL_BINDIR "mybindir")' in out
assert 'set(CMAKE_INSTALL_SBINDIR "mybindir")' in out
assert 'set(CMAKE_INSTALL_LIBEXECDIR "mybindir")' in out
assert 'set(CMAKE_INSTALL_LIBDIR "mylibdir")' in out
assert 'set(CMAKE_INSTALL_INCLUDEDIR "myincludedir")' in out

_assert_install(c.out)
assert "CMAKE_INSTALL_PREFIX" in c.out

c.run("build .")
_assert_install(c.out)
assert "CMAKE_INSTALL_PREFIX" not in c.out