Use CMake for Android builds (externalNativeBuild)
Signed-off-by: Lukas Lihotzki <lukas@lihotzki.de>
This commit is contained in:
parent
18ad6cb067
commit
2949811917
23 changed files with 36 additions and 120 deletions
|
@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.4)
|
||||||
|
|
||||||
project(olm VERSION 3.2.2 LANGUAGES CXX C)
|
project(olm VERSION 3.2.2 LANGUAGES CXX C)
|
||||||
|
|
||||||
|
option(OLM_ANDROID_JNI "Add Android JNI support" OFF)
|
||||||
option(OLM_TESTS "Build tests" ON)
|
option(OLM_TESTS "Build tests" ON)
|
||||||
option(BUILD_SHARED_LIBS "Build as a shared library" ON)
|
option(BUILD_SHARED_LIBS "Build as a shared library" ON)
|
||||||
|
|
||||||
|
@ -48,6 +49,21 @@ add_library(olm
|
||||||
lib/curve25519-donna/curve25519-donna.c)
|
lib/curve25519-donna/curve25519-donna.c)
|
||||||
add_library(Olm::Olm ALIAS olm)
|
add_library(Olm::Olm ALIAS olm)
|
||||||
|
|
||||||
|
if(OLM_ANDROID_JNI)
|
||||||
|
target_sources(olm PRIVATE
|
||||||
|
jni/olm_account.cpp
|
||||||
|
jni/olm_session.cpp
|
||||||
|
jni/olm_jni_helper.cpp
|
||||||
|
jni/olm_inbound_group_session.cpp
|
||||||
|
jni/olm_outbound_group_session.cpp
|
||||||
|
jni/olm_utility.cpp
|
||||||
|
jni/olm_manager.cpp
|
||||||
|
jni/olm_pk.cpp
|
||||||
|
jni/olm_sas.cpp)
|
||||||
|
target_link_libraries(olm log)
|
||||||
|
target_compile_definitions(olm PRIVATE "$<$<CONFIG:DEBUG>:NDK_DEBUG>")
|
||||||
|
endif()
|
||||||
|
|
||||||
target_include_directories(olm
|
target_include_directories(olm
|
||||||
PUBLIC
|
PUBLIC
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
import org.apache.tools.ant.taskdefs.condition.Os
|
|
||||||
|
|
||||||
apply plugin: 'com.android.library'
|
apply plugin: 'com.android.library'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 30
|
compileSdkVersion 30
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 14
|
minSdkVersion 16
|
||||||
targetSdkVersion 30
|
targetSdkVersion 30
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
|
@ -14,6 +12,21 @@ android {
|
||||||
// "pm clear" command after each test invocation. This command ensures
|
// "pm clear" command after each test invocation. This command ensures
|
||||||
// that the app's state is completely cleared between tests.
|
// that the app's state is completely cleared between tests.
|
||||||
testInstrumentationRunnerArguments clearPackageData: 'true'
|
testInstrumentationRunnerArguments clearPackageData: 'true'
|
||||||
|
|
||||||
|
externalNativeBuild {
|
||||||
|
cmake {
|
||||||
|
arguments '-DANDROID_STL=c++_static',
|
||||||
|
'-DCMAKE_C_FLAGS=-fstack-protector-all -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Wall',
|
||||||
|
'-DCMAKE_CXX_FLAGS=-fstack-protector-all -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Wall',
|
||||||
|
'-DCMAKE_SHARED_LINKER_FLAGS=-z relro -z now',
|
||||||
|
'-DOLM_ANDROID_JNI=on',
|
||||||
|
'-DOLM_TESTS=off'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ndk {
|
||||||
|
abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86_64', 'x86'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
debug {
|
debug {
|
||||||
|
@ -31,9 +44,10 @@ android {
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sourceSets.main {
|
externalNativeBuild {
|
||||||
jniLibs.srcDir 'src/main/libs'
|
cmake {
|
||||||
jni.srcDirs = []
|
path '../../CMakeLists.txt'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task buildJavaDoc(type: Javadoc) {
|
task buildJavaDoc(type: Javadoc) {
|
||||||
|
@ -44,37 +58,11 @@ android {
|
||||||
failOnError false
|
failOnError false
|
||||||
}
|
}
|
||||||
|
|
||||||
task ndkBuildNativeRelease(type: Exec, description: 'NDK building..') {
|
|
||||||
println 'ndkBuildNativeRelease starts..'
|
|
||||||
workingDir file('src/main')
|
|
||||||
commandLine getNdkBuildCmd(), 'NDK_DEBUG=0'
|
|
||||||
}
|
|
||||||
|
|
||||||
task ndkBuildNativeDebug(type: Exec, description: 'NDK building..') {
|
|
||||||
println 'ndkBuildNativeDebug starts..'
|
|
||||||
workingDir file('src/main')
|
|
||||||
commandLine getNdkBuildCmd(), 'NDK_DEBUG=1'
|
|
||||||
}
|
|
||||||
|
|
||||||
task cleanNative(type: Exec, description: 'Clean NDK build') {
|
|
||||||
workingDir file('src/main')
|
|
||||||
commandLine getNdkBuildCmd(), 'clean'
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
compileTask ->
|
compileTask ->
|
||||||
if (compileTask.name.startsWith('compileDebugJava')) {
|
|
||||||
println 'test compile: Debug'
|
|
||||||
compileTask.dependsOn ndkBuildNativeDebug
|
|
||||||
} else if (compileTask.name.startsWith('compileReleaseJava')) {
|
|
||||||
println 'test compile: Release'
|
|
||||||
compileTask.dependsOn ndkBuildNativeRelease
|
|
||||||
}
|
|
||||||
compileTask.dependsOn buildJavaDoc
|
compileTask.dependsOn buildJavaDoc
|
||||||
}
|
}
|
||||||
|
|
||||||
clean.dependsOn cleanNative
|
|
||||||
|
|
||||||
|
|
||||||
libraryVariants.all { variant ->
|
libraryVariants.all { variant ->
|
||||||
variant.outputs.each { output ->
|
variant.outputs.each { output ->
|
||||||
|
@ -86,24 +74,6 @@ android {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def getNdkFolder() {
|
|
||||||
Properties properties = new Properties()
|
|
||||||
properties.load(project.rootProject.file('local.properties').newDataInputStream())
|
|
||||||
def ndkFolder = properties.getProperty('ndk.dir', null)
|
|
||||||
if (ndkFolder == null)
|
|
||||||
throw new GradleException("NDK location missing. Define it with ndk.dir in the local.properties file")
|
|
||||||
|
|
||||||
return ndkFolder
|
|
||||||
}
|
|
||||||
|
|
||||||
def getNdkBuildCmd() {
|
|
||||||
def ndkBuildCmd = getNdkFolder() + "/ndk-build"
|
|
||||||
if (Os.isFamily(Os.FAMILY_WINDOWS))
|
|
||||||
ndkBuildCmd += ".cmd"
|
|
||||||
|
|
||||||
return ndkBuildCmd
|
|
||||||
}
|
|
||||||
|
|
||||||
def gitRevision() {
|
def gitRevision() {
|
||||||
def cmd = "git rev-parse --short HEAD"
|
def cmd = "git rev-parse --short HEAD"
|
||||||
return cmd.execute().text.trim()
|
return cmd.execute().text.trim()
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
LOCAL_PATH := $(call my-dir)
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
|
|
||||||
LOCAL_MODULE := olm
|
|
||||||
|
|
||||||
SRC_ROOT_DIR := ../../../../..
|
|
||||||
|
|
||||||
include $(LOCAL_PATH)/$(SRC_ROOT_DIR)/common.mk
|
|
||||||
OLM_VERSION := $(MAJOR).$(MINOR).$(PATCH)
|
|
||||||
|
|
||||||
$(info LOCAL_PATH=$(LOCAL_PATH))
|
|
||||||
$(info SRC_ROOT_DIR=$(SRC_ROOT_DIR))
|
|
||||||
$(info OLM_VERSION=$(OLM_VERSION))
|
|
||||||
|
|
||||||
LOCAL_CPPFLAGS+= -std=c++11 -Wall
|
|
||||||
LOCAL_CONLYFLAGS+= -std=c99
|
|
||||||
LOCAL_CFLAGS+= -DOLMLIB_VERSION_MAJOR=$(MAJOR) \
|
|
||||||
-DOLMLIB_VERSION_MINOR=$(MINOR) \
|
|
||||||
-DOLMLIB_VERSION_PATCH=$(PATCH)
|
|
||||||
|
|
||||||
#LOCAL_CFLAGS+= -DNDK_DEBUG
|
|
||||||
|
|
||||||
LOCAL_CFLAGS+=-fstack-protector-all -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Wall
|
|
||||||
LOCAL_LDFLAGS=-z relro -z now
|
|
||||||
|
|
||||||
LOCAL_C_INCLUDES+= $(LOCAL_PATH)/$(SRC_ROOT_DIR)/include/ \
|
|
||||||
$(LOCAL_PATH)/$(SRC_ROOT_DIR)/lib
|
|
||||||
|
|
||||||
$(info LOCAL_C_INCLUDES=$(LOCAL_C_INCLUDES))
|
|
||||||
|
|
||||||
LOCAL_SRC_FILES := $(SRC_ROOT_DIR)/src/account.cpp \
|
|
||||||
$(SRC_ROOT_DIR)/src/base64.cpp \
|
|
||||||
$(SRC_ROOT_DIR)/src/cipher.cpp \
|
|
||||||
$(SRC_ROOT_DIR)/src/crypto.cpp \
|
|
||||||
$(SRC_ROOT_DIR)/src/memory.cpp \
|
|
||||||
$(SRC_ROOT_DIR)/src/message.cpp \
|
|
||||||
$(SRC_ROOT_DIR)/src/olm.cpp \
|
|
||||||
$(SRC_ROOT_DIR)/src/pickle.cpp \
|
|
||||||
$(SRC_ROOT_DIR)/src/ratchet.cpp \
|
|
||||||
$(SRC_ROOT_DIR)/src/session.cpp \
|
|
||||||
$(SRC_ROOT_DIR)/src/utility.cpp \
|
|
||||||
$(SRC_ROOT_DIR)/src/pk.cpp \
|
|
||||||
$(SRC_ROOT_DIR)/src/sas.c \
|
|
||||||
$(SRC_ROOT_DIR)/src/ed25519.c \
|
|
||||||
$(SRC_ROOT_DIR)/src/error.c \
|
|
||||||
$(SRC_ROOT_DIR)/src/inbound_group_session.c \
|
|
||||||
$(SRC_ROOT_DIR)/src/megolm.c \
|
|
||||||
$(SRC_ROOT_DIR)/src/outbound_group_session.c \
|
|
||||||
$(SRC_ROOT_DIR)/src/pickle_encoding.c \
|
|
||||||
$(SRC_ROOT_DIR)/lib/crypto-algorithms/sha256.c \
|
|
||||||
$(SRC_ROOT_DIR)/lib/crypto-algorithms/aes.c \
|
|
||||||
$(SRC_ROOT_DIR)/lib/curve25519-donna/curve25519-donna.c \
|
|
||||||
olm_account.cpp \
|
|
||||||
olm_session.cpp \
|
|
||||||
olm_jni_helper.cpp \
|
|
||||||
olm_inbound_group_session.cpp \
|
|
||||||
olm_outbound_group_session.cpp \
|
|
||||||
olm_utility.cpp \
|
|
||||||
olm_manager.cpp \
|
|
||||||
olm_pk.cpp \
|
|
||||||
olm_sas.cpp
|
|
||||||
|
|
||||||
LOCAL_LDLIBS := -llog
|
|
||||||
|
|
||||||
include $(BUILD_SHARED_LIBRARY)
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
APP_PLATFORM := android-16
|
|
||||||
APP_ABI := arm64-v8a armeabi-v7a x86_64 x86
|
|
||||||
APP_STL := c++_static
|
|
Loading…
Reference in a new issue