子模块1:gmath静态库CMakeLists.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)
add_library(gmath STATIC src/gmath.c)
set(distribution_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../distribution)
set_target_properties(gmath PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${distribution_DIR}/gmath/lib/${ANDROID_ABI}")
add_custom_command(TARGET gmath POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/src/gmath.h" "${distribution_DIR}/gmath/include/gmath.h" COMMENT "Copying gmath to output directory")
|
子模块2:gpref动态库CMakeLists.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| cmake_minimum_required(VERSION 3.4.1) set(CMAKE_VERBOSE_MAKEFILE on)
add_library(gperf SHARED src/gperf.c)
set(distribution_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../distribution)
set_target_properties(gperf PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${distribution_DIR}/gperf/lib/${ANDROID_ABI}")
add_custom_command(TARGET gperf POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/src/gperf.h" "${distribution_DIR}/gperf/include/gperf.h" COMMENT "Copying gperf to output directory")
|
主模块:CMakeLists.txt
1 2 3 4 5 6 7 8 9 10 11
| cmake_minimum_required(VERSION 3.4.1) set(CMAKE_VERBOSE_MAKEFILE on)
set(lib_src_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(lib_build_DIR $ENV{HOME}/tmp/${ANDROID_ABI}) file(MAKE_DIRECTORY ${lib_build_DIR})
add_subdirectory(${lib_src_DIR}/gmath ${lib_build_DIR}/gmath) add_subdirectory(${lib_src_DIR}/gperf ${lib_build_DIR}/gperf)
|
主工程引入使用gmath静态库和gpref动态库:CMakeLists.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| cmake_minimum_required(VERSION 3.4.1) set(distribution_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../distribution)
add_library(lib_gmath STATIC IMPORTED)
set_target_properties(lib_gmath PROPERTIES IMPORTED_LOCATION ${distribution_DIR}/gmath/lib/${ANDROID_ABI}/libgmath.a)
add_library(lib_gperf SHARED IMPORTED)
set_target_properties(lib_gperf PROPERTIES IMPORTED_LOCATION ${distribution_DIR}/gperf/lib/${ANDROID_ABI}/libgperf.so)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
add_library(hello-libs SHARED hello-libs.cpp)
target_include_directories(hello-libs PRIVATE ${distribution_DIR}/gmath/include ${distribution_DIR}/gperf/include)
target_link_libraries(hello-libs android lib_gmath lib_gperf log)
defaultConfig { externalNativeBuild { cmake {//cmake编译方式 arguments '-DANDROID_STL=c++_static' //通过宏指定使用的c++模板库为c++_static } } } externalNativeBuild { cmake { version '3.10.2' //cmake版本号 path 'src/main/cpp/CMakeLists.txt' //CMakeLists.txt文件路径 } }
|
Cmake官方文档:https://cmake.org/documentation/ 结合Quick Search快速搜索学习很方便
参考链接:http://t.zoukankan.com/yongfengnice-p-13695598.html