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

update backward-cpp #88

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion osrf_testing_tools_cpp/src/memory_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ target_include_directories(memory_tools
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(memory_tools PRIVATE Backward::Backward)


if(CMAKE_DL_LIBS)
target_link_libraries(memory_tools PUBLIC ${CMAKE_DL_LIBS})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ set(STACK_DETAILS_BFD FALSE CACHE BOOL
set(STACK_DETAILS_DWARF FALSE CACHE BOOL
"Use libdwarf/libelf to read debug info")

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND NOT DEFINED BACKWARD_TESTS)
# If this is a top level CMake project, we most lixely want the tests
set(BACKWARD_TESTS ON CACHE BOOL "Enable tests")
else()
set(BACKWARD_TESTS OFF CACHE BOOL "Enable tests")
endif()
###############################################################################
# CONFIGS
###############################################################################
Expand Down Expand Up @@ -79,18 +73,31 @@ if (STACK_WALKING_LIBUNWIND)

# Disable other unwinders if libunwind is found
set(STACK_WALKING_UNWIND FALSE)
set(STACK_WALKING_BACKTRACE FALSE)
set(STACK_WALKING_BACKTRACE FALSE)
endif()

if (${STACK_DETAILS_AUTO_DETECT} AND NOT WIN32)
if (${STACK_DETAILS_AUTO_DETECT})
if(NOT CMAKE_VERSION VERSION_LESS 3.17)
set(_name_mismatched_arg NAME_MISMATCHED)
endif()
# find libdw
find_path(LIBDW_INCLUDE_DIR NAMES "elfutils/libdw.h" "elfutils/libdwfl.h")
find_library(LIBDW_LIBRARY dw)
# in case it's statically linked, look for all the possible dependencies
find_library(LIBELF_LIBRARY elf)
find_library(LIBPTHREAD_LIBRARY pthread)
find_library(LIBZ_LIBRARY z)
find_library(LIBBZ2_LIBRARY bz2)
find_library(LIBLZMA_LIBRARY lzma)
find_library(LIBZSTD_LIBRARY zstd)
set(LIBDW_INCLUDE_DIRS ${LIBDW_INCLUDE_DIR} )
set(LIBDW_LIBRARIES ${LIBDW_LIBRARY} )
set(LIBDW_LIBRARIES ${LIBDW_LIBRARY}
$<$<BOOL:${LIBELF_LIBRARY}>:${LIBELF_LIBRARY}>
$<$<BOOL:${LIBPTHREAD_LIBRARY}>:${LIBPTHREAD_LIBRARY}>
$<$<BOOL:${LIBZ_LIBRARY}>:${LIBZ_LIBRARY}>
$<$<BOOL:${LIBBZ2_LIBRARY}>:${LIBBZ2_LIBRARY}>
$<$<BOOL:${LIBLZMA_LIBRARY}>:${LIBLZMA_LIBRARY}>
$<$<BOOL:${LIBZSTD_LIBRARY}>:${LIBZSTD_LIBRARY}>)
find_package_handle_standard_args(libdw ${_name_mismatched_arg}
REQUIRED_VARS LIBDW_LIBRARY LIBDW_INCLUDE_DIR)
mark_as_advanced(LIBDW_INCLUDE_DIR LIBDW_LIBRARY)
Expand Down Expand Up @@ -139,6 +146,11 @@ if (${STACK_DETAILS_AUTO_DETECT} AND NOT WIN32)
# If we attempt to link against static bfd, make sure to link its dependencies, too
get_filename_component(bfd_lib_ext "${LIBBFD_LIBRARY}" EXT)
if (bfd_lib_ext STREQUAL "${CMAKE_STATIC_LIBRARY_SUFFIX}")
find_library(LIBSFRAME_LIBRARY NAMES sframe)
if (LIBSFRAME_LIBRARY)
list(APPEND _BACKWARD_LIBRARIES ${LIBSFRAME_LIBRARY})
endif()

list(APPEND _BACKWARD_LIBRARIES iberty z)
endif()

Expand Down Expand Up @@ -190,14 +202,24 @@ if (NOT _BACKWARD_DEFINITIONS)
endif()

if(WIN32)
list(APPEND _BACKWARD_LIBRARIES dbghelp psapi)
list(APPEND _BACKWARD_LIBRARIES dbghelp psapi)
if(MINGW)
set(MINGW_MSVCR_LIBRARY "msvcr90$<$<CONFIG:DEBUG>:d>" CACHE STRING "Mingw MSVC runtime import library")
list(APPEND _BACKWARD_LIBRARIES ${MINGW_MSVCR_LIBRARY})
endif()
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-gcodeview SUPPORT_WINDOWS_DEBUG_INFO)
if(SUPPORT_WINDOWS_DEBUG_INFO)
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--pdb= ")
add_compile_options(-gcodeview)
else()
set(MINGW_MSVCR_LIBRARY "msvcr90$<$<CONFIG:DEBUG>:d>" CACHE STRING "Mingw MSVC runtime import library")
list(APPEND _BACKWARD_LIBRARIES ${MINGW_MSVCR_LIBRARY})
endif()
endif()
endif()

