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

CMakeDeps omit libpaths for header-libraries #13704

Closed
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
18 changes: 8 additions & 10 deletions conan/tools/cmake/cmakedeps/templates/target_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from conan.tools.cmake.cmakedeps.templates import CMakeDepsFileTemplate
from conans.errors import ConanException
from conans.model.dependencies import get_transitive_requires

from conans.model.pkg_type import PackageType

"""

Expand Down Expand Up @@ -63,11 +63,6 @@ def context(self):
"dependency_filenames": " ".join(dependency_filenames),
"dependency_find_modes": dependency_find_modes}

@property
def cmake_package_type(self):
return {"shared-library": "SHARED",
"static-library": "STATIC"}.get(str(self.conanfile.package_type), "UNKNOWN")

@property
def is_host_windows(self):
# to account for all WindowsStore, WindowsCE and Windows OS in settings
Expand Down Expand Up @@ -176,7 +171,7 @@ def _get_global_cpp_cmake(self):
global_cppinfo = self.conanfile.cpp_info.aggregated_components()
pfolder_var_name = "{}_PACKAGE_FOLDER{}".format(self.pkg_name, self.config_suffix)
return _TargetDataContext(global_cppinfo, pfolder_var_name, self._root_folder,
self.require, self.cmake_package_type, self.is_host_windows)
self.require, self.conanfile.package_type, self.is_host_windows)

@property
def _root_folder(self):
Expand All @@ -191,7 +186,7 @@ def _get_required_components_cpp(self):
transitive_requires = get_transitive_requires(self.cmakedeps._conanfile, self.conanfile)
for comp_name, comp in sorted_comps.items():
deps_cpp_cmake = _TargetDataContext(comp, pfolder_var_name, self._root_folder,
self.require, self.cmake_package_type,
self.require, self.conanfile.package_type,
self.is_host_windows)

public_comp_deps = []
Expand Down Expand Up @@ -252,7 +247,7 @@ def _get_dependencies_find_modes(self):

class _TargetDataContext(object):

def __init__(self, cpp_info, pfolder_var_name, package_folder, require, library_type,
def __init__(self, cpp_info, pfolder_var_name, package_folder, require, package_type,
is_host_windows):

def join_paths(paths):
Expand Down Expand Up @@ -299,7 +294,8 @@ def join_defines(values, prefix=""):
self.frameworks = join_flags(" ", cpp_info.frameworks)
self.defines = join_defines(cpp_info.defines, "-D")
self.compile_definitions = join_defines(cpp_info.defines)
self.library_type = library_type
self.library_type = {"shared-library": "SHARED",
"static-library": "STATIC"}.get(str(package_type), "UNKNOWN")
self.is_host_windows = "1" if is_host_windows else "0"

# For modern CMake targets we need to prepare a list to not
Expand All @@ -324,6 +320,8 @@ def join_defines(values, prefix=""):
if require and not require.libs:
# self.lib_paths = "" IMPORTANT! LINKERS IN LINUX FOR SHARED MIGHT NEED IT EVEN IF
# NOT REALLY LINKING LIB
if package_type == PackageType.HEADER:
self.lib_paths = ""
self.libs = ""
if cpp_info.frameworkdirs: # Only invalidate for in-package frameworks
# FIXME: The mix of in-package frameworks + system ones is broken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,3 +549,19 @@ class App(ConanFile):
app = c.load("app/header-release-data.cmake")
assert "set(header_SYSTEM_LIBS_RELEASE dl)" in app
assert "set(header_FRAMEWORKS_RELEASE CoreDriver)" in app


def test_header_no_libpaths():
"""
https://github.com/conan-io/conan/issues/13702
"""
c = TestClient()
header = GenConanfile("header", "0.1").with_package_type("header-library")
app = GenConanfile().with_requires("header/0.1").with_settings("build_type")\
.with_generator("CMakeDeps")
c.save({"header/conanfile.py": header,
"app/conanfile.py": app})
c.run("create header")
c.run("install app")
dep = c.load("app/header-release-data.cmake")
assert "set(header_LIB_DIRS_RELEASE )" in dep