Skip to content

Commit

Permalink
config it
Browse files Browse the repository at this point in the history
  • Loading branch information
baiiu committed Apr 22, 2021
1 parent e664f20 commit cf01225
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 49 deletions.
32 changes: 2 additions & 30 deletions jni/cmaketest/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
plugins {
id 'com.android.application'
}
// cmake参数设置
apply from: 'config.gradle'

android {
compileSdkVersion rootProject.ext.compileSdkVersion as Integer
Expand All @@ -14,36 +16,6 @@ android {


testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

def ENABLE_LOG = false

int a = 0x01;
int b = 0x02;

// int result = 0
int result = a
// int result = b
// int result = a | b

printf("result: %d\n", result)

if (result & a) {
printf("result is a\n")
}

externalNativeBuild {
cmake {
cppFlags "-std=c++11"
arguments "-DANDROID_STL=c++_shared",
"-DENABLE_LOG=${ENABLE_LOG}",
"-DTRANSPORT_LAYER=${result}"

// arguments "-DANDROID_STL=c++_static" // android-ndk-r16b/sources/cxx-stl/llvm-libc++
// arguments "-DANDROID_STL=c++_shared" // android-ndk-r16b/sources/cxx-stl/llvm-libc++
// arguments "-DANDROID_STL=gnustl_static" // android-ndk-r16b/sources/cxx-stl/gnu-libstdc++

}
}
}

buildTypes {
Expand Down
45 changes: 45 additions & 0 deletions jni/cmaketest/config.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// applicationName property to gradle.properties


def ENABLE_LOG = false

int a = 0x01;
int b = 0x02;

// int result = 0
// int result = a
// int result = b
int result = a | b

printf("result: %d\n", result)

if (result & a) {
printf("result is a\n")
}


android.defaultConfig.externalNativeBuild {
def list = [
"-DANDROID_STL=c++_shared",
"-DENABLE_LOG=${ENABLE_LOG}",
"-DTRANSPORT_LAYER=${result}",
]
list.add("-DTEST_ONE=1")

println "class: " + list.class + ", " + list.toString()
list.each {
println "item: $it"
}

cmake {
cppFlags "-std=c++11"
list.each {
arguments it
}

// arguments "-DANDROID_STL=c++_static" // android-ndk-r16b/sources/cxx-stl/llvm-libc++
// arguments "-DANDROID_STL=c++_shared" // android-ndk-r16b/sources/cxx-stl/llvm-libc++
// arguments "-DANDROID_STL=gnustl_static" // android-ndk-r16b/sources/cxx-stl/gnu-libstdc++

}
}
26 changes: 8 additions & 18 deletions jni/cmaketest/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,11 @@ message(CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME})
message(CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID})
message(CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS})
message(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES: ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
message(CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX})
message(CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH})
message(HAI_BUILD_PROFILE: $ENV{HAI_BUILD_PROFILE})
message(HAI_BUILD_PROFILE: $ENV{HAI_BUILD_PROFILE})

#list(REMOVE_AT CMAKE_CXX_IMPLICIT_LINK_LIBRARIES 0)

foreach (LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
message(LIB: ${LIB})
endforeach ()
message(SRT_LIBS_PRIVATE: ${SRT_LIBS_PRIVATE})

#pkg_check_modules (GNUSTL REQUIRED gnustl)
message(GNUSTL_LIBRARY_DIRS: ${GNUSTL_LIBRARY_DIRS})

set(var hello)
message(${var})
Expand All @@ -39,6 +34,7 @@ message(${var})
set(var 111)
message(${var})

# 添加即执行,添加顺序决定执行顺序
add_subdirectory(boolean_test)
add_subdirectory(function_test)
#include(ndk-stl-config.cmake)
Expand All @@ -61,6 +57,9 @@ else ()
message(log off)
ENDIF ()

if (TEST_ONE)
message(TEST_ONE: ${TEST_ONE})
endif ()

message(TRANSPORT_LAYER: ${TRANSPORT_LAYER})

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


if (${TRANSPORT_LAYER} EQUAL 2)
message(transport: 22222222222)
ENDIF ()

if (${TRANSPORT_LAYER} EQUAL 3)
message(transport: 333333333333)
ENDIF ()


6 changes: 6 additions & 0 deletions jni/cmaketest/src/main/cpp/boolean_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ ENDIF ()


# list操作
# 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.
set(helloList a b c d e)
list(REMOVE_ITEM helloList a)
list(REMOVE_AT helloList 0)
list(INSERT helloList 0 /Users/baiiu/framework/android-ndk-r14b/sources/cxx-stl/llvm-libc++/libs/armeabi/libc++_shared.so)
list(APPEND helloList last)
message(helloList: ${helloList})
foreach (item ${helloList})
message(item: ${item})
endforeach ()

foreach (LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
message(LIB: ${LIB})
endforeach ()
58 changes: 57 additions & 1 deletion jni/cmaketest/src/main/cpp/function_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,60 @@ cmake_minimum_required(VERSION 3.4.1)
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

message(function test)
# https://cmake.org/cmake/help/latest/command/function.html

function(functionName args)
message(function-->args: ${args})
endfunction()

functionName(helloFunction)


#macro()
#endmacro()


set(mList 1 2 3 first)
message(mList: ${mList})


function(whenOne arg)
# 直接操作arg无效,形参
# list(APPEND arg 111)
# set(arg ${arg} 111)
message(arg: ${arg})
message(ARGV: ${ARGV})
set(ARGV ${ARGV} one one one PARENT_SCOPE)
message(whenOne-->${ARGV})

list(APPEND ARGV one one one PARENT_SCOPE)
message(whenOne-->${ARGV})
endfunction()

function(whenTwo arg)
# list(APPEND arg 222)
# message(whenTwo-->${arg})
endfunction()


if (${TRANSPORT_LAYER} EQUAL 1)
message(transport: 111111111111)
whenOne(mList)
ENDIF ()

if (${TRANSPORT_LAYER} EQUAL 2)
message(transport: 22222222222)
whenTwo(mList)
ENDIF ()

if (${TRANSPORT_LAYER} EQUAL 3)
message(transport: 333333333333)
whenOne(${mList})
whenTwo(${mList})
ENDIF ()

list(APPEND mList last)
set(mList ${mList} 1 2 3 4 5 6)
message(mList: ${mList})


0 comments on commit cf01225

Please sign in to comment.