Skip to content

Commit 85cd62f

Browse files
committed
config it
1 parent e664f20 commit 85cd62f

File tree

5 files changed

+118
-49
lines changed

5 files changed

+118
-49
lines changed

jni/cmaketest/build.gradle

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
plugins {
22
id 'com.android.application'
33
}
4+
// cmake参数设置
5+
apply from: 'cmake.gradle'
46

57
android {
68
compileSdkVersion rootProject.ext.compileSdkVersion as Integer
@@ -14,36 +16,6 @@ android {
1416

1517

1618
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17-
18-
def ENABLE_LOG = false
19-
20-
int a = 0x01;
21-
int b = 0x02;
22-
23-
// int result = 0
24-
int result = a
25-
// int result = b
26-
// int result = a | b
27-
28-
printf("result: %d\n", result)
29-
30-
if (result & a) {
31-
printf("result is a\n")
32-
}
33-
34-
externalNativeBuild {
35-
cmake {
36-
cppFlags "-std=c++11"
37-
arguments "-DANDROID_STL=c++_shared",
38-
"-DENABLE_LOG=${ENABLE_LOG}",
39-
"-DTRANSPORT_LAYER=${result}"
40-
41-
// arguments "-DANDROID_STL=c++_static" // android-ndk-r16b/sources/cxx-stl/llvm-libc++
42-
// arguments "-DANDROID_STL=c++_shared" // android-ndk-r16b/sources/cxx-stl/llvm-libc++
43-
// arguments "-DANDROID_STL=gnustl_static" // android-ndk-r16b/sources/cxx-stl/gnu-libstdc++
44-
45-
}
46-
}
4719
}
4820

4921
buildTypes {

jni/cmaketest/cmake.gradle

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// applicationName property to gradle.properties
2+
3+
4+
def ENABLE_LOG = false
5+
6+
int a = 0x01;
7+
int b = 0x02;
8+
9+
// int result = 0
10+
// int result = a
11+
// int result = b
12+
int result = a | b
13+
14+
printf("result: %d\n", result)
15+
16+
if (result & a) {
17+
printf("result is a\n")
18+
}
19+
20+
21+
android.defaultConfig.externalNativeBuild {
22+
def list = [
23+
"-DANDROID_STL=c++_shared",
24+
"-DENABLE_LOG=${ENABLE_LOG}",
25+
"-DTRANSPORT_LAYER=${result}",
26+
]
27+
list.add("-DTEST_ONE=1")
28+
29+
println "class: " + list.class + ", " + list.toString()
30+
list.each {
31+
println "item: $it"
32+
}
33+
34+
cmake {
35+
cppFlags "-std=c++11"
36+
list.each {
37+
arguments it
38+
}
39+
40+
// arguments "-DANDROID_STL=c++_static" // android-ndk-r16b/sources/cxx-stl/llvm-libc++
41+
// arguments "-DANDROID_STL=c++_shared" // android-ndk-r16b/sources/cxx-stl/llvm-libc++
42+
// arguments "-DANDROID_STL=gnustl_static" // android-ndk-r16b/sources/cxx-stl/gnu-libstdc++
43+
44+
}
45+
}

jni/cmaketest/src/main/cpp/CMakeLists.txt

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,11 @@ message(CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME})
2121
message(CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID})
2222
message(CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS})
2323
message(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES: ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
24+
message(CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX})
25+
message(CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH})
26+
message(HAI_BUILD_PROFILE: $ENV{HAI_BUILD_PROFILE})
27+
message(HAI_BUILD_PROFILE: $ENV{HAI_BUILD_PROFILE})
2428

