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

backward-cpp: add header_only option #19095

Merged
merged 2 commits into from
Oct 27, 2023
Merged
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
48 changes: 37 additions & 11 deletions recipes/backward-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir
from conan.tools.layout import basic_layout
from conan.tools.scm import Version
import os

Expand All @@ -20,12 +21,14 @@ class BackwardCppConan(ConanFile):
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"header_only": [True, False],
"shared": [True, False],
"fPIC": [True, False],
"stack_walking": ["unwind", "libunwind", "backtrace"],
"stack_details": ["dw", "bfd", "dwarf", "backtrace_symbol"],
}
default_options = {
"header_only": False,
"shared": False,
"fPIC": True,
"stack_walking": "unwind",
Expand All @@ -34,7 +37,7 @@ class BackwardCppConan(ConanFile):

@property
def _supported_os(self):
supported_os = ["Linux", "Macos", "Android"]
supported_os = ["Linux", "FreeBSD", "Android", "Macos"]
if Version(self.version) >= "1.5":
supported_os.append("Windows")
return supported_os
Expand All @@ -57,23 +60,33 @@ def config_options(self):
self.options.stack_details = "backtrace_symbol"

def configure(self):
if self.options.shared:
if self.options.header_only:
self.options.rm_safe("fPIC")
self.options.rm_safe("shared")
if self.options.get_safe("shared"):
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self, src_folder="src")
if self.options.header_only:
basic_layout(self, src_folder="src")
else:
cmake_layout(self, src_folder="src")

def package_id(self):
if self.info.options.header_only:
self.info.clear()

def requirements(self):
if self.settings.os in ["Linux", "Android"]:
if self.settings.os in ["Linux", "FreeBSD", "Android"]:
if self._has_stack_walking("libunwind"):
self.requires("libunwind/1.6.2", transitive_headers=True)
if self._has_stack_details("dwarf"):
self.requires("libdwarf/20191104", transitive_headers=True, transitive_libs=True)
self.requires("libelf/0.8.13")
if self._has_stack_details("dw"):
self.requires("elfutils/0.186", transitive_headers=True, transitive_libs=True)
self.requires("elfutils/0.186", transitive_headers=True)
if self._has_stack_details("bfd"):
self.requires("binutils/2.38", transitive_headers=True, transitive_libs=True)
self.requires("binutils/2.38", transitive_headers=True)

def validate(self):
if self.settings.os not in self._supported_os:
Expand All @@ -95,6 +108,8 @@ def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
if self.options.header_only:
return
tc = CMakeToolchain(self)
tc.variables["STACK_WALKING_UNWIND"] = self._has_stack_walking("unwind")
tc.variables["STACK_WALKING_LIBUNWIND"] = self._has_stack_walking("libunwind")
Expand All @@ -113,15 +128,22 @@ def generate(self):

def build(self):
apply_conandata_patches(self)
if self.options.header_only:
return
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, "LICENSE*", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "backward"))
if self.options.header_only:
copy(self, pattern="*.hpp",
src=self.source_folder,
dst=os.path.join(self.package_folder, "include"))
else:
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "backward"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "Backward")
Expand All @@ -137,8 +159,12 @@ def package_info(self):
self.cpp_info.defines.append(f"BACKWARD_HAS_DWARF={int(self._has_stack_details('dwarf'))}")
self.cpp_info.defines.append(f"BACKWARD_HAS_PDB_SYMBOL={int(self.settings.os == 'Windows')}")

self.cpp_info.libs = ["backward"]
if self.settings.os == "Linux":
if self.options.header_only:
self.cpp_info.libdirs = []
self.cpp_info.bindirs = []
else:
self.cpp_info.libs = ["backward"]
if self.settings.os in ["Linux", "FreeBSD", "Android"]:
self.cpp_info.system_libs.extend(["dl", "m"])
if self.settings.os == "Windows":
self.cpp_info.system_libs.extend(["psapi", "dbghelp"])
Expand Down