Skip to content

Commit

Permalink
[develop2] fixing transitive linux libraries cmake (#13010)
Browse files Browse the repository at this point in the history
* fixing transitive linux libraries cmake

* adding test and support for components
  • Loading branch information
memsharded authored Jan 31, 2023
1 parent 5421bf2 commit ee475f0
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
6 changes: 6 additions & 0 deletions conan/tools/cmake/cmakedeps/templates/target_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def template(self):
set_property(TARGET {{root_target_name}}
PROPERTY INTERFACE_INCLUDE_DIRECTORIES
$<$<CONFIG:{{configuration}}>:${{'{'}}{{pkg_name}}_INCLUDE_DIRS{{config_suffix}}}> APPEND)
# Necessary to find LINK shared libraries in Linux
set_property(TARGET {{root_target_name}}
PROPERTY INTERFACE_LINK_DIRECTORIES
$<$<CONFIG:{{configuration}}>:${{'{'}}{{pkg_name}}_LIB_DIRS{{config_suffix}}}> APPEND)
set_property(TARGET {{root_target_name}}
PROPERTY INTERFACE_COMPILE_DEFINITIONS
$<$<CONFIG:{{configuration}}>:${{'{'}}{{pkg_name}}_COMPILE_DEFINITIONS{{config_suffix}}}> APPEND)
Expand Down Expand Up @@ -184,6 +188,8 @@ def template(self):
$<$<CONFIG:{{ configuration }}>:{{tvalue(pkg_name, comp_variable_name, 'LINKER_FLAGS', config_suffix)}}> APPEND)
set_property(TARGET {{ comp_target_name }} PROPERTY INTERFACE_INCLUDE_DIRECTORIES
$<$<CONFIG:{{ configuration }}>:{{tvalue(pkg_name, comp_variable_name, 'INCLUDE_DIRS', config_suffix)}}> APPEND)
set_property(TARGET {{comp_target_name }} PROPERTY INTERFACE_LINK_DIRECTORIES
$<$<CONFIG:{{ configuration }}>:{{tvalue(pkg_name, comp_variable_name, 'LIB_DIRS', config_suffix)}}> APPEND)
set_property(TARGET {{ comp_target_name }} PROPERTY INTERFACE_COMPILE_DEFINITIONS
$<$<CONFIG:{{ configuration }}>:{{tvalue(pkg_name, comp_variable_name, 'COMPILE_DEFINITIONS', config_suffix)}}> APPEND)
set_property(TARGET {{ comp_target_name }} PROPERTY INTERFACE_COMPILE_OPTIONS
Expand Down
3 changes: 2 additions & 1 deletion conan/tools/cmake/cmakedeps/templates/target_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ def join_defines(values, prefix=""):
if require and not require.headers:
self.include_paths = ""
if require and not require.libs:
self.lib_paths = ""
# self.lib_paths = "" IMPORTANT! LINKERS IN LINUX FOR SHARED MIGHT NEED IT EVEN IF
# NOT REALLY LINKING LIB
self.libs = ""
self.system_libs = ""
self.frameworks = ""
Expand Down
84 changes: 84 additions & 0 deletions conans/test/functional/toolchains/cmake/test_shared_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,90 @@ def test_shared_cmake_toolchain():
assert "chat: Release!" in client.out
assert "hello: Release!" in client.out

# https://github.com/conan-io/conan/issues/13000
# This failed, because of rpath link in Linux
client = TestClient(servers=client.servers, inputs=["admin", "password"])
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 * -c -r default")
client.run("remove * -c")

client = TestClient(servers=client.servers)
client.run("install --requires=app/0.1@ -o chat*:shared=True -o hello/*:shared=True -g VirtualRunEnv")
# This only finds "app" executable because the "app/0.1" is declaring package_type="application"
# otherwise, run=None and nothing can tell us if the conanrunenv should have the PATH.
command = environment_wrap_command("conanrun", client.current_folder, "app")

client.run_command(command)
assert "main: Release!" in client.out
assert "chat: Release!" in client.out
assert "hello: Release!" in client.out


@pytest.mark.tool("cmake")
def test_shared_cmake_toolchain_components():
""" the same as above, but with components.
"""
client = TestClient(default_server_user=True)

client.save(pkg_cmake("hello", "0.1"))
conanfile = client.load("conanfile.py")
conanfile2 = conanfile.replace('self.cpp_info.libs = ["hello"]',
'self.cpp_info.components["hi"].libs = ["hello"]')
assert conanfile != conanfile2
client.save({"conanfile.py": conanfile2})
client.run("create . -o hello/*:shared=True")
# Chat
client.save(pkg_cmake("chat", "0.1", requires=["hello/0.1"]), clean_first=True)
conanfile = client.load("conanfile.py")
conanfile2 = conanfile.replace('self.cpp_info.libs = ["chat"]',
'self.cpp_info.components["talk"].libs = ["chat"]\n'
' self.cpp_info.components["talk"].requires=["hello::hi"]')
assert conanfile != conanfile2
client.save({"conanfile.py": conanfile2})
client.run("create . -o chat/*:shared=True -o hello/*:shared=True")

# App
client.save(pkg_cmake_app("app", "0.1", requires=["chat/0.1"]), clean_first=True)
cmakelist = client.load("CMakeLists.txt")
cmakelist2 = cmakelist.replace('target_link_libraries(app chat::chat )',
'target_link_libraries(app chat::talk )')
assert cmakelist != cmakelist2
client.save({"CMakeLists.txt": cmakelist2})
client.run("create . -o chat/*:shared=True -o hello/*:shared=True")
client.run("upload * -c -r default")
client.run("remove * -c")

client = TestClient(servers=client.servers)
client.run("install --requires=app/0.1@ -o chat*:shared=True -o hello/*:shared=True -g VirtualRunEnv")
# This only finds "app" executable because the "app/0.1" is declaring package_type="application"
# otherwise, run=None and nothing can tell us if the conanrunenv should have the PATH.
command = environment_wrap_command("conanrun", client.current_folder, "app")

client.run_command(command)
assert "main: Release!" in client.out
assert "chat: Release!" in client.out
assert "hello: Release!" in client.out

# https://github.com/conan-io/conan/issues/13000
# This failed, because of rpath link in Linux
client = TestClient(servers=client.servers, inputs=["admin", "password"])
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 * -c -r default")
client.run("remove * -c")

client = TestClient(servers=client.servers)
client.run("install --requires=app/0.1@ -o chat*:shared=True -o hello/*:shared=True -g VirtualRunEnv")
# This only finds "app" executable because the "app/0.1" is declaring package_type="application"
# otherwise, run=None and nothing can tell us if the conanrunenv should have the PATH.
command = environment_wrap_command("conanrun", client.current_folder, "app")

client.run_command(command)
assert "main: Release!" in client.out
assert "chat: Release!" in client.out
assert "hello: Release!" in client.out


@pytest.mark.tool("cmake")
def test_shared_cmake_toolchain_test_package():
Expand Down

0 comments on commit ee475f0

Please sign in to comment.