From dfa69289728aa4e89b0ea140b9e4c1b2d65d9a68 Mon Sep 17 00:00:00 2001 From: Nobuhiro Ban Date: Wed, 4 Dec 2024 17:59:42 +0900 Subject: [PATCH 1/2] build: use find_dependency in exported CMake Config --- CMakeLists.txt | 3 ++- cmake/Config.cmake.in | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d7d5fe..a34e228 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,9 +36,10 @@ find_package(ICU 60 set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) +set(boost_stacktrace_component stacktrace_backtrace) find_package(Boost 1.65 COMPONENTS container - COMPONENTS stacktrace_backtrace + COMPONENTS ${boost_stacktrace_component} REQUIRED) find_package(Doxygen diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in index 978ab20..595a0ad 100644 --- a/cmake/Config.cmake.in +++ b/cmake/Config.cmake.in @@ -1 +1,4 @@ +include(CMakeFindDependencyMacro) +find_dependency(Boost 1.65 COMPONENTS @boost_stacktrace_component@ REQUIRED) + include("${CMAKE_CURRENT_LIST_DIR}/@package_name@-targets.cmake") From 9f18defbb717d50e485f0acc94a071d32c1b43e3 Mon Sep 17 00:00:00 2001 From: Nobuhiro Ban Date: Fri, 6 Dec 2024 20:06:05 +0900 Subject: [PATCH 2/2] build: change the logic to select Boost stacktrace component; if stacktrace_backtrace is not available, fall back to stacktrace_basic --- CMakeLists.txt | 11 +++++++++-- src/CMakeLists.txt | 6 +++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a34e228..74a22ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,11 +36,18 @@ find_package(ICU 60 set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) -set(boost_stacktrace_component stacktrace_backtrace) find_package(Boost 1.65 COMPONENTS container - COMPONENTS ${boost_stacktrace_component} + OPTIONAL_COMPONENTS stacktrace_backtrace stacktrace_basic REQUIRED) +if(Boost_STACKTRACE_BACKTRACE_FOUND + AND (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")) + set(boost_stacktrace_component stacktrace_backtrace) +elseif(Boost_STACKTRACE_BASIC_FOUND) + set(boost_stacktrace_component stacktrace_basic) +else() + message(FATAL_ERROR "No usable Boost stacktrace component") +endif() find_package(Doxygen OPTIONAL_COMPONENTS dot) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eb86205..5e584e1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -245,7 +245,7 @@ target_compile_definitions(takatori PUBLIC BOOST_ENABLE_ASSERT_DEBUG_HANDLER ) -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") +if (boost_stacktrace_component STREQUAL "stacktrace_backtrace") target_link_libraries(takatori PUBLIC Boost::stacktrace_backtrace PUBLIC ${CMAKE_DL_LIBS} @@ -254,9 +254,9 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") PUBLIC BOOST_STACKTRACE_USE_BACKTRACE ) else() - # FIXME: more compilers target_link_libraries(takatori - PUBLIC Boost::stacktrace_noop + PUBLIC Boost::stacktrace_basic + PUBLIC ${CMAKE_DL_LIBS} ) endif()