Skip to content

Commit f65d5fb

Browse files
committed
better project config
1 parent 1fae6ce commit f65d5fb

File tree

7 files changed

+76
-21
lines changed

7 files changed

+76
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ target/
99
tmp
1010
objs/
1111
obj/
12+
build/

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@
55
"files.exclude": {
66
},
77
"files.associations": {
8+
"*.h": "cpp",
9+
"*.cc": "cpp",
10+
"params.txt": "json",
11+
"CMakeLists*.txt": "cmake",
12+
"__config": "c"
813
}
914
}

library/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

library/build.gradle

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ apply plugin: 'com.android.library'
22

33
def usingCMakeCompile() {
44
/// define gradle.ext.usingCMakeCompile = false to disable CMakeCompile Mode.
5-
return gradle.ext == null || !gradle.ext.has("usingCMakeCompile") || !gradle.ext.has("usingCMakeCompile");
5+
return gradle.ext != null && gradle.ext.has("usingCMakeCompile") && gradle.ext.usingCMakeCompile;
66
}
77

88
android {
99
compileSdkVersion 25
1010
if(usingCMakeCompile()) {
11-
ndkVersion "24.0.8215888"
11+
ndkVersion "23.1.7779620"
1212
}
1313

1414
defaultConfig {
@@ -30,7 +30,7 @@ android {
3030
}
3131
externalNativeBuild {
3232
cmake {
33-
path 'CMakeLists.txt'
33+
path 'src/main/jni/CMakeLists.txt'
3434
}
3535
}
3636

@@ -44,14 +44,17 @@ android {
4444
////////////////////////////////////////
4545

4646
sourceSets.main {
47-
jniLibs.srcDir 'src/main/libs' //set libs as .so's location instead of jni
48-
//jni.srcDirs = [] //disable automatic ndk-build call with auto-generated Android.mk file
47+
if(usingCMakeCompile()) {
48+
jniLibs.srcDir 'src/main/libs' //set libs as .so's location instead of jni
49+
}
50+
else {
51+
jni.srcDirs = [] //disable automatic ndk-build call with auto-generated Android.mk file
52+
}
4953
}
5054
compileOptions {
5155
sourceCompatibility JavaVersion.VERSION_1_8
5256
targetCompatibility JavaVersion.VERSION_1_8
5357
}
54-
5558
}
5659

5760
dependencies {

library/src/main/jni/CMakeLists.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,25 @@ if (NOT DEFINED ANDROID_GRADLE)
2222

2323
set(NDK_STANDALONE_TOOLCHAIN $ENV{NDK}/ndk-build-toolchain)
2424
message(${NDK_STANDALONE_TOOLCHAIN})
25-
set(CMAKE_SYSTEM_NAME AndroidARM)
2625
set(CMAKE_C_COMPILER ${NDK_STANDALONE_TOOLCHAIN}/bin/clang)
2726
set(CMAKE_CXX_COMPILER ${NDK_STANDALONE_TOOLCHAIN}/bin/clang++)
27+
set(CMAKE_SYSROOT ${NDK_STANDALONE_TOOLCHAIN}/sysroot)
2828
set(CMAKE_FIND_ROOT_PATH ${NDK_STANDALONE_TOOLCHAIN})
2929

30-
add_definitions(--sysroot=${NDK_STANDALONE_TOOLCHAIN}/sysroot)
3130
if (DEFINED NDK_STANDALONE_TOOLCHAIN)
32-
include_directories(${NDK_STANDALONE_TOOLCHAIN}/sysroot/usr/include)
31+
set(NDK_INCLUDE_DIR ${NDK_STANDALONE_TOOLCHAIN}/sysroot/usr/include)
32+
if (EXISTS ${NDK_STANDALONE_TOOLCHAIN}/sysroot/usr/include/aarch64-linux-android)
33+
set(NDK_INCLUDE_DIR ${NDK_INCLUDE_DIR}
34+
${NDK_STANDALONE_TOOLCHAIN}/sysroot/usr/include/aarch64-linux-android)
35+
endif ()
36+
include_directories(${NDK_INCLUDE_DIR})
3337
endif ()
3438
endif ()
3539

3640
if (NOT DEFINED ANDROID_ABI)
3741
add_definitions(-DANDROID_ABI=arm64-v8a)
42+
else ()
43+
add_definitions(-DANDROID_ABI=${ANDROID_ABI})
3844
endif ()
3945

4046
execute_process(COMMAND find ${CMAKE_CURRENT_SOURCE_DIR}/cge -maxdepth 3 -type d OUTPUT_VARIABLE CGE_CORE_HEADER_DIR)
@@ -52,7 +58,7 @@ include_directories(
5258
${CMAKE_CURRENT_SOURCE_DIR}/custom
5359
${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg)
5460

55-
add_definitions(-DANDROID_NDK -DCGE_LOG_TAG=\"libCGE\" -DCGE_TEXTURE_PREMULTIPLIED=1 -D_CGE_USE_FFMPEG_ -D__STDC_CONSTANT_MACROS -D_CGE_DISABLE_GLOBALCONTEXT_ -O3 -ffast-math -D_CGE_ONLY_FILTERS_ -DANDROID_ARM_NEON)
61+
add_definitions(-DANDROID_NDK -DCGE_LOG_TAG=\"libCGE\" -DCGE_TEXTURE_PREMULTIPLIED=1 -D_CGE_USE_FFMPEG_ -D__STDC_CONSTANT_MACROS -D_CGE_DISABLE_GLOBALCONTEXT_ -O3 -D_CGE_ONLY_FILTERS_)
5662

5763
add_library(CGE
5864
${CGE_CORE_SRC}
Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,52 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
2+
3+
if [[ "$1" == "-f" ]]; then
4+
if command -v trash &>/dev/null; then
5+
trash "$NDK/ndk-build-toolchain"
6+
else
7+
rm -rf "$NDK/ndk-build-toolchain"
8+
fi
9+
10+
unset NDK_STANDALONE_TOOLCHAIN
11+
fi
212

313
if [[ "$NDK_STANDALONE_TOOLCHAIN" == "" ]]; then
414

515
if [[ "$NDK" == "" ]]; then
616
echo "You should set the NDK variable to your ndk-dir!"
7-
exit
17+
exit 1
818
fi
919

1020
export NDK_STANDALONE_TOOLCHAIN=$NDK/ndk-build-toolchain
1121

1222
if [[ ! -d "$NDK_STANDALONE_TOOLCHAIN" ]]; then
1323

14-
$NDK/build/tools/make-standalone-toolchain.sh --toolchain=arm-linux-android-clang3.6 --arch=arm --platform=android-19 --install-dir=$NDK_STANDALONE_TOOLCHAIN --stl=libc++
24+
NDK_VER=$(grep -i revision "$NDK/source.properties")
1525

16-
fi
26+
NDK_VER="${NDK_VER/* /}"
27+
echo "NDK_VER=$NDK_VER"
28+
29+
NDK_MAJOR_VER="${NDK_VER/.*/}"
30+
echo "NDK_MAJOR_VER=$NDK_MAJOR_VER"
1731

32+
if [[ "$NDK_MAJOR_VER" -ge 23 ]]; then
33+
# NDK23 and later does not support 'standardalone-toolchain'
34+
# according to <https://developer.android.com/ndk/guides/other_build_systems > export directly
35+
echo "NDK23 and later does not support 'standardalone-toolchain', export directly"
36+
if [[ $(uname -s) == "Darwin" ]]; then
37+
export NDK_STANDALONE_TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/darwin-x86_64"
38+
elif [[ $(uname -s) == "Linux" ]]; then
39+
export NDK_STANDALONE_TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/linux-x86_64"
40+
else # windows (没啥意义)
41+
export NDK_STANDALONE_TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/windows-x86_64"
42+
fi
43+
pushd .
44+
cd $NDK && ln -snf "$NDK_STANDALONE_TOOLCHAIN" ndk-build-toolchain
45+
popd
46+
else
47+
$NDK/build/tools/make-standalone-toolchain.sh --toolchain=arm-linux-android-clang3.6 --arch=arm --platform=android-26 --install-dir=$NDK_STANDALONE_TOOLCHAIN --stl=libc++
48+
fi
49+
fi
1850
fi
51+
1952
echo "NDK_STANDALONE_TOOLCHAIN=$NDK_STANDALONE_TOOLCHAIN"

settings.gradle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
11
include ':library', ':cgeDemo'
2+
3+
def pFile = new File(settingsDir, 'local.properties')
4+
Properties properties = new Properties()
5+
properties.load(pFile.newDataInputStream())
6+
7+
if (properties.getProperty('usingCMakeCompile', null) == null) {
8+
pFile.append('\nusingCMakeCompile=false\n')
9+
}
10+
11+
if (gradle.ext == null) {
12+
gradle.ext = {}
13+
}
14+
15+
gradle.ext.usingCMakeCompile = properties.getProperty("usingCMakeCompile", "") == "true"

0 commit comments

Comments
 (0)