Skip to content

Commit

Permalink
better cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
jerson committed Aug 5, 2021
1 parent 745aa06 commit 268dd13
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 120 deletions.
30 changes: 13 additions & 17 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
cmake_minimum_required(VERSION 3.10.0)
cmake_minimum_required(VERSION 3.9.0)

include_directories(
../cpp
../node_modules/react-native/ReactCommon/jsi
)

add_definitions(
-DFOLLY_USE_LIBCPP=1
-DFOLLY_NO_CONFIG=1
-DFOLLY_HAVE_MEMRCHR=1
)
set (CMAKE_VERBOSE_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 14)
set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build)

add_library(openpgp_bridge SHARED IMPORTED )
add_library(openpgp_bridge SHARED IMPORTED)

set_target_properties(openpgp_bridge
PROPERTIES
Expand All @@ -20,17 +13,20 @@ set_target_properties(openpgp_bridge

add_library(fast-openpgp
SHARED
../node_modules/react-native/ReactCommon/jsi/jsi/jsi.cpp
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp"
../cpp/react-native-fast-openpgp.cpp
../cpp/react-native-fast-openpgp.h
fast-openpgp-adapter.cpp
)

find_library(
log-lib
log )
include_directories(
fast-openpgp
PRIVATE
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
../cpp
)

target_link_libraries(fast-openpgp
openpgp_bridge
android
${log-lib})
log)
207 changes: 105 additions & 102 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
buildscript {
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['FastOpenpgp_kotlinVersion']
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['Leveldb_kotlinVersion']

repositories {
google()
jcenter()
}
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
Expand All @@ -18,128 +18,131 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

def getExtOrDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['FastOpenpgp_' + name]
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['FastOpenpgp_' + name]
}

def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['FastOpenpgp_' + name]).toInteger()
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['FastOpenpgp_' + name]).toInteger()
}

android {
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
buildToolsVersion getExtOrDefault('buildToolsVersion')
defaultConfig {
minSdkVersion 16
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
versionCode 1
versionName "1.0"

compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
buildToolsVersion getExtOrDefault('buildToolsVersion')
defaultConfig {
minSdkVersion 16
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
versionCode 1
versionName "1.0"

externalNativeBuild {
cmake {
cppFlags "-O2 -frtti -fexceptions -Wall -Wno-unused-variable -fstack-protector-all"
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
arguments "-DNODE_MODULES_DIR=${rootDir}/../node_modules"
}
}
}

externalNativeBuild {
cmake {
cppFlags "-O2 -frtti -fexceptions -Wall -Wno-unused-variable -fstack-protector-all"
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
version '3.10.0+'
path "CMakeLists.txt"
}
}

}

externalNativeBuild {
cmake {
version '3.10.0+'
path "CMakeLists.txt"
}
}

buildTypes {
release {
minifyEnabled false
buildTypes {
release {
minifyEnabled false
}
}
}
lintOptions {
disable 'GradleCompatible'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
disable 'GradleCompatible'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
pickFirst "**/libopenpgp_bridge.so"
}

}

repositories {
mavenCentral()
jcenter()
google()

def found = false
def defaultDir = null
def androidSourcesName = 'React Native sources'

if (rootProject.ext.has('reactNativeAndroidRoot')) {
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
} else {
defaultDir = new File(
projectDir,
'/../../../node_modules/react-native/android'
)
}
mavenCentral()
jcenter()
google()

if (defaultDir.exists()) {
maven {
url defaultDir.toString()
name androidSourcesName
def found = false
def defaultDir = null
def androidSourcesName = 'React Native sources'

if (rootProject.ext.has('reactNativeAndroidRoot')) {
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
} else {
defaultDir = new File(
projectDir,
'/../../../node_modules/react-native/android'
)
}

logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
found = true
} else {
def parentDir = rootProject.projectDir

1.upto(5, {
if (found) return true
parentDir = parentDir.parentFile

def androidSourcesDir = new File(
parentDir,
'node_modules/react-native'
)

def androidPrebuiltBinaryDir = new File(
parentDir,
'node_modules/react-native/android'
)

if (androidPrebuiltBinaryDir.exists()) {
if (defaultDir.exists()) {
maven {
url androidPrebuiltBinaryDir.toString()
name androidSourcesName
url defaultDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
found = true
} else if (androidSourcesDir.exists()) {
maven {
url androidSourcesDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
found = true
}
})
}
} else {
def parentDir = rootProject.projectDir

1.upto(5, {
if (found) return true
parentDir = parentDir.parentFile

def androidSourcesDir = new File(
parentDir,
'node_modules/react-native'
)

def androidPrebuiltBinaryDir = new File(
parentDir,
'node_modules/react-native/android'
)

if (androidPrebuiltBinaryDir.exists()) {
maven {
url androidPrebuiltBinaryDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
found = true
} else if (androidSourcesDir.exists()) {
maven {
url androidSourcesDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
found = true
}
})
}

if (!found) {
throw new GradleException(
"${project.name}: unable to locate React Native android sources. " +
"Ensure you have you installed React Native as a dependency in your project and try again."
)
}
if (!found) {
throw new GradleException(
"${project.name}: unable to locate React Native android sources. " +
"Ensure you have you installed React Native as a dependency in your project and try again."
)
}
}

def kotlin_version = getExtOrDefault('kotlinVersion')

dependencies {
// noinspection GradleDynamicVersion
api 'com.facebook.react:react-native:+'
implementation group: 'com.google.flatbuffers', name: 'flatbuffers-java', version: '2.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
// noinspection GradleDynamicVersion
api 'com.facebook.react:react-native:+'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-fast-openpgp",
"version": "2.0.0",
"version": "2.0.0-rc1",
"description": "library for use openPGP",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down

0 comments on commit 268dd13

Please sign in to comment.