Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build native libs via cmake #29

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ build/
*.log
*.so
local.properties
.cxx
Empty file modified LICENSE-docs
100755 → 100644
Empty file.
13 changes: 13 additions & 0 deletions src/java/xcrash/xcrash_lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
consumerProguardFiles 'proguard-rules.pro'
externalNativeBuild {
cmake {
cppFlags "-std=c++11"
}
}
ndk {
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
}
compileOptions {
sourceCompatibility rootProject.ext.javaVersion
Expand All @@ -20,6 +28,11 @@ android {
minifyEnabled false
}
}
externalNativeBuild {
cmake {
path "../../../native/CMakeLists.txt"
}
}
}

apply from: rootProject.file('gradle/check.gradle')
Expand Down
2 changes: 1 addition & 1 deletion src/java/xcrash/xcrash_sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
versionCode 1
versionName "1.0"
ndk {
abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
}
compileOptions {
Expand Down
9 changes: 9 additions & 0 deletions src/native/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.6)

PROJECT(xcrash_native)

FIND_LIBRARY(libdl dl)
FIND_LIBRARY(liblog log)
ADD_SUBDIRECTORY(common)
ADD_SUBDIRECTORY(libxcrash/jni)
ADD_SUBDIRECTORY(libxcrash_dumper/jni)
31 changes: 31 additions & 0 deletions src/native/build_via_cmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
if [ ! -d ${ANDROID_SDK_ROOT} ] || [ ! -d ${ANDROID_NDK_ROOT} ]; then
echo '# Please check the env ANDROID_SDK_ROOT & ANDROID_NDK_ROOT before run this script:
# ANDROID_SDK_ROOT="${HOME}/Android/Sdk" # macOS
# ANDROID_NDK_ROOT="${ANDROID_SDK_ROOT}/ndk-bundle" # deps'
exit -1
fi
ANDROID_CMAKE_TOOLCHAIN_FILE="${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake"
XCRASH_NATIVE_ROOT="$(cd `dirname $0`;pwd)"
XCRASH_NATIVE_ROOT="${XCRASH_NATIVE_ROOT:-$(pwd)}" # double check
XCRASH_BUILD_DIRECTORY="${XCRASH_NATIVE_ROOT}/build"
XCRASH_OUTPUT_DIRECTORY="${XCRASH_NATIVE_ROOT/src\/native/src\/java\/xcrash\/xcrash_lib\/src\/main\/jniLibs}"

for abi in armeabi-v7a arm64-v8a x86 x86_64
do
rm -rf ${XCRASH_BUILD_DIRECTORY}
mkdir -p ${XCRASH_BUILD_DIRECTORY}
pushd ${XCRASH_BUILD_DIRECTORY}
EXEC_CMD="cmake ${XCRASH_NATIVE_ROOT} \
-DCMAKE_TOOLCHAIN_FILE=\"${ANDROID_CMAKE_TOOLCHAIN_FILE}\" \
-DCMAKE_BUILD_TYPE=Release \
-DANDROID_TOOLCHAIN=clang \
-DANDROID_NATIVE_API_LEVEL=19 \
-DANDROID_ABI=${abi} \
-DANDROID_NDK=\"${ANDROID_NDK_ROOT}\" \
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=\"${XCRASH_OUTPUT_DIRECTORY}/${abi}\""
echo "${EXEC_CMD[@]}"
eval "${EXEC_CMD[@]}"
make
popd
done
19 changes: 19 additions & 0 deletions src/native/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SET(xcrash_common_sources
xcc_b64.c
xcc_fmt.c
xcc_libc_support.c
xcc_meminfo.c
xcc_signal.c
xcc_unwind.c
xcc_unwind_clang.c
xcc_unwind_libcorkscrew.c
xcc_unwind_libunwind.c
xcc_util.c)
ADD_LIBRARY(xcrash_common STATIC ${xcrash_common_sources})
TARGET_INCLUDE_DIRECTORIES(xcrash_common PUBLIC .)
TARGET_COMPILE_OPTIONS(xcrash_common
PRIVATE
-std=c11
-Weverything
-Werror
-O0)
18 changes: 18 additions & 0 deletions src/native/libxcrash/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
SET(xcrash_sources
xc_common.c
xc_crash.c
xc_dl.c
xc_fallback.c
xc_jni.c
xc_test.c
xc_trace.c
xc_util.c)
ADD_LIBRARY(xcrash SHARED ${xcrash_sources})
TARGET_INCLUDE_DIRECTORIES(xcrash PRIVATE .)
TARGET_COMPILE_OPTIONS(xcrash
PRIVATE
-std=c11
-Weverything
-Werror
-fvisibility=hidden)
TARGET_LINK_LIBRARIES(xcrash xcrash_common ${libdl} ${liblog})
33 changes: 33 additions & 0 deletions src/native/libxcrash_dumper/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
ADD_SUBDIRECTORY(lzma)

SET(xcrash_dumper_sources
xcd_arm_exidx.c
xcd_core.c
xcd_dwarf.c
xcd_elf.c
xcd_elf_interface.c
xcd_frames.c
xcd_map.c
xcd_maps.c
xcd_md5.c
xcd_memory.c
xcd_memory_buf.c
xcd_memory_file.c
xcd_memory_remote.c
xcd_process.c
xcd_regs_arm.c
xcd_regs_arm64.c
xcd_regs_x86.c
xcd_regs_x86_64.c
xcd_sys.c
xcd_thread.c
xcd_util.c)
ADD_LIBRARY(xcrash_dumper SHARED ${xcrash_dumper_sources})
TARGET_INCLUDE_DIRECTORIES(xcrash_dumper PRIVATE .)
TARGET_COMPILE_OPTIONS(xcrash_dumper
PRIVATE
-std=c11
-Weverything
-Werror
-fvisibility=hidden)
TARGET_LINK_LIBRARIES(xcrash_dumper PRIVATE xcrash_common lzma ${libdl} ${liblog})
39 changes: 39 additions & 0 deletions src/native/libxcrash_dumper/jni/lzma/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
SET(lzma_sources
7zAlloc.c
7zCrc.c
7zCrcOpt.c
Alloc.c
Bra.c
Bra86.c
BraIA64.c
CpuArch.c
Delta.c
Lzma2Dec.c
LzmaDec.c
Sha256.c
Xz.c
XzCrc64.c
XzCrc64Opt.c
XzDec.c)
ADD_LIBRARY(lzma STATIC ${lzma_sources})
TARGET_INCLUDE_DIRECTORIES(lzma PUBLIC .)
TARGET_COMPILE_OPTIONS(lzma
PRIVATE
-std=c11
-Weverything
-Werror
-Wno-enum-conversion
-Wno-reserved-id-macro
-Wno-undef
-Wno-missing-prototypes
-Wno-missing-variable-declarations
-Wno-cast-align
-Wno-sign-conversion
-Wno-assign-enum
-Wno-unused-macros
-Wno-padded
-Wno-cast-qual
-Wno-strict-prototypes
-fPIC
-D_7ZIP_ST)
TARGET_LINK_LIBRARIES(lzma)