Skip to content

Commit 09545cc

Browse files
committed
moves most third-party packages into /third_party
Proper use of `FetchContent` requires sequencing all calls to `FetchContent_Declare` before any calls to `FetchContent_MakeAvailable`. This allows dependencies with similar `FetchContent` calls to coalesce their declarations, so that projects don't end up repeatedly downloading and building identical packages. We introduce a directory dedicated to third-party packages for two reasons: 1. Moving all of the third-party packages into a single directory improves readability, as it becomes more apparent that calls to `FetchContent_Declare` and `FetchContent_MakeAvailable` are correctly sequenced. 2. Providing each third-party package with its own directory allows us to colocate the `FindPackage_Declare` with any relevant project-local patches. There aren't any at present, so we document how this ought to be done below. libdwarf and libunwind are still handled in `/CMakeLists.txt`. Their requirements seem to be substantially more complicated than all other third-party packages, so we'll migrate them into `/third_party` at a later time. **How to patch a third-party package** Suppose googletest needed to be updated, and requires a local patch so cpptrace can continue to support C++11. To integrate this with FetchContent, we: 1. Make the necessary changes in our local fork of `google/googletest`. 2. Run `git format-patch @{u} -o /path/to/cpptrace/third_party/googletest` to generate the patch files directly into `/third_party/googletest`. 3. Edit `/third_party/googletest/CMakeLists.txt` like so: ``` FetchContent_Declare( "${package_name}" GIT_REPOSITORY "https://github.com/google/googletest.git" - GIT_TAG release-v1.12.1 # last to support C++11 + GIT_TAG v1.17.0 + PATCH_COMMAND git am 0001-makes-foo-c++11-compatible.patch + 0002-makes-bar-c++11-compatible.patch + 0003-makes-baz-c++11-compatible.patch OVERRIDE_FIND_PACKAGE SYSTEM ) ``` This will apply the patches during the `FetchContent` process, and because all the `FetchContent_Declare`s come first, it will ensure that the patches aren't clobbered by any dependencies.
1 parent 829d06a commit 09545cc

File tree

12 files changed

+109
-57
lines changed

12 files changed

+109
-57
lines changed

CMakeLists.txt

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ else()
9191
)
9292
endif()
9393

94+
add_subdirectory(third_party)
95+
9496
# Target that we can modify (can't modify ALIAS targets)
9597
# Target name should not be the same as ${PROJECT_NAME}, causes add_subdirectory issues
9698
set(target_name "cpptrace-lib")
@@ -347,26 +349,6 @@ if(CPPTRACE_GET_SYMBOLS_WITH_LIBDWARF)
347349
endif()
348350
else()
349351
include(FetchContent)
350-
# First, dependencies: Zstd and zlib (currently relying on system zlib)
351-
if(CPPTRACE_USE_EXTERNAL_ZSTD)
352-
find_package(zstd)
353-
else()
354-
cmake_policy(SET CMP0074 NEW)
355-
set(ZSTD_BUILD_PROGRAMS OFF)
356-
set(ZSTD_BUILD_CONTRIB OFF)
357-
set(ZSTD_BUILD_TESTS OFF)
358-
set(ZSTD_BUILD_STATIC ON)
359-
set(ZSTD_BUILD_SHARED OFF)
360-
set(ZSTD_LEGACY_SUPPORT OFF)
361-
FetchContent_Declare(
362-
zstd
363-
SOURCE_SUBDIR build/cmake
364-
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
365-
URL "${CPPTRACE_ZSTD_URL}"
366-
)
367-
FetchContent_MakeAvailable(zstd)
368-
endif()
369-
# Libdwarf itself
370352
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
371353
set(PIC_ALWAYS TRUE)
372354
set(BUILD_DWARFDUMP FALSE)

benchmarking/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ set(
77
${warning_options} $<$<CXX_COMPILER_ID:GNU>:-Wno-infinite-recursion>
88
)
99

10-
include(FetchContent)
11-
set(BENCHMARK_ENABLE_TESTING OFF)
12-
FetchContent_Declare(
13-
googlebench
14-
GIT_REPOSITORY "https://github.com/google/benchmark.git"
15-
GIT_TAG 12235e24652fc7f809373e7c11a5f73c5763fc4c # v1.9.0
16-
)
17-
FetchContent_MakeAvailable(googlebench)
18-
1910
add_executable(benchmark_unwinding unwinding.cpp)
2011
target_compile_features(benchmark_unwinding PRIVATE cxx_std_20)
2112
target_link_libraries(benchmark_unwinding PRIVATE ${target_name} benchmark::benchmark)

test/CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,9 @@ endfunction()
123123

