Skip to content

Commit 7862a81

Browse files
committed
better cmake config
1 parent e5c8007 commit 7862a81

File tree

5 files changed

+47
-12
lines changed

5 files changed

+47
-12
lines changed

library/build.gradle

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ def usingCMakeCompile() {
55
return gradle.ext != null && gradle.ext.has("usingCMakeCompile") && gradle.ext.usingCMakeCompile;
66
}
77

8+
def usingCMakeCompileDebug() {
9+
/// define gradle.ext.usingCMakeCompileDebug = true to enable CMake Debug Mode.
10+
return gradle.ext != null && gradle.ext.has("usingCMakeCompileDebug") && gradle.ext.usingCMakeCompileDebug;
11+
}
12+
813
android {
914
compileSdkVersion rootProject.ext.android.compileSdkVersion
1015
buildToolsVersion rootProject.ext.android.buildToolsVersion
@@ -22,22 +27,48 @@ android {
2227
if (usingCMakeCompile()) {
2328
externalNativeBuild {
2429
cmake {
25-
arguments "-DCGE_USE_VIDEO_MODULE=1",
30+
31+
def cmakeBuildType = "";
32+
def cppExtraFlags = "";
33+
34+
if (usingCMakeCompileDebug()) {
35+
cmakeBuildType = "-DCMAKE_BUILD_TYPE=Debug"
36+
cppExtraFlags = "-DDEBUG=1 -D_DEBUG=1"
37+
} else {
38+
cmakeBuildType = "-DCMAKE_BUILD_TYPE=Release"
39+
cppExtraFlags = "-Os -DNDEBUG=1 -D_NDEBUG=1"
40+
}
41+
42+
arguments "-DCGE_USE_VIDEO_MODULE=ON",
2643
"-DANDROID_STL=c++_static",
2744
"-DANDROID_ARM_NEON=TRUE",
28-
"-DANDROID_GRADLE=1",
29-
"-DCGE_USE_VIDEO_MODULE=1"
45+
"-DANDROID_GRADLE=ON",
46+
cmakeBuildType
3047

31-
cppFlags "-frtti -std=c++14"
48+
cFlags "-mfloat-abi=softfp -mfpu=vfp -Os -ffast-math -fPIC -DNO_LOCALE_SUPPORT -DANDROID_NDK"
49+
cppFlags "-frtti -std=c++14 -fPIE -fPIC -fno-exceptions -fvisibility-inlines-hidden -DNO_LOCALE_SUPPORT -DANDROID_NDK ${cppExtraFlags}"
50+
51+
52+
53+
println("cmake arguments: " + arguments)
54+
println("cppFlags: " + cppFlags)
3255
}
3356
}
57+
58+
ndk {
59+
abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86_64', 'x86'
60+
// if (!usingCMakeCompileDebug()) {
61+
// debugSymbolLevel ''
62+
// }
63+
}
3464
}
3565
}
3666

3767
if (usingCMakeCompile()) {
3868
externalNativeBuild {
3969
cmake {
4070
path 'src/main/jni/CMakeLists.txt'
71+
version "3.22.1"
4172
}
4273
}
4374
}

library/src/main/jni/Android.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ LOCAL_SRC_FILES := \
101101
$(CGE_ROOT)/interface/cgeDeformFilterWrapper.cpp \
102102

103103

104-
LOCAL_CPPFLAGS := -frtti -std=c++11
104+
LOCAL_CPPFLAGS := -frtti -std=c++14
105105
LOCAL_LDLIBS := -llog -lEGL -lGLESv2 -ljnigraphics
106106

107107
# 'CGE_USE_VIDEO_MODULE' determines if the project should compile with ffmpeg.
@@ -156,7 +156,7 @@ include $(BUILD_SHARED_LIBRARY)
156156

157157
include $(CLEAR_VARS)
158158
LOCAL_MODULE := ffmpeg
159-
LOCAL_CFLAGS := -mfloat-abi=softfp -mfpu=vfp -O3 -ffast-math -funroll-loops -fPIC
159+
LOCAL_CFLAGS := -mfloat-abi=softfp -mfpu=vfp -Os -ffast-math -fPIC
160160
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
161161
LOCAL_CFLAGS := $(LOCAL_CFLAGS) march=armv7-a -mfpu=neon
162162
endif

library/src/main/jni/Application.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ APP_STL := c++_static
99

1010
#APP_CPPFLAGS := -frtti -fexceptions
1111
#APP_CPPFLAGS := -fpermissive
12-
APP_CPPFLAGS := -frtti -std=c++11
12+
APP_CPPFLAGS := -frtti -std=c++14
1313

1414
APP_OPTIM := release

library/src/main/jni/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ project(CGE)
44

55
set(CMAKE_CXX_STANDARD 14)
66

7-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
8-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -frtti -std=c++14")
9-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie")
10-
117
option(CGE_USE_VIDEO_MODULE "boolean option to enable video module" OFF)
128

139
if (NOT DEFINED ANDROID_GRADLE)
@@ -24,6 +20,9 @@ if (NOT DEFINED ANDROID_GRADLE)
2420

2521
set(NDK_STANDALONE_TOOLCHAIN $ENV{NDK}/ndk-build-toolchain)
2622
message(${NDK_STANDALONE_TOOLCHAIN})
23+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
24+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -frtti -std=c++14")
25+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE")
2726
set(CMAKE_C_COMPILER ${NDK_STANDALONE_TOOLCHAIN}/bin/clang)
2827
set(CMAKE_CXX_COMPILER ${NDK_STANDALONE_TOOLCHAIN}/bin/clang++)
2928
set(CMAKE_SYSROOT ${NDK_STANDALONE_TOOLCHAIN}/sysroot)

settings.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ if (properties.getProperty('usingCMakeCompile', null) == null) {
88
pFile.append('\nusingCMakeCompile=false\n')
99
}
1010

11+
if (properties.getProperty('usingCMakeCompileDebug', null) == null) {
12+
pFile.append('\nusingCMakeCompileDebug=false\n')
13+
}
14+
1115
if (gradle.ext == null) {
1216
gradle.ext = {}
1317
}
1418

15-
gradle.ext.usingCMakeCompile = properties.getProperty("usingCMakeCompile", "") == "true"
19+
gradle.ext.usingCMakeCompile = properties.getProperty("usingCMakeCompile", "") == "true"
20+
gradle.ext.usingCMakeCompileDebug = properties.getProperty("usingCMakeCompileDebug", "") == "true"

0 commit comments

Comments
 (0)