Skip to content

Commit 8a2ddfc

Browse files
authored
build: Add CMake files for crashpad (#2)
* build: add CMake files for crashpad * add explicit submodule for mini_chromium * make cmake builds work on windows * review feedback, add separate getsentry README * better document changes, add update instructions
1 parent 49414c4 commit 8a2ddfc

18 files changed

+1177
-9
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,5 @@
2121
/third_party/linux/sysroot
2222
/third_party/lss/lss
2323
/third_party/gyp/gyp
24-
/third_party/mini_chromium/mini_chromium
25-
/third_party/zlib/zlib
2624
/xcodebuild
2725
tags

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "third_party/mini_chromium/mini_chromium"]
2+
path = third_party/mini_chromium/mini_chromium
3+
url = https://chromium.googlesource.com/chromium/mini_chromium
4+
[submodule "third_party/zlib/zlib"]
5+
path = third_party/zlib/zlib
6+
url = https://chromium.googlesource.com/chromium/src/third_party/zlib

CMakeLists.txt

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
cmake_minimum_required(VERSION 3.0)
2+
project(crashpad LANGUAGES C CXX)
3+
4+
if(WIN32)
5+
enable_language(ASM_MASM)
6+
else()
7+
enable_language(ASM)
8+
endif()
9+
10+
set(CMAKE_CXX_STANDARD 14)
11+
set(CMAKE_CXX_STANDARD_REQUIRED True)
12+
13+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
14+
set(LINUX TRUE)
15+
endif()
16+
17+
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
18+
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third_party/mini_chromium/mini_chromium")
19+
20+
# These should really be in `compat`, but we want them for the whole project
21+
if(APPLE)
22+
include_directories(SYSTEM "compat/mac")
23+
else()
24+
include_directories(PUBLIC "compat/non_mac")
25+
endif()
26+
27+
if(LINUX OR ANDROID)
28+
include_directories(SYSTEM "compat/linux")
29+
endif()
30+
if(ANDROID)
31+
include_directories(SYSTEM "compat/android")
32+
endif()
33+
34+
if(WIN32)
35+
include_directories(SYSTEM "compat/win")
36+
else()
37+
include_directories(PUBLIC "compat/non_win")
38+
endif()
39+
40+
if(NOT LINUX AND NOT ANDROID)
41+
include_directories(SYSTEM "compat/non_elf")
42+
endif()
43+
44+
if(WIN32)
45+
add_definitions(
46+
/DNOMINMAX
47+
/DUNICODE
48+
/DWIN32_LEAN_AND_MEAN
49+
/D_CRT_SECURE_NO_WARNINGS
50+
/D_HAS_EXCEPTIONS=0
51+
/D_UNICODE
52+
/FS
53+
/W4
54+
/WX
55+
/Zi
56+
/bigobj # Support larger number of sections in obj file.
57+
/wd4100 # Unreferenced formal parameter.
58+
/wd4127 # Conditional expression is constant.
59+
/wd4324 # Structure was padded due to alignment specifier.
60+
/wd4351 # New behavior: elements of array will be default initialized.
61+
/wd4577 # 'noexcept' used with no exception handling mode specified.
62+
/wd4996 # 'X' was declared deprecated.
63+
)
64+
endif()
65+
66+
add_subdirectory(client)
67+
add_subdirectory(compat)
68+
add_subdirectory(handler)
69+
add_subdirectory(minidump)
70+
add_subdirectory(snapshot)
71+
add_subdirectory(tools)
72+
add_subdirectory(util)
73+
add_subdirectory(third_party/mini_chromium)
74+
75+
if(WIN32)
76+
add_subdirectory(third_party/getopt)
77+
add_subdirectory(third_party/zlib)
78+
endif()

Makefile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@ PATH := $(PWD)/../depot_tools:$(PATH)
44
all:
55
echo 'Nothing to do' && exit 1
66

7-
build:
7+
build-with-gn:
88
gn gen out/Default
99
ninja -C out/Default
10-
.PHONY: build
10+
.PHONY: build-with-gn
1111