set(BACKWARD_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}")
set(BACKWARD_INCLUDE_DIR
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

set(BACKWARD_HAS_EXTERNAL_LIBRARIES FALSE)
set(FIND_PACKAGE_REQUIRED_VARS BACKWARD_INCLUDE_DIR)
Expand All @@ -208,40 +230,41 @@ endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Backward
REQUIRED_VARS ${FIND_PACKAGE_REQUIRED_VARS}
REQUIRED_VARS ${FIND_PACKAGE_REQUIRED_VARS}
)
list(APPEND _BACKWARD_INCLUDE_DIRS ${BACKWARD_INCLUDE_DIR})

# add_backward, optional bool argument; if passed and true, backward will be included as a system header
macro(add_backward target)
target_include_directories(${target} PRIVATE ${BACKWARD_INCLUDE_DIRS})
message(DEPRECATION "The add_backward() macro is deprecated, use target_link_libraries() to link to "
"one of the exported targets: Backward::Interface, Backward::Object, or Backward::Backward."
)
if ("${ARGN}")
target_include_directories(${target} SYSTEM PRIVATE ${BACKWARD_INCLUDE_DIRS})
else()
target_include_directories(${target} PRIVATE ${BACKWARD_INCLUDE_DIRS})
endif()
set_property(TARGET ${target} APPEND PROPERTY COMPILE_DEFINITIONS ${BACKWARD_DEFINITIONS})
set_property(TARGET ${target} APPEND PROPERTY LINK_LIBRARIES ${BACKWARD_LIBRARIES})
endmacro()

set(BACKWARD_INCLUDE_DIRS ${_BACKWARD_INCLUDE_DIRS} CACHE INTERNAL "_BACKWARD_INCLUDE_DIRS")
set(BACKWARD_INCLUDE_DIRS ${_BACKWARD_INCLUDE_DIRS} CACHE INTERNAL "BACKWARD_INCLUDE_DIRS")
set(BACKWARD_DEFINITIONS ${_BACKWARD_DEFINITIONS} CACHE INTERNAL "BACKWARD_DEFINITIONS")
set(BACKWARD_LIBRARIES ${_BACKWARD_LIBRARIES} CACHE INTERNAL "BACKWARD_LIBRARIES")
mark_as_advanced(BACKWARD_INCLUDE_DIRS BACKWARD_DEFINITIONS BACKWARD_LIBRARIES)

# Expand each definition in BACKWARD_DEFINITIONS to its own cmake var and export
# to outer scope
foreach(var ${BACKWARD_DEFINITIONS})
string(REPLACE "=" ";" var_as_list ${var})
list(GET var_as_list 0 var_name)
list(GET var_as_list 1 var_value)
set(${var_name} ${var_value})
mark_as_advanced(${var_name})
string(REPLACE "=" ";" var_as_list ${var})
list(GET var_as_list 0 var_name)
list(GET var_as_list 1 var_value)
set(${var_name} ${var_value})
mark_as_advanced(${var_name})
endforeach()

if (NOT TARGET Backward::Backward)
add_library(Backward::Backward INTERFACE IMPORTED)
set_target_properties(Backward::Backward PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${BACKWARD_INCLUDE_DIRS}"
INTERFACE_COMPILE_DEFINITIONS "${BACKWARD_DEFINITIONS}"
)
if(BACKWARD_HAS_EXTERNAL_LIBRARIES)
set_target_properties(Backward::Backward PROPERTIES
INTERFACE_LINK_LIBRARIES "${BACKWARD_LIBRARIES}"
)
endif()
# if this file is used from the install tree by find_package(), include the
# file CMake-generated file where the targets are defined
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/BackwardTargets.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/BackwardTargets.cmake)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.14)
project(backward CXX)

# Introduce variables:
Expand All @@ -31,6 +31,22 @@ include(GNUInstallDirs)

include(BackwardConfig.cmake)