25-
#list(REMOVE_AT CMAKE_CXX_IMPLICIT_LINK_LIBRARIES 0)
26-
27-
foreach (LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
28-
message(LIB: ${LIB})
29-
endforeach ()
30-
message(SRT_LIBS_PRIVATE: ${SRT_LIBS_PRIVATE})
31-
32-
#pkg_check_modules (GNUSTL REQUIRED gnustl)
33-
message(GNUSTL_LIBRARY_DIRS: ${GNUSTL_LIBRARY_DIRS})
3429

3530
set(var hello)
3631
message(${var})
@@ -39,6 +34,7 @@ message(${var})
3934
set(var 111)
4035
message(${var})
4136

37+
# 添加即执行,添加顺序决定执行顺序
4238
add_subdirectory(boolean_test)
4339
add_subdirectory(function_test)
4440
#include(ndk-stl-config.cmake)
@@ -61,6 +57,9 @@ else ()
6157
message(log off)
6258
ENDIF ()
6359

60+
if (TEST_ONE)
61+
message(TEST_ONE: ${TEST_ONE})
62+
endif ()
6463

6564
message(TRANSPORT_LAYER: ${TRANSPORT_LAYER})
6665

@@ -80,12 +79,3 @@ find_library(log-lib log)
8079
target_link_libraries(native-lib ${log-lib})
8180

8281

83-
if (${TRANSPORT_LAYER} EQUAL 2)
84-
message(transport: 22222222222)
85-
ENDIF ()
86-
87-
if (${TRANSPORT_LAYER} EQUAL 3)
88-
message(transport: 333333333333)
89-
ENDIF ()
90-
91-

jni/cmaketest/src/main/cpp/boolean_test/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@ ENDIF ()
3535

3636

3737
# list操作
38+
# set(var a b c d e) creates a list with a;b;c;d;e, and set(var “a b c d e”) creates a string or a list with one item in it.
3839
set(helloList a b c d e)
3940
list(REMOVE_ITEM helloList a)
4041
list(REMOVE_AT helloList 0)
4142
list(INSERT helloList 0 /Users/baiiu/framework/android-ndk-r14b/sources/cxx-stl/llvm-libc++/libs/armeabi/libc++_shared.so)
43+
list(APPEND helloList last)
4244
message(helloList: ${helloList})
4345
foreach (item ${helloList})
4446
message(item: ${item})
4547
endforeach ()
48+
49+
foreach (LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
50+
message(LIB: ${LIB})
51+
endforeach ()

jni/cmaketest/src/main/cpp/function_test/CMakeLists.txt

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,60 @@ cmake_minimum_required(VERSION 3.4.1)
1010
# You can define multiple libraries, and CMake builds them for you.
1111
# Gradle automatically packages shared libraries with your APK.
1212

13-
message(function test)
13+
# https://cmake.org/cmake/help/latest/command/function.html
14+
15+
function(functionName args)
16+
message(function-->args: ${args})
17+
endfunction()
18+
19+
functionName(helloFunction)
20+
21+
22+
#macro()
23+
#endmacro()
24+
25+
26+
set(mList 1 2 3 first)
27+
message(mList: ${mList})
28+
29+
30+
function(whenOne arg)
31+
# 直接操作arg无效,形参
32+
# list(APPEND arg 111)
33+
# set(arg ${arg} 111)
34+
message(arg: ${arg})
35+
message(ARGV: ${ARGV})
36+
set(ARGV ${ARGV} one one one PARENT_SCOPE)
37+
message(whenOne-->${ARGV})
38+
39+
list(APPEND ARGV one one one PARENT_SCOPE)
40+
message(whenOne-->${ARGV})
41+
endfunction()
42+
43+
function(whenTwo arg)
44+
# list(APPEND arg 222)
45+
# message(whenTwo-->${arg})
46+
endfunction()
47+
48+
49+
if (${TRANSPORT_LAYER} EQUAL 1)
50+
message(transport: 111111111111)
51+
whenOne(mList)
52+
ENDIF ()
53+
54+
if (${TRANSPORT_LAYER} EQUAL 2)
55+
message(transport: 22222222222)
56+
whenTwo(mList)
57+
ENDIF ()
58+
59+
if (${TRANSPORT_LAYER} EQUAL 3)
60+
message(transport: 333333333333)
61+
whenOne(${mList})
62+
whenTwo(${mList})
63+
ENDIF ()
64+
65+
list(APPEND mList last)
66+
set(mList ${mList} 1 2 3 4 5 6)
67+
message(mList: ${mList})
68+
69+

0 commit comments

Comments
 (0)