Skip to content

Commit 627b80e

Browse files
hwwan80memsharded
andauthored
Fix cmake target not generated with CMake2 generator when only system… (#17868)
* Fix cmake target not generated with CMake2 generator when only system_libs are defined * add test --------- Co-authored-by: memsharded <james@conan.io>
1 parent fb537c7 commit 627b80e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

conan/tools/cmake/cmakedeps2/target_configuration.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def _get_libs(self, cpp_info, pkg_name, pkg_folder, pkg_folder_var) -> dict:
154154
return libs
155155

156156
def _get_cmake_lib(self, info, components, pkg_folder, pkg_folder_var):
157-
if info.exe or not (info.includedirs or info.libs):
157+
if info.exe or not (info.includedirs or info.libs or info.system_libs):
158158
return
159159

160160
includedirs = ";".join(self._path(i, pkg_folder, pkg_folder_var)

test/integration/toolchains/cmake/cmakedeps2/test_cmakedeps.py

+26
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,29 @@ class TestConan(ConanFile):
152152
assert "WARN: Using the new CMakeConfigDeps generator" in c.out
153153
c.run("install app -c tools.cmake.cmakedeps:new=recipe_will_break")
154154
assert "WARN: Using the new CMakeConfigDeps generator" in c.out
155+
156+
157+
def test_system_wrappers():
158+
c = TestClient()
159+
conanfile = textwrap.dedent("""
160+
import os
161+
from conan.tools.files import copy
162+
from conan import ConanFile
163+
class TestConan(ConanFile):
164+
name = "lib"
165+
version = "system"
166+
package_type = "shared-library"
167+
168+
def package_info(self):
169+
self.cpp_info.includedirs = []
170+
self.cpp_info.libdirs = []
171+
self.cpp_info.system_libs = ["my_system_cool_lib"]
172+
""")
173+
c.save({"conanfile.py": conanfile})
174+
c.run("create .")
175+
176+
c.run(f"install --requires=lib/system -g CMakeConfigDeps "
177+
f"-c tools.cmake.cmakedeps:new={new_value}")
178+
cmake = c.load("lib-Targets-release.cmake")
179+
assert "add_library(lib::lib INTERFACE IMPORTED)" in cmake
180+
assert "target_link_libraries(lib::lib INTERFACE my_system_cool_lib)" in cmake

0 commit comments

Comments
 (0)