Skip to content

Commit

Permalink
build: use backtrace package, add option to include Debug symbols (#121)
Browse files Browse the repository at this point in the history
* build: use backtrace package and set RelWithDebInfo as default

* Apply suggestions from code review

Co-authored-by: kyle-cochran <[email protected]>

* build: add debug flag option

* build: leverage debug option

* build: remove stdc++ and include explicit path to backtrace.h incase we use clang

* style: format

---------

Co-authored-by: Vishwa Shah <[email protected]>
Co-authored-by: kyle-cochran <[email protected]>
  • Loading branch information
3 people authored Jun 23, 2023
1 parent 2f90dd9 commit 58f780a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ build/
*.so*
*.a
*.exe*
*.rpm*
packages/
coverage/

Expand Down
50 changes: 24 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ OPTION (BUILD_UNIT_TESTS "Build tests" ON)
OPTION (BUILD_PYTHON_BINDINGS "Build Python bindings." ON)
OPTION (BUILD_CODE_COVERAGE "Build code coverage" OFF)
OPTION (BUILD_DOCUMENTATION "Build documentation" OFF)
OPTION (BUILD_WITH_CLANG_COMPILER "Use Clang compiler." ON)
OPTION (BUILD_WITH_CLANG_COMPILER "Use Clang compiler." OFF)
OPTION (BUILD_WITH_DEBUG_SYMBOLS "Build with debug symbols." ON)

## Setup

Expand Down Expand Up @@ -113,7 +114,7 @@ MESSAGE (STATUS "C++ compiler: ${CMAKE_CXX_COMPILER}")

PROJECT (${PROJECT_NAME} VERSION ${PROJECT_VERSION_STRING} LANGUAGES "C" "CXX")

SET (CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Limited Configs" FORCE)
SET (CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo" CACHE STRING "Limited Configs" FORCE)

IF (BUILD_CODE_COVERAGE)
SET (CMAKE_BUILD_TYPE "Debug")
Expand All @@ -135,6 +136,10 @@ IF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")

SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wshadow -Wno-deprecated")

ELSE ()

SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wshadow")

ENDIF ()

### C++ 17 support
Expand All @@ -143,7 +148,15 @@ SET (CMAKE_CXX_STANDARD 17)
SET (CMAKE_CXX_STANDARD_REQUIRED ON)
SET (CMAKE_CXX_EXTENSIONS OFF)

## Debugging Options
### Debug symbols

IF (BUILD_WITH_DEBUG_SYMBOLS)

SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")

ENDIF ()

### Debugging Options

SET (CMAKE_VERBOSE_MAKEFILE 0) # Use 1 for debugging, 0 for release

Expand Down Expand Up @@ -219,7 +232,11 @@ ENDFOREACH ()
SET (Boost_USE_STATIC_LIBS ON)
SET (Boost_USE_MULTITHREADED ON)

FIND_PACKAGE ("Boost" "1.82" REQUIRED COMPONENTS "system" "filesystem" "regex" "log" "stacktrace_basic")
FIND_PACKAGE ("Boost" "1.82" REQUIRED COMPONENTS "system" "filesystem" "regex" "log" "stacktrace_backtrace")

## Stacktrace definitions

ADD_DEFINITIONS(-DBOOST_STACKTRACE_USE_BACKTRACE -DBOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE=</usr/lib/gcc/x86_64-linux-gnu/9/include/backtrace.h>)

IF (NOT Boost_FOUND)
MESSAGE (SEND_ERROR "[Boost] not found.")
Expand Down Expand Up @@ -278,10 +295,8 @@ IF (BUILD_SHARED_LIBRARY)
TARGET_INCLUDE_DIRECTORIES (${SHARED_LIBRARY_TARGET} PUBLIC "${PROJECT_SOURCE_DIR}/include/")
TARGET_INCLUDE_DIRECTORIES (${SHARED_LIBRARY_TARGET} PUBLIC "${PROJECT_SOURCE_DIR}/src/")

TARGET_LINK_LIBRARIES (${SHARED_LIBRARY_TARGET} "stdc++")
TARGET_LINK_LIBRARIES (${SHARED_LIBRARY_TARGET} "pthread")
TARGET_LINK_LIBRARIES (${SHARED_LIBRARY_TARGET} "Boost::filesystem" "Boost::log" ${Boost_STACKTRACE_BASIC_LIBRARY})
TARGET_LINK_LIBRARIES (${SHARED_LIBRARY_TARGET} "dl")
TARGET_LINK_LIBRARIES (${SHARED_LIBRARY_TARGET} "Boost::filesystem" "Boost::log" ${Boost_STACKTRACE_BACKTRACE_LIBRARY})
TARGET_LINK_LIBRARIES (${SHARED_LIBRARY_TARGET} "yaml-cpp")

SET_TARGET_PROPERTIES ( ${SHARED_LIBRARY_TARGET} PROPERTIES
Expand Down Expand Up @@ -312,8 +327,7 @@ IF (BUILD_STATIC_LIBRARY)
TARGET_INCLUDE_DIRECTORIES (${STATIC_LIBRARY_TARGET} PUBLIC "${PROJECT_SOURCE_DIR}/include/")

TARGET_LINK_LIBRARIES (${STATIC_LIBRARY_TARGET} "pthread")
TARGET_LINK_LIBRARIES (${STATIC_LIBRARY_TARGET} "Boost::filesystem" "Boost::log" ${Boost_STACKTRACE_BASIC_LIBRARY})
TARGET_LINK_LIBRARIES (${STATIC_LIBRARY_TARGET} "dl")
TARGET_LINK_LIBRARIES (${STATIC_LIBRARY_TARGET} "Boost::filesystem" "Boost::log" ${Boost_STACKTRACE_BACKTRACE_LIBRARY})
TARGET_LINK_LIBRARIES (${STATIC_LIBRARY_TARGET} "yaml-cpp")

SET_TARGET_PROPERTIES (${STATIC_LIBRARY_TARGET} PROPERTIES VERSION ${PROJECT_VERSION_STRING} OUTPUT_NAME ${SHARED_LIBRARY_NAME} CLEAN_DIRECT_OUTPUT 1 INSTALL_RPATH "$ORIGIN/../lib:$ORIGIN/")
Expand Down Expand Up @@ -341,8 +355,7 @@ IF (BUILD_UTILITY)
TARGET_INCLUDE_DIRECTORIES (${UTILITY_TARGET} PUBLIC "${PROJECT_SOURCE_DIR}/include/")

TARGET_LINK_LIBRARIES (${UTILITY_TARGET} "pthread")
TARGET_LINK_LIBRARIES (${UTILITY_TARGET} "Boost::filesystem" "Boost::log" ${Boost_STACKTRACE_BASIC_LIBRARY})
TARGET_LINK_LIBRARIES (${UTILITY_TARGET} "dl")
TARGET_LINK_LIBRARIES (${UTILITY_TARGET} "Boost::filesystem" "Boost::log" ${Boost_STACKTRACE_BACKTRACE_LIBRARY})
TARGET_LINK_LIBRARIES (${UTILITY_TARGET} ${SHARED_LIBRARY_TARGET})

SET_TARGET_PROPERTIES (${UTILITY_TARGET} PROPERTIES VERSION ${PROJECT_VERSION_STRING} OUTPUT_NAME ${SHARED_LIBRARY_NAME} CLEAN_DIRECT_OUTPUT 1 INSTALL_RPATH "$ORIGIN/../lib:$ORIGIN/")
Expand Down Expand Up @@ -522,20 +535,5 @@ SET (CPACK_COMPONENT_GROUP_PYTHON_DESCRIPTION "Python bindings")
SET (CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})

SET (CPACK_DEB_COMPONENT_INSTALL "ON")
SET (CPACK_RPM_COMPONENT_INSTALL "ON")

SET (CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST
/usr
/usr/bin
/usr/include
/usr/lib
/usr/share
/usr/local
/usr/local/bin
/usr/local/include
/usr/local/lib
/usr/local/share
/usr/share/man
)

INCLUDE (CPack)
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ build-packages-cpp-standalone: ## Build C++ packages (standalone)
--volume="/app/build" \
--workdir=/app/build \
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash -c "cmake -DBUILD_WITH_CLANG_COMPILER=OFF -DBUILD_UNIT_TESTS=OFF -DBUILD_PYTHON_BINDINGS=OFF -DCPACK_GENERATOR=DEB .. \
/bin/bash -c "cmake -DBUILD_UNIT_TESTS=OFF -DBUILD_PYTHON_BINDINGS=OFF -DCPACK_GENERATOR=DEB .. \
&& $(MAKE) package \
&& mkdir -p /app/packages/cpp \
&& mv /app/build/*.deb /app/packages/cpp"
Expand All @@ -221,7 +221,7 @@ build-packages-python-standalone: ## Build Python packages (standalone)
--volume="/app/build" \
--workdir=/app/build \
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash -c "cmake -DBUILD_WITH_CLANG_COMPILER=OFF -DBUILD_UNIT_TESTS=OFF -DBUILD_PYTHON_BINDINGS=ON .. \
/bin/bash -c "cmake -DBUILD_UNIT_TESTS=OFF -DBUILD_PYTHON_BINDINGS=ON .. \
&& $(MAKE) -j 4 \
&& mkdir -p /app/packages/python \
&& mv /app/build/bindings/python/dist/*.whl /app/packages/python"
Expand Down Expand Up @@ -471,7 +471,7 @@ test-coverage-cpp-standalone: ## Run C++ tests with coverage (standalone)
--volume="/app/build" \
--workdir=/app/build \
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash -c "cmake -DBUILD_WITH_CLANG_COMPILER=OFF -DBUILD_UNIT_TESTS=ON -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_CODE_COVERAGE=ON .. \
/bin/bash -c "cmake -DBUILD_UNIT_TESTS=ON -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_CODE_COVERAGE=ON .. \
&& $(MAKE) -j $(nproc) \
&& $(MAKE) coverage \
&& (rm -rf /app/coverage || true) \
Expand Down

0 comments on commit 58f780a

Please sign in to comment.