12-
update:
12+
build-with-cmake:
13+
mkdir -p cmakebuild
14+
cd cmakebuild; cmake ..
15+
cmake --build cmakebuild --parallel
16+
.PHONY: build-with-cmake
17+
18+
update-with-gclient:
1319
gclient sync
20+
.PHONY: update-with-gclient
1421

15-
example:
22+
example: build-with-gn
1623
g++ -g \
1724
-o example example.cpp \
1825
-I. -I./third_party/mini_chromium/mini_chromium \

README.getsentry.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Sentry Modifications
2+
3+
- File attachments support for MacOS and Windows. Based on changes made in
4+
https://github.com/Youw/crashpad/, distributed with Apache 2.0 License.
5+
- Add `throws` declaration to `memfd_create` for compatibility with different
6+
libc versions.
7+
- Build System Changes Listed Below
8+
9+
# Build System Changes
10+
11+
In order to minimize external dependencies, and to better integrate with
12+
`sentry-native`, this fork replaced usage of `depo_tools` with explicit
13+
submodules, and added CMake files for building.
14+
15+
Both submodules and CMake files currently only support building on macOS and
16+
Windows, and do only export the necessary libraries and executables to
17+
integrate the crashpad client.
18+
19+
When updating this fork, make sure to keep the files in sync, as explained
20+
below.
21+
22+
## Submodules
23+
24+
For macOS and Windows support, only `third_party/mini_chromium` and
25+
`third_party/zlib` are needed.
26+
27+
The specific submodule commit hashes can be found in the `./DEPS` file.
28+
29+
## CMake Integration
30+
31+
To allow building crashpad with CMake, the following CMake files were created
32+
by manually translating the `BUILD.gn` files in the same folders (and following
33+
included files):
34+
35+
- `./CMakeLists.txt`
36+
- `./client/CMakeLists.txt`
37+
- `./compat/CMakeLists.txt`
38+
- `./handler/CMakeLists.txt`
39+
- `./minidump/CMakeLists.txt`
40+
- `./snapshot/CMakeLists.txt`
41+
- `./third_party/getopt/CMakeLists.txt`
42+
- `./third_party/mini_chromium/CMakeLists.txt`
43+
- `./third_party/lib/CMakeLists.txt`
44+
- `./tools/CMakeLists.txt`
45+
- `./util/CMakeLists.txt`
46+
47+
The important thing here is to keep the list of source files in sync when
48+
updating.
49+
50+
# How To Update
51+
52+
- Bump the submodules to the commit hashes specified in `./DEPS`
53+
- Go through the changes in `BUILD.gn` files, and apply them to the
54+
corresponding `CMakeLists.txt`. See the list above.

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ https://chromium.googlesource.com/crashpad/crashpad.
4343

4444
## Sentry modifications
4545

46-
File attachments support for MacOS and Windows.
47-
48-
Based on changes made in https://github.com/Youw/crashpad/, distributed with Apache 2.0 License.
46+
See [README.getsentry.md](README.getsentry.md) for more information on the
47+
changes, and on maintaining the fork.
4948

5049
Generating patch:
5150

