From 3fb74f531a52194fc03328d74b21d31390f17f16 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 30 May 2021 20:07:02 +0200 Subject: [PATCH] Feature/default skip rpaths (#9024) * try default skip_rpaths=False * wip * added test in Win and Linux * remove check of CMAKE_SKIP_RPATH in OSX --- conan/tools/cmake/toolchain.py | 8 ++-- conans/test/assets/pkg_cmake.py | 40 +++++++++++++++++++ .../functional/toolchains/cmake/test_cmake.py | 1 - .../toolchains/cmake/test_shared_cmake.py | 24 +++++++++++ 4 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 conans/test/functional/toolchains/cmake/test_shared_cmake.py diff --git a/conan/tools/cmake/toolchain.py b/conan/tools/cmake/toolchain.py index 4b132ba4f76..4906778867f 100644 --- a/conan/tools/cmake/toolchain.py +++ b/conan/tools/cmake/toolchain.py @@ -175,16 +175,18 @@ def context(self): class SkipRPath(Block): template = textwrap.dedent(""" + {% if skip_rpath %} set(CMAKE_SKIP_RPATH 1 CACHE BOOL "rpaths" FORCE) # Policy CMP0068 # We want the old behavior, in CMake >= 3.9 CMAKE_SKIP_RPATH won't affect install_name in OSX set(CMAKE_INSTALL_NAME_DIR "") + {% endif %} """) + skip_rpath = False + def context(self): - if self._conanfile.settings.get_safe("os") != "Macos": - return - return {"skip_rpath": True} + return {"skip_rpath": self.skip_rpath} class ArchitectureBlock(Block): diff --git a/conans/test/assets/pkg_cmake.py b/conans/test/assets/pkg_cmake.py index 9214f89763e..1895869dbd2 100644 --- a/conans/test/assets/pkg_cmake.py +++ b/conans/test/assets/pkg_cmake.py @@ -18,6 +18,8 @@ class Pkg(ConanFile): exports = "*" {deps} settings = "os", "compiler", "arch", "build_type" + options = {{"shared": [True, False]}} + default_options = {{"shared": False}} generators = "CMakeToolchain", "CMakeDeps" def build(self): @@ -49,3 +51,41 @@ def package_info(self): "src/{}.cpp".format(name): src, "src/CMakeLists.txt": cmake, "conanfile.py": conanfile} + + +def pkg_cmake_app(name, version, requires=None): + refs = [ConanFileReference.loads(r) for r in requires or []] + pkg_name = name + name = name.replace(".", "_") + conanfile = textwrap.dedent("""\ + from conans import ConanFile + from conan.tools.cmake import CMake + class Pkg(ConanFile): + name = "{pkg_name}" + version = "{version}" + exports = "*" + {deps} + settings = "os", "compiler", "arch", "build_type" + generators = "CMakeToolchain", "CMakeDeps" + + def build(self): + cmake = CMake(self) + cmake.configure(source_folder="src") + cmake.build() + + def package(self): + self.copy("*/app.exe", dst="bin", keep_path=False) + self.copy("*app", dst="bin", keep_path=False) + + """) + deps = "requires = " + ", ".join('"{}"'.format(r) for r in requires) if requires else "" + conanfile = conanfile.format(pkg_name=pkg_name, name=name, version=version, deps=deps) + + deps = [r.name.replace(".", "_") for r in refs] + src = gen_function_cpp(name="main", includes=deps, calls=deps) + deps = [r.name for r in refs] + cmake = gen_cmakelists(appname=name, appsources=["{}.cpp".format(name)], find_package=deps) + + return {"src/{}.cpp".format(name): src, + "src/CMakeLists.txt": cmake, + "conanfile.py": conanfile} diff --git a/conans/test/functional/toolchains/cmake/test_cmake.py b/conans/test/functional/toolchains/cmake/test_cmake.py index 4e5b823a9fb..a1211ec6743 100644 --- a/conans/test/functional/toolchains/cmake/test_cmake.py +++ b/conans/test/functional/toolchains/cmake/test_cmake.py @@ -422,7 +422,6 @@ def test_toolchain_apple(self, build_type, cppstd, shared): "CMAKE_C_FLAGS_RELEASE": "-O3 -DNDEBUG", "CMAKE_SHARED_LINKER_FLAGS": "-m64", "CMAKE_EXE_LINKER_FLAGS": "-m64", - "CMAKE_SKIP_RPATH": "1", "CMAKE_INSTALL_NAME_DIR": "" } diff --git a/conans/test/functional/toolchains/cmake/test_shared_cmake.py b/conans/test/functional/toolchains/cmake/test_shared_cmake.py new file mode 100644 index 00000000000..0d379e67e33 --- /dev/null +++ b/conans/test/functional/toolchains/cmake/test_shared_cmake.py @@ -0,0 +1,24 @@ +from conan.tools.env.environment import environment_wrap_command +from conans.test.assets.pkg_cmake import pkg_cmake, pkg_cmake_app +from conans.test.utils.tools import TestClient + + +def test_shared_cmake_toolchain(): + client = TestClient(default_server_user=True) + + client.save(pkg_cmake("hello", "0.1")) + client.run("create . -o hello:shared=True") + client.save(pkg_cmake("chat", "0.1", requires=["hello/0.1"]), clean_first=True) + client.run("create . -o chat:shared=True -o hello:shared=True") + client.save(pkg_cmake_app("app", "0.1", requires=["chat/0.1"]), clean_first=True) + client.run("create . -o chat:shared=True -o hello:shared=True") + client.run("upload * --all -c") + client.run("remove * -f") + + client = TestClient(servers=client.servers, users=client.users) + client.run("install app/0.1@ -o chat:shared=True -o hello:shared=True -g VirtualEnv") + command = environment_wrap_command("conanrunenv", "app", cwd=client.current_folder) + client.run_command(command) + assert "main: Release!" in client.out + assert "chat: Release!" in client.out + assert "hello: Release!" in client.out