From 02dda255d2626ea2ed3e5985b1a8b6cdc806ba1e Mon Sep 17 00:00:00 2001 From: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com> Date: Tue, 25 Jul 2023 16:45:49 -0400 Subject: [PATCH] Force shared library under libbacktrace, allow shared or static otherwise (#22) --- .github/workflows/cmake-integration.yml | 4 +- .github/workflows/performance-tests.yml | 8 +-- CMakeLists.txt | 87 +++++++++++++------------ README.md | 6 +- ci/speedtest.py | 5 +- ci/test-all-configs.py | 12 ++-- 6 files changed, 60 insertions(+), 62 deletions(-) diff --git a/.github/workflows/cmake-integration.yml b/.github/workflows/cmake-integration.yml index 4b4ffd1..1933f8c 100644 --- a/.github/workflows/cmake-integration.yml +++ b/.github/workflows/cmake-integration.yml @@ -32,7 +32,7 @@ jobs: tag=$(git rev-parse --abbrev-ref HEAD) mkdir build cd build - cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=On + cmake .. -DCMAKE_BUILD_TYPE=Debug sudo make -j install cd ../.. cp -rv cpptrace/test/findpackage-integration . @@ -64,7 +64,7 @@ jobs: tag=$(git rev-parse --abbrev-ref HEAD) mkdir build cd build - cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=On + cmake .. -DCMAKE_BUILD_TYPE=Debug sudo make -j install cd ../.. cp -rv cpptrace/test/findpackage-integration . diff --git a/.github/workflows/performance-tests.yml b/.github/workflows/performance-tests.yml index 5ac2fd5..c331bc6 100644 --- a/.github/workflows/performance-tests.yml +++ b/.github/workflows/performance-tests.yml @@ -35,13 +35,12 @@ jobs: -DCMAKE_CXX_STANDARD=${{matrix.std}} \ ${{matrix.config}} \ -DCPPTRACE_BACKTRACE_PATH=/usr/lib/gcc/x86_64-linux-gnu/11/include/backtrace.h \ - -DCPPTRACE_BUILD_SPEEDTEST=On \ - -DBUILD_SHARED_LIBS=On + -DCPPTRACE_BUILD_SPEEDTEST=On make -j - name: test working-directory: build run: | - ./speedtest | python3 ../ci/speedtest.py ${{matrix.config}} + ./speedtest | python3 ../ci/speedtest.py ${{matrix.compiler}} ${{matrix.config}} # TODO: For some reason this is slow on github's runner #performancetest-windows: # runs-on: windows-2019 @@ -67,8 +66,7 @@ jobs: # -DCMAKE_CXX_COMPILER=${{matrix.compiler}} ` # -DCMAKE_CXX_STANDARD=${{matrix.std}} ` # ${{matrix.config}} ` - # -DCPPTRACE_BUILD_SPEEDTEST=On ` - # -DBUILD_SHARED_LIBS=On + # -DCPPTRACE_BUILD_SPEEDTEST=On # msbuild .\cpptrace.sln # - name: test # working-directory: build diff --git a/CMakeLists.txt b/CMakeLists.txt index 0225ebc..c226134 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,46 +10,10 @@ project( LANGUAGES CXX ) -set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) - -set(CMAKE_POSITION_INDEPENDENT_CODE ON) - include(GNUInstallDirs) include(CheckCXXSourceCompiles) include(CheckCXXCompilerFlag) -file(GLOB_RECURSE sources src/*.cpp) -add_library(cpptrace ${sources} include/cpptrace/cpptrace.hpp) - -target_include_directories( - cpptrace - PUBLIC - $ - $ -) - -# TODO -target_compile_features( - cpptrace - PUBLIC - cxx_std_11 -) - -set_target_properties( - cpptrace - PROPERTIES - CXX_STANDARD_REQUIRED TRUE - CXX_EXTENSIONS OFF -) - -target_compile_options( - cpptrace - PRIVATE - $<$>:-Wall -Wextra -Werror=return-type -Wshadow -Wundef> - $<$:-Wuseless-cast -Wnonnull-compare> - $<$:/W4 /WX /permissive-> -) - option(CPPTRACE_FULL_TRACE_WITH_LIBBACKTRACE "" OFF) option(CPPTRACE_FULL_TRACE_WITH_STACKTRACE "" OFF) @@ -252,6 +216,50 @@ else() #message(STATUS "Manual demangling back-end specified") endif() +# =============================================== Now define the library =============================================== + +set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +file(GLOB_RECURSE sources src/*.cpp) + +# TODO: This feels like a hack. +if(CPPTRACE_FULL_TRACE_WITH_LIBBACKTRACE OR CPPTRACE_GET_SYMBOLS_WITH_LIBBACKTRACE) + add_library(cpptrace SHARED ${sources} include/cpptrace/cpptrace.hpp) +else() + add_library(cpptrace ${sources} include/cpptrace/cpptrace.hpp) +endif() + +target_include_directories( + cpptrace + PUBLIC + $ + $ +) + +# TODO +target_compile_features( + cpptrace + PUBLIC + cxx_std_11 +) + +set_target_properties( + cpptrace + PROPERTIES + CXX_STANDARD_REQUIRED TRUE + CXX_EXTENSIONS OFF +) + +target_compile_options( + cpptrace + PRIVATE + $<$>:-Wall -Wextra -Werror=return-type -Wshadow -Wundef> + $<$:-Wuseless-cast -Wnonnull-compare> + $<$:/W4 /WX /permissive-> +) + # =============================================== Apply options to build =============================================== function(check_backtrace_error) @@ -369,13 +377,6 @@ endif() # ====================================================================================================================== -#target_link_libraries( -# cpptrace -# PRIVATE -# #$<$:dbghelp> -# #${CMAKE_DL_LIBS} -#) - if(CMAKE_BUILD_TYPE STREQUAL "") message(FATAL_ERROR "Setting CMAKE_BUILD_TYPE is required") endif() diff --git a/README.md b/README.md index a6e9e1a..057ac23 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ git clone https://github.com/jeremy-rifkin/cpptrace.git # optional: git checkout mkdir cpptrace/build cd cpptrace/build -cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=On +cmake .. -DCMAKE_BUILD_TYPE=Release make -j sudo make install ``` @@ -95,7 +95,7 @@ git clone https://github.com/jeremy-rifkin/cpptrace.git # optional: git checkout mkdir cpptrace/build cd cpptrace/build -cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=On +cmake .. -DCMAKE_BUILD_TYPE=Release msbuild cpptrace.sln msbuild INSTALL.vcxproj ``` @@ -113,7 +113,7 @@ git clone https://github.com/jeremy-rifkin/cpptrace.git # optional: git checkout mkdir cpptrace/build cd cpptrace/build -cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=On -DCMAKE_INSTALL_PREFIX=$HOME/wherever +cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$HOME/wherever make -j sudo make install ``` diff --git a/ci/speedtest.py b/ci/speedtest.py index 93627f0..89614f9 100644 --- a/ci/speedtest.py +++ b/ci/speedtest.py @@ -12,7 +12,10 @@ def main(): dwarf4 = any(["DWARF4" in arg for arg in sys.argv[1:]]) dwarf5 = any(["DWARF5" in arg for arg in sys.argv[1:]]) - expect_slow = dwarf4 + clang = any(["clang" in arg for arg in sys.argv[1:]]) + # Somehow -gdwarf-4 clang is fast after a completely unrelated PR? Weird. Something to do with static linking...? + # https://github.com/jeremy-rifkin/cpptrace/pull/22 + expect_slow = dwarf4 and not clang threshold = 100 # ms diff --git a/ci/test-all-configs.py b/ci/test-all-configs.py index d2d59ef..d5e4b13 100644 --- a/ci/test-all-configs.py +++ b/ci/test-all-configs.py @@ -157,8 +157,7 @@ def build(matrix): f"-D{matrix['symbols']}=On", f"-D{matrix['demangle']}=On", "-DCPPTRACE_BACKTRACE_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/include/backtrace.h", - "-DCPPTRACE_BUILD_TEST=On", - "-DBUILD_SHARED_LIBS=On" + "-DCPPTRACE_BUILD_TEST=On" ] if matrix['symbols'] == "CPPTRACE_GET_SYMBOLS_WITH_LIBDL": args.append("-DCPPTRACE_BUILD_TEST_RDYNAMIC=On") @@ -175,8 +174,7 @@ def build(matrix): f"-D{matrix['unwind']}=On", f"-D{matrix['symbols']}=On", f"-D{matrix['demangle']}=On", - "-DCPPTRACE_BUILD_TEST=On", - "-DBUILD_SHARED_LIBS=On" + "-DCPPTRACE_BUILD_TEST=On" ] if matrix["compiler"] == "g++": args.append("-GUnix Makefiles") @@ -196,8 +194,7 @@ def build_full_or_auto(matrix): f"-DCMAKE_CXX_COMPILER={matrix['compiler']}", f"-DCMAKE_CXX_STANDARD={matrix['std']}", f"-DCPPTRACE_BACKTRACE_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/include/backtrace.h", - "-DCPPTRACE_BUILD_TEST=On", - "-DBUILD_SHARED_LIBS=On" + "-DCPPTRACE_BUILD_TEST=On" ] if matrix["config"] != "": args.append(f"{matrix['config']}") @@ -211,8 +208,7 @@ def build_full_or_auto(matrix): f"-DCMAKE_BUILD_TYPE={matrix['target']}", f"-DCMAKE_CXX_COMPILER={matrix['compiler']}", f"-DCMAKE_CXX_STANDARD={matrix['std']}", - "-DCPPTRACE_BUILD_TEST=On", - "-DBUILD_SHARED_LIBS=On" + "-DCPPTRACE_BUILD_TEST=On" ] if matrix["config"] != "": args.append(f"{matrix['config']}")