client/CMakeLists.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
list(APPEND CLIENT_SOURCES
2+
annotation.cc
3+
annotation.h
4+
annotation_list.cc
5+
annotation_list.h
6+
crash_report_database.cc
7+
crash_report_database.h
8+
crashpad_client.h
9+
crashpad_info.cc
10+
crashpad_info.h
11+
prune_crash_reports.cc
12+
prune_crash_reports.h
13+
settings.cc
14+
settings.h
15+
simple_address_range_bag.h
16+
simple_string_dictionary.h
17+
simulate_crash.h
18+
)
19+
20+
if(APPLE)
21+
list(APPEND CLIENT_SOURCES
22+
crash_report_database_mac.mm
23+
crashpad_client_mac.cc
24+
simulate_crash_mac.cc
25+
simulate_crash_mac.h
26+
)
27+
endif()
28+
29+
if(LINUX OR ANDROID)
30+
list(APPEND CLIENT_SOURCES
31+
crashpad_client_linux.cc
32+
simulate_crash_linux.h
33+
client_argv_handling.cc
34+
client_argv_handling.h
35+
crashpad_info_note.S
36+
crash_report_database_generic.cc
37+
)
38+
endif()
39+
40+
if(WIN32)
41+
list(APPEND CLIENT_SOURCES
42+
crash_report_database_win.cc
43+
crashpad_client_win.cc
44+
simulate_crash_win.h
45+
)
46+
endif()
47+
48+
add_library(crashpad_client STATIC ${CLIENT_SOURCES})
49+
target_link_libraries(crashpad_client
50+
crashpad_compat
51+
crashpad_util
52+
mini_chromium
53+
)
54+
55+
if(WIN32)
56+
target_link_libraries(crashpad_client "rpcrt4")
57+
target_compile_options(crashpad_client PUBLIC "/wd4201")
58+
endif()

compat/CMakeLists.txt

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
list(APPEND COMPAT_SOURCES "")
2+
3+
if(APPLE)
4+
list(APPEND COMPAT_SOURCES
5+
mac/AvailabilityMacros.h
6+
mac/kern/exc_resource.h
7+
mac/mach-o/loader.h
8+
mac/mach/mach.h
9+
mac/sys/resource.h
10+
)
11+
else()
12+
list(APPEND COMPAT_SOURCES
13+
non_mac/mach-o/loader.h
14+
non_mac/mach/mach.h
15+
non_mac/mach/machine.h
16+
non_mac/mach/vm_prot.h
17+
)
18+
endif()
19+
20+
if(LINUX OR ANDROID)
21+
list(APPEND COMPAT_SOURCES
22+
linux/signal.h
23+
linux/sys/mman.cc
24+
linux/sys/mman.h
25+
linux/sys/ptrace.h
26+
linux/sys/user.h
27+
)
28+
endif()
29+
30+
if(ANDROID)
31+
list(APPEND COMPAT_SOURCES
32+
android/android/api-level.cc
33+
android/android/api-level.h
34+
android/dlfcn_internal.cc
35+
android/dlfcn_internal.h
36+
android/elf.h
37+
android/linux/elf.h
38+
android/linux/prctl.h
39+
android/linux/ptrace.h
40+
android/sched.h
41+
android/sys/epoll.cc
42+
android/sys/epoll.h
43+
android/sys/mman.cc
44+
android/sys/mman.h
45+
android/sys/syscall.h
46+
android/sys/user.h
47+
)
48+
endif()
49+
50+
if(WIN32)
51+
list(APPEND COMPAT_SOURCES
52+
win/getopt.h
53+
win/strings.cc
54+
win/strings.h
55+
win/sys/types.h
56+
win/time.cc
57+
win/time.h
58+
win/winbase.h
59+
win/winnt.h
60+
win/winternl.h
61+
)
62+
else()
63+
list(APPEND COMPAT_SOURCES
64+
non_win/dbghelp.h
65+
non_win/minwinbase.h
66+
non_win/timezoneapi.h
67+
non_win/verrsrc.h
68+
non_win/windows.h
69+
non_win/winnt.h
70+
)
71+
endif()
72+
73+
if(NOT LINUX AND NOT ANDROID)
74+
list(APPEND COMPAT_SOURCES
75+
non_elf/elf.h
76+
)
77+
endif()
78+
79+
if(APPLE)
80+
add_library(crashpad_compat INTERFACE)
81+
list(TRANSFORM COMPAT_SOURCES PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/")
82+
target_sources(crashpad_compat INTERFACE ${COMPAT_SOURCES})
83+
else()
84+
add_library(crashpad_compat STATIC ${COMPAT_SOURCES})
85+
endif()
86+
87+
if(WIN32)
88+
target_link_libraries(crashpad_compat getopt)
89+
endif()

0 commit comments

Comments
 (0)