Skip to content

Commit

Permalink
refactor: Restructure CMake build and internal definitions (#149)
Browse files Browse the repository at this point in the history
* refactor: Restructure CMake build and internal definitions

This moves a lot of files around, and changes the modulefinder
and symbolizer to be defined via compiletime definitions.

* fix build on windows and android
  • Loading branch information
Swatinem authored Feb 24, 2020
1 parent e4bed02 commit 9ceaa7d
Show file tree
Hide file tree
Showing 57 changed files with 406 additions and 441 deletions.
92 changes: 21 additions & 71 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ project (Sentry-Native LANGUAGES C CXX ASM)

include(CMakeDependentOption)

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(LINUX TRUE)
endif()

OPTION(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" ON)
CMAKE_DEPENDENT_OPTION(WITH_CRASHPAD "Build and use the Crashpad integration" ON "APPLE OR WIN32" OFF)

Expand All @@ -22,10 +26,6 @@ if(WITH_TSAN_OPTION)
link_libraries("-fsanitize=thread")
endif()

include_directories("include")

set(SENTRY_NATIVE_SOURCE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src)

if(BUILD_SHARED_LIBS)
add_definitions(-DSENTRY_BUILD_SHARED)
else()
Expand All @@ -34,6 +34,7 @@ endif()

FIND_PACKAGE(CURL)
if(CURL_FOUND)
set(WITH_CURL TRUE)
add_definitions(-DSENTRY_WITH_LIBCURL_TRANSPORT)
include_directories(${CURL_INCLUDE_DIR})
set(LINK_LIBRARIES ${LINK_LIBRARIES} ${CURL_LIBRARIES})
Expand All @@ -56,75 +57,24 @@ if(WITH_CRASHPAD AND WIN32)
add_definitions(/wd4005)
endif()

file(GLOB SENTRY_NATIVE_SOURCES
${SENTRY_NATIVE_SOURCE_ROOT}/*.c
${SENTRY_NATIVE_SOURCE_ROOT}/transports/sentry_disk_transport.c
${SENTRY_NATIVE_SOURCE_ROOT}/transports/sentry_function_transport.c
)

file(GLOB SENTRY_NATIVE_LIBCURL_TRANSPORT_SOURCES
${SENTRY_NATIVE_SOURCE_ROOT}/transports/sentry_libcurl_transport.c
)

file(GLOB SENTRY_NATIVE_INPROC_BACKEND_SOURCES
${SENTRY_NATIVE_SOURCE_ROOT}/backends/sentry_inproc_*.c
)

file(GLOB SENTRY_NATIVE_UNIX_SOURCES
${SENTRY_NATIVE_SOURCE_ROOT}/unix/*.c
)

file(GLOB SENTRY_NATIVE_LINUX_SOURCES
${SENTRY_NATIVE_SOURCE_ROOT}/linux/*.c
)

file(GLOB SENTRY_NATIVE_DARWIN_SOURCES
${SENTRY_NATIVE_SOURCE_ROOT}/darwin/*.c
)

file(GLOB SENTRY_NATIVE_ANDROID_SOURCES
${SENTRY_NATIVE_SOURCE_ROOT}/linux/sentry_procmaps_modulefinder.c
${SENTRY_NATIVE_SOURCE_ROOT}/unix/sentry_unix_unwinder_libunwindstack.cpp
)
if(ANDROID)
set(WITH_LIBUNWINDSTACK TRUE)
elseif(NOT WIN32)
set(WITH_LIBBACKTRACE TRUE)
endif()

file(GLOB SENTRY_NATIVE_WINDOWS_SOURCES
${SENTRY_NATIVE_SOURCE_ROOT}/windows/*.c
)
include_directories("include")
include_directories("src")

file(GLOB_RECURSE SENTRY_NATIVE_TEST_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/tests/*.c
)

set(SENTRY_NATIVE_ALL_SOURCES ${SENTRY_NATIVE_SOURCES})
if(WIN32)
set(SENTRY_NATIVE_ALL_SOURCES ${SENTRY_NATIVE_ALL_SOURCES}
${SENTRY_NATIVE_WINDOWS_SOURCES})
else()
set(SENTRY_NATIVE_ALL_SOURCES ${SENTRY_NATIVE_ALL_SOURCES}
${SENTRY_NATIVE_UNIX_SOURCES} ${SENTRY_NATIVE_INPROC_BACKEND_SOURCES})
endif()

if(CURL_FOUND)
set(SENTRY_NATIVE_ALL_SOURCES ${SENTRY_NATIVE_ALL_SOURCES}
${SENTRY_NATIVE_LIBCURL_TRANSPORT_SOURCES})
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(SENTRY_NATIVE_ALL_SOURCES ${SENTRY_NATIVE_ALL_SOURCES}
${SENTRY_NATIVE_DARWIN_SOURCES})
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(SENTRY_NATIVE_ALL_SOURCES ${SENTRY_NATIVE_ALL_SOURCES}
${SENTRY_NATIVE_LINUX_SOURCES})

if(LINUX)
set(LINK_LIBRARIES ${LINK_LIBRARIES} "pthread" "dl")
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Android")
set(SENTRY_NATIVE_ALL_SOURCES ${SENTRY_NATIVE_ALL_SOURCES}
${SENTRY_NATIVE_ANDROID_SOURCES})

if(WITH_LIBUNWINDSTACK)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/libunwindstack-ndk/include)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/libunwindstack-ndk/cmake)
set(LINK_LIBRARIES ${LINK_LIBRARIES} "unwindstack")
Expand All @@ -149,17 +99,14 @@ if(WITH_CRASHPAD)
include_directories(external/crashpad external/crashpad/third_party/mini_chromium/mini_chromium)
add_definitions(-DSENTRY_WITH_CRASHPAD_BACKEND)
set(LINK_LIBRARIES ${LINK_LIBRARIES} crashpad_client crashpad_util)
set(SENTRY_NATIVE_ALL_SOURCES ${SENTRY_NATIVE_ALL_SOURCES}
${SENTRY_NATIVE_SOURCE_ROOT}/backends/sentry_crashpad_backend.cpp)
install(TARGETS "crashpad_handler")
endif()

# msgpack
set(SENTRY_NATIVE_ALL_SOURCES ${SENTRY_NATIVE_ALL_SOURCES} vendor/mpack.c)

# ===== sentry library =====

add_library("sentry" ${SENTRY_NATIVE_ALL_SOURCES})
add_library("sentry" "vendor/mpack.c")
add_subdirectory(src)

set_target_properties("sentry" PROPERTIES PUBLIC_HEADER "include/sentry.h")
target_link_libraries("sentry" ${LINK_LIBRARIES})
install(TARGETS "sentry")
Expand All @@ -172,11 +119,14 @@ endif()

# compile tests separately and pass an extra preprocessor define so we can
# switch some internal modes for the unittests.
# TODO: get sources from "sentry"
get_target_property(SENTRY_NATIVE_ALL_SOURCES sentry SOURCES)
add_executable("sentry_tests" EXCLUDE_FROM_ALL
${SENTRY_NATIVE_ALL_SOURCES}
${SENTRY_NATIVE_TEST_SOURCES}
)
target_compile_definitions("sentry_tests" PUBLIC -DSENTRY_UNITTEST)
get_target_property(SENTRY_DEFS sentry COMPILE_DEFINITIONS)
target_compile_definitions("sentry_tests" PUBLIC SENTRY_UNITTEST ${SENTRY_DEFS})
target_link_libraries("sentry_tests" ${LINK_LIBRARIES})

# to fix some issues with tests (dladdr can't find functions otherwise)
Expand Down
121 changes: 121 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
list(APPEND SENTRY_SOURCES
sentry_alloc.c
sentry_alloc.h
sentry_backend.c
sentry_backend.h
sentry_boot.h
sentry_core.c
sentry_core.h
sentry_database.c
sentry_database.h
sentry_envelope.c
sentry_envelope.h
sentry_json.c
sentry_json.h
sentry_modulefinder.h
sentry_path.h
sentry_random.c
sentry_random.h
sentry_scope.c
sentry_scope.h
sentry_slice.c
sentry_slice.h
sentry_string.c
sentry_string.h
sentry_symbolizer.h
sentry_sync.c
sentry_sync.h
sentry_transport.c
sentry_transport.h
sentry_utils.c
sentry_utils.h
sentry_uuid.c
sentry_uuid.h
sentry_value.c
sentry_value.h
path/sentry_path.c
transports/sentry_disk_transport.c
transports/sentry_disk_transport.h
transports/sentry_function_transport.c
transports/sentry_function_transport.h
unwinder/sentry_unwinder.c
)

# generic platform / path / symbolizer
if(WIN32)
list(APPEND SENTRY_SOURCES
sentry_windows_dbghelp.c
sentry_windows_dbghelp.h
path/sentry_path_windows.c
symbolizer/sentry_symbolizer_windows.c
)
else()
list(APPEND SENTRY_SOURCES
sentry_unix_pageallocator.c
sentry_unix_pageallocator.h
sentry_unix_spinlock.h
path/sentry_path_unix.c
symbolizer/sentry_symbolizer_unix.c
)
endif()

# module finder
if(WIN32)
list(APPEND SENTRY_SOURCES
modulefinder/sentry_modulefinder_windows.c
)
elseif(APPLE)
list(APPEND SENTRY_SOURCES
modulefinder/sentry_modulefinder_apple.c
)
elseif(LINUX OR ANDROID)
list(APPEND SENTRY_SOURCES
modulefinder/sentry_modulefinder_linux.c
)
endif()

# curl transport
if(WITH_CURL)
list(APPEND SENTRY_SOURCES
transports/sentry_libcurl_transport.c
transports/sentry_libcurl_transport.h
)
endif()

# backends
if(WITH_CRASHPAD)
list(APPEND SENTRY_SOURCES
backends/sentry_crashpad_backend.cpp
backends/sentry_crashpad_backend.h
)
elseif(NOT WIN32)
list(APPEND SENTRY_SOURCES
backends/sentry_inproc_backend.c
backends/sentry_inproc_backend.h
)
endif()

# unwinder
if(WITH_LIBBACKTRACE)
target_compile_definitions(sentry PUBLIC SENTRY_WITH_UNWINDER_LIBBACKTRACE)
list(APPEND SENTRY_SOURCES
unwinder/sentry_unwinder_libbacktrace.c
)
endif()
if(WITH_LIBUNWINDSTACK)
target_compile_definitions(sentry PUBLIC SENTRY_WITH_UNWINDER_LIBUNWINDSTACK)
list(APPEND SENTRY_SOURCES
unwinder/sentry_unwinder_libunwindstack.cpp
)
endif()
if(WIN32)
target_compile_definitions(sentry PUBLIC SENTRY_WITH_UNWINDER_DBGHELP)
list(APPEND SENTRY_SOURCES
unwinder/sentry_unwinder_dbghelp.c
)
endif()

# make paths absolute
list(TRANSFORM SENTRY_SOURCES PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/")
target_sources(sentry PUBLIC ${SENTRY_SOURCES})
target_compile_definitions(sentry PUBLIC )
10 changes: 5 additions & 5 deletions src/backends/sentry_crashpad_backend.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "sentry_crashpad_backend.h"

extern "C" {
#include "../sentry_alloc.h"
#include "../sentry_core.h"
#include "../sentry_database.h"
#include "../sentry_path.h"
#include "../sentry_utils.h"
#include "sentry_alloc.h"
#include "sentry_core.h"
#include "sentry_database.h"
#include "sentry_path.h"
#include "sentry_utils.h"
}

#include <map>
Expand Down
4 changes: 2 additions & 2 deletions src/backends/sentry_crashpad_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
extern "C" {
#endif

#include "../sentry_boot.h"
#include "sentry_boot.h"

#include "../sentry_backend.h"
#include "sentry_backend.h"

sentry_backend_t *sentry__new_crashpad_backend(void);

Expand Down
12 changes: 6 additions & 6 deletions src/backends/sentry_inproc_backend.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "sentry_inproc_backend.h"

#include "../sentry_alloc.h"
#include "../sentry_core.h"
#include "../sentry_envelope.h"
#include "../sentry_scope.h"
#include "../sentry_sync.h"
#include "../unix/sentry_unix_pageallocator.h"
#include "sentry_alloc.h"
#include "sentry_core.h"
#include "sentry_envelope.h"
#include "sentry_scope.h"
#include "sentry_sync.h"
#include "sentry_unix_pageallocator.h"
#include <string.h>

#define SIGNAL_DEF(Sig, Desc) \
Expand Down
6 changes: 3 additions & 3 deletions src/backends/sentry_inproc_backend.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef SENTRY_INPROC_BACKEND_H_INCLUDED
#define SENTRY_INPROC_BACKEND_H_INCLUDED

#include "../sentry_boot.h"
#include "sentry_boot.h"

#include "../sentry_backend.h"
#include "sentry_backend.h"

sentry_backend_t *sentry__new_inproc_backend(void);

#endif
#endif
8 changes: 0 additions & 8 deletions src/darwin/sentry_darwin_modulefinder.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "sentry_darwin_modulefinder.h"
#include "../sentry_sync.h"
#include "../sentry_value.h"
#include "sentry_boot.h"

#include "sentry_sync.h"
#include "sentry_value.h"

#include <dlfcn.h>
#include <limits.h>
Expand Down Expand Up @@ -125,7 +126,7 @@ remove_image(const struct mach_header *mh, intptr_t vmaddr_slide)
}

sentry_value_t
sentry__darwin_modules_get_list(void)
sentry__modules_get_list(void)
{
sentry__mutex_lock(&g_mutex);
if (!g_initialized) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "sentry_procmaps_modulefinder.h"
#include "../sentry_core.h"
#include "../sentry_path.h"
#include "../sentry_string.h"
#include "../sentry_sync.h"
#include "../sentry_value.h"
#include "sentry_modulefinder_linux.h"

#include "sentry_core.h"
#include "sentry_path.h"
#include "sentry_string.h"
#include "sentry_sync.h"
#include "sentry_value.h"

#include <arpa/inet.h>
#include <elf.h>
#include <fcntl.h>
Expand Down Expand Up @@ -334,7 +336,7 @@ load_modules(sentry_value_t modules)
}

sentry_value_t
sentry__procmaps_modules_get_list(void)
sentry__modules_get_list(void)
{
sentry__mutex_lock(&g_mutex);
if (!g_initialized) {
Expand Down
Loading

0 comments on commit 9ceaa7d

Please sign in to comment.