Skip to content

Commit

Permalink
Feature/default skip rpaths (#9024)
Browse files Browse the repository at this point in the history
* try default skip_rpaths=False

* wip

* added test in Win and Linux

* remove check of CMAKE_SKIP_RPATH in OSX
  • Loading branch information
memsharded committed May 30, 2021
1 parent a5676f4 commit 3fb74f5
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
8 changes: 5 additions & 3 deletions conan/tools/cmake/toolchain.py
Expand Up @@ -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):
Expand Down
40 changes: 40 additions & 0 deletions conans/test/assets/pkg_cmake.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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}
1 change: 0 additions & 1 deletion conans/test/functional/toolchains/cmake/test_cmake.py
Expand Up @@ -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": ""
}

Expand Down
24 changes: 24 additions & 0 deletions 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

0 comments on commit 3fb74f5

Please sign in to comment.