###############################################################################
# OPTIONS
###############################################################################

option(BACKWARD_SHARED "Build backward as a shared library" OFF)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND NOT DEFINED BACKWARD_TESTS)
# If this is a top level CMake project, we most lixely want the tests
set(BACKWARD_TESTS ON CACHE BOOL "Enable tests")
else()
set(BACKWARD_TESTS OFF CACHE BOOL "Enable tests")
endif()

###############################################################################
# COMPILER FLAGS
###############################################################################

# check if compiler is nvcc or nvcc_wrapper
set(COMPILER_IS_NVCC false)
get_filename_component(COMPILER_NAME ${CMAKE_CXX_COMPILER} NAME)
Expand All @@ -52,10 +68,6 @@ if (${COMPILER_IS_NVCC})
set(CMAKE_CXX_EXTENSIONS OFF)
endif()

###############################################################################
# COMPILER FLAGS
###############################################################################

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
if (NOT ${COMPILER_IS_NVCC})
Expand All @@ -65,27 +77,43 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
endif()

###############################################################################
# BACKWARD OBJECT
# BACKWARD INTERFACE
###############################################################################

add_library(backward_object OBJECT backward.cpp)
target_compile_definitions(backward_object PRIVATE ${BACKWARD_DEFINITIONS})
target_include_directories(backward_object PRIVATE ${BACKWARD_INCLUDE_DIRS})
set(BACKWARD_ENABLE $<TARGET_OBJECTS:backward_object> CACHE STRING
"Link with this object to setup backward automatically")
add_library(backward_interface INTERFACE)
set_target_properties(backward_interface PROPERTIES EXPORT_NAME Interface)
target_compile_definitions(backward_interface INTERFACE ${BACKWARD_DEFINITIONS})
target_include_directories(backward_interface INTERFACE ${BACKWARD_INCLUDE_DIRS})
if(BACKWARD_HAS_EXTERNAL_LIBRARIES)
target_link_libraries(backward_interface INTERFACE ${BACKWARD_LIBRARIES})
endif()
add_library(Backward::Interface ALIAS backward_interface)

###############################################################################
# BACKWARD OBJECT (Includes backward.cpp)
# (Note that this target is not exported, since CMake currently does not allow
# exporting an OBJECT library.)
###############################################################################

add_library(backward_object OBJECT backward.cpp)
set_target_properties(backward_object PROPERTIES EXPORT_NAME Object)
target_link_libraries(backward_object PUBLIC Backward::Interface)
add_library(Backward::Object ALIAS backward_object)

###############################################################################
# BACKWARD LIBRARY (Includes backward.cpp)
# (Note that the linker will not include unused objects from a static library,
# unless the -Wl,--whole-archive option (or similar) is used.)
###############################################################################
option(BACKWARD_SHARED "Build dynamic backward-cpp shared lib" OFF)

set(libtype STATIC)
if(BACKWARD_SHARED)
set(libtype SHARED)
endif()
add_library(backward ${libtype} backward.cpp)
target_compile_definitions(backward PUBLIC ${BACKWARD_DEFINITIONS})
target_include_directories(backward PUBLIC ${BACKWARD_INCLUDE_DIRS})
set_target_properties(backward PROPERTIES EXPORT_NAME Backward)
target_link_libraries(backward PUBLIC Backward::Interface)
add_library(Backward::Backward ALIAS backward)

###############################################################################
# TESTS
Expand All @@ -102,7 +130,7 @@ if(BACKWARD_TESTS)

add_executable(${test_name} ${src} ${ARGN} $<TARGET_OBJECTS:test_main>)

target_link_libraries(${test_name} PRIVATE Backward::Backward)
target_link_libraries(${test_name} PRIVATE Backward::Interface)

add_test(NAME ${name} COMMAND ${test_name})
endmacro()
Expand All @@ -125,7 +153,7 @@ if(BACKWARD_TESTS)
)

foreach(test ${TESTS})
backward_add_test(test/${test}.cpp ${BACKWARD_ENABLE})
backward_add_test(test/${test}.cpp backward.cpp)
endforeach()
endif()

Expand All @@ -135,5 +163,14 @@ install(
)
install(
FILES "BackwardConfig.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/backward
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
# check if Backward is being used as a top-level project or included as a subproject
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
# export the targets (note that exporting backward_object does not make sense)
install(TARGETS backward_interface backward EXPORT BackwardTargets)
# install a CMake file for the exported targets
install(EXPORT BackwardTargets
NAMESPACE Backward::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
endif()
Loading