124124
# primarily a workaround for github actions issue https://github.com/actions/runner-images/issues/8659
125125
if(NOT CPPTRACE_SKIP_UNIT)
126-
if(CPPTRACE_USE_EXTERNAL_GTEST)
127-
find_package(GTest)
128-
else()
129-
include(FetchContent)
130-
FetchContent_Declare(
131-
googletest
132-
GIT_REPOSITORY "https://github.com/google/googletest.git"
133-
GIT_TAG 58d77fa8070e8cec2dc1ed015d66b454c8d78850 # v1.12.1, last to support C++11
134-
)
126+
if(NOT CPPTRACE_USE_EXTERNAL_GTEST)
135127
# For Windows: Prevent overriding the parent project's compiler/linker settings
136128
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
137-
FetchContent_MakeAvailable(googletest)
138129
endif()
139130

140131
test_cpptrace(TEST_NAME unittest)

third_party/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
include(FetchContent)
2+
3+
set(CPPTRACE_THIRD_PARTY_DECLARATIONS)
4+
5+
function(declaration_is_unique declaration)
6+
list(FIND "${declaration}" CPPTRACE_THIRD_PARTY_DECLARATIONS declaration_index)
7+
if(NOT declaration_index EQUAL -1)
8+
message(FATAL_ERROR "${declaration} was previously added to CPPTRACE_THIRD_PARTY_DECLARATIONS (index ${declaration_index})")
9+
endif()
10+
endfunction()
11+
12+
include("${CMAKE_CURRENT_SOURCE_DIR}/FetchContent_Declare.cmake")
13+
include("${CMAKE_CURRENT_SOURCE_DIR}/FetchContent_MakeAvailable.cmake")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
add_subdirectory(benchmark)
2+
add_subdirectory(fmt)
3+
add_subdirectory(googletest)
4+
add_subdirectory(libdwarf)
5+
add_subdirectory(lyra)
6+
add_subdirectory(zstd)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
foreach(package IN LISTS CPPTRACE_THIRD_PARTY_DECLARATIONS)
2+
FetchContent_MakeAvailable(${package})
3+
endforeach()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
if(CPPTRACE_BUILD_BENCHMARKING)
2+
set(package_name "googlebench")
3+
declaration_is_unique("${package_name}")
4+
set(BENCHMARK_ENABLE_TESTING OFF)
5+
FetchContent_Declare(
6+
"${package_name}"
7+
GIT_REPOSITORY "https://github.com/google/benchmark.git"
8+
GIT_TAG 12235e24652fc7f809373e7c11a5f73c5763fc4c # v1.9.0
9+
OVERRIDE_FIND_PACKAGE
10+
SYSTEM
11+
)
12+
13+
list(APPEND CPPTRACE_THIRD_PARTY_DECLARATIONS "${package_name}")
14+
endif()

third_party/fmt/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
if(CPPTRACE_BUILD_TOOLS)
2+
set(package_name "fmt")
3+
declaration_is_unique("${package_name}")
4+
FetchContent_Declare(
5+
"${package_name}"
6+
GIT_SHALLOW TRUE
7+
GIT_REPOSITORY "https://github.com/fmtlib/fmt.git"
8+
GIT_TAG "e69e5f977d458f2650bb346dadf2ad30c5320281" # v10.2.1
9+
OVERRIDE_FIND_PACKAGE
10+
SYSTEM
11+
)
12+
13+
list(APPEND CPPTRACE_THIRD_PARTY_DECLARATIONS "${package_name}")
14+
endif()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
if(CPPTRACE_USE_EXTERNAL_GTEST)
2+
find_package(GTest)
3+
else()
4+
set(package_name "googletest")
5+
declaration_is_unique("${package_name}")
6+
FetchContent_Declare(
7+
"${package_name}"
8+
GIT_REPOSITORY "https://github.com/google/googletest.git"
9+
GIT_TAG release-v1.12.1 # last to support C++11
10+
OVERRIDE_FIND_PACKAGE
11+
SYSTEM
12+
)
13+
14+
list(APPEND CPPTRACE_THIRD_PARTY_DECLARATIONS googletest)
15+
endif()

third_party/lyra/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
if(CPPTRACE_BUILD_TOOLS)
2+
set(package_name "lyra")
3+
declaration_is_unique("${package_name}")
4+
FetchContent_Declare(
5+
"${package_name}"
6+
GIT_SHALLOW TRUE
7+
GIT_REPOSITORY "https://github.com/bfgroup/Lyra.git"
8+
GIT_TAG "ee3c076fa6b9d64c9d249a21f5b9b5a8dae92cd8"
9+
OVERRIDE_FIND_PACKAGE
10+
SYSTEM
11+
)
12+
13+
list(APPEND CPPTRACE_THIRD_PARTY_DECLARATIONS lyra)
14+
endif()

0 commit comments

Comments
 (0)