Skip to content

Commit

Permalink
(#15933) libbacktrace: modernize more for conan v2
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm authored Feb 13, 2023
1 parent 15e7cd6 commit cd6ae52
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
21 changes: 9 additions & 12 deletions recipes/libbacktrace/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.env import Environment, VirtualBuildEnv
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rename, rm
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import check_min_vs, is_msvc, unix_path
import os

required_conan_version = ">=1.53.0"
required_conan_version = ">=1.54.0"


class LibbacktraceConan(ConanFile):
Expand All @@ -18,6 +18,7 @@ class LibbacktraceConan(ConanFile):
homepage = "https://github.com/ianlancetaylor/libbacktrace"
license = "BSD-3-Clause"
topics = ("backtrace", "stack-trace")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand Down Expand Up @@ -50,20 +51,19 @@ def layout(self):

def validate(self):
check_min_vs(self, "180")
if is_msvc(self) and self.info.options.shared:
if is_msvc(self) and self.options.shared:
raise ConanInvalidConfiguration("libbacktrace shared is not supported with Visual Studio")

def build_requirements(self):
if self._settings_build.os == "Windows":
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", default=False, check_type=bool):
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
self.tool_requires("msys2/cci.latest")
if is_msvc(self):
self.tool_requires("automake/1.16.5")

def source(self):
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
env = VirtualBuildEnv(self)
Expand All @@ -73,10 +73,8 @@ def generate(self):
if is_msvc(self):
# https://github.com/conan-io/conan/issues/6514
tc.extra_cflags.append("-FS")
tc.generate()

env = tc.environment()
if is_msvc(self):
env = Environment()
compile_wrapper = unix_path(self, self.conf.get("user.automake:compile-wrapper"))
ar_wrapper = unix_path(self, self.conf.get("user.automake:lib-wrapper"))
env.define("CC", f"{compile_wrapper} cl -nologo")
Expand All @@ -87,7 +85,7 @@ def generate(self):
env.define("OBJDUMP", ":")
env.define("RANLIB", ":")
env.define("STRIP", ":")
env.vars(self).save_script("conanbuild_libbacktrace_msvc")
tc.generate(env)

def build(self):
apply_conandata_patches(self)
Expand All @@ -98,8 +96,7 @@ def build(self):
def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
autotools = Autotools(self)
# see https://github.com/conan-io/conan/issues/12006
autotools.install(args=[f"DESTDIR={unix_path(self, self.package_folder)}"])
autotools.install()
lib_folder = os.path.join(self.package_folder, "lib")
rm(self, "*.la", lib_folder)
fix_apple_shared_install_name(self)
Expand Down
8 changes: 3 additions & 5 deletions recipes/libbacktrace/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES C)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(libbacktrace REQUIRED CONFIG)

add_executable(test_package ../test_package/test_package.c)
target_link_libraries(test_package PRIVATE libbacktrace::libbacktrace)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)

0 comments on commit cd6ae52

Please sign in to comment.