diff --git a/recipes/stacktrace/all/conanfile.py b/recipes/stacktrace/all/conanfile.py new file mode 100644 index 0000000000000..8d61ffc2c0c32 --- /dev/null +++ b/recipes/stacktrace/all/conanfile.py @@ -0,0 +1,58 @@ +import os + +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.files import copy, download + +required_conan_version = ">=2.0" + + +class PackageConan(ConanFile): + name = "stacktrace" + description = "Print stack backtrace programmatically with demangled function names" + license = "WTFPL" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://panthema.net/2008/0901-stacktrace-demangled/" + topics = ("stacktrace", "backtrace", "backtrace_symbols", "demangle", "header-only") + package_type = "header-library" + settings = "os", "arch", "compiler", "build_type" + no_copy_source = True + + def source(self): + download( + self, + url="https://panthema.net/2008/0901-stacktrace-demangled/stacktrace.h", + filename="stacktrace.h", + sha256="f850b0b859595f26121ccc9c8b9a82d9ed9acfe35fdea01554b257e95301310b", + ) + + def export_sources(self): + copy(self, "stacktrace.h", self.recipe_folder, self.export_sources_folder) + + def package_id(self): + self.info.clear() + + def validate(self): + check_min_cppstd(self, 98) + if str(self.settings.compiler) not in ["gcc", "clang"]: + raise ConanInvalidConfiguration( + f"{self.ref} does only demangle gcc and clang properly." + ) + if self.settings.os == "Windows": + raise ConanInvalidConfiguration(f"{self.ref} might not compile on Windows.") + + def build(self): + pass + + def package(self): + copy( + self, + "stacktrace.h", + self.source_folder, + os.path.join(self.package_folder, "include"), + ) + + def package_info(self): + self.cpp_info.bindirs = [] + self.cpp_info.libdirs = [] diff --git a/recipes/stacktrace/all/test_package/CMakeLists.txt b/recipes/stacktrace/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..188318d5bd8de --- /dev/null +++ b/recipes/stacktrace/all/test_package/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) + +find_package(stacktrace REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE stacktrace::stacktrace) diff --git a/recipes/stacktrace/all/test_package/conanfile.py b/recipes/stacktrace/all/test_package/conanfile.py new file mode 100644 index 0000000000000..2e77b4246fa81 --- /dev/null +++ b/recipes/stacktrace/all/test_package/conanfile.py @@ -0,0 +1,25 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/stacktrace/all/test_package/test_package.cpp b/recipes/stacktrace/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..1c240d875828d --- /dev/null +++ b/recipes/stacktrace/all/test_package/test_package.cpp @@ -0,0 +1,38 @@ +#include "stacktrace.h" +#include + +namespace Nu { + +template +struct Alpha { + struct Beta { + void func() { + print_stacktrace(); + } + void func(Type) { + print_stacktrace(); + } + }; +}; + +struct Gamma { + template + void unroll(double d) { + unroll(d); + } +}; + +template<> +void Gamma::unroll<0>(double) { + print_stacktrace(); +} + +} // namespace Nu + +int main(void) { + Nu::Alpha::Beta().func(42); + Nu::Alpha::Beta().func("42"); + Nu::Alpha< Nu::Alpha< std::map > >::Beta().func(); + Nu::Gamma().unroll<5>(42.0); + return EXIT_SUCCESS; +} diff --git a/recipes/stacktrace/config.yml b/recipes/stacktrace/config.yml new file mode 100644 index 0000000000000..40341aa3db6cd --- /dev/null +++ b/recipes/stacktrace/config.yml @@ -0,0 +1,3 @@ +versions: + "1.0.0": + folder: all