├── .idea ├── misc.xml └── vcs.xml ├── CMakeLists.txt ├── CMakeModule ├── AndroidBP │ ├── Parse.cmake │ ├── ParseOther.cmake │ ├── rmComment │ │ ├── Android.bp │ │ ├── CMakeLists.txt │ │ └── main.cpp │ ├── rm_comment │ └── rm_comment.exe ├── AndroidMK │ ├── LoadModule.cmake │ ├── Parse.cmake │ ├── ParseIf.cmake │ ├── ParseValues.cmake │ ├── addTarget.cmake │ ├── dep │ │ ├── Android.mk │ │ ├── common.cpp │ │ ├── common.h │ │ ├── help │ │ │ └── common.cpp │ │ ├── help_suffix.cpp │ │ ├── test.cpp │ │ └── test.h │ └── test │ │ ├── Android.mk │ │ ├── common.cpp │ │ ├── common.h │ │ ├── test.cpp │ │ └── test.h ├── android.env.cmake ├── android.flag.cmake ├── android.func.cmake ├── android.module.cmake ├── android.toolchain.cmake ├── arm │ ├── armv7-a-neon.cmake │ └── armv7-a.cmake ├── arm64 │ ├── armv8-2a.cmake │ └── armv8-a.cmake ├── exe32.cmake └── exe64.cmake ├── LICENSE ├── README.md ├── README_zh-CN.md └── android-test ├── CMakeLists.txt ├── include └── test.h ├── main.c └── test.c /.idea/misc.xml: -------------------------------------------------------------------------------- 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 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 141 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.6.0-rc2) 2 | 3 | SET(ANDROID_TEST_MODE OFF) 4 | SET(PROJECT_DIR "${CMAKE_HOME_DIRECTORY}") 5 | include(CMakeModule/android.env.cmake) 6 | include(CMakeModule/android.func.cmake) 7 | set(CMAKE_TOOLCHAIN_FILE ${PROJECT_DIR}/CMakeModule/android.toolchain.cmake) 8 | 9 | project(Android) 10 | 11 | if (ANDROID) 12 | message("Hello from Android build!") 13 | endif() 14 | 15 | ENABLE_LANGUAGE(ASM) 16 | 17 | include_directories( SYSTEM 18 | ${PROJECT_DIR}/libnativehelper/include/nativehelper 19 | ${PROJECT_DIR}/external/libcxx/include 20 | ${PROJECT_DIR}/external/libcxxabi/include 21 | ) 22 | #system 23 | include_directories( SYSTEM 24 | "${PROJECT_DIR}/system/core/include" 25 | "${PROJECT_DIR}/system/media/audio/include" 26 | "${PROJECT_DIR}/hardware/libhardware/include" 27 | "${PROJECT_DIR}/hardware/libhardware_legacy/include" 28 | "${PROJECT_DIR}/libnativehelper/include" 29 | "${PROJECT_DIR}/frameworks/native/include" 30 | "${PROJECT_DIR}/frameworks/native/opengl/include" 31 | "${PROJECT_DIR}/frameworks/av/include" 32 | "${PROJECT_DIR}/frameworks/base/include" 33 | "${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}/obj/include" 34 | "${PROJECT_DIR}/bionic/libc/arch-${ANDROID_SYSROOT_ABI}/include" 35 | "${PROJECT_DIR}/bionic/libc/include" 36 | "${PROJECT_DIR}/bionic/libc/kernel/uapi" 37 | "${PROJECT_DIR}/bionic/libc/kernel/android/uapi" 38 | "${PROJECT_DIR}/bionic/libc/kernel/common" 39 | "${PROJECT_DIR}/bionic/libc/kernel/uapi/asm-${ANDROID_SYSROOT_ABI}" 40 | "${PROJECT_DIR}/bionic/libm/include" 41 | "${PROJECT_DIR}/bionic/libm/include/${ANDROID_SYSROOT_ABI}" 42 | ) 43 | 44 | if(NOT ANDROID_TEST_MODE) 45 | include(CMakeModule/android.module.cmake) 46 | endif() 47 | 48 | if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/android-test/CMakeLists.txt) 49 | add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/android-test) 50 | endif() 51 | -------------------------------------------------------------------------------- /CMakeModule/AndroidBP/Parse.cmake: -------------------------------------------------------------------------------- 1 | 2 | SET(ANDROID_BP_DEBUG_LOCAL OFF) 3 | 4 | SET(ANDROID_BP_NONE 0) 5 | SET(ANDROID_BP_DEFAULT 1) 6 | SET(ANDROID_BP_HEADERS 2) 7 | SET(ANDROID_BP_MODULES 3) 8 | SET(ANDROID_BP_NORMAL 4) 9 | 10 | include(${CMAKE_CURRENT_LIST_DIR}/ParseOther.cmake) 11 | 12 | ## Init env. 13 | function(initBpEnv) 14 | SET(LOCAL_MODULE "" PARENT_SCOPE) 15 | SET(LOCAL_CFLAGS "" PARENT_SCOPE) 16 | SET(LOCAL_CPPFLAGS "" PARENT_SCOPE) 17 | SET(LOCAL_SRC_FILES "" PARENT_SCOPE) 18 | SET(LOCAL_C_INCLUDES "" PARENT_SCOPE) 19 | SET(LOCAL_SHARED_LIBRARIES "" PARENT_SCOPE) 20 | SET(LOCAL_STATIC_LIBRARIES "" PARENT_SCOPE) 21 | SET(LOCAL_EXPORT_C_INCLUDE_DIRS "" PARENT_SCOPE) 22 | endfunction() 23 | 24 | ## unused. 25 | function(doCatLine in out) 26 | string(LENGTH "${in}" texr_fun_length) 27 | message("texr_fun_length=${texr_fun_length}") 28 | string(FIND "${in}" "//" fun_num) 29 | if("${Brackets_num}" EQUAL "-1" ) 30 | return() 31 | endif() 32 | 33 | string(FIND "${in}" "\n" fun_enter_num) 34 | string(SUBSTRING "${in}" "0" "${fun_num}" begin_text) 35 | message("begin_text=${begin_text}") 36 | string(SUBSTRING "${in}" "${fun_enter_num}" "${texr_fun_length}" end_text) 37 | message("end_text=${end_text}") 38 | 39 | set(${out} "${begin_text}${end_text}") 40 | endfunction() 41 | 42 | function(myListAppend org append out) 43 | if("${append}" STREQUAL "" ) 44 | SET("${out}" "${org}" PARENT_SCOPE) 45 | return() 46 | endif() 47 | 48 | if("${org}" STREQUAL "" ) 49 | SET("${out}" "${append}" PARENT_SCOPE) 50 | else() 51 | SET("${out}" "${org};${append}" PARENT_SCOPE) 52 | endif() 53 | endfunction() 54 | 55 | ## Add local_path to export dir 56 | function(exportExpand local_path) 57 | foreach(export ${LOCAL_EXPORT_C_INCLUDE_DIRS}) 58 | if("${export}" STREQUAL ".") 59 | list(APPEND exportExpand_tmp "${local_path}") 60 | else() 61 | list(APPEND exportExpand_tmp "${local_path}/${export}") 62 | endif() 63 | endforeach() 64 | SET(LOCAL_EXPORT_C_INCLUDE_DIRS "${exportExpand_tmp}" PARENT_SCOPE) 65 | endfunction() 66 | 67 | ## For export_static_lib_headers/export_shared_lib_headers in module 68 | function(doOtherLibExport module module_type libName type) 69 | containsModule("${libName}_${type}" is_find) 70 | if(is_find) 71 | getModuleExport("${libName}" "${type}" export_list) 72 | myListAppend("${LOCAL_EXPORT_C_INCLUDE_DIRS}" "${export_list}" doOtherLibExport_include_dirs) 73 | SET(LOCAL_EXPORT_C_INCLUDE_DIRS "${doOtherLibExport_include_dirs}" PARENT_SCOPE) 74 | else() 75 | addNeedExport("${module}" "${module_type}" "${libName}" "${type}") 76 | endif() 77 | endfunction() 78 | 79 | function(isVariable list out) 80 | set(isVariable_list "${list}") 81 | foreach(variable ${isVariable_list}) 82 | if(${variable}_V) 83 | list(REMOVE_ITEM isVariable_list "${variable}") 84 | list(APPEND isVariable_list "${${variable}_V}") 85 | endif() 86 | endforeach() 87 | SET("${out}" "${isVariable_list}" PARENT_SCOPE) 88 | endfunction() 89 | 90 | ## For value in module item 91 | function(BracketsToList line out) 92 | string(REPLACE "[" "" BracketsToList_line "${line}") 93 | string(REPLACE "]" "" BracketsToList_line "${BracketsToList_line}") 94 | string(REPLACE "\\\"" "'" BracketsToList_line "${BracketsToList_line}") 95 | string(REPLACE "\"" "" BracketsToList_line "${BracketsToList_line}") 96 | string(REPLACE "'" "\"" BracketsToList_line "${BracketsToList_line}") 97 | string(REPLACE "," " " BracketsToList_line "${BracketsToList_line}") 98 | string(REGEX REPLACE " +" " " BracketsToList_line "${BracketsToList_line}") 99 | string(STRIP ${BracketsToList_line} BracketsToList_line) 100 | string(REPLACE " " ";" BracketsToList_line "${BracketsToList_line}") 101 | set(${out} "${BracketsToList_line}" PARENT_SCOPE) 102 | endfunction() 103 | 104 | ## For xxxx = [ xxxx, xxxx, xxx] 105 | function(doVariable line) 106 | string(LENGTH "${line}" doVariable_length) 107 | string(FIND "${line}" "=" name_num) 108 | string(SUBSTRING ${line} "0" "${name_num}" doVariable_name) 109 | string(STRIP ${doVariable_name} doVariable_name) 110 | #message("doVariable_name:${doVariable_name}") 111 | math(EXPR name_num "${name_num} + 1") 112 | string(SUBSTRING ${line} "${name_num}" "${doVariable_length}" doVariable_value) 113 | BracketsToList("${doVariable_value}" doVariable_value) 114 | SET("${doVariable_name}_V" "${doVariable_value}" PARENT_SCOPE) 115 | endfunction() 116 | 117 | ## For xxxx_headers in Android.bp 118 | function(doHeader line header_name) 119 | if("${line}" MATCHES "^export_include_dirs:.*") 120 | string(REPLACE "export_include_dirs:" "" line "${line}") 121 | string(STRIP ${line} line) 122 | BracketsToList("${line}" export_include_dirs) 123 | SET(${header_name}_export_include_dirs "${export_include_dirs}" PARENT_SCOPE) 124 | endif() 125 | endfunction() 126 | 127 | ## For xxxx_default in Android.bp 128 | function(doDefault line default_name) 129 | 130 | if("${line}" MATCHES "^cflags: .*") 131 | string(REPLACE "cflags:" "" line "${line}") 132 | string(STRIP ${line} line) 133 | BracketsToList("${line}" c_flags) 134 | isVariable("${c_flags}" c_flags) 135 | SET(${default_name}_c_flags "${c_flags}" PARENT_SCOPE) 136 | elseif("${line}" MATCHES "^cppflags: .*") 137 | string(REPLACE "cppflags:" "" line "${line}") 138 | string(STRIP ${line} line) 139 | BracketsToList("${line}" cppflags) 140 | isVariable("${cppflags}" cppflags) 141 | SET(${default_name}_cpp_flags "${cppflags}" PARENT_SCOPE) 142 | elseif("${line}" MATCHES "^static_libs: .*") 143 | string(REPLACE "static_libs:" "" line "${line}") 144 | string(STRIP ${line} line) 145 | BracketsToList("${line}" static_libs) 146 | isVariable("${static_libs}" static_libs) 147 | SET(${default_name}_static_libs "${static_libs}" PARENT_SCOPE) 148 | elseif("${line}" MATCHES "^shared_libs: .*") 149 | string(REPLACE "shared_libs:" "" line "${line}") 150 | string(STRIP ${line} line) 151 | BracketsToList("${line}" shared_libs) 152 | isVariable("${shared_libs}" shared_libs) 153 | SET(${default_name}_shared_libs "${shared_libs}" PARENT_SCOPE) 154 | elseif("${line}" MATCHES "^srcs: .*") 155 | string(REPLACE "srcs:" "" line "${line}") 156 | string(STRIP ${line} line) 157 | BracketsToList("${line}" srcs) 158 | isVariable("${srcs}" srcs) 159 | SET(${default_name}_srcs "${srcs}" PARENT_SCOPE) 160 | elseif("${line}" MATCHES "^include_dirs: .*") 161 | string(REPLACE "include_dirs:" "" line "${line}") 162 | string(STRIP ${line} line) 163 | BracketsToList("${line}" include_dirs) 164 | isVariable("${include_dirs}" include_dirs) 165 | SET(${default_name}_include_dirs "${include_dirs}" PARENT_SCOPE) 166 | elseif("${line}" MATCHES "^export_include_dirs:.*") 167 | string(REPLACE "export_include_dirs:" "" line "${line}") 168 | string(STRIP ${line} line) 169 | BracketsToList("${line}" export_include_dirs) 170 | isVariable("${export_include_dirs}" export_include_dirs) 171 | SET(${default_name}_export_include_dirs "${export_include_dirs}" PARENT_SCOPE) 172 | elseif("${line}" MATCHES "^export_header_lib_headers:.*") 173 | string(REPLACE "export_header_lib_headers:" "" line "${line}") 174 | string(STRIP ${line} line) 175 | BracketsToList("${line}" export_header_lib_headers) 176 | isVariable("${export_header_lib_headers}" export_header_lib_headers) 177 | SET(${default_name}_export_header_lib_headers "${export_header_lib_headers}" PARENT_SCOPE) 178 | endif() 179 | endfunction() 180 | 181 | ## For cc_library_xx/cc_binary in Android.bp 182 | function(doModule line) 183 | if("${line}" MATCHES "^srcs:.*") 184 | string(REPLACE "srcs:" "" line "${line}") 185 | string(STRIP ${line} line) 186 | BracketsToList("${line}" srcs) 187 | myListAppend("${srcs}" "${LOCAL_SRC_FILES}" doModule_srcs) 188 | foreach(src ${doModule_srcs}) 189 | if("${src}" MATCHES "^:.*$") 190 | string(REPLACE ":" "" src "${src}") 191 | string(STRIP ${src} src) 192 | list(REMOVE_ITEM doModule_srcs "${src}") 193 | # myListAppend("${LOCAL_SRC_FILES}" "${${doModule_default}_srcs}" LOCAL_SRC_FILES) 194 | list(APPEND doModule_srcs "${${src}_srcs}") 195 | elseif(NOT "${src}" MATCHES "^.*\\..*$") 196 | list(REMOVE_ITEM doModule_srcs "${src}") 197 | list(APPEND doModule_srcs ${${src}_V}) 198 | endif() 199 | endforeach() 200 | SET(LOCAL_SRC_FILES "${doModule_srcs}" PARENT_SCOPE) 201 | elseif("${line}" MATCHES "^static_libs:.*") 202 | string(REPLACE "static_libs:" "" line "${line}") 203 | string(STRIP ${line} line) 204 | BracketsToList("${line}" static_libs) 205 | myListAppend("${static_libs}" "${LOCAL_STATIC_LIBRARIES}" doModule_static_libs) 206 | isVariable("${doModule_static_libs}" doModule_static_libs) 207 | SET(LOCAL_STATIC_LIBRARIES "${doModule_static_libs}" PARENT_SCOPE) 208 | elseif("${line}" MATCHES "^whole_static_libs:.*") 209 | string(REPLACE "whole_static_libs:" "" line "${line}") 210 | string(STRIP ${line} line) 211 | BracketsToList("${line}" whole_static_libs) 212 | myListAppend("${whole_static_libs}" "${LOCAL_STATIC_LIBRARIES}" doModule_whole_static_libs) 213 | isVariable("${doModule_whole_static_libs}" doModule_whole_static_libs) 214 | SET(LOCAL_STATIC_LIBRARIES "${doModule_whole_static_libs}" PARENT_SCOPE) 215 | elseif("${line}" MATCHES "^shared_libs:.*") 216 | string(REPLACE "shared_libs:" "" line "${line}") 217 | string(STRIP ${line} line) 218 | BracketsToList("${line}" shared_libs) 219 | myListAppend("${shared_libs}" "${LOCAL_SHARED_LIBRARIES}" doModule_shared_libs) 220 | isVariable("${doModule_shared_libs}" doModule_shared_libs) 221 | SET(LOCAL_SHARED_LIBRARIES "${doModule_shared_libs}" PARENT_SCOPE) 222 | elseif("${line}" MATCHES "^cppflags:.*") 223 | string(REPLACE "cppflags:" "" line "${line}") 224 | string(STRIP ${line} line) 225 | BracketsToList("${line}" cppflags) 226 | myListAppend("${cppflags}" "${LOCAL_CPPFLAGS}" doModule_cppflags) 227 | isVariable("${doModule_cppflags}" doModule_cppflags) 228 | SET(LOCAL_CPPFLAGS "${doModule_cppflags}" PARENT_SCOPE) 229 | elseif("${line}" MATCHES "^cflags:.*") 230 | string(REPLACE "cflags:" "" line "${line}") 231 | string(STRIP ${line} line) 232 | BracketsToList("${line}" cflags) 233 | myListAppend("${cflags}" "${LOCAL_CFLAGS}" doModule_cflags) 234 | isVariable("${doModule_cflags}" doModule_cflags) 235 | SET(LOCAL_CFLAGS "${doModule_cflags}" PARENT_SCOPE) 236 | elseif("${line}" MATCHES "^include_dirs:.*") 237 | string(REPLACE "include_dirs:" "" line "${line}") 238 | string(STRIP ${line} line) 239 | BracketsToList("${line}" include_dirs) 240 | myListAppend("${include_dirs}" "${LOCAL_C_INCLUDES}" doModule_include_dirs) 241 | isVariable("${doModule_include_dirs}" doModule_include_dirs) 242 | SET(LOCAL_C_INCLUDES "${doModule_include_dirs}" PARENT_SCOPE) 243 | elseif("${line}" MATCHES "^export_include_dirs:.*") 244 | string(REPLACE "export_include_dirs:" "" line "${line}") 245 | string(STRIP ${line} line) 246 | BracketsToList("${line}" export_include_dirs) 247 | myListAppend("${export_include_dirs}" "${LOCAL_EXPORT_C_INCLUDE_DIRS}" doModule_export_include_dirs) 248 | isVariable("${doModule_export_include_dirs}" doModule_export_include_dirs) 249 | SET(LOCAL_EXPORT_C_INCLUDE_DIRS "${doModule_export_include_dirs}" PARENT_SCOPE) 250 | endif() 251 | endfunction() 252 | 253 | function(parseAndroidBP module_name type path) 254 | SET(bp_path ${path}/Android.bp) 255 | message("AndroidBP:${bp_path}") 256 | ## Rm android.bp comment. 257 | if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) 258 | execute_process(COMMAND ${PROJECT_DIR}/CMakeModule/AndroidBP/rm_comment.exe ${bp_path} OUTPUT_VARIABLE MyFile) 259 | else() 260 | execute_process(COMMAND ${PROJECT_DIR}/CMakeModule/AndroidBP/rm_comment ${bp_path} OUTPUT_VARIABLE MyFile) 261 | endif() 262 | STRING(REGEX REPLACE ";" "\\\\;" MyFile "${MyFile}") 263 | ## Read line android.bp. 264 | STRING(REGEX REPLACE "\n" ";" MyFile "${MyFile}") 265 | ## Read brackets num. 266 | SET(Brackets_num 0) 267 | ## Parsing type. 268 | SET(bpType "${ANDROID_BP_NONE}") 269 | # SET(LOCAL_MODULE "") 270 | SET(default_name "") 271 | SET(normal_name "") 272 | SET(header_name "") 273 | SET(module_type "") 274 | 275 | SET(blockBrackets "0") 276 | SET(isBlock OFF) 277 | 278 | foreach(line ${MyFile}) 279 | ## \n is converted to ";" when the file is read. It needs to be replaced. 280 | string(STRIP "${line}" line) 281 | if("${line}" MATCHES "^//+") 282 | continue() 283 | endif() 284 | string(REPLACE ";" "" line "${line}") 285 | ## Remove \t. 286 | string(REGEX REPLACE "(\t)+" " " line "${line}") 287 | string(REGEX REPLACE " +" " " line "${line}") 288 | #message("parseAndroidBP: ${line}") 289 | 290 | if("${line}" MATCHES ".*{$") 291 | math(EXPR Brackets_num "${Brackets_num} + 1") 292 | if("${Brackets_num}" EQUAL "1" ) 293 | ## Set parsing type. 294 | if("${line}" MATCHES ".*defaults.*") 295 | SET(bpType "${ANDROID_BP_DEFAULT}") 296 | elseif("${line}" MATCHES ".*headers.*") 297 | SET(bpType "${ANDROID_BP_HEADERS}") 298 | elseif("${line}" MATCHES "^cc_.*") 299 | SET(bpType "${ANDROID_BP_MODULES}") 300 | if("${line}" MATCHES ".*cc_library.*") 301 | SET(module_type "${type}") 302 | elseif("${line}" MATCHES ".*cc_binary.*") 303 | SET(module_type "${MK_EXECAB}") 304 | elseif("${line}" MATCHES ".*cc_library_static.*") 305 | SET(module_type "${MK_STATIC}") 306 | elseif("${line}" MATCHES ".*cc_library_shared.*") 307 | SET(module_type "${MK_SHARED}") 308 | endif() 309 | else() 310 | SET(bpType "${ANDROID_BP_NORMAL}") 311 | endif() 312 | elseif("${Brackets_num}" GREATER "1" ) 313 | ## Block some line. 314 | if("${line}" MATCHES ".*host.*" OR "${line}" MATCHES ".*windows.*" OR "${line}" MATCHES ".*x86.*" OR "${line}" MATCHES ".*x86_64.*") 315 | SET(blockBrackets "${Brackets_num}") 316 | SET(isBlock ON) 317 | endif() 318 | endif() 319 | elseif("${line}" MATCHES "^}.*") 320 | math(EXPR Brackets_num "${Brackets_num} - 1") 321 | if("${Brackets_num}" EQUAL "0" ) 322 | if("${bpType}" STREQUAL "${ANDROID_BP_MODULES}") 323 | ## Add android target. 324 | exportExpand("${LOCAL_PATH}") 325 | if(ANDROID_BP_DEBUG_LOCAL) 326 | message("LOCAL_MODULE=${LOCAL_MODULE}") 327 | message("LOCAL_SRC_FILES=${LOCAL_SRC_FILES}") 328 | message("LOCAL_CFLAGS=${LOCAL_CFLAGS}") 329 | message("LOCAL_CPPFLAGS=${LOCAL_CPPFLAGS}") 330 | message("LOCAL_SHARED_LIBRARIES=${LOCAL_SHARED_LIBRARIES}") 331 | message("LOCAL_STATIC_LIBRARIES=${LOCAL_STATIC_LIBRARIES}") 332 | message("LOCAL_C_INCLUDES=${LOCAL_C_INCLUDES}") 333 | message("LOCAL_EXPORT_C_INCLUDE_DIRS=${LOCAL_EXPORT_C_INCLUDE_DIRS}") 334 | endif() 335 | if("${LOCAL_MODULE}" STREQUAL "${module_name}" ) 336 | if("${module_type}" STREQUAL "${type}" ) 337 | addTarget("${type}") 338 | initBpEnv() 339 | break() 340 | endif() 341 | endif() 342 | endif() 343 | initBpEnv() 344 | SET(bpType "${ANDROID_BP_NONE}") 345 | else() 346 | ## Remove block flag. 347 | if(isBlock) 348 | if("${Brackets_num}" LESS "${blockBrackets}" ) 349 | SET(isBlock OFF) 350 | SET(blockBrackets "0") 351 | endif() 352 | endif() 353 | endif() 354 | elseif("${line}" MATCHES "^name: .*") 355 | string(REPLACE "name:" "" parseAndroidBP_name "${line}") 356 | string(STRIP ${parseAndroidBP_name} parseAndroidBP_name) 357 | string(REPLACE "\"" "" parseAndroidBP_name "${parseAndroidBP_name}") 358 | string(REPLACE "," "" parseAndroidBP_name "${parseAndroidBP_name}") 359 | ## Set type name. 360 | if("${bpType}" STREQUAL "${ANDROID_BP_DEFAULT}") 361 | SET(default_name "${parseAndroidBP_name}") 362 | elseif("${bpType}" STREQUAL "${ANDROID_BP_HEADERS}") 363 | SET(header_name "${parseAndroidBP_name}") 364 | elseif("${bpType}" STREQUAL "${ANDROID_BP_MODULES}") 365 | SET(LOCAL_MODULE "${parseAndroidBP_name}") 366 | elseif("${bpType}" STREQUAL "${ANDROID_BP_NORMAL}") 367 | SET(normal_name "${parseAndroidBP_name}") 368 | endif() 369 | elseif("${line}" MATCHES "^defaults: .*") 370 | if("${LOCAL_MODULE}" STREQUAL "${module_name}" ) 371 | string(REPLACE "defaults:" "" line "${line}") 372 | string(STRIP ${line} line) 373 | BracketsToList("${line}" defaults) 374 | foreach(doModule_default ${defaults}) 375 | ## Parsing "default" in the module. 376 | myListAppend("${LOCAL_CFLAGS}" "${${doModule_default}_c_flags}" LOCAL_CFLAGS) 377 | myListAppend("${LOCAL_CPPFLAGS}" "${${doModule_default}_cpp_flags}" LOCAL_CPPFLAGS) 378 | myListAppend("${LOCAL_SRC_FILES}" "${${doModule_default}_srcs}" LOCAL_SRC_FILES) 379 | myListAppend("${LOCAL_C_INCLUDES}" "${${doModule_default}_include_dirs}" LOCAL_C_INCLUDES) 380 | myListAppend("${LOCAL_STATIC_LIBRARIES}" "${${doModule_default}_static_libs}" LOCAL_STATIC_LIBRARIES) 381 | myListAppend("${LOCAL_SHARED_LIBRARIES}" "${${doModule_default}_shared_libs}" LOCAL_SHARED_LIBRARIES) 382 | myListAppend("${LOCAL_EXPORT_C_INCLUDE_DIRS}" "${${doModule_default}_export_include_dirs}" LOCAL_EXPORT_C_INCLUDE_DIRS) 383 | ## Parsing "default->export_header_lib_headers->export_include_dirs" in the used module. 384 | foreach(export_header_lib "${${doModule_default}_export_header_lib_headers}") 385 | myListAppend("${LOCAL_EXPORT_C_INCLUDE_DIRS}" "${${export_header_lib}_export_include_dirs}" LOCAL_EXPORT_C_INCLUDE_DIRS) 386 | endforeach() 387 | endforeach() 388 | endif() 389 | elseif("${line}" MATCHES "^export_header_lib_headers:.*") 390 | if("${LOCAL_MODULE}" STREQUAL "${module_name}" AND "${bpType}" STREQUAL "${ANDROID_BP_MODULES}") 391 | ## Parsing "cc_library_xx/cc_binary->export_header_lib_headers" in the module. 392 | string(REPLACE "export_header_lib_headers:" "" line "${line}") 393 | string(STRIP ${line} line) 394 | BracketsToList("${line}" export_header_lib_headers) 395 | foreach(export_header ${export_header_lib_headers}) 396 | myListAppend("${LOCAL_EXPORT_C_INCLUDE_DIRS}" "${${export_header}_export_include_dirs}" LOCAL_EXPORT_C_INCLUDE_DIRS) 397 | endforeach() 398 | elseif("${bpType}" STREQUAL "${ANDROID_BP_DEFAULT}") 399 | ## Parsing "xxx_default->export_header_lib_headers" in the default. 400 | doDefault("${line}" "${default_name}") 401 | endif() 402 | elseif("${line}" MATCHES "^export_static_lib_headers:.*") 403 | ## Parsing "export_static_lib_headers" in the module. 404 | if("${LOCAL_MODULE}" STREQUAL "${module_name}" AND "${bpType}" STREQUAL "${ANDROID_BP_MODULES}") 405 | string(REPLACE "export_static_lib_headers:" "" line "${line}") 406 | string(STRIP ${line} line) 407 | BracketsToList("${line}" export_static_lib_headers) 408 | foreach(export_static ${export_static_lib_headers}) 409 | doOtherLibExport("${LOCAL_MODULE}" "${module_type}" "${export_static}" ${MK_STATIC}) 410 | endforeach() 411 | endif() 412 | elseif("${line}" MATCHES "^export_shared_lib_headers:.*") 413 | ## Parsing "export_shared_lib_headers" in the module. 414 | if("${LOCAL_MODULE}" STREQUAL "${module_name}" AND "${bpType}" STREQUAL "${ANDROID_BP_MODULES}") 415 | string(REPLACE "export_shared_lib_headers:" "" line "${line}") 416 | string(STRIP ${line} line) 417 | BracketsToList("${line}" export_shared_lib_headers) 418 | foreach(export_shared ${export_shared_lib_headers}) 419 | doOtherLibExport("${LOCAL_MODULE}" "${module_type}" "${export_shared}" ${MK_SHARED}) 420 | endforeach() 421 | endif() 422 | elseif(NOT isBlock) 423 | ## If not block parsing line by type. 424 | if("${bpType}" STREQUAL "${ANDROID_BP_DEFAULT}") 425 | doDefault("${line}" "${default_name}") 426 | elseif("${bpType}" STREQUAL "${ANDROID_BP_NORMAL}") 427 | doDefault("${line}" "${normal_name}") 428 | elseif("${bpType}" STREQUAL "${ANDROID_BP_HEADERS}") 429 | doHeader("${line}" "${header_name}") 430 | elseif("${bpType}" STREQUAL "${ANDROID_BP_MODULES}") 431 | doModule("${line}") 432 | else() 433 | ## Parsing line "build = [xxxx.bp]". 434 | if("${line}" MATCHES "build.*=.*") 435 | string(REGEX REPLACE "build.*=" "" line "${line}") 436 | string(STRIP ${line} line) 437 | BracketsToList("${line}" doBuild_value) 438 | parseOtherBP("${LOCAL_PATH}/${doBuild_value}") 439 | #message("build:${module_name}") 440 | elseif("${line}" MATCHES ".*=.*\\[") 441 | doVariable("${line}") 442 | endif() 443 | endif() 444 | endif() 445 | endforeach() 446 | 447 | ## Find the dependencies of the module, and parsing. 448 | doModuleDependencies("${module_name}_${type}") 449 | ## Find and set the export include of the module. 450 | doExportInclude("${module_name}_${type}") 451 | endfunction() -------------------------------------------------------------------------------- /CMakeModule/AndroidBP/ParseOther.cmake: -------------------------------------------------------------------------------- 1 | 2 | function(doHeaderOther line header_name out) 3 | if("${line}" MATCHES "^export_include_dirs:.*") 4 | string(REPLACE "export_include_dirs:" "" line "${line}") 5 | string(STRIP ${line} line) 6 | BracketsToList("${line}" export_include_dirs) 7 | SET(${header_name}_export_include_dirs "${export_include_dirs}" PARENT_SCOPE) 8 | SET("${out}" "${header_name}_export_include_dirs" PARENT_SCOPE) 9 | endif() 10 | endfunction() 11 | 12 | function(doVariableOther line out) 13 | string(LENGTH "${line}" doVariable_length) 14 | string(FIND "${line}" "=" name_num) 15 | string(SUBSTRING ${line} "0" "${name_num}" doVariable_name) 16 | string(STRIP ${doVariable_name} doVariable_name) 17 | math(EXPR name_num "${name_num} + 1") 18 | string(SUBSTRING ${line} "${name_num}" "${doVariable_length}" doVariable_value) 19 | BracketsToList("${doVariable_value}" doVariable_value) 20 | SET("${out}" "${doVariable_name}" PARENT_SCOPE) 21 | SET("${doVariable_name}" "${doVariable_value}" PARENT_SCOPE) 22 | endfunction() 23 | 24 | function(doDefaultOther line default_name out) 25 | 26 | if("${line}" MATCHES "^cflags: .*") 27 | string(REPLACE "cflags:" "" line "${line}") 28 | string(STRIP ${line} line) 29 | BracketsToList("${line}" c_flags) 30 | SET(${default_name}_c_flags "${c_flags}" PARENT_SCOPE) 31 | SET("${out}" "${default_name}_c_flags" PARENT_SCOPE) 32 | elseif("${line}" MATCHES "^cppflags: .*") 33 | string(REPLACE "cppflags:" "" line "${line}") 34 | string(STRIP ${line} line) 35 | BracketsToList("${line}" cppflags) 36 | SET(${default_name}_cpp_flags "${cppflags}" PARENT_SCOPE) 37 | SET("${out}" "${default_name}_cpp_flags" PARENT_SCOPE) 38 | elseif("${line}" MATCHES "^static_libs: .*") 39 | string(REPLACE "static_libs:" "" line "${line}") 40 | string(STRIP ${line} line) 41 | BracketsToList("${line}" static_libs) 42 | SET(${default_name}_static_libs "${static_libs}" PARENT_SCOPE) 43 | SET("${out}" "${default_name}_static_libs" PARENT_SCOPE) 44 | elseif("${line}" MATCHES "^shared_libs: .*") 45 | string(REPLACE "shared_libs:" "" line "${line}") 46 | string(STRIP ${line} line) 47 | BracketsToList("${line}" shared_libs) 48 | SET(${default_name}_shared_libs "${shared_libs}" PARENT_SCOPE) 49 | SET("${out}" "${default_name}_shared_libs" PARENT_SCOPE) 50 | elseif("${line}" MATCHES "^srcs: .*") 51 | string(REPLACE "srcs:" "" line "${line}") 52 | string(STRIP ${line} line) 53 | BracketsToList("${line}" srcs) 54 | SET(${default_name}_srcs "${srcs}" PARENT_SCOPE) 55 | SET("${out}" "${default_name}_srcs" PARENT_SCOPE) 56 | elseif("${line}" MATCHES "^include_dirs: .*") 57 | string(REPLACE "include_dirs:" "" line "${line}") 58 | string(STRIP ${line} line) 59 | BracketsToList("${line}" include_dirs) 60 | SET(${default_name}_include_dirs "${include_dirs}" PARENT_SCOPE) 61 | SET("${out}" "${default_name}_include_dirs" PARENT_SCOPE) 62 | elseif("${line}" MATCHES "^export_include_dirs:.*") 63 | string(REPLACE "export_include_dirs:" "" line "${line}") 64 | string(STRIP ${line} line) 65 | BracketsToList("${line}" export_include_dirs) 66 | SET(${default_name}_export_include_dirs "${export_include_dirs}" PARENT_SCOPE) 67 | SET("${out}" "${default_name}_export_include_dirs" PARENT_SCOPE) 68 | endif() 69 | endfunction() 70 | 71 | function(parseOtherBP parseOtherBP_path) 72 | message("OtherBP:${parseOtherBP_path}") 73 | execute_process(COMMAND ${PROJECT_DIR}/CMakeModule/AndroidBP/rm_comment ${parseOtherBP_path} OUTPUT_VARIABLE parseOtherBP_MyFile) 74 | STRING(REGEX REPLACE ";" "\\\\;" parseOtherBP_MyFile "${parseOtherBP_MyFile}") 75 | STRING(REGEX REPLACE "\n" ";" parseOtherBP_MyFile "${parseOtherBP_MyFile}") 76 | 77 | SET(parseOtherBP_Brackets_num 0) 78 | SET(parseOtherBP_bpType "${ANDROID_BP_NONE}") 79 | # SET(LOCAL_MODULE "") 80 | SET(parseOtherBP_default_name "") 81 | SET(parseOtherBP_header_name "") 82 | SET(parseOtherBP_module_type "") 83 | 84 | SET(parseOtherBP_blockBrackets "0") 85 | SET(parseOtherBP_isBlock OFF) 86 | 87 | foreach(parseOtherBP_line ${parseOtherBP_MyFile}) 88 | string(STRIP "${parseOtherBP_line}" parseOtherBP_line) 89 | if("${parseOtherBP_line}" MATCHES "^//+") 90 | continue() 91 | endif() 92 | string(REPLACE ";" "" parseOtherBP_line "${parseOtherBP_line}") 93 | string(REGEX REPLACE "(\t)+" " " parseOtherBP_line "${parseOtherBP_line}") 94 | string(REGEX REPLACE " +" " " parseOtherBP_line "${parseOtherBP_line}") 95 | 96 | if("${parseOtherBP_line}" MATCHES ".*{$") 97 | math(EXPR parseOtherBP_Brackets_num "${parseOtherBP_Brackets_num} + 1") 98 | if("${parseOtherBP_Brackets_num}" EQUAL "1" ) 99 | if("${parseOtherBP_line}" MATCHES ".*defaults.*") 100 | SET(parseOtherBP_bpType "${ANDROID_BP_DEFAULT}") 101 | elseif("${parseOtherBP_line}" MATCHES ".*headers.*") 102 | SET(parseOtherBP_bpType "${ANDROID_BP_HEADERS}") 103 | endif() 104 | elseif("${parseOtherBP_Brackets_num}" GREATER "1" ) 105 | if("${parseOtherBP_line}" MATCHES ".*host.*" OR "${parseOtherBP_line}" MATCHES ".*windows.*" OR "${parseOtherBP_line}" MATCHES ".*x86.*" OR "${parseOtherBP_line}" MATCHES ".*x86_64.*") 106 | SET(parseOtherBP_blockBrackets "${parseOtherBP_Brackets_num}") 107 | SET(parseOtherBP_isBlock ON) 108 | endif() 109 | endif() 110 | elseif("${parseOtherBP_line}" MATCHES "^}.*") 111 | math(EXPR parseOtherBP_Brackets_num "${parseOtherBP_Brackets_num} - 1") 112 | if("${parseOtherBP_Brackets_num}" EQUAL "0" ) 113 | SET(parseOtherBP_bpType "${ANDROID_BP_NONE}") 114 | else() 115 | if(parseOtherBP_isBlock) 116 | if("${parseOtherBP_Brackets_num}" LESS "${parseOtherBP_blockBrackets}" ) 117 | SET(parseOtherBP_isBlock OFF) 118 | SET(parseOtherBP_blockBrackets "0") 119 | endif() 120 | endif() 121 | endif() 122 | elseif("${parseOtherBP_line}" MATCHES "^name: .*") 123 | string(REPLACE "name:" "" parseOtherBP_name "${parseOtherBP_line}") 124 | string(STRIP ${parseOtherBP_name} parseOtherBP_name) 125 | string(REPLACE "\"" "" parseOtherBP_name "${parseOtherBP_name}") 126 | string(REPLACE "," "" parseOtherBP_name "${parseOtherBP_name}") 127 | if("${parseOtherBP_bpType}" STREQUAL "${ANDROID_BP_DEFAULT}") 128 | SET(parseOtherBP_default_name "${parseOtherBP_name}") 129 | elseif("${parseOtherBP_bpType}" STREQUAL "${ANDROID_BP_HEADERS}") 130 | SET(parseOtherBP_header_name "${parseOtherBP_name}") 131 | endif() 132 | elseif(NOT parseOtherBP_isBlock) 133 | if("${parseOtherBP_bpType}" STREQUAL "${ANDROID_BP_DEFAULT}") 134 | doDefaultOther("${parseOtherBP_line}" "${parseOtherBP_default_name}" name) 135 | SET("${name}" "${${name}}" PARENT_SCOPE) 136 | elseif("${parseOtherBP_bpType}" STREQUAL "${ANDROID_BP_HEADERS}") 137 | doHeaderOther("${parseOtherBP_line}" "${parseOtherBP_default_name}" name) 138 | SET("${name}" "${${name}}" PARENT_SCOPE) 139 | elseif("${parseOtherBP_line}" MATCHES ".*=.*") 140 | doVariableOther("${parseOtherBP_line}" name) 141 | SET("${name}" "${${name}}" PARENT_SCOPE) 142 | endif() 143 | endif() 144 | endforeach() 145 | endfunction() -------------------------------------------------------------------------------- /CMakeModule/AndroidBP/rmComment/Android.bp: -------------------------------------------------------------------------------- 1 | default{ 2 | //lilililili 3 | test1 4 | //llilililili 5 | test2 // lilililili 6 | 7 | } -------------------------------------------------------------------------------- /CMakeModule/AndroidBP/rmComment/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.6) 2 | project(rm_comment) 3 | 4 | set(CMAKE_CXX_STANDARD 14) 5 | SET(CMAKE_EXE_LINKER_FLAGS "-static") 6 | add_executable(rm_comment main.cpp) -------------------------------------------------------------------------------- /CMakeModule/AndroidBP/rmComment/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define debug 0 5 | 6 | int main(int argc, char** argv) { 7 | if(argc < 1) return -1; 8 | 9 | std::ifstream infile(argv[1]); 10 | std::string line; 11 | while (std::getline(infile, line)){ 12 | #if debug 13 | std::cout << "1:" << line << std::endl; 14 | #endif 15 | line.erase(0,line.find_first_not_of(' ')); 16 | line.erase(line.find_last_not_of(' ') + 1); 17 | #if debug 18 | std::cout << "2:" << line << std::endl; 19 | #endif 20 | size_t index = line.find("//"); 21 | #if debug 22 | std::cout << "3:index=" << std::to_string(index) << std::endl; 23 | #endif 24 | if(index == 0){ 25 | continue; 26 | }else if( index != std::string::npos){ 27 | line.erase(index, line.length()); 28 | } 29 | std::cout << line << std::endl; 30 | } 31 | infile.close(); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /CMakeModule/AndroidBP/rm_comment: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ahren-Li/android-cmake-project/b3297ea3a51da3130caf29cd4892041bbec20a64/CMakeModule/AndroidBP/rm_comment -------------------------------------------------------------------------------- /CMakeModule/AndroidBP/rm_comment.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ahren-Li/android-cmake-project/b3297ea3a51da3130caf29cd4892041bbec20a64/CMakeModule/AndroidBP/rm_comment.exe -------------------------------------------------------------------------------- /CMakeModule/AndroidMK/LoadModule.cmake: -------------------------------------------------------------------------------- 1 | SET(LOAD_MODULE_DEBUG OFF) 2 | SET(MK_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/AndroidMK") 3 | SET(MK_DEP_DIR "${MK_OUT_DIR}/dep") 4 | SET(MK_EXP_DIR "${MK_OUT_DIR}/export") 5 | SET(MK_NEED_EXP_DIR "${MK_OUT_DIR}/need_export") 6 | 7 | function(paresPath in out) 8 | string(REGEX REPLACE " +|\"|\\[|\\]" "" paresPath_tmp ${in}) 9 | string(REGEX REPLACE ":{.*" "" paresPath_name ${paresPath_tmp}) 10 | string(REGEX REPLACE ".*path:" "" paresPath_tmp ${paresPath_tmp}) 11 | string(REGEX REPLACE ",.*" "" paresPath_path ${paresPath_tmp}) 12 | if(LOAD_MODULE_DEBUG) 13 | message("paresPath: name = ${name}") 14 | message("paresPath: path = ${path}") 15 | endif() 16 | SET(${out} "${paresPath_name}:${paresPath_path}\n" PARENT_SCOPE) 17 | endfunction() 18 | 19 | function(getModulePath type module out) 20 | SET(getModulePath_module_path "") 21 | string(REPLACE "+" "\\+" module "${module}") 22 | file(STRINGS ${MK_OUT_DIR}/${type}.module getModulePath_module_paths REGEX "^${module}:.*") 23 | foreach(getModulePath_path ${getModulePath_module_paths}) 24 | if(LOAD_MODULE_DEBUG) 25 | message("getModlePath: ${type} = ${getModulePath_path}") 26 | endif() 27 | string(REPLACE ":" ";" getModulePath_path ${getModulePath_path}) 28 | LIST(GET getModulePath_path 1 getModulePath_path) 29 | SET(getModulePath_module_path ${getModulePath_path}) 30 | endforeach() 31 | SET(${out} "${getModulePath_module_path}" PARENT_SCOPE) 32 | endfunction() 33 | 34 | function(containsModule name out) 35 | SET(${out} OFF PARENT_SCOPE) 36 | if(EXISTS ${MK_OUT_DIR}/module.list) 37 | string(REPLACE "+" "\\+" name "${name}") 38 | file(STRINGS ${MK_OUT_DIR}/module.list containsModule_module_list REGEX "^${name}:") 39 | foreach(containsModule_module_path ${containsModule_module_list}) 40 | # TODO 41 | SET(${out} ON PARENT_SCOPE) 42 | endforeach() 43 | endif() 44 | endfunction() 45 | 46 | function(containsDependencies module type name out) 47 | SET(${out} OFF PARENT_SCOPE) 48 | if(EXISTS ${MK_DEP_DIR}/${module}.dep) 49 | string(REPLACE "+" "\\+" name "${name}") 50 | file(STRINGS ${MK_DEP_DIR}/${module}.dep containsDependencies_list REGEX "^${name}:${type}") 51 | foreach(containsDependencies ${containsDependencies_list}) 52 | # TODO 53 | SET(${out} ON PARENT_SCOPE) 54 | endforeach() 55 | endif() 56 | endfunction() 57 | 58 | function(containsNeedExport module_name module_type libName type out) 59 | SET(${out} OFF PARENT_SCOPE) 60 | if(EXISTS "${MK_NEED_EXP_DIR}/${libName}_${type}.list") 61 | file(STRINGS "${MK_NEED_EXP_DIR}/${libName}_${type}.list" containsNeedExport_list REGEX "^${module_name}:${module_type}") 62 | if(NOT "${containsNeedExport_list}" STREQUAL "") 63 | SET(${out} ON PARENT_SCOPE) 64 | endif() 65 | endif() 66 | endfunction() 67 | 68 | function(getModuleDependencies module out) 69 | SET(${out} "" PARENT_SCOPE) 70 | if(EXISTS ${MK_DEP_DIR}/${module}.dep) 71 | file(STRINGS ${MK_DEP_DIR}/${module}.dep getModuleDependencies_list) 72 | set(${out} "${getModuleDependencies_list}" PARENT_SCOPE) 73 | endif() 74 | endfunction() 75 | 76 | function(doModuleDependencies module) 77 | getModuleDependencies("${module}" doModuleDependencies_list) 78 | foreach(doModuleDependencies_module ${doModuleDependencies_list}) 79 | string(REPLACE ":" ";" doModuleDependencies_module "${doModuleDependencies_module}") 80 | LIST(GET doModuleDependencies_module 0 doModuleDependencies_name) 81 | LIST(GET doModuleDependencies_module 1 doModuleDependencies_type) 82 | parseAndroidMK("${doModuleDependencies_name}" "${doModuleDependencies_type}") 83 | endforeach() 84 | endfunction() 85 | 86 | function(getModuleExport module_name type out) 87 | SET(${out} "" PARENT_SCOPE) 88 | if(EXISTS "${MK_EXP_DIR}/${module_name}_${type}.export") 89 | file(STRINGS "${MK_EXP_DIR}/${module_name}_${type}.export" getModuleExport_list) 90 | SET(${out} "${getModuleExport_list}" PARENT_SCOPE) 91 | endif() 92 | endfunction() 93 | 94 | function(doExportInclude module) 95 | getModuleDependencies("${module}" doModuleDependencies_list) 96 | foreach(doModuleDependencies_module ${doModuleDependencies_list}) 97 | string(REPLACE ":" ";" doModuleDependencies_module "${doModuleDependencies_module}") 98 | LIST(GET doModuleDependencies_module 0 doModuleDependencies_name) 99 | LIST(GET doModuleDependencies_module 1 doModuleDependencies_type) 100 | addExportInclude("${module}" "${MK_EXP_DIR}/${doModuleDependencies_name}_${doModuleDependencies_type}.export") 101 | endforeach() 102 | endfunction() 103 | 104 | function(doNeedExport module_type list) 105 | if(EXISTS "${MK_NEED_EXP_DIR}/${module_type}.list") 106 | file(STRINGS "${MK_NEED_EXP_DIR}/${module_type}.list" doNeedExport_list) 107 | foreach(doNeedExport_module ${doNeedExport_list}) 108 | string(REPLACE ":" "_" doNeedExport_module "${doNeedExport_module}") 109 | foreach(doNeedExport_dir ${list}) 110 | if(LOAD_MODULE_DEBUG) 111 | message("doNeedExport ${doNeedExport_module} add include ${doNeedExport_dir}") 112 | endif() 113 | saveExportInclude("${doNeedExport_module}" "${doNeedExport_dir}") 114 | endforeach() 115 | endforeach() 116 | endif() 117 | endfunction() 118 | 119 | ####### save someing ####### 120 | 121 | function(saveExportInclude module path) 122 | file(APPEND ${MK_EXP_DIR}/${module}.export "${path}\n") 123 | endfunction() 124 | 125 | function(addModuleDependencies module type dependency) 126 | containsDependencies("${module}" "${type}" "${dependency}" addModuleDependencies_is_add) 127 | if(NOT addModuleDependencies_is_add) 128 | file(APPEND ${MK_DEP_DIR}/${module}.dep "${dependency}:${type}\n") 129 | endif() 130 | endfunction() 131 | 132 | function(addModule name path) 133 | file(APPEND ${MK_OUT_DIR}/module.list "${name}:${path}\n") 134 | endfunction() 135 | 136 | function(addNeedExport module module_type libName type) 137 | containsNeedExport("${module}" "${module_type}" "${libName}" "${type}" isFind) 138 | if(NOT isFind) 139 | file(APPEND ${MK_NEED_EXP_DIR}/${libName}_${type}.list "${module}:${module_type}\n") 140 | endif() 141 | endfunction() 142 | 143 | function(loadModule ) 144 | parseInit() 145 | SET(loadModule_shared_file_path ${MK_OUT_DIR}/${MK_SHARED}.module) 146 | SET(loadModule_static_file_path ${MK_OUT_DIR}/${MK_STATIC}.module) 147 | SET(loadModule_execab_file_path ${MK_OUT_DIR}/${MK_EXECAB}.module) 148 | 149 | SET(loadModule_shared_list "") 150 | SET(loadModule_static_list "") 151 | SET(loadModule_execab_list "") 152 | 153 | if(NOT EXISTS ${loadModule_shared_file_path}) 154 | set(loadModule_need ON) 155 | endif() 156 | if(NOT EXISTS ${loadModule_static_file_path}) 157 | set(loadModule_need ON) 158 | endif() 159 | if(NOT EXISTS ${loadModule_execab_file_path}) 160 | set(loadModule_need ON) 161 | endif() 162 | if(loadModule_need) 163 | file(REMOVE ${loadModule_shared_file_path}) 164 | file(REMOVE ${loadModule_static_file_path}) 165 | file(REMOVE ${loadModule_execab_file_path}) 166 | else() 167 | return() 168 | endif() 169 | 170 | message("loadModule start ${ANDROID_LUNCH}") 171 | file(STRINGS ${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}/module-info.json MyFile REGEX "(SHARED_LIBRARIES|STATIC_LIBRARIES|EXECUTABLES)") 172 | message("loadModule end") 173 | foreach(line ${MyFile}) 174 | string(STRIP "${line}" line) 175 | # message(${line}) 176 | paresPath("${line}" loadModule_line) 177 | if( "${line}" MATCHES ".*STATIC_LIBRARIES.*") 178 | set(loadModule_static_list "${loadModule_static_list}${loadModule_line}") 179 | endif() 180 | if( "${line}" MATCHES ".*SHARED_LIBRARIES.*") 181 | set(loadModule_shared_list "${loadModule_shared_list}${loadModule_line}") 182 | endif() 183 | if( "${line}" MATCHES ".*EXECUTABLES.*") 184 | set(loadModule_execab_list "${loadModule_execab_list}${loadModule_line}") 185 | endif() 186 | endforeach() 187 | file(WRITE ${loadModule_shared_file_path} "${loadModule_shared_list}") 188 | file(WRITE ${loadModule_static_file_path} "${loadModule_static_list}") 189 | file(WRITE ${loadModule_execab_file_path} "${loadModule_execab_list}") 190 | endfunction() 191 | 192 | function(parseInit) 193 | file(REMOVE ${MK_OUT_DIR}/module.list) 194 | file(REMOVE_RECURSE ${MK_DEP_DIR}) 195 | file(REMOVE_RECURSE ${MK_EXP_DIR}) 196 | endfunction() -------------------------------------------------------------------------------- /CMakeModule/AndroidMK/Parse.cmake: -------------------------------------------------------------------------------- 1 | SET(MK_DEBUG OFF) 2 | SET(MK_LINE_DEBUG OFF) 3 | SET(MK_SHARED "SHARED") 4 | SET(MK_STATIC "STATIC") 5 | SET(MK_EXECAB "EXECAB") 6 | 7 | SET(MODULE_START OFF) 8 | 9 | SET(TARGET_TEST true) 10 | SET(TARGET_USES_HWC2 true) 11 | SET(TARGET_BUILD_VARIANT eng) 12 | SET(TARGET_BOARD_TEST TARGET_BOARD_PLATFORM) 13 | SET(TARGET_BOARD_PLATFORM rk3399) 14 | SET(TARGET_BOARD_PLATFORM_PRODUCT box) 15 | ########################### 16 | SET(TOP ${PROJECT_DIR}) 17 | SET(JNI_H_INCLUDE "libnativehelper/include/nativehelper") 18 | 19 | include(${CMAKE_CURRENT_LIST_DIR}/ParseIf.cmake) 20 | include(${CMAKE_CURRENT_LIST_DIR}/addTarget.cmake) 21 | include(${CMAKE_CURRENT_LIST_DIR}/ParseValues.cmake) 22 | 23 | function(parseLine line module_name type out_stop) 24 | 25 | if("${line}" MATCHES ".*CLEAR_VARS.*") 26 | initEnv() 27 | SET(MODULE_START ON PARENT_SCOPE) 28 | return() 29 | elseif("${line}" MATCHES ".*BUILD_SHARED_LIBRARY.*") 30 | if(MODULE_START AND "${module_name}" STREQUAL "${LOCAL_MODULE}" AND "${type}" STREQUAL "${MK_SHARED}") 31 | addTarget("${MK_SHARED}") 32 | set(${out_stop} ON PARENT_SCOPE) 33 | endif() 34 | SET(MODULE_START OFF PARENT_SCOPE) 35 | return() 36 | elseif("${line}" MATCHES ".*BUILD_STATIC_LIBRARY.*") 37 | if(MODULE_START AND "${module_name}" STREQUAL "${LOCAL_MODULE}" AND "${type}" STREQUAL "${MK_STATIC}") 38 | addTarget("${MK_STATIC}") 39 | set(${out_stop} ON PARENT_SCOPE) 40 | endif() 41 | SET(MODULE_START OFF PARENT_SCOPE) 42 | return() 43 | elseif("${line}" MATCHES ".*BUILD_EXECUTABLE.*") 44 | if(MODULE_START AND "${module_name}" STREQUAL "${LOCAL_MODULE}" AND "${type}" STREQUAL "${MK_EXECAB}") 45 | addTarget("${MK_EXECAB}") 46 | set(${out_stop} ON PARENT_SCOPE) 47 | endif() 48 | SET(MODULE_START OFF PARENT_SCOPE) 49 | return() 50 | elseif( "${line}" MATCHES "^( *)ifeq.*" ) 51 | if(IN_IF_BLOCK) 52 | math(EXPR parseLine_block_num "${IN_IF_BLOCK_NUM} + 1") 53 | SET(IN_IF_BLOCK_NUM ${parseLine_block_num} PARENT_SCOPE) 54 | else() 55 | string(REPLACE "ifeq" "" line "${line}") 56 | string(STRIP "${line}" line) 57 | doIfeq("${line}" if_block) 58 | if(if_block) 59 | SET(IN_IF_BLOCK_NUM "0" PARENT_SCOPE) 60 | endif() 61 | SET(IN_IF_BLOCK ${if_block} PARENT_SCOPE) 62 | endif() 63 | return() 64 | elseif("${line}" MATCHES "^( *)ifdef.*") 65 | if(IN_IF_BLOCK) 66 | math(EXPR parseLine_block_num "${IN_IF_BLOCK_NUM} + 1") 67 | SET(IN_IF_BLOCK_NUM ${parseLine_block_num} PARENT_SCOPE) 68 | else() 69 | string(REPLACE "ifdef" "" line "${line}") 70 | string(STRIP "${line}" line) 71 | if(line) 72 | SET(IN_IF_BLOCK OFF PARENT_SCOPE) 73 | else() 74 | SET(IN_IF_BLOCK_NUM "0" PARENT_SCOPE) 75 | SET(IN_IF_BLOCK ON PARENT_SCOPE) 76 | endif() 77 | endif() 78 | elseif( "${line}" MATCHES "^( *)ifneq.*" ) 79 | if(IN_IF_BLOCK) 80 | math(EXPR parseLine_block_num "${IN_IF_BLOCK_NUM} + 1") 81 | SET(IN_IF_BLOCK_NUM ${parseLine_block_num} PARENT_SCOPE) 82 | else() 83 | string(REPLACE "ifneq" "" line "${line}") 84 | string(STRIP "${line}" line) 85 | doIfneq("${line}" if_block) 86 | if(if_block) 87 | SET(IN_IF_BLOCK_NUM "0" PARENT_SCOPE) 88 | endif() 89 | SET(IN_IF_BLOCK ${if_block} PARENT_SCOPE) 90 | endif() 91 | return() 92 | elseif( "${line}" MATCHES "^( *)else.*" ) 93 | if(NOT IN_IF_BLOCK_NUM) 94 | if(IN_IF_BLOCK) 95 | SET(IN_IF_BLOCK OFF PARENT_SCOPE) 96 | else() 97 | SET(IN_IF_BLOCK ON PARENT_SCOPE) 98 | endif() 99 | endif() 100 | return() 101 | elseif("${line}" MATCHES "^( *)endif.*") 102 | if(NOT IN_IF_BLOCK_NUM) 103 | if(MK_DEBUG) 104 | message("parseLine: ======= endif =======") 105 | endif() 106 | SET(IN_IF_BLOCK OFF PARENT_SCOPE) 107 | else() 108 | math(EXPR parseLine_block_num "${IN_IF_BLOCK_NUM} - 1") 109 | SET(IN_IF_BLOCK_NUM ${parseLine_block_num} PARENT_SCOPE) 110 | if(MK_DEBUG) 111 | message("parseLine:out of block num=${IN_IF_BLOCK_NUM}") 112 | endif() 113 | endif() 114 | return() 115 | elseif("${line}" MATCHES "^( *)include.*") 116 | if(MK_DEBUG) 117 | message("parseLine: current not supprot include") 118 | endif() 119 | return() 120 | endif() 121 | 122 | if(MK_DEBUG) 123 | message("parseLine:IN_IF_BLOCK = ${IN_IF_BLOCK}") 124 | message("parseLine:IN_IF_BLOCK_NUM = ${IN_IF_BLOCK_NUM}") 125 | endif() 126 | 127 | if(IN_IF_BLOCK) 128 | if(MK_DEBUG) 129 | message("parseLine: ======= if block =======") 130 | endif() 131 | return() 132 | endif() 133 | parseValues("${line}" local_key) 134 | SET(${local_key} "${${local_key}}" PARENT_SCOPE) 135 | endfunction() 136 | 137 | function(initEnv) 138 | SET(LOCAL_PATH "" PARENT_SCOPE) 139 | SET(LOCAL_MODULE "" PARENT_SCOPE) 140 | SET(LOCAL_CFLAGS "" PARENT_SCOPE) 141 | SET(LOCAL_CPPFLAGS "" PARENT_SCOPE) 142 | SET(LOCAL_SRC_FILES "" PARENT_SCOPE) 143 | SET(LOCAL_C_INCLUDES "" PARENT_SCOPE) 144 | SET(LOCAL_SHARED_LIBRARIES "" PARENT_SCOPE) 145 | SET(LOCAL_STATIC_LIBRARIES "" PARENT_SCOPE) 146 | SET(LOCAL_EXPORT_C_INCLUDE_DIRS "" PARENT_SCOPE) 147 | endfunction() 148 | 149 | function(parseAndroidMK module_name type) 150 | 151 | containsModule("${module_name}_${type}" is_find) 152 | if(is_find) 153 | return() 154 | endif() 155 | 156 | getModulePath("${type}" "${module_name}" path) 157 | if(NOT path) 158 | message("parseAndroidMK: ${type} ${module_name} not found!") 159 | return() 160 | endif() 161 | 162 | initEnv() 163 | SET(local_path ${PROJECT_DIR}/${path}) 164 | SET(LOCAL_PATH ${local_path}) 165 | SET(mk_path ${local_path}/Android.mk) 166 | if(NOT EXISTS ${mk_path}) 167 | parseAndroidBP("${module_name}" "${type}" "${local_path}") 168 | return() 169 | endif() 170 | 171 | message("AndroidMK:${mk_path}") 172 | 173 | if(MK_DEBUG) 174 | message("LOCAL_PATH:${LOCAL_PATH}") 175 | endif() 176 | 177 | File(STRINGS ${mk_path} MyFile) 178 | 179 | set(parseAndroidMK_stop OFF) 180 | 181 | foreach(line ${MyFile}) 182 | # 读取文件的时候 \\n 会被转换成 " ;"需要替换掉 183 | string(STRIP "${line}" line) 184 | string(REPLACE ";" "" line "${line}") 185 | string(REGEX REPLACE "(\t)+" " " line "${line}") 186 | string(REGEX REPLACE " +" " " line "${line}") 187 | if( "${line}" MATCHES "^( *)#.*") 188 | continue() 189 | endif() 190 | if( "${line}" MATCHES "^( *)LOCAL_PATH.*:=.*") 191 | continue() 192 | endif() 193 | string(REGEX REPLACE " +" " " line "${line}") 194 | if(MK_LINE_DEBUG) 195 | message("parseAndroidMK: ${line}") 196 | endif() 197 | parseLine("${line}" "${module_name}" "${type}" parseAndroidMK_stop) 198 | if(parseAndroidMK_stop) 199 | break() 200 | endif() 201 | endforeach() 202 | 203 | containsModule("${module_name}_${type}" is_find) 204 | if(NOT is_find) 205 | parseAndroidBP("${module_name}" "${type}" "${local_path}") 206 | return() 207 | endif() 208 | 209 | doModuleDependencies("${module_name}_${type}") 210 | doExportInclude("${module_name}_${type}") 211 | endfunction() -------------------------------------------------------------------------------- /CMakeModule/AndroidMK/ParseIf.cmake: -------------------------------------------------------------------------------- 1 | SET(PARSE_IF_DEBUG OFF) 2 | SET(IF_PARAM1 "") 3 | SET(IF_PARAM2 "") 4 | 5 | function(marchIfBrackets in out) 6 | set(marchIfBrackets_str "${in}") 7 | set(marchIfBrackets_num "0") 8 | set(marchIfBrackets_split "") 9 | string(LENGTH "${marchIfBrackets_str}" marchIfBrackets_length) 10 | math(EXPR marchIfBrackets_last_index "${marchIfBrackets_length} - 1") 11 | foreach(marchIfBrackets_index RANGE "${marchIfBrackets_last_index}" "0") 12 | string(SUBSTRING "${marchIfBrackets_str}" "${marchIfBrackets_index}" "1" marchIfBrackets_sub) 13 | 14 | if("${marchIfBrackets_sub}" STREQUAL ")" ) 15 | math(EXPR marchIfBrackets_num "${marchIfBrackets_num} + 1") 16 | elseif("${marchIfBrackets_sub}" STREQUAL "(" ) 17 | math(EXPR marchIfBrackets_num "${marchIfBrackets_num} - 1") 18 | elseif("${marchIfBrackets_sub}" STREQUAL ",") 19 | #判断是否有括号对 20 | if("${marchIfBrackets_num}" EQUAL "1" ) 21 | math(EXPR marchIfBrackets_index_end "${marchIfBrackets_index} + 1") 22 | string(SUBSTRING "${marchIfBrackets_str}" "${marchIfBrackets_index_end}" "65536" marchIfBrackets_tmp_str) 23 | string(SUBSTRING "${marchIfBrackets_str}" "0" "${marchIfBrackets_index}" marchIfBrackets_str) 24 | string(STRIP ${marchIfBrackets_tmp_str} marchIfBrackets_tmp_str) 25 | list(INSERT marchIfBrackets_split "0" "${marchIfBrackets_tmp_str}") 26 | endif() 27 | endif() 28 | endforeach() 29 | 30 | if(NOT marchIfBrackets_split) 31 | set(marchIfBrackets_split "${in}") 32 | endif() 33 | 34 | if(marchIfBrackets_str) 35 | list(INSERT marchIfBrackets_split "0" "${marchIfBrackets_str}") 36 | endif() 37 | 38 | if (PARSE_IF_DEBUG) 39 | message("marchIfBrackets_split:${marchIfBrackets_split}") 40 | endif () 41 | set(${out} "${marchIfBrackets_split}" PARENT_SCOPE) 42 | endfunction() 43 | 44 | function(parseIf line param1 param2) 45 | string(STRIP ${line} parseIf_line) 46 | marchIfBrackets("${parseIf_line}" parseIf_line_out) 47 | 48 | string(REGEX REPLACE "^\\(" "" parseIf_line_out "${parseIf_line_out}") 49 | string(REGEX REPLACE "\\)$" "" parseIf_line_out "${parseIf_line_out}") 50 | # if( "${parseIf_line}" MATCHES "^,.*" ) 51 | # string(REGEX REPLACE "^," ";" parseIf_line_list ${parseIf_line}) 52 | # elseif("${parseIf_line}" MATCHES ".*,$") 53 | # string(REGEX REPLACE ",$" ";" parseIf_line_list ${parseIf_line}) 54 | # else() 55 | # 56 | # string(REPLACE "," ";" parseIf_line_list ${parseIf_line}) 57 | # endif() 58 | list(GET parseIf_line_out 0 parseIf_local_param1) 59 | list(GET parseIf_line_out 1 parseIf_local_param2) 60 | if(PARSE_IF_DEBUG) 61 | message("parseIf: param1 = ${parseIf_local_param1}") 62 | message("parseIf: param2 = ${parseIf_local_param2}") 63 | endif() 64 | 65 | parseMakeFileFunc("${parseIf_local_param1}" parseIf_local_param1) 66 | SET(${param1} ${parseIf_local_param1} PARENT_SCOPE) 67 | parseMakeFileFunc("${parseIf_local_param2}" parseIf_local_param2) 68 | SET(${param2} ${parseIf_local_param2} PARENT_SCOPE) 69 | endfunction() 70 | 71 | function(doIfeq line block) 72 | parseIf(${line} doIfeq_IF_PARAM1 doIfeq_IF_PARAM2) 73 | if(PARSE_IF_DEBUG) 74 | message("doIfeq: IF_PARAM1 = ${doIfeq_IF_PARAM1}") 75 | message("doIfeq: IF_PARAM2 = ${doIfeq_IF_PARAM2}") 76 | endif() 77 | if( "${doIfeq_IF_PARAM1}" STREQUAL "${doIfeq_IF_PARAM2}" ) 78 | SET(${block} OFF PARENT_SCOPE) 79 | else() 80 | SET(${block} ON PARENT_SCOPE) 81 | endif() 82 | endfunction() 83 | 84 | function(doIfneq line block) 85 | parseIf(${line} doIfneq_IF_PARAM1 doIfneq_IF_PARAM2) 86 | if(PARSE_IF_DEBUG) 87 | message("doIfneq: IF_PARAM1 = ${doIfneq_IF_PARAM1}") 88 | message("doIfneq: IF_PARAM2 = ${doIfneq_IF_PARAM2}") 89 | endif() 90 | if( "${doIfneq_IF_PARAM1}" STREQUAL "${doIfneq_IF_PARAM2}" ) 91 | if(PARSE_IF_DEBUG) 92 | message("doIfneq: block = ON") 93 | endif() 94 | SET(${block} ON PARENT_SCOPE) 95 | else() 96 | if(PARSE_IF_DEBUG) 97 | message("doIfneq: block = OFF") 98 | endif() 99 | SET(${block} OFF PARENT_SCOPE) 100 | endif() 101 | endfunction() -------------------------------------------------------------------------------- /CMakeModule/AndroidMK/ParseValues.cmake: -------------------------------------------------------------------------------- 1 | SET(PARSE_VALUES_DEBUG OFF) 2 | 3 | function(catParam param out_prefix out_param out_suffix) 4 | SET(catParam_param "${param}") 5 | SET(catParam_prefix "") 6 | SET(catParam_suffix "") 7 | 8 | string(FIND "${param}" "$" catParam_prefix_index) 9 | if(NOT "${catParam_prefix_index}" EQUAL "0") 10 | string(SUBSTRING "${param}" "0" "${catParam_prefix_index}" catParam_prefix) 11 | string(SUBSTRING "${param}" "${catParam_prefix_index}" "65536" catParam_param) 12 | endif() 13 | 14 | string(FIND "${catParam_param}" ")" catParam_suffix_index REVERSE) 15 | if(NOT "${catParam_suffix_index}" EQUAL "-1") 16 | math(EXPR catParam_suffix_index "${catParam_suffix_index} + 1") 17 | string(SUBSTRING "${catParam_param}" "${catParam_suffix_index}" "65536" catParam_suffix) 18 | string(SUBSTRING "${catParam_param}" "0" "${catParam_suffix_index}" catParam_param) 19 | endif() 20 | 21 | SET(${out_prefix} ${catParam_prefix} PARENT_SCOPE) 22 | SET(${out_param} ${catParam_param} PARENT_SCOPE) 23 | SET(${out_suffix} ${catParam_suffix} PARENT_SCOPE) 24 | endfunction() 25 | 26 | #注意不能输入list,否则无法解析 27 | function(parseMakeFileFunc param out) 28 | if("${param}" MATCHES ".*;.*") 29 | #list 30 | foreach(param_one ${param}) 31 | parseMakeFileFunc("${param_one}" tmp_param_one) 32 | list(APPEND tmp_param "${tmp_param_one}") 33 | endforeach() 34 | elseif( "${param}" MATCHES "^\\(.*") 35 | string(REGEX REPLACE "^\\(" "" param ${param}) 36 | string(REGEX REPLACE "\\)$" "" param ${param}) 37 | parseMakeFileFunc("${param}" tmp_param) 38 | elseif( "${param}" MATCHES "^\\$\\(strip") 39 | if(PARSE_VALUES_DEBUG) 40 | MESSAGE("parseMakeFileFunc: strip = ${param}") 41 | endif() 42 | string(REPLACE "$(strip" "" strip_param ${param}) 43 | string(REGEX REPLACE "\\)$" "" strip_param "${strip_param}") 44 | string(STRIP "${strip_param}" strip_param) 45 | parseMakeFileFunc("${strip_param}" strip_tmp_param) 46 | set(tmp_param "${strip_tmp_param}") 47 | elseif( "${param}" MATCHES "^\\$\\(subst") 48 | if(PARSE_VALUES_DEBUG) 49 | MESSAGE("parseMakeFileFunc: subst = ${param}") 50 | endif() 51 | string(REPLACE "$(subst" "" subst_param ${param}) 52 | string(REGEX REPLACE "\\)$" "" subst_param "${subst_param}") 53 | string(REPLACE "," ";" subst_param ${subst_param}) 54 | 55 | LIST(GET subst_param 0 subst_param0) 56 | LIST(GET subst_param 1 subst_param1) 57 | LIST(GET subst_param 2 subst_param2) 58 | 59 | if(subst_param0) 60 | parseMakeFileFunc(${subst_param0} subst_param0) 61 | endif() 62 | if(subst_param1) 63 | parseMakeFileFunc(${subst_param1} subst_param1) 64 | endif() 65 | if(subst_param2) 66 | parseMakeFileFunc(${subst_param2} subst_param2) 67 | endif() 68 | 69 | if(PARSE_VALUES_DEBUG) 70 | MESSAGE("parseMakeFileFunc: subst_param0 = ${subst_param0}") 71 | MESSAGE("parseMakeFileFunc: subst_param1 = ${subst_param1}") 72 | MESSAGE("parseMakeFileFunc: subst_param2 = ${subst_param2}") 73 | endif() 74 | 75 | string(REPLACE "${subst_param0}" "${subst_param1}" subst_param_tmp "${subst_param2}") 76 | set(tmp_param "${subst_param_tmp}") 77 | elseif( "${param}" MATCHES "^\\$\\(filter-out" ) 78 | 79 | elseif( "${param}" MATCHES "^\\$\\(filter" ) 80 | if(PARSE_VALUES_DEBUG) 81 | MESSAGE("parseMakeFileFunc: filter = ${param}") 82 | endif() 83 | if( "${param}" MATCHES ".*,.*" ) 84 | string(REPLACE "$(filter" "" filter_param ${param}) 85 | string(REGEX REPLACE "\\)$" "" filter_param "${filter_param}") 86 | string(REPLACE "," ";" filter_list ${filter_param}) 87 | LIST(GET filter_list 0 filter_param1) 88 | string(STRIP ${filter_param1} filter_param1) 89 | LIST(GET filter_list 1 filter_param2) 90 | string(STRIP ${filter_param2} filter_param2) 91 | parseMakeFileFunc(${filter_param1} filter_param1) 92 | parseMakeFileFunc(${filter_param2} filter_param2) 93 | if( "${filter_param1}" MATCHES ".*${filter_param2}.*") 94 | SET(tmp_param "${filter_param2}") 95 | else() 96 | SET(tmp_param "") 97 | endif() 98 | else() 99 | endif() 100 | elseif( "${param}" MATCHES "^\\$.*\\)$") 101 | if(PARSE_VALUES_DEBUG) 102 | MESSAGE("parseMakeFileFunc: func = ${param}") 103 | endif() 104 | 105 | string(REGEX REPLACE "^\\$" "" func_param ${param}) 106 | string(REGEX REPLACE "^\\(|\\)$" "" func_param "${func_param}") 107 | 108 | string(STRIP "${func_param}" func_param) 109 | 110 | if("${func_param}" MATCHES "^\\$.*") 111 | parseMakeFileFunc(${func_param} func_tmp_param) 112 | SET(tmp_param "${${func_tmp_param}}") 113 | else() 114 | string(REGEX REPLACE "\\(|\\)" "" func_param ${func_param}) 115 | parseMakeFileFunc("${${func_param}}" no_func_tmp_param) 116 | SET(tmp_param "${no_func_tmp_param}") 117 | endif() 118 | elseif( "${param}" MATCHES ".*\\$.*") 119 | if(PARSE_VALUES_DEBUG) 120 | MESSAGE("parseMakeFileFunc: func_in = ${param}") 121 | endif() 122 | 123 | catParam("${param}" func_in_prefix func_in_param func_in_suffix) 124 | 125 | if(PARSE_VALUES_DEBUG) 126 | message("parseMakeFileFunc: func_in_param=${func_in_param}") 127 | message("parseMakeFileFunc: func_in_prefix=${func_in_prefix}") 128 | message("parseMakeFileFunc: func_in_suffix=${func_in_suffix}") 129 | endif() 130 | 131 | parseMakeFileFunc("${func_in_param}" func_in_tmp_param) 132 | set(tmp_param "${func_in_prefix}${func_in_tmp_param}${func_in_suffix}") 133 | else() 134 | if(PARSE_VALUES_DEBUG) 135 | MESSAGE("parseMakeFileFunc: normal = ${param}") 136 | endif() 137 | SET(tmp_param "${param}") 138 | endif() 139 | 140 | if(PARSE_VALUES_DEBUG) 141 | MESSAGE("parseMakeFileFunc: ${out} = ${tmp_param}") 142 | endif() 143 | SET(${out} ${tmp_param} PARENT_SCOPE) 144 | endfunction() 145 | 146 | function(marchBrackets in out) 147 | set(marchBrackets_str "${in}") 148 | set(marchBrackets_num "0") 149 | set(marchBrackets_split "") 150 | string(LENGTH "${marchBrackets_str}" marchBrackets_length) 151 | math(EXPR marchBrackets_last_index "${marchBrackets_length} - 1") 152 | foreach(marchBrackets_index RANGE "${marchBrackets_last_index}" "0") 153 | string(SUBSTRING "${marchBrackets_str}" "${marchBrackets_index}" "1" marchBrackets_sub) 154 | 155 | if("${marchBrackets_sub}" STREQUAL ")" ) 156 | math(EXPR marchBrackets_num "${marchBrackets_num} + 1") 157 | elseif("${marchBrackets_sub}" STREQUAL "(" ) 158 | math(EXPR marchBrackets_num "${marchBrackets_num} - 1") 159 | elseif("${marchBrackets_sub}" STREQUAL " ") 160 | #判断是否有括号对 161 | if("${marchBrackets_num}" EQUAL "0" ) 162 | string(SUBSTRING "${marchBrackets_str}" "${marchBrackets_index}" "65536" marchBrackets_tmp_str) 163 | string(SUBSTRING "${marchBrackets_str}" "0" "${marchBrackets_index}" marchBrackets_str) 164 | string(STRIP ${marchBrackets_tmp_str} marchBrackets_tmp_str) 165 | list(INSERT marchBrackets_split "0" "${marchBrackets_tmp_str}") 166 | endif() 167 | endif() 168 | endforeach() 169 | 170 | if(NOT marchBrackets_split) 171 | set(marchBrackets_split "${in}") 172 | endif() 173 | 174 | if(marchBrackets_str) 175 | list(INSERT marchBrackets_split "0" "${marchBrackets_str}") 176 | endif() 177 | 178 | if (PARSE_VALUES_DEBUG) 179 | message("marchBrackets_split:${marchBrackets_split}") 180 | endif () 181 | set(${out} "${marchBrackets_split}" PARENT_SCOPE) 182 | endfunction() 183 | 184 | function(parseValues line local_key) 185 | SET(parseValues_valueAppend OFF) 186 | SET(parseValues_valueQuestion OFF) 187 | 188 | if( "${line}" MATCHES ".*:=.*") 189 | string(REPLACE ":=" ";" parseValues_line_list "${line}") 190 | elseif( "${line}" MATCHES ".*\\+=.*") 191 | string(REPLACE "+=" ";" parseValues_line_list "${line}") 192 | SET(parseValues_valueAppend ON) 193 | elseif( "${line}" MATCHES ".*\\?=.*") 194 | string(REPLACE "?=" ";" parseValues_line_list "${line}") 195 | SET(parseValues_valueQuestion ON) 196 | elseif( "${line}" MATCHES ".*=.*") 197 | string(REPLACE "=" ";" parseValues_line_list "${line}") 198 | endif() 199 | 200 | list(GET parseValues_line_list 0 parseValues_key) 201 | string(STRIP "${parseValues_key}" parseValues_key) 202 | if(parseValues_valueQuestion) 203 | if(NOT "${${parseValues_key}}" STREQUAL "") 204 | return() 205 | endif() 206 | endif() 207 | if(PARSE_VALUES_DEBUG) 208 | message("parseValues: key = ${parseValues_key}") 209 | endif() 210 | 211 | 212 | list(GET parseValues_line_list 1 parseValues_values) 213 | string(STRIP "${parseValues_values}" parseValues_values) 214 | # Convert to list 215 | if(PARSE_VALUES_DEBUG) 216 | message("parseValues values start = ${parseValues_values}") 217 | endif() 218 | 219 | if("${parseValues_values}" MATCHES " +" AND "${parseValues_values}" MATCHES "\\$") 220 | marchBrackets("${parseValues_values}" parseValues_values) 221 | else() 222 | string(REGEX REPLACE " +" ";" parseValues_values "${parseValues_values}") 223 | endif() 224 | 225 | string(REPLACE "-include;" "-include " parseValues_values "${parseValues_values}") 226 | 227 | if(PARSE_VALUES_DEBUG) 228 | message("parseValues values end = ${parseValues_values}") 229 | endif() 230 | 231 | SET(${local_key} ${parseValues_key} PARENT_SCOPE) 232 | 233 | if(parseValues_valueAppend) 234 | LIST(APPEND ${parseValues_key} ${parseValues_values}) 235 | else() 236 | SET(${parseValues_key} ${parseValues_values}) 237 | endif() 238 | 239 | SET(${parseValues_key} ${${parseValues_key}} PARENT_SCOPE) 240 | endfunction() -------------------------------------------------------------------------------- /CMakeModule/AndroidMK/addTarget.cmake: -------------------------------------------------------------------------------- 1 | SET(ADD_TARGET_DEBUG OFF) 2 | 3 | SET(TMP_SRC_FILES "") 4 | SET(TARGET_COMPILE_OPTIONS_FILTER "(-O.*)") 5 | 6 | function(getSrc out) 7 | foreach(getSrc_src_list ${LOCAL_SRC_FILES}) 8 | if( "${getSrc_src_list}" MATCHES ".*\\$.*") 9 | parseMakeFileFunc("${getSrc_src_list}" getSrc_src_list) 10 | endif() 11 | foreach(getSrc_src ${getSrc_src_list}) 12 | if(EXISTS ${LOCAL_PATH}/${getSrc_src}) 13 | LIST(APPEND tmp_list ${LOCAL_PATH}/${getSrc_src}) 14 | endif() 15 | endforeach() 16 | endforeach() 17 | SET(${out} "${tmp_list}" PARENT_SCOPE) 18 | endfunction() 19 | 20 | function(addFlag module in) 21 | foreach(addFlag_flg_list ${${in}}) 22 | if( "${addFlag_flg_list}" MATCHES ".*\\$.*") 23 | parseMakeFileFunc("${addFlag_flg_list}" addFlag_flg_list) 24 | endif() 25 | foreach(addFlag_flg ${addFlag_flg_list}) 26 | if("${addFlag_flg}" MATCHES "^\\-D.*") 27 | string(REPLACE "\\" "" addFlag_flg "${addFlag_flg}") 28 | if(ADD_TARGET_DEBUG) 29 | message("addFlag: ${addFlag_flg}") 30 | endif() 31 | target_compile_definitions(${module} PRIVATE "${addFlag_flg}") 32 | else() 33 | if(NOT ${addFlag_flg} MATCHES "${TARGET_COMPILE_OPTIONS_FILTER}") 34 | if(ADD_TARGET_DEBUG) 35 | message("addFlag Option: ${addFlag_flg}") 36 | endif() 37 | # target_compile_options(${module} PRIVATE ${addFlag_flg}) 38 | endif() 39 | endif() 40 | endforeach() 41 | endforeach() 42 | endfunction() 43 | 44 | function(addInclude module in) 45 | target_include_directories(${module} PRIVATE ${LOCAL_PATH}) 46 | foreach(addInclude_include_list ${${in}}) 47 | if( "${addInclude_include_list}" MATCHES ".*\\$.*") 48 | parseMakeFileFunc("${addInclude_include_list}" addInclude_include_list) 49 | endif() 50 | foreach(addInclude_include ${addInclude_include_list}) 51 | # target_include_directories(${module} PRIVATE ${PROJECT_DIR}/${addInclude_include}) 52 | if( "${addInclude_include}" MATCHES "^/") 53 | if ("${addInclude_include}" MATCHES "^${PROJECT_DIR}.*" ) 54 | set(addInclude_directories "${addInclude_include}") 55 | else() 56 | set(addInclude_directories "${PROJECT_DIR}${addInclude_include}") 57 | endif () 58 | else() 59 | set(addInclude_directories "${PROJECT_DIR}/${addInclude_include}") 60 | endif() 61 | if(ADD_TARGET_DEBUG) 62 | message("addInclude dir: ${addInclude_directories}") 63 | endif() 64 | target_include_directories(${module} PRIVATE ${addInclude_directories}) 65 | endforeach() 66 | endforeach() 67 | endfunction() 68 | 69 | function(addExportInclude module path) 70 | if(EXISTS "${path}") 71 | file(STRINGS ${path} addExportInclude_list) 72 | foreach(addExportInclude_include ${addExportInclude_list}) 73 | if(ADD_TARGET_DEBUG) 74 | message("${module} addExportInclude : ${addExportInclude_include}") 75 | endif() 76 | target_include_directories("${module}" PRIVATE ${addExportInclude_include}) 77 | endforeach() 78 | endif() 79 | endfunction() 80 | 81 | function(exportInclude module_type) 82 | foreach(exportInclude_include_list ${LOCAL_EXPORT_C_INCLUDE_DIRS}) 83 | if( "${exportInclude_include_list}" MATCHES ".*\\$.*") 84 | parseMakeFileFunc("${exportInclude_include_list}" exportInclude_include_list) 85 | endif() 86 | foreach(exportInclude_include ${exportInclude_include_list}) 87 | saveExportInclude("${module_type}" "${exportInclude_include}") 88 | endforeach() 89 | doNeedExport("${module_type}" "${exportInclude_include_list}") 90 | endforeach() 91 | endfunction() 92 | 93 | function(addDependencies module lib path) 94 | # TODO Android.mk 95 | parseAndroidMK(${PROJECT_DIR}/${path}/Android.mk) 96 | endfunction() 97 | 98 | function(addModuleLibraries module libraries type) 99 | string(REPLACE "@" "-" ${libraries} "${${libraries}}") 100 | foreach(addModuleLibraries_lib_list ${${libraries}}) 101 | if( "${addModuleLibraries_lib_list}" MATCHES ".*\\$.*") 102 | parseMakeFileFunc("${addModuleLibraries_lib_list}" addModuleLibraries_lib_list) 103 | endif() 104 | 105 | foreach(addModuleLibraries_lib ${addModuleLibraries_lib_list}) 106 | # containsModule("${addModuleLibraries_lib}_${type}" is_find) 107 | # if(is_find) 108 | # continue() 109 | # endif() 110 | 111 | if(ADD_TARGET_DEBUG) 112 | message("addModuleLibraries: ${type} ${addModuleLibraries_lib}") 113 | endif() 114 | addModuleDependencies("${module}" "${type}" "${addModuleLibraries_lib}") 115 | endforeach() 116 | 117 | endforeach() 118 | endfunction() 119 | 120 | function(addTarget type) 121 | if("${LOCAL_MODULE}" MATCHES ".*@.*") 122 | string(REPLACE "@" "-" LOCAL_MODULE "${LOCAL_MODULE}") 123 | endif() 124 | containsModule("${LOCAL_MODULE}_${type}" is_find) 125 | if(is_find) 126 | return() 127 | endif() 128 | 129 | getSrc(TMP_SRC_FILES) 130 | SET(local_module "${LOCAL_MODULE}_${type}") 131 | if(NOT TMP_SRC_FILES) 132 | message(STATUS "${local_module}: null src, continue and skip.") 133 | addModule("${local_module}" "${LOCAL_PATH}") 134 | return() 135 | endif() 136 | message("addTarget: ${local_module}") 137 | if("${type}" MATCHES "(${MK_SHARED}|${MK_STATIC})") 138 | add_library(${local_module} ${type} ${TMP_SRC_FILES}) 139 | set_target_properties(${local_module} PROPERTIES PREFIX "") 140 | set_target_properties(${local_module} PROPERTIES OUTPUT_NAME "${LOCAL_MODULE}") 141 | else() 142 | add_executable(${local_module} ${TMP_SRC_FILES}) 143 | endif() 144 | addFlag(${local_module} LOCAL_CFLAGS) 145 | addFlag(${local_module} LOCAL_CPPFLAGS) 146 | addInclude(${local_module} LOCAL_C_INCLUDES) 147 | addModule("${local_module}" "${LOCAL_PATH}") 148 | addModuleLibraries("${local_module}" LOCAL_SHARED_LIBRARIES "${MK_SHARED}") 149 | addModuleLibraries("${local_module}" LOCAL_STATIC_LIBRARIES "${MK_STATIC}") 150 | exportInclude("${local_module}") 151 | endfunction() -------------------------------------------------------------------------------- /CMakeModule/AndroidMK/dep/Android.mk: -------------------------------------------------------------------------------- 1 | include $(CLEAR_VARS) 2 | 3 | LIST_TEST := MK_DEFINE 4 | 5 | commsrc := common.cpp 6 | comm := help 7 | 8 | LOCAL_CFLAGS += -DLILI -D$(LIST_TEST)_TT 9 | 10 | ifneq ($(strip $(TARGET_BOARD_PLATFORM)),rk3399) 11 | LOCAL_CFLAGS += -DSF_RK3288 12 | else 13 | LOCAL_CFLAGS += -DSF_RK3399 14 | endif 15 | 16 | ifneq ($(TARGET_BOARD_PLATFORM),rk3399) 17 | LOCAL_CFLAGS += -DNO_FUNC 18 | else 19 | LOCAL_CFLAGS += -DHAVE_FUNC 20 | endif 21 | 22 | ifneq ($(filter userdebug eng user,$(TARGET_BUILD_VARIANT)),) 23 | init_options += -DALLOW_LOCAL_PROP_OVERRIDE=1 -DALLOW_DISABLE_SELINUX=1 24 | else 25 | init_options += -DALLOW_LOCAL_PROP_OVERRIDE=0 -DALLOW_DISABLE_SELINUX=0 26 | endif 27 | 28 | LOCAL_SRC_FILES := \ 29 | $(commsrc) \ 30 | $(comm)_suffix.cpp \ 31 | $(comm)/common.cpp \ 32 | test.cpp 33 | 34 | LOCAL_MODULE := lili_dep 35 | 36 | LOCAL_C_INCLUDES += system/extras/ext4_utils 37 | LOCAL_C_INCLUDES += system/core/fs_mgr/include 38 | 39 | include $(BUILD_SHARED_LIBRARY) -------------------------------------------------------------------------------- /CMakeModule/AndroidMK/dep/common.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by lili on 19-1-15. 3 | // 4 | 5 | #include "common.h" 6 | -------------------------------------------------------------------------------- /CMakeModule/AndroidMK/dep/common.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by lili on 19-1-15. 3 | // 4 | 5 | #ifndef ANDROID_COMMON_H 6 | #define ANDROID_COMMON_H 7 | 8 | 9 | class common { 10 | 11 | }; 12 | 13 | 14 | #endif //ANDROID_COMMON_H 15 | -------------------------------------------------------------------------------- /CMakeModule/AndroidMK/dep/help/common.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by lili on 19-1-15. 3 | // 4 | 5 | #include "common.h" 6 | -------------------------------------------------------------------------------- /CMakeModule/AndroidMK/dep/help_suffix.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by lili on 19-1-15. 3 | // 4 | 5 | #include "common.h" 6 | -------------------------------------------------------------------------------- /CMakeModule/AndroidMK/dep/test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by lili on 19-1-15. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | #include "test.h" 9 | 10 | int main(int argc, char** argv){ 11 | #ifdef SF_RK3399 12 | printf("hello word SF_RK3399\n"); 13 | #endif 14 | #ifdef SF_RK3288 15 | printf("hello word SF_RK3288\n"); 16 | #endif 17 | 18 | #ifdef NO_FUNC 19 | printf("hello word NO_FUNC\n"); 20 | #endif 21 | 22 | #ifdef HAVE_FUNC 23 | printf("hello word NO_FUNC\n"); 24 | #endif 25 | } 26 | -------------------------------------------------------------------------------- /CMakeModule/AndroidMK/dep/test.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by lili on 19-1-15. 3 | // 4 | 5 | #ifndef ANDROID_TEST_H 6 | #define ANDROID_TEST_H 7 | 8 | 9 | class test { 10 | 11 | }; 12 | #endif //ANDROID_TEST_H 13 | -------------------------------------------------------------------------------- /CMakeModule/AndroidMK/test/Android.mk: -------------------------------------------------------------------------------- 1 | include $(CLEAR_VARS) 2 | 3 | commsrc += common.cpp 4 | 5 | LOCAL_CFLAGS += -DLILI 6 | 7 | ifeq ($(strip ($($(TARGET_BOARD_TEST)))),rk3399) 8 | LOCAL_CFLAGS += -DSF_RK3399 9 | else 10 | LOCAL_CFLAGS += -DSF_RK3288 11 | endif 12 | 13 | LOCAL_CFLAGS += -DLILIXXX 14 | 15 | LOCAL_SRC_FILES := \ 16 | $(commsrc) \ 17 | test.cpp 18 | 19 | LOCAL_MODULE := lili_test 20 | 21 | LOCAL_SHARED_LIBRARIES := lili_dep 22 | #LOCAL_STATIC_LIBRARIES := libadb 23 | 24 | LOCAL_C_INCLUDES += system/extras/ext4_utils 25 | LOCAL_C_INCLUDES += system/core/fs_mgr/include 26 | 27 | include $(BUILD_SHARED_LIBRARY) -------------------------------------------------------------------------------- /CMakeModule/AndroidMK/test/common.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by lili on 19-1-15. 3 | // 4 | 5 | #include "common.h" 6 | -------------------------------------------------------------------------------- /CMakeModule/AndroidMK/test/common.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by lili on 19-1-15. 3 | // 4 | 5 | #ifndef ANDROID_COMMON_H 6 | #define ANDROID_COMMON_H 7 | 8 | 9 | class common { 10 | 11 | }; 12 | 13 | 14 | #endif //ANDROID_COMMON_H 15 | -------------------------------------------------------------------------------- /CMakeModule/AndroidMK/test/test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by lili on 19-1-15. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | #include "test.h" 9 | 10 | int main(int argc, char** argv){ 11 | #ifdef SF_RK3399 12 | printf("hello word SF_RK3399\n"); 13 | #endif 14 | #ifdef SF_RK3288 15 | printf("hello word SF_RK3288\n"); 16 | #endif 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /CMakeModule/AndroidMK/test/test.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by lili on 19-1-15. 3 | // 4 | 5 | #ifndef ANDROID_TEST_H 6 | #define ANDROID_TEST_H 7 | 8 | 9 | class test { 10 | 11 | }; 12 | #endif //ANDROID_TEST_H 13 | -------------------------------------------------------------------------------- /CMakeModule/android.env.cmake: -------------------------------------------------------------------------------- 1 | 2 | if(EXISTS ${PROJECT_DIR}/android.env.cmake) 3 | include(${PROJECT_DIR}/android.env.cmake) 4 | else("default") 5 | ########## get_build_var 6 | set(TARGET_BOARD_HARDWARE rk30board ) 7 | ######### config your lunch target 8 | set(ANDROID_LUNCH rk3399) 9 | set(ANDROID_SDK_VERSION 28) 10 | set(ANDROID_TARGET_ARCH arm64) 11 | set(ANDROID_ARCH_VARIANT armv8-a) 12 | set(ANDROID_CPU_VARIANT "cortex-a53") 13 | ######### build abi 14 | #set(ANDROID_ABI "armeabi-v7a") 15 | #set(ANDROID_ABI "armeabi-v7a with NEON") 16 | set(ANDROID_ABI "arm64-v8a") 17 | #########window 18 | set(ANDROID_NDK "J://androidSdk/ndk-bundle") 19 | endif() 20 | 21 | ######### 22 | if(ANDROID_SDK_VERSION EQUAL 29) 23 | set(ANDROID_CLANG_VERSION "clang-r353983c") 24 | elseif(ANDROID_SDK_VERSION EQUAL 28) 25 | set(ANDROID_CLANG_VERSION "clang-4691093") 26 | elseif(ANDROID_SDK_VERSION EQUAL 27) 27 | set(ANDROID_CLANG_VERSION "clang-4053586") 28 | elseif(ANDROID_SDK_VERSION EQUAL 26) 29 | set(ANDROID_CLANG_VERSION "clang-4053586") 30 | elseif(ANDROID_SDK_VERSION EQUAL 25) 31 | set(ANDROID_CLANG_VERSION "clang-2690385") 32 | endif() 33 | 34 | 35 | include(${CMAKE_CURRENT_LIST_DIR}/AndroidMK/LoadModule.cmake) 36 | include(${CMAKE_CURRENT_LIST_DIR}/AndroidMK/Parse.cmake) 37 | include(${CMAKE_CURRENT_LIST_DIR}/AndroidBP/Parse.cmake) 38 | loadModule() 39 | -------------------------------------------------------------------------------- /CMakeModule/android.flag.cmake: -------------------------------------------------------------------------------- 1 | 2 | set(COMBO_GLOBAL_CFLAGS 3 | -fno-exceptions 4 | -Wno-multichar) 5 | if (ANDROID_SYSROOT_ABI STREQUAL arm) 6 | list(APPEND COMBO_GLOBAL_CFLAGS 7 | -msoft-float) 8 | else() 9 | list(APPEND COMBO_GLOBAL_CFLAGS -fno-strict-aliasing) 10 | list(APPEND COMBO_GLOBAL_CFLAGS 11 | -Werror=pointer-to-int-cast 12 | -Werror=int-to-pointer-cast 13 | -Werror=implicit-function-declaration) 14 | endif () 15 | 16 | ## mach cpu 17 | if(ANDROID_ABI STREQUAL arm64-v8a) 18 | include(${CMAKE_CURRENT_LIST_DIR}/arm64/armv8-a.cmake) 19 | elseif(ANDROID_ABI STREQUAL "arm64-v8a2") 20 | include(${CMAKE_CURRENT_LIST_DIR}/arm64/armv8-2a.cmake) 21 | elseif(ANDROID_ABI STREQUAL "armeabi-v7a with NEON") 22 | include(${CMAKE_CURRENT_LIST_DIR}/arm/armv7-a-neon.cmake) 23 | elseif(ANDROID_ABI STREQUAL armeabi-v7a) 24 | include(${CMAKE_CURRENT_LIST_DIR}/arm/armv7-a.cmake) 25 | endif() 26 | 27 | list(APPEND COMBO_GLOBAL_CFLAGS 28 | -ffunction-sections 29 | -fdata-sections 30 | -funwind-tables 31 | -fstack-protector-strong 32 | -Wa,--noexecstack 33 | -Werror=format-security 34 | -D_FORTIFY_SOURCE=2 35 | -fno-short-enums 36 | -no-canonical-prefixes 37 | ${ARCH_VARIANT_CLFAGS} 38 | ) 39 | 40 | set(COMBO_GLOBAL_CPPFLAGS -fvisibility-inlines-hidden) 41 | 42 | set(COMMON_GLOBAL_CFLAGS 43 | -DANDROID 44 | -fmessage-length=0 45 | -W -Wall -Wno-unused 46 | -Winit-self 47 | -Wpointer-arith) 48 | 49 | set(COMMON_GLOBAL_CPPFLAGS 50 | -Wsign-promo 51 | -Wno-inconsistent-missing-override 52 | -Wno-null-dereference 53 | -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS 54 | -Wno-thread-safety-negative 55 | -Wno-gnu-include-next) 56 | 57 | set(TARGET_ERROR_FLAGS 58 | -Werror=return-type 59 | -Werror=non-virtual-dtor 60 | -Werror=address 61 | -Werror=sequence-point 62 | -Werror=date-time) 63 | 64 | set(TARGET_RELEASE_CFLAGS 65 | -DNDEBUG -UDEBUG 66 | -O2 -g 67 | -Wno-strict-aliasing 68 | -fno-exceptions) 69 | 70 | set(TARGET_DEBUG_CFLAGS 71 | -DNDEBUG -UDEBUG 72 | -O0 -g 73 | -Wno-strict-aliasing 74 | -fno-exceptions 75 | -fno-limit-debug-info 76 | ) 77 | 78 | ############################################################################## 79 | # clang 80 | set(CLANG_CONFIG_EXTRA_CFLAGS -D__compiler_offsetof=__builtin_offsetof ) 81 | # Help catch common 32/64-bit errors. 82 | list(APPEND CLANG_CONFIG_EXTRA_CFLAGS -Werror=int-conversion) 83 | # Disable overly aggressive warning for macros defined with a leading underscore 84 | # This used to happen in AndroidConfig.h, which was included everywhere. 85 | list(APPEND CLANG_CONFIG_EXTRA_CFLAGS -Wno-reserved-id-macro) 86 | # Disable overly aggressive warning for format strings. 87 | # Bug: 20148343 88 | list(APPEND CLANG_CONFIG_EXTRA_CFLAGS -Wno-format-pedantic) 89 | # Workaround for ccache with clang. 90 | # See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html. 91 | list(APPEND CLANG_CONFIG_EXTRA_CFLAGS -Wno-unused-command-line-argument) 92 | if(${ANDROID_SDK_VERSION} GREATER_EQUAL 27) 93 | list(APPEND CLANG_CONFIG_EXTRA_CFLAGS -Wno-expansion-to-defined) 94 | endif() 95 | list(APPEND CLANG_CONFIG_EXTRA_CFLAGS -ffunction-sections) 96 | list(APPEND CLANG_CONFIG_EXTRA_CFLAGS -fdata-sections) 97 | list(APPEND CLANG_CONFIG_EXTRA_CFLAGS -fno-short-enums -funwind-tables -fstack-protector-strong) 98 | list(APPEND CLANG_CONFIG_EXTRA_CFLAGS -fdebug-prefix-map=${PROJECT_DIR}/=) 99 | 100 | list(APPEND CLANG_CONFIG_EXTRA_CFLAGS -nostdlibinc) 101 | list(APPEND CLANG_CONFIG_EXTRA_CFLAGS 102 | "-target ${ANDROID_TOOLCHAIN_NAME}" 103 | "-B${ANDROID_TOOLCHAIN_ROOT}/bin") 104 | 105 | set(CLANG_CONFIG_EXTRA_CPPFLAGS -Wno-inconsistent-missing-override) 106 | 107 | set(COMMON_TARGET_RTTI_FLAG -fno-rtti) 108 | set(COMMON_TARGET_CFLAGS -fpie -D_USING_LIBCXX -DANDROID_STRICT) 109 | set(COMMON_TARGET_GLOBAL_CONLYFLAGS -std=gnu99) 110 | set(COMMON_TARGET_GLOBAL_CPPFLAGS -std=gnu++14) 111 | set(COMMON_TARGET_CFLAGS_NO_OVERRIDE 112 | -Werror=int-to-pointer-cast 113 | -Werror=pointer-to-int-cast 114 | -Werror=address-of-temporary 115 | -Werror=null-dereference 116 | -Werror=return-type 117 | -Wno-enum-compare 118 | ) 119 | 120 | if(${ANDROID_SDK_VERSION} GREATER_EQUAL 28) 121 | list(APPEND COMMON_TARGET_CFLAGS_NO_OVERRIDE 122 | -Wno-tautological-constant-compare 123 | -Wno-null-pointer-arithmetic 124 | -Wno-enum-compare-switch 125 | ) 126 | endif() 127 | 128 | ####################################################################### 129 | if(ANDROID_SYSROOT_ABI STREQUAL arm64) 130 | set(ANDROID_LINKER /system/bin/linker64) 131 | else() 132 | set(ANDROID_LINKER /system/bin/linker) 133 | endif() 134 | if(${ANDROID_SDK_VERSION} GREATER_EQUAL 29) 135 | set(ANDROID_GLOBAL_LD_DIRS 136 | ${ANDROID_TARGET_OUT_DIR}/symbols/system/${ANDROID_LIBDIR_NAME} 137 | ${ANDROID_TARGET_OUT_DIR}/symbols/system/${ANDROID_LIBDIR_NAME}/bootstrap 138 | ${ANDROID_TARGET_OUT_DIR}/symbols/vendor/${ANDROID_LIBDIR_NAME} 139 | ) 140 | else() 141 | set(ANDROID_GLOBAL_LD_DIRS ${ANDROID_TARGET_OUT_DIR}/${ANDROID_OBJ_DIR}/lib) 142 | endif() 143 | 144 | set(ANDROID_GLOBAL_EXE_LINK_FLAGS 145 | -pie 146 | -nostdlib 147 | -Bdynamic 148 | -Wl,-dynamic-linker,${ANDROID_LINKER} 149 | -Wl,--gc-sections 150 | -Wl,-z,nocopyreloc 151 | ) 152 | 153 | set(ANDROID_GLOBAL_SHARED_LINK_FLAGS 154 | -shared -nostdlib -Wl,--gc-sections 155 | ) 156 | 157 | foreach(dir ${ANDROID_GLOBAL_LD_DIRS}) 158 | list(APPEND ANDROID_GLOBAL_EXE_LINK_FLAGS 159 | -Wl,-rpath-link=${dir} 160 | -L${dir}) 161 | list(APPEND ANDROID_GLOBAL_SHARED_LINK_FLAGS 162 | -Wl,-rpath-link=${dir} 163 | -L${dir}) 164 | endforeach() 165 | 166 | if(${ANDROID_SDK_VERSION} GREATER_EQUAL 29) 167 | android_get_soong_intermediates_dir("bionic/libc" "crtbegin_dynamic" ANDROID_SOONG_CRTBEGIN) 168 | set(ANDROID_CRTBEGIN_DYNAMIC_O ${ANDROID_SOONG_CRTBEGIN}/crtbegin_dynamic.o) 169 | android_get_soong_intermediates_dir("bionic/libc" "crtbegin_so" ANDROID_SOONG_CRTBEGIN_SO_PATH) 170 | set(ANDROID_CRTBEGIN_SO ${ANDROID_SOONG_CRTBEGIN_SO_PATH}/crtbegin_so.o) 171 | android_get_soong_intermediates_obj_dir("bionic/libc" "crtend_android" "bionic" ANDROID_SOONG_CRTEND_PATH) 172 | set(ANDROID_CRTEND_O ${ANDROID_SOONG_CRTEND_PATH}/crtend.o) 173 | android_get_soong_intermediates_obj_dir("bionic/libc" "crtend_so" "bionic" ANDROID_SOONG_CRTEND_SO_PATH) 174 | set(ANDROID_CRTEND_SO ${ANDROID_SOONG_CRTEND_SO_PATH}/crtend_so.o) 175 | else() 176 | set(ANDROID_CRTBEGIN_DYNAMIC_O ${ANDROID_GLOBAL_LD_DIRS}/crtbegin_dynamic.o) 177 | set(ANDROID_CRTEND_O ${ANDROID_GLOBAL_LD_DIRS}/crtend_android.o) 178 | set(ANDROID_CRTBEGIN_SO ${ANDROID_GLOBAL_LD_DIRS}/crtbegin_so.o) 179 | set(ANDROID_CRTEND_SO ${ANDROID_GLOBAL_LD_DIRS}/crtend_so.o) 180 | staticLibDir(compiler_rt-extras compiler_rt_static_lib) 181 | set(ANDROID_NEED_STATIC_LIBRARIES ${compiler_rt_static_lib}) 182 | endif() 183 | 184 | 185 | if(${ANDROID_SDK_VERSION} GREATER_EQUAL 27) 186 | if(${ANDROID_SDK_VERSION} GREATER_EQUAL 28) 187 | staticLibDir(clang_rt.ubsan_minimal-aarch64-android clang_rt_static_lib) 188 | list(APPEND ANDROID_NEED_STATIC_LIBRARIES ${clang_rt_static_lib}) 189 | endif() 190 | staticLibDir(atomic atomic_static_lib) 191 | staticLibDir(gcc gcc_static_lib) 192 | set(ANDROID_ATOMIC_STATIC_LIBRARIES ${atomic_static_lib}) 193 | set(ANDROID_GCC_STATIC_LIBRARIES ${gcc_static_lib}) 194 | else() 195 | set(ANDROID_ATOMIC_STATIC_LIBRARIES 196 | ${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_NAME}/${ANDROID_LIBDIR_NAME}/libatomic.a) 197 | set(ANDROID_GCC_STATIC_LIBRARIES 198 | ${ANDROID_TOOLCHAIN_ROOT}/lib/gcc/${ANDROID_TOOLCHAIN_NAME}/4.9/libgcc.a) 199 | endif() 200 | 201 | set(ANDROID_NEED_SHARED_LIBRARIES -lc++ -lc -lm -ldl) 202 | set(ANDROID_GLOBAL_LDFLAGS 203 | -Wl,-z,noexecstack 204 | -Wl,-z,relro 205 | -Wl,-z,now 206 | -Wl,--build-id=md5 207 | -Wl,--warn-shared-textrel 208 | -Wl,--fatal-warnings 209 | -Wl,--no-undefined-version 210 | ${ARCH_VARIANT_LDLFAGS} 211 | -target ${ANDROID_TOOLCHAIN_NAME} 212 | -B${ANDROID_TOOLCHAIN_ROOT}/bin 213 | ) 214 | set(ANDROID_LDFLAGS 215 | -Wl,--exclude-libs,libclang_rt.ubsan_minimal-aarch64-android.a 216 | -Wl,--no-undefined) 217 | 218 | ####################################################################### 219 | set(ANDROID_COMPILER_FLAGS 220 | ${COMBO_GLOBAL_CFLAGS} 221 | ${COMMON_GLOBAL_CFLAGS} 222 | ${TARGET_ERROR_FLAGS} 223 | ${CLANG_CONFIG_EXTRA_CFLAGS} 224 | ${COMMON_TARGET_RTTI_FLAG} 225 | ${COMMON_TARGET_CFLAGS} 226 | ${COMMON_TARGET_GLOBAL_CONLYFLAGS} 227 | ${COMMON_TARGET_CFLAGS_NO_OVERRIDE} 228 | ) 229 | 230 | set(ANDROID_COMPILER_FLAGS_CXX 231 | ${COMBO_GLOBAL_CFLAGS} 232 | ${COMBO_GLOBAL_CPPFLAGS} 233 | ${COMMON_GLOBAL_CFLAGS} 234 | ${COMMON_GLOBAL_CPPFLAGS} 235 | ${TARGET_ERROR_FLAGS} 236 | ${CLANG_CONFIG_EXTRA_CFLAGS} 237 | ${CLANG_CONFIG_EXTRA_CPPFLAGS} 238 | ${COMMON_TARGET_RTTI_FLAG} 239 | ${COMMON_TARGET_CFLAGS} 240 | ${COMMON_TARGET_GLOBAL_CPPFLAGS} 241 | ${COMMON_TARGET_CFLAGS_NO_OVERRIDE} 242 | ) 243 | 244 | set(ANDROID_COMPILER_FLAGS_RELEASE ${TARGET_RELEASE_CFLAGS}) 245 | set(ANDROID_COMPILER_FLAGS_DEBUG ${TARGET_DEBUG_CFLAGS}) 246 | 247 | set(ANDROID_LINKER_FLAGS_EXE 248 | ${ANDROID_GLOBAL_EXE_LINK_FLAGS} 249 | ${ANDROID_CRTBEGIN_DYNAMIC_O} 250 | ) 251 | set(ANDROID_LINKER_FLAGS_SHARED 252 | ${ANDROID_GLOBAL_SHARED_LINK_FLAGS} 253 | ${ANDROID_CRTBEGIN_SO} 254 | ) 255 | set(ANDROID_LDFLAGS_EXE 256 | -Wl,--no-whole-archive 257 | ${ANDROID_NEED_STATIC_LIBRARIES} 258 | ${ANDROID_ATOMIC_STATIC_LIBRARIES} 259 | ${ANDROID_GCC_STATIC_LIBRARIES} 260 | ${ANDROID_GLOBAL_LDFLAGS} 261 | ${ANDROID_LDFLAGS} 262 | ${ANDROID_NEED_SHARED_LIBRARIES} 263 | ) 264 | -------------------------------------------------------------------------------- /CMakeModule/android.func.cmake: -------------------------------------------------------------------------------- 1 | 2 | function(staticLibDir name out) 3 | set(${out} ${ANDROID_TARGET_OUT_DIR}/${ANDROID_OBJ_DIR}/STATIC_LIBRARIES/lib${name}_intermediates/lib${name}.a PARENT_SCOPE) 4 | endfunction() 5 | 6 | function(sharedLibDir name out) 7 | set(${out} ${ANDROID_TARGET_OUT_DIR}/${ANDROID_OBJ_DIR}/SHARED_LIBRARIES/lib${name}_intermediates/lib${name}.so PARENT_SCOPE) 8 | endfunction() 9 | 10 | function(android_target_link_static_libraries target ...) 11 | math(EXPR NUM "${ARGC} - 1") 12 | foreach(i RANGE 1 ${NUM}) 13 | set(name ${ARGV${i}}) 14 | if("${name}" MATCHES "^lib.*") 15 | string(REPLACE "lib" "" name "${name}") 16 | endif() 17 | target_link_libraries(${target} PRIVATE ${ANDROID_TARGET_OUT_DIR}/${ANDROID_OBJ_DIR}/STATIC_LIBRARIES/lib${name}_intermediates/lib${name}.a) 18 | endforeach() 19 | endfunction() 20 | 21 | function(android_target_link_shared_libraries target ...) 22 | math(EXPR NUM "${ARGC} - 1") 23 | foreach(i RANGE 1 ${NUM}) 24 | set(name ${ARGV${i}}) 25 | if("${name}" MATCHES "^lib.*") 26 | string(REPLACE "lib" "" name "${name}") 27 | endif() 28 | target_link_libraries(${target} PRIVATE ${name}) 29 | endforeach() 30 | endfunction() 31 | 32 | function(android_get_soong_intermediates_dir_namespace dir name namespace out) 33 | set(${out} ${PROJECT_DIR}/out/soong/.intermediates/${dir}/${name}/android_${ANDROID_TARGET_ARCH}_${ANDROID_ARCH_VARIANT}_${ANDROID_CPU_VARIANT}_${namespace} PARENT_SCOPE) 34 | endfunction() 35 | 36 | function(android_get_soong_intermediates_dir dir name out) 37 | android_get_soong_intermediates_dir_namespace(${dir} ${name} "core" dir_tmp_out) 38 | set(${out} ${dir_tmp_out} PARENT_SCOPE) 39 | endfunction() 40 | 41 | function(android_get_soong_intermediates_obj_dir_namespace dir name obj namespace out) 42 | android_get_soong_intermediates_dir_namespace(${dir} ${name} ${namespace} tmp_out) 43 | set(${out} ${tmp_out}/obj/${dir}/arch-common/${obj} PARENT_SCOPE) 44 | endfunction() 45 | 46 | function(android_get_soong_intermediates_obj_dir dir name obj out) 47 | android_get_soong_intermediates_obj_dir_namespace(${dir} ${name} ${obj} "core" obj_tmp_out) 48 | set(${out} ${obj_tmp_out} PARENT_SCOPE) 49 | endfunction() -------------------------------------------------------------------------------- /CMakeModule/android.module.cmake: -------------------------------------------------------------------------------- 1 | parseAndroidMK(libsurfaceflinger ${MK_SHARED}) -------------------------------------------------------------------------------- /CMakeModule/android.toolchain.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Ahren liliorg@163.com 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cmake_minimum_required(VERSION 3.6.0) 16 | 17 | set(CMAKE_SYSTEM_VERSION 1) 18 | 19 | file(TO_CMAKE_PATH "${PROJECT_DIR}" PROJECT_DIR) 20 | # ################################ 21 | if(ANDROID_NDK_TOOLCHAIN_INCLUDED) 22 | return() 23 | endif(ANDROID_NDK_TOOLCHAIN_INCLUDED) 24 | set(ANDROID_NDK_TOOLCHAIN_INCLUDED true) 25 | # ################################ 26 | 27 | if(NOT ANDROID_ABI) 28 | set(ANDROID_ABI "armeabi-v7a with NEON") 29 | endif() 30 | 31 | if(NOT ANDROID_CCACHE) 32 | set(ANDROID_CCACHE OFF) 33 | endif() 34 | 35 | if(NOT ANDROID_ARM_MODE) 36 | set(ANDROID_ARM_MODE thumb) 37 | endif() 38 | 39 | # Standard cross-compiling stuff. 40 | set(ANDROID TRUE) 41 | set(CMAKE_SYSTEM_NAME Android) 42 | 43 | # Allow users to override these values in case they want more strict behaviors. 44 | # For example, they may want to prevent the NDK's libz from being picked up so 45 | # they can use their own. 46 | # https://github.com/android-ndk/ndk/issues/517 47 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 48 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 49 | endif() 50 | 51 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 52 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 53 | endif() 54 | 55 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 56 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 57 | endif() 58 | 59 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 60 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 61 | endif() 62 | 63 | # ABI 64 | set(CMAKE_ANDROID_ARCH_ABI ${ANDROID_ABI}) 65 | if(ANDROID_ABI MATCHES "^armeabi(-v7a)?$") 66 | set(ANDROID_SYSROOT_ABI arm) 67 | set(ANDROID_TOOLCHAIN_NAME arm-linux-androideabi) 68 | set(ANDROID_TOOLCHAIN_ROOT ${ANDROID_TOOLCHAIN_NAME}) 69 | set(ANDROID_HEADER_TRIPLE arm-linux-androideabi) 70 | if(ANDROID_ABI STREQUAL armeabi) 71 | message(WARNING "armeabi is deprecated and will be removed in a future NDK release.") 72 | set(CMAKE_SYSTEM_PROCESSOR armv5te) 73 | set(ANDROID_LLVM_TRIPLE armv5te-none-linux-androideabi) 74 | elseif(ANDROID_ABI STREQUAL armeabi-v7a) 75 | set(CMAKE_SYSTEM_PROCESSOR armv7-a) 76 | set(ANDROID_LLVM_TRIPLE armv7-none-linux-androideabi) 77 | endif() 78 | elseif(ANDROID_ABI STREQUAL arm64-v8a) 79 | set(ANDROID_SYSROOT_ABI arm64) 80 | set(CMAKE_SYSTEM_PROCESSOR aarch64) 81 | set(ANDROID_TOOLCHAIN_NAME aarch64-linux-android) 82 | set(ANDROID_TOOLCHAIN_ROOT ${ANDROID_TOOLCHAIN_NAME}) 83 | set(ANDROID_LLVM_TRIPLE aarch64-none-linux-android) 84 | set(ANDROID_HEADER_TRIPLE aarch64-linux-android) 85 | elseif(ANDROID_ABI STREQUAL x86) 86 | set(ANDROID_SYSROOT_ABI x86) 87 | set(CMAKE_SYSTEM_PROCESSOR i686) 88 | set(ANDROID_TOOLCHAIN_NAME i686-linux-android) 89 | set(ANDROID_TOOLCHAIN_ROOT ${ANDROID_ABI}) 90 | set(ANDROID_LLVM_TRIPLE i686-none-linux-android) 91 | set(ANDROID_HEADER_TRIPLE i686-linux-android) 92 | elseif(ANDROID_ABI STREQUAL x86_64) 93 | set(ANDROID_SYSROOT_ABI x86_64) 94 | set(CMAKE_SYSTEM_PROCESSOR x86_64) 95 | set(ANDROID_TOOLCHAIN_NAME x86_64-linux-android) 96 | set(ANDROID_TOOLCHAIN_ROOT ${ANDROID_ABI}) 97 | set(ANDROID_LLVM_TRIPLE x86_64-none-linux-android) 98 | set(ANDROID_HEADER_TRIPLE x86_64-linux-android) 99 | elseif(ANDROID_ABI STREQUAL mips) 100 | set(ANDROID_SYSROOT_ABI mips) 101 | set(CMAKE_SYSTEM_PROCESSOR mips) 102 | set(ANDROID_TOOLCHAIN_NAME mips64el-linux-android) 103 | set(ANDROID_TOOLCHAIN_ROOT ${ANDROID_TOOLCHAIN_NAME}) 104 | set(ANDROID_LLVM_TRIPLE mipsel-none-linux-android) 105 | set(ANDROID_HEADER_TRIPLE mipsel-linux-android) 106 | elseif(ANDROID_ABI STREQUAL mips64) 107 | set(ANDROID_SYSROOT_ABI mips64) 108 | set(CMAKE_SYSTEM_PROCESSOR mips64) 109 | set(ANDROID_TOOLCHAIN_NAME mips64el-linux-android) 110 | set(ANDROID_TOOLCHAIN_ROOT ${ANDROID_TOOLCHAIN_NAME}) 111 | set(ANDROID_LLVM_TRIPLE mips64el-none-linux-android) 112 | set(ANDROID_HEADER_TRIPLE mips64el-linux-android) 113 | else() 114 | message(FATAL_ERROR "Invalid Android ABI: ${ANDROID_ABI}.") 115 | endif() 116 | 117 | if(ANDROID_SYSROOT_ABI STREQUAL arm) 118 | set(ANDROID_LIBDIR_NAME lib) 119 | if(ANDROID_TARGET_ARCH STREQUAL arm64) 120 | set(ANDROID_OBJ_DIR obj_arm) 121 | endif() 122 | else() 123 | set(ANDROID_LIBDIR_NAME lib64) 124 | set(ANDROID_OBJ_DIR obj) 125 | if(ANDROID_TARGET_ARCH STREQUAL arm) 126 | message(FATAL_ERROR "android ANDROID_TARGET_ARCH=arm, but ANDROID_ABI=arm64-v8a") 127 | endif() 128 | endif() 129 | 130 | ########################################################################################################### 131 | 132 | set(ANDROID_COMPILER_FLAGS) 133 | set(ANDROID_COMPILER_FLAGS_CXX) 134 | set(ANDROID_COMPILER_FLAGS_DEBUG) 135 | set(ANDROID_COMPILER_FLAGS_RELEASE) 136 | set(ANDROID_LINKER_FLAGS) 137 | set(ANDROID_LINKER_FLAGS_EXE) 138 | SET(ANDROID_LINKER_FLAGS_SHARD) 139 | 140 | # STL. 141 | set(ANDROID_STL_STATIC_LIBRARIES) 142 | set(ANDROID_STL_SHARED_LIBRARIES) 143 | 144 | # out 145 | set(ANDROID_TARGET_OUT_DIR ${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}) 146 | 147 | # Behavior of CMAKE_SYSTEM_LIBRARY_PATH and CMAKE_LIBRARY_PATH are really weird 148 | # when CMAKE_SYSROOT is set. The library path is appended to the sysroot even if 149 | # the library path is an abspath. Using a relative path from the sysroot doesn't 150 | # work either, because the relative path is abspath'd relative to the current 151 | # CMakeLists.txt file before being appended :( 152 | # 153 | # We can try to get out of this problem by providing another root path for cmake 154 | # to check. CMAKE_FIND_ROOT_PATH is intended for this purpose: 155 | # https://cmake.org/cmake/help/v3.8/variable/CMAKE_FIND_ROOT_PATH.html 156 | # 157 | # In theory this should just be our sysroot, but since we don't have a single 158 | # sysroot that is correct (there's only one set of headers, but multiple 159 | # locations for libraries that need to be handled differently). Some day we'll 160 | # want to move all the libraries into ${ANDROID_NDK}/sysroot, but we'll need to 161 | # make some fixes to Clang, various build systems, and possibly CMake itself to 162 | # get that working. 163 | list(APPEND CMAKE_FIND_ROOT_PATH "${PROJECT_DIR}/bionic/libc") 164 | 165 | # We need different sysroots for linking and compiling, but cmake doesn't 166 | # support that. Pass the sysroot flag manually when linking. 167 | set(ANDROID_SYSTEM_LIBRARY_PATH "${ANDROID_TARGET_OUT_DIR}/symbols/system/${ANDROID_LIBDIR_NAME}") 168 | 169 | # find_library searches a handful of paths as described by 170 | # https://cmake.org/cmake/help/v3.6/command/find_library.html. Since libraries 171 | # are per-API level and headers aren't, We don't have libraries in the 172 | # CMAKE_SYSROOT. Set up CMAKE_SYSTEM_LIBRARY_PATH 173 | # (https://cmake.org/cmake/help/v3.6/variable/CMAKE_SYSTEM_LIBRARY_PATH.html) 174 | # instead. 175 | # 176 | # NB: The suffix is just lib here instead of dealing with lib64 because 177 | # apparently CMake does some automatic rewriting of that? I've been testing by 178 | # building my own CMake with a bunch of logging added, and that seems to be the 179 | # case. 180 | list(APPEND CMAKE_SYSTEM_LIBRARY_PATH "${ANDROID_SYSTEM_LIBRARY_PATH}") 181 | 182 | # Toolchain. 183 | if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux) 184 | set(ANDROID_HOST_TAG linux-x86) 185 | elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) 186 | set(ANDROID_HOST_TAG darwin-x86_64) 187 | elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) 188 | set(ANDROID_HOST_TAG windows-x86_64) 189 | set(ANDROID_TOOLCHAIN_SUFFIX .exe) 190 | if(NOT ANDROID_NDK) 191 | message(FATAL_ERROR "Android NDK not set!") 192 | return() 193 | endif() 194 | endif() 195 | 196 | ################toolchain 197 | set(ANDROID_TOOLCHAIN_ROOT 198 | "${PROJECT_DIR}/prebuilts/gcc/${ANDROID_HOST_TAG}/${CMAKE_SYSTEM_PROCESSOR}/${ANDROID_TOOLCHAIN_NAME}-4.9") 199 | if ("${ANDROID_HOST_TAG}" MATCHES "windows.*") 200 | set(ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}-4.9/prebuilt/${ANDROID_HOST_TAG}") 201 | endif () 202 | set(ANDROID_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_NAME}-") 203 | 204 | if ("${ANDROID_HOST_TAG}" MATCHES "windows.*") 205 | set(ANDROID_LLVM_TOOLCHAIN_PREFIX "${ANDROID_NDK}/toolchains/llvm/prebuilt/${ANDROID_HOST_TAG}/bin/") 206 | else() 207 | if(NOT ANDROID_CLANG_VERSION) 208 | set(ANDROID_CLANG_VERSION "clang-2690385") 209 | endif() 210 | set(ANDROID_LLVM_TOOLCHAIN_PREFIX "${PROJECT_DIR}/prebuilts/clang/host/${ANDROID_HOST_TAG}/${ANDROID_CLANG_VERSION}/bin/") 211 | endif() 212 | set(ANDROID_C_COMPILER "${ANDROID_LLVM_TOOLCHAIN_PREFIX}clang${ANDROID_TOOLCHAIN_SUFFIX}") 213 | set(ANDROID_CXX_COMPILER "${ANDROID_LLVM_TOOLCHAIN_PREFIX}clang++${ANDROID_TOOLCHAIN_SUFFIX}") 214 | set(ANDROID_ASM_COMPILER "${ANDROID_LLVM_TOOLCHAIN_PREFIX}clang${ANDROID_TOOLCHAIN_SUFFIX}") 215 | # Clang can fail to compile if CMake doesn't correctly supply the target and 216 | # external toolchain, but to do so, CMake needs to already know that the 217 | # compiler is clang. Tell CMake that the compiler is really clang, but don't 218 | # use CMakeForceCompiler, since we still want compile checks. We only want 219 | # to skip the compiler ID detection step. 220 | set(CMAKE_C_COMPILER_ID_RUN TRUE) 221 | set(CMAKE_CXX_COMPILER_ID_RUN TRUE) 222 | set(CMAKE_C_COMPILER_ID Clang) 223 | set(CMAKE_CXX_COMPILER_ID Clang) 224 | set(CMAKE_C_COMPILER_VERSION 3.8) 225 | set(CMAKE_CXX_COMPILER_VERSION 3.8) 226 | set(CMAKE_C_STANDARD_COMPUTED_DEFAULT 11) 227 | set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT 98) 228 | 229 | set(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN "${ANDROID_TOOLCHAIN_ROOT}") 230 | set(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN "${ANDROID_TOOLCHAIN_ROOT}") 231 | set(CMAKE_ASM_COMPILER_EXTERNAL_TOOLCHAIN "${ANDROID_TOOLCHAIN_ROOT}") 232 | 233 | if(EXISTS ${ANDROID_LLVM_TOOLCHAIN_PREFIX}llvm-ar${ANDROID_TOOLCHAIN_SUFFIX}) 234 | set(ANDROID_AR "${ANDROID_LLVM_TOOLCHAIN_PREFIX}llvm-ar${ANDROID_TOOLCHAIN_SUFFIX}") 235 | else() 236 | set(ANDROID_AR "${ANDROID_TOOLCHAIN_PREFIX}ar${ANDROID_TOOLCHAIN_SUFFIX}") 237 | endif() 238 | if(EXISTS ${ANDROID_LLVM_TOOLCHAIN_PREFIX}llvm-ranlib${ANDROID_TOOLCHAIN_SUFFIX}) 239 | set(ANDROID_RANLIB "${ANDROID_LLVM_TOOLCHAIN_PREFIX}llvm-ranlib${ANDROID_TOOLCHAIN_SUFFIX}") 240 | else() 241 | set(ANDROID_RANLIB "${ANDROID_TOOLCHAIN_PREFIX}ranlib${ANDROID_TOOLCHAIN_SUFFIX}") 242 | endif() 243 | 244 | if(ANDROID_CCACHE) 245 | set(CMAKE_C_COMPILER_LAUNCHER "${ANDROID_CCACHE}") 246 | set(CMAKE_CXX_COMPILER_LAUNCHER "${ANDROID_CCACHE}") 247 | endif() 248 | 249 | set(CMAKE_C_COMPILER "${ANDROID_C_COMPILER}") 250 | set(CMAKE_CXX_COMPILER "${ANDROID_CXX_COMPILER}") 251 | set(CMAKE_AR "${ANDROID_AR}" CACHE FILEPATH "Archiver") 252 | set(CMAKE_RANLIB "${ANDROID_RANLIB}" CACHE FILEPATH "Ranlib") 253 | set(_CMAKE_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_PREFIX}") 254 | 255 | if(ANDROID_ABI STREQUAL "x86" OR ANDROID_ABI STREQUAL "x86_64") 256 | set(CMAKE_ASM_NASM_COMPILER 257 | "${ANDROID_HOST_PREBUILTS}/bin/yasm${ANDROID_TOOLCHAIN_SUFFIX}") 258 | set(CMAKE_ASM_NASM_COMPILER_ARG1 "-DELF") 259 | endif() 260 | 261 | include(${CMAKE_CURRENT_LIST_DIR}/android.func.cmake) 262 | ################flag 263 | include(${CMAKE_CURRENT_LIST_DIR}/android.flag.cmake) 264 | 265 | list(APPEND ANDROID_COMPILER_FLAGS -DPLATFORM_SDK_VERSION=${ANDROID_SDK_VERSION}) 266 | list(APPEND ANDROID_COMPILER_FLAGS_CXX -DPLATFORM_SDK_VERSION=${ANDROID_SDK_VERSION}) 267 | 268 | # Set or retrieve the cached flags. 269 | # This is necessary in case the user sets/changes flags in subsequent 270 | # configures. If we included the Android flags in here, they would get 271 | # overwritten. 272 | set(CMAKE_C_FLAGS "" 273 | CACHE STRING "Flags used by the compiler during all build types.") 274 | set(CMAKE_CXX_FLAGS "" 275 | CACHE STRING "Flags used by the compiler during all build types.") 276 | set(CMAKE_ASM_FLAGS "" 277 | CACHE STRING "Flags used by the compiler during all build types.") 278 | set(CMAKE_C_FLAGS_DEBUG "" 279 | CACHE STRING "Flags used by the compiler during debug builds.") 280 | set(CMAKE_CXX_FLAGS_DEBUG "" 281 | CACHE STRING "Flags used by the compiler during debug builds.") 282 | set(CMAKE_ASM_FLAGS_DEBUG "" 283 | CACHE STRING "Flags used by the compiler during debug builds.") 284 | set(CMAKE_C_FLAGS_RELEASE "" 285 | CACHE STRING "Flags used by the compiler during release builds.") 286 | set(CMAKE_CXX_FLAGS_RELEASE "" 287 | CACHE STRING "Flags used by the compiler during release builds.") 288 | set(CMAKE_ASM_FLAGS_RELEASE "" 289 | CACHE STRING "Flags used by the compiler during release builds.") 290 | set(CMAKE_MODULE_LINKER_FLAGS "" 291 | CACHE STRING "Flags used by the linker during the creation of modules.") 292 | set(CMAKE_SHARED_LINKER_FLAGS "" 293 | CACHE STRING "Flags used by the linker during the creation of dll's.") 294 | set(CMAKE_EXE_LINKER_FLAGS "" 295 | CACHE STRING "Flags used by the linker.") 296 | 297 | string(REPLACE ";" " " ANDROID_COMPILER_FLAGS "${ANDROID_COMPILER_FLAGS}") 298 | string(REPLACE ";" " " ANDROID_COMPILER_FLAGS_CXX "${ANDROID_COMPILER_FLAGS_CXX}") 299 | string(REPLACE ";" " " ANDROID_COMPILER_FLAGS_DEBUG "${ANDROID_COMPILER_FLAGS_DEBUG}") 300 | string(REPLACE ";" " " ANDROID_COMPILER_FLAGS_RELEASE "${ANDROID_COMPILER_FLAGS_RELEASE}") 301 | string(REPLACE ";" " " ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS}") 302 | string(REPLACE ";" " " ANDROID_LINKER_FLAGS_EXE "${ANDROID_LINKER_FLAGS_EXE}") 303 | string(REPLACE ";" " " ANDROID_LDFLAGS_EXE "${ANDROID_LDFLAGS_EXE}") 304 | string(REPLACE ";" " " ANDROID_LINKER_FLAGS_SHARED "${ANDROID_LINKER_FLAGS_SHARED}") 305 | 306 | set(CMAKE_C_FLAGS ${ANDROID_COMPILER_FLAGS}) 307 | set(CMAKE_CXX_FLAGS ${ANDROID_COMPILER_FLAGS_CXX}) 308 | set(CMAKE_ASM_FLAGS ${ANDROID_COMPILER_FLAGS}) 309 | 310 | set(CMAKE_C_FLAGS_DEBUG ${ANDROID_COMPILER_FLAGS_DEBUG}) 311 | set(CMAKE_CXX_FLAGS_DEBUG ${ANDROID_COMPILER_FLAGS_DEBUG}) 312 | set(CMAKE_ASM_FLAGS_DEBUG ${ANDROID_COMPILER_FLAGS_DEBUG}) 313 | 314 | set(CMAKE_C_FLAGS_RELEASE ${ANDROID_COMPILER_FLAGS_RELEASE}) 315 | set(CMAKE_CXX_FLAGS_RELEASE ${ANDROID_COMPILER_FLAGS_RELEASE}) 316 | set(CMAKE_ASM_FLAGS_RELEASE ${ANDROID_COMPILER_FLAGS_RELEASE}) 317 | 318 | # link 319 | set(CMAKE_SHARED_LINKER_FLAGS ${ANDROID_LINKER_FLAGS_SHARED}) 320 | set(CMAKE_MODULE_LINKER_FLAGS ${ANDROID_LINKER_FLAGS_SHARED}) 321 | set(CMAKE_EXE_LINKER_FLAGS ${ANDROID_LINKER_FLAGS_EXE}) 322 | 323 | set(CMAKE_ASM_CREATE_SHARED_LIBRARY 324 | "ld -E -b -o ") 325 | 326 | set(CMAKE_C_CREATE_SHARED_LIBRARY 327 | " ${ANDROID_LDFLAGS_EXE} -o ${ANDROID_CRTEND_SO} ") 328 | set(CMAKE_CXX_CREATE_SHARED_LIBRARY 329 | " ${ANDROID_LDFLAGS_EXE} -o ${ANDROID_CRTEND_SO} ") 330 | set(CMAKE_C_CREATE_SHARED_MODULE 331 | " ${ANDROID_LDFLAGS_EXE} -o ${ANDROID_CRTEND_SO} ") 332 | set(CMAKE_CXX_CREATE_SHARED_MODULE 333 | " ${ANDROID_LDFLAGS_EXE} -o ${ANDROID_CRTEND_SO} ") 334 | 335 | set(CMAKE_C_LINK_EXECUTABLE 336 | " ${ANDROID_LDFLAGS_EXE} -o ${ANDROID_CRTEND_O} ") 337 | set(CMAKE_CXX_LINK_EXECUTABLE 338 | " ${ANDROID_LDFLAGS_EXE} -o ${ANDROID_CRTEND_O} ") 339 | 340 | #static lib 341 | set(CMAKE_C_ARCHIVE_CREATE " cqsD -format=gnu ") 342 | set(CMAKE_CXX_ARCHIVE_CREATE " cqsD -format=gnu ") 343 | 344 | # Export configurable variables for the try_compile() command. 345 | set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES 346 | PROJECT_DIR 347 | ANDROID_NDK 348 | ANDROID_LUNCH 349 | ANDROID_TARGET_ARCH 350 | ANDROID_TOOLCHAIN 351 | ANDROID_ARCH_VARIANT 352 | ANDROID_CPU_VARIANT 353 | ANDROID_ABI 354 | ANDROID_ARM_MODE 355 | CMAKE_C_LINK_EXECUTABLE 356 | CMAKE_CXX_LINK_EXECUTABLE 357 | # ANDROID_PLATFORM 358 | # ANDROID_STL 359 | # ANDROID_PIE 360 | # ANDROID_CPP_FEATURES 361 | # ANDROID_ALLOW_UNDEFINED_SYMBOLS 362 | # ANDROID_ARM_MODE 363 | # ANDROID_ARM_NEON 364 | # ANDROID_DISABLE_NO_EXECUTE 365 | # ANDROID_DISABLE_RELRO 366 | # ANDROID_DISABLE_FORMAT_STRING_CHECKS 367 | ANDROID_CCACHE 368 | ANDROID_SDK_VERSION 369 | ) -------------------------------------------------------------------------------- /CMakeModule/arm/armv7-a-neon.cmake: -------------------------------------------------------------------------------- 1 | 2 | set(ARCH_VARIANT_CLFAGS 3 | -march=armv7-a 4 | -mfloat-abi=softfp 5 | ) 6 | if(ANDROID_CPU_VARIANT STREQUAL "cortex-a7") 7 | list(APPEND ARCH_VARIANT_CLFAGS 8 | -mcpu=cortex-a7 9 | -mfpu=neon-vfpv4 10 | -D__ARM_FEATURE_LPAE=1 11 | ) 12 | elseif(ANDROID_CPU_VARIANT STREQUAL "cortex-a8") 13 | list(APPEND ARCH_VARIANT_CLFAGS 14 | -mcpu=cortex-a8 15 | ) 16 | elseif(ANDROID_CPU_VARIANT MATCHES "^(cortex-a15|krait)") 17 | list(APPEND ARCH_VARIANT_CLFAGS 18 | -mcpu=cortex-a15 19 | -mfpu=neon-vfpv4 20 | -D__ARM_FEATURE_LPAE=1 21 | ) 22 | elseif(ANDROID_CPU_VARIANT MATCHES "^(cortex-a53|cortex-a53.57|cortex-a55|cortex-a75|kryo)") 23 | list(APPEND ARCH_VARIANT_CLFAGS 24 | -mcpu=cortex-a53 25 | -mfpu=neon-fp-armv8 26 | -D__ARM_FEATURE_LPAE=1 27 | ) 28 | else() 29 | list(APPEND ARCH_VARIANT_CLFAGS 30 | -mcpu=cortex-a7 31 | -mfpu=neon 32 | ) 33 | endif() 34 | 35 | if(ANDROID_ARM_MODE STREQUAL thumb) 36 | list(APPEND ARCH_VARIANT_CLFAGS 37 | -mthumb -Os 38 | -fomit-frame-pointer 39 | ) 40 | else() 41 | list(APPEND ARCH_VARIANT_CLFAGS 42 | -marm 43 | -fstrict-aliasing 44 | ) 45 | endif() 46 | 47 | if(ANDROID_CPU_VARIANT STREQUAL "cortex-a8") 48 | set(ARCH_VARIANT_LDLFAGS -Wl,--fix-cortex-a8) 49 | else() 50 | set(ARCH_VARIANT_LDLFAGS -Wl,--no-fix-cortex-a8) 51 | endif() 52 | 53 | list(APPEND ARCH_VARIANT_LDLFAGS 54 | -Wl,--icf=safe 55 | -Wl,--hash-style=gnu 56 | -Wl,-m,armelf 57 | ) -------------------------------------------------------------------------------- /CMakeModule/arm/armv7-a.cmake: -------------------------------------------------------------------------------- 1 | set(ARCH_VARIANT_CLFAGS 2 | -march=armv7-a 3 | -mfloat-abi=softfp 4 | -mfpu=vfpv3-d16 5 | ) 6 | if(ANDROID_CPU_VARIANT STREQUAL "cortex-a7") 7 | list(APPEND ARCH_VARIANT_CLFAGS 8 | -mcpu=cortex-a7 9 | ) 10 | elseif(ANDROID_CPU_VARIANT STREQUAL "cortex-a8") 11 | list(APPEND ARCH_VARIANT_CLFAGS 12 | -mcpu=cortex-a8 13 | ) 14 | elseif(ANDROID_CPU_VARIANT MATCHES "^(cortex-a15|krait)") 15 | list(APPEND ARCH_VARIANT_CLFAGS 16 | -mcpu=cortex-a15 17 | ) 18 | elseif(ANDROID_CPU_VARIANT MATCHES "^(cortex-a53|cortex-a53.57|cortex-a55|cortex-a75|kryo)") 19 | list(APPEND ARCH_VARIANT_CLFAGS 20 | -mcpu=cortex-a53 21 | ) 22 | else() 23 | list(APPEND ARCH_VARIANT_CLFAGS 24 | -mcpu=cortex-a7 25 | ) 26 | endif() 27 | 28 | if(ANDROID_ARM_MODE STREQUAL thumb) 29 | list(APPEND ARCH_VARIANT_CLFAGS 30 | -mthumb -Os 31 | -fomit-frame-pointer 32 | ) 33 | else() 34 | list(APPEND ARCH_VARIANT_CLFAGS 35 | -marm 36 | -fstrict-aliasing 37 | ) 38 | endif() 39 | 40 | if(ANDROID_CPU_VARIANT STREQUAL "cortex-a8") 41 | set(ARCH_VARIANT_LDLFAGS -Wl,--fix-cortex-a8) 42 | else() 43 | set(ARCH_VARIANT_LDLFAGS -Wl,--no-fix-cortex-a8) 44 | endif() 45 | 46 | list(APPEND ARCH_VARIANT_LDLFAGS 47 | -Wl,--icf=safe 48 | -Wl,--hash-style=gnu 49 | -Wl,-m,armelf 50 | ) -------------------------------------------------------------------------------- /CMakeModule/arm64/armv8-2a.cmake: -------------------------------------------------------------------------------- 1 | set(ARCH_VARIANT_CLFAGS -march=armv8.2a) 2 | set(ARCH_VARIANT_LDLFAGS 3 | -Wl,-m,aarch64_elf64_le_vec 4 | -Wl,--hash-style=gnu 5 | -fuse-ld=gold 6 | -Wl,--icf=safe 7 | ) 8 | if(ANDROID_CPU_VARIANT MATCHES "^(cortex-a53|cortex-a55|cortex-a75)") 9 | list(APPEND ARCH_VARIANT_CLFAGS -mcpu=cortex-a53) 10 | elseif(ANDROID_CPU_VARIANT MATCHES "kryo") 11 | list(APPEND ARCH_VARIANT_CLFAGS -mcpu=cortex-a57) 12 | elseif(ANDROID_CPU_VARIANT MATCHES "exynos-m1") 13 | list(APPEND ARCH_VARIANT_CLFAGS -mcpu=exynos-m1) 14 | elseif(ANDROID_CPU_VARIANT MATCHES "exynos-m2") 15 | list(APPEND ARCH_VARIANT_CLFAGS -mcpu=exynos-m2) 16 | endif() 17 | 18 | list(APPEND ARCH_VARIANT_LDLFAGS -Wl,--fix-cortex-a53-843419) -------------------------------------------------------------------------------- /CMakeModule/arm64/armv8-a.cmake: -------------------------------------------------------------------------------- 1 | set(ARCH_VARIANT_CLFAGS -march=armv8-a) 2 | set(ARCH_VARIANT_LDLFAGS 3 | -Wl,-m,aarch64_elf64_le_vec 4 | -Wl,--hash-style=gnu 5 | -fuse-ld=gold 6 | -Wl,--icf=safe 7 | ) 8 | if(ANDROID_CPU_VARIANT MATCHES "^(cortex-a53|cortex-a55|cortex-a75)") 9 | list(APPEND ARCH_VARIANT_CLFAGS -mcpu=cortex-a53) 10 | elseif(ANDROID_CPU_VARIANT MATCHES "kryo") 11 | list(APPEND ARCH_VARIANT_CLFAGS -mcpu=cortex-a57) 12 | elseif(ANDROID_CPU_VARIANT MATCHES "exynos-m1") 13 | list(APPEND ARCH_VARIANT_CLFAGS -mcpu=exynos-m1) 14 | elseif(ANDROID_CPU_VARIANT MATCHES "exynos-m2") 15 | list(APPEND ARCH_VARIANT_CLFAGS -mcpu=exynos-m2) 16 | else() 17 | list(APPEND ARCH_VARIANT_CLFAGS -mcpu=cortex-a53) 18 | endif() 19 | 20 | list(APPEND ARCH_VARIANT_LDLFAGS -Wl,--fix-cortex-a53-843419) -------------------------------------------------------------------------------- /CMakeModule/exe32.cmake: -------------------------------------------------------------------------------- 1 | # ###########################arm-c/cpp 2 | # -I 3 | set(PRIVATE_C_INCLUDES 4 | device/htc/m8-common/include 5 | android-test/test 6 | /Misc/CyanogenMod/out/target/product/m8/obj/EXECUTABLES/test_intermediates 7 | /Misc/CyanogenMod/out/target/product/m8/gen/EXECUTABLES/test_intermediates 8 | libnativehelper/include/nativehelper) 9 | # $(shell cat /Misc/CyanogenMod/out/target/product/m8/obj/EXECUTABLES/test_intermediates/import_include) 10 | 11 | # system filter-out PRIVATE_C_INCLUDES 12 | set(PRIVATE_TARGET_PROJECT_INCLUDES 13 | system/core/include 14 | system/media/audio/include 15 | hardware/libhardware/include 16 | hardware/libhardware_legacy/include 17 | libnativehelper/include 18 | frameworks/native/include 19 | frameworks/native/opengl/include 20 | frameworks/av/include 21 | frameworks/base/include 22 | hardware/ril-caf/include 23 | /Misc/CyanogenMod/out/target/product/m8/obj/include) 24 | 25 | set(PRIVATE_TARGET_C_INCLUDES 26 | bionic/libc/arch-arm/include 27 | bionic/libc/include 28 | bionic/libc/kernel/uapi 29 | bionic/libc/kernel/common 30 | bionic/libc/kernel/uapi/asm-arm 31 | bionic/libm/include 32 | bionic/libm/include/arm) 33 | 34 | # flag 35 | set(PRIVATE_TARGET_GLOBAL_CFLAGS 36 | -fno-exceptions 37 | -Wno-multichar 38 | -msoft-float 39 | -ffunction-sections 40 | -fdata-sections 41 | -funwind-tables 42 | -fstack-protector-strong 43 | -Wa,--noexecstack 44 | -Werror=format-security 45 | -D_FORTIFY_SOURCE=2 46 | -fno-short-enums 47 | -no-canonical-prefixes 48 | -mcpu=cortex-a15 49 | -mfpu=neon-vfpv4 50 | -D__ARM_FEATURE_LPAE=1 51 | -mfloat-abi=softfp 52 | -DQCOM_HARDWARE -DQCOM_BSP -DQTI_BSP -DANDROID 53 | -fmessage-length=0 54 | -W -Wall -Wno-unused -Winit-self -Wpointer-arith -Werror=return-type 55 | -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point 56 | -Werror=date-time -DNDEBUG -g -Wstrict-aliasing=2 57 | -DNDEBUG -UDEBUG -D__compiler_offsetof=__builtin_offsetof 58 | -Werror=int-conversion -Wno-reserved-id-macro -Wno-format-pedantic 59 | -Wno-unused-command-line-argument 60 | -fcolor-diagnostics -nostdlibinc 61 | -mcpu=krait -mfpu=neon-vfpv4 62 | -target arm-linux-androideabi 63 | -target arm-linux-androideabi 64 | -Bprebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/arm-linux-androideabi/bin) 65 | 66 | #cpp 67 | set(PRIVATE_TARGET_GLOBAL_CPPFLAGS 68 | -fvisibility-inlines-hidden 69 | -DQCOM_HARDWARE -DQCOM_BSP -DQTI_BSP 70 | -Wsign-promo -Wno-inconsistent-missing-override 71 | -nostdlibinc -target arm-linux-androideabi) 72 | #arm 73 | set(PRIVATE_ARM_CFLAGS 74 | -mthumb -Os -fomit-frame-pointer 75 | -fno-strict-aliasing) 76 | # cpp 77 | set(PRIVATE_RTTI_FLAG -fno-rtti) 78 | 79 | set(PRIVATE_CFLAGS -fpie -D_USING_LIBCXX) 80 | # c 81 | set(PRIVATE_TARGET_GLOBAL_CONLYFLAGS -std=gnu99) 82 | # cpp 83 | set(PRIVATE_CPPFLAGS -std=gnu++14) 84 | 85 | set(PRIVATE_DEBUG_CFLAGS ) 86 | set(PRIVATE_CFLAGS_NO_OVERRIDE 87 | -Werror=int-to-pointer-cast 88 | -Werror=pointer-to-int-cast 89 | -Werror=address-of-temporary 90 | -Werror=null-dereference 91 | -Werror=return-type) 92 | #cpp 93 | set(PRIVATE_CPPFLAGS_NO_OVERRIDE ) 94 | 95 | # link 96 | set(PRIVATE_LINKER 97 | /system/bin/linker) 98 | set(PRIVATE_TARGET_GLOBAL_LD_DIRS 99 | -L/Misc/CyanogenMod/out/target/product/m8/obj/lib) 100 | set(PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES 101 | /Misc/CyanogenMod/out/target/product/m8/obj/lib) 102 | set(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O 103 | /Misc/CyanogenMod/out/target/product/m8/obj/lib/crtbegin_dynamic.o) 104 | set(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES ) 105 | set(PRIVATE_GROUP_STATIC_LIBRARIES ) 106 | set(PRIVATE_ALL_STATIC_LIBRARIES 107 | /Misc/CyanogenMod/out/target/product/m8/obj/STATIC_LIBRARIES/libunwind_llvm_intermediates/libunwind_llvm.a 108 | /Misc/CyanogenMod/out/target/product/m8/obj/STATIC_LIBRARIES/libcompiler_rt-extras_intermediates/libcompiler_rt-extras.a) 109 | set(PRIVATE_GROUP_STATIC_LIBRARIES ) 110 | set(NATIVE_COVERAGE ) 111 | set(PRIVATE_TARGET_COVERAGE_LIB 112 | prebuilts/clang/host/linux-x86/clang-2690385/bin/../lib64/clang/3.8/lib/linux//libclang_rt.profile-arm-android.a) 113 | set(PRIVATE_TARGET_LIBATOMIC 114 | prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/lib/libatomic.a) 115 | set(PRIVATE_TARGET_LIBGCC 116 | prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/../lib/gcc/arm-linux-androideabi/4.9/libgcc.a) 117 | set(PRIVATE_ALL_SHARED_LIBRARIES 118 | /Misc/CyanogenMod/out/target/product/m8/obj/lib/libc++.so 119 | /Misc/CyanogenMod/out/target/product/m8/obj/lib/libdl.so 120 | /Misc/CyanogenMod/out/target/product/m8/obj/lib/libc.so 121 | /Misc/CyanogenMod/out/target/product/m8/obj/lib/libm.so) 122 | set(PRIVATE_TARGET_GLOBAL_LDFLAGS 123 | -Wl,-z,noexecstack 124 | -Wl,-z,relro 125 | -Wl,-z,now 126 | -Wl,--build-id=md5 127 | -Wl,--warn-shared-textrel 128 | -Wl,--fatal-warnings 129 | -Wl,--icf=safe 130 | -Wl,--hash-style=gnu 131 | -Wl,--no-undefined-version 132 | -Wl,--no-fix-cortex-a8 133 | -target arm-linux-androideabi 134 | -Bprebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/arm-linux-androideabi/bin) 135 | set(PRIVATE_LDFLAGS 136 | -Wl,--exclude-libs,libunwind_llvm.a -Wl,--no-undefined) 137 | set(PRIVATE_TARGET_CRTEND_O 138 | /Misc/CyanogenMod/out/target/product/m8/obj/lib/crtend_android.o) 139 | set(PRIVATE_LDLIBS ) -------------------------------------------------------------------------------- /CMakeModule/exe64.cmake: -------------------------------------------------------------------------------- 1 | # ###########################arm64-c/cpp 2 | # -I 3 | set(PRIVATE_C_INCLUDES 4 | device/htc/m8-common/include 5 | android-test/test 6 | /Misc/CyanogenMod/out/target/product/m8/obj/EXECUTABLES/test_intermediates 7 | /Misc/CyanogenMod/out/target/product/m8/gen/EXECUTABLES/test_intermediates 8 | libnativehelper/include/nativehelper) 9 | # $(shell cat /Misc/CyanogenMod/out/target/product/m8/obj/EXECUTABLES/test_intermediates/import_include) 10 | 11 | # system filter-out PRIVATE_C_INCLUDES 12 | set(PRIVATE_TARGET_PROJECT_INCLUDES 13 | system/core/include 14 | system/media/audio/include 15 | hardware/libhardware/include 16 | hardware/libhardware_legacy/include 17 | libnativehelper/include 18 | frameworks/native/include 19 | frameworks/native/opengl/include 20 | frameworks/av/include 21 | frameworks/base/include 22 | hardware/ril-caf/include 23 | /Misc/CyanogenMod/out/target/product/m8/obj/include) 24 | 25 | set(PRIVATE_TARGET_C_INCLUDES 26 | bionic/libc/arch-arm/include 27 | bionic/libc/include 28 | bionic/libc/kernel/uapi 29 | bionic/libc/kernel/common 30 | bionic/libc/kernel/uapi/asm-arm 31 | bionic/libm/include 32 | bionic/libm/include/arm) 33 | 34 | set(PRIVATE_TARGET_GLOBAL_CFLAGS= 35 | -fno-exceptions 36 | -Wno-multichar 37 | -fno-strict-aliasing 38 | -fstack-protector-strong 39 | -ffunction-sections 40 | -fdata-sections 41 | -funwind-tables 42 | -Wa,--noexecstack 43 | -Werror=format-security 44 | -D_FORTIFY_SOURCE=2 45 | -fno-short-enums 46 | -no-canonical-prefixes 47 | -mcpu=cortex-a53 48 | -Werror=pointer-to-int-cast 49 | -Werror=int-to-pointer-cast 50 | -Werror=implicit-function-declaration 51 | -DQCOM_HARDWARE -DQCOM_BSP -DQTI_BSP -DANDROID 52 | -fmessage-length=0 -W -Wall -Wno-unused -Winit-self -Wpointer-arith -Werror=return-type 53 | -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point 54 | -Werror=date-time -DNDEBUG -O2 -g -Wstrict-aliasing=2 55 | -DNDEBUG -UDEBUG -D__compiler_offsetof=__builtin_offsetof 56 | -Werror=int-conversion -Wno-reserved-id-macro -Wno-format-pedantic 57 | -Wno-unused-command-line-argument 58 | -fcolor-diagnostics -nostdlibinc 59 | -target aarch64-linux-android 60 | -Bprebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin) 61 | 62 | set(PRIVATE_TARGET_GLOBAL_CPPFLAGS 63 | -fvisibility-inlines-hidden 64 | -DQCOM_HARDWARE -DQCOM_BSP -DQTI_BSP 65 | -Wsign-promo -Wno-inconsistent-missing-override 66 | -nostdlibinc) 67 | 68 | set(PRIVATE_ARM_CFLAGS ) 69 | 70 | #cpp 71 | set(PRIVATE_RTTI_FLAG -fno-rtti) 72 | 73 | set(PRIVATE_CFLAGS -fpie -D_USING_LIBCXX) 74 | #c 75 | set(PRIVATE_TARGET_GLOBAL_CONLYFLAGS -std=gnu99) 76 | 77 | set(PRIVATE_DEBUG_CFLAGS ) 78 | set(PRIVATE_CFLAGS_NO_OVERRIDE 79 | -Werror=int-to-pointer-cast 80 | -Werror=pointer-to-int-cast 81 | -Werror=address-of-temporary 82 | -Werror=null-dereference 83 | -Werror=return-type) 84 | 85 | #link 86 | set(PRIVATE_LINKER 87 | /system/bin/linker64) 88 | set(PRIVATE_TARGET_GLOBAL_LD_DIRS 89 | -L/Misc/CyanogenMod/out/target/product/m8/obj/lib) 90 | set(PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES 91 | /Misc/CyanogenMod/out/target/product/m8/obj/lib) 92 | set(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O 93 | /Misc/CyanogenMod/out/target/product/m8/obj/lib/crtbegin_dynamic.o) 94 | set(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES ) 95 | set(PRIVATE_GROUP_STATIC_LIBRARIES ) 96 | set(PRIVATE_ALL_STATIC_LIBRARIES 97 | /Misc/CyanogenMod/out/target/product/m8/obj/STATIC_LIBRARIES/libcompiler_rt-extras_intermediates/libcompiler_rt-extras.a) 98 | set(PRIVATE_GROUP_STATIC_LIBRARIES ) 99 | set(NATIVE_COVERAGE ) 100 | set(PRIVATE_TARGET_COVERAGE_LIB 101 | prebuilts/clang/host/linux-x86/clang-2690385/bin/../lib64/clang/3.8/lib/linux//libclang_rt.profile-arm-android.a) 102 | set(PRIVATE_TARGET_LIBATOMIC 103 | prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/lib/libatomic.a) 104 | set(PRIVATE_TARGET_LIBGCC 105 | prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/../lib/gcc/arm-linux-androideabi/4.9/libgcc.a) 106 | set(PRIVATE_ALL_SHARED_LIBRARIES 107 | /Misc/CyanogenMod/out/target/product/m8/obj/lib/libc++.so 108 | /Misc/CyanogenMod/out/target/product/m8/obj/lib/libdl.so 109 | /Misc/CyanogenMod/out/target/product/m8/obj/lib/libc.so 110 | /Misc/CyanogenMod/out/target/product/m8/obj/lib/libm.so) 111 | set(PRIVATE_TARGET_GLOBAL_LDFLAGS 112 | -Wl,-z,noexecstack 113 | -Wl,-z,relro 114 | -Wl,-z,now 115 | -Wl,--build-id=md5 116 | -Wl,--warn-shared-textrel 117 | -Wl,--fatal-warnings 118 | -Wl,-maarch64linux 119 | -Wl,--hash-style=gnu 120 | -Wl,--fix-cortex-a53-843419 121 | -fuse-ld=gold 122 | -Wl,--icf=safe 123 | -Wl,--no-undefined-version 124 | -Wl,--allow-shlib-undefined 125 | -target aarch64-linux-android 126 | -Bprebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin) 127 | set(PRIVATE_LDFLAGS 128 | -Wl,--no-undefined) 129 | set(PRIVATE_TARGET_CRTEND_O 130 | /Misc/CyanogenMod/out/target/product/m8/obj/lib/crtend_android.o) 131 | set(PRIVATE_LDLIBS ) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # android-cmake-project 2 | 3 | [中文](https://github.com/Ahren-Li/android-cmake-project/blob/automatic/README_zh-CN.md) 4 | 5 | ## Background 6 | To import C/C++ code for Android Native using Clion, implement code hinting, custom module compilation. 7 | 8 | Currently supports. 9 | * Automatically find the path where `Android.mk`, `Android.bp` of the configuration module is located. 10 | * Automatically parse `Android.mk`, `Android.bp` under the module path. 11 | * Automatically parse the source and header files of the module. 12 | * Automatically parse module dependencies, and dependent header paths. 13 | * Automatically parse some (some syntax complex can't be parsed) C/C++ Flags. 14 | * Generate **rough** CMakeList.txt via `Android.mk`, `Android.bp`. 15 | * Configured global Clang environment to support cross-compilation of custom C/C++ projects on CLion (need to write CMakeList.txt by yourself). 16 | 17 | Known issues: 18 | * Complex syntax cannot be parsed. 19 | * Android HIDL module does not parse properly. 20 | * Cross-compilation may not work properly. 21 | 22 | The above problem may have to wait for my new project `AndroidCMakeSoong` to be solved. 23 | For now it is still up to the point where it works. 24 | * Most of the modules can parse the source files normally, and the header files can be parsed normally in most cases, so it is helpful for code hinting. 25 | * The dependency part of the header file can also be parsed normally, so the hints for other modules can also be done, the most typical ones are `libutils` and `libcutils`. 26 | * You can add your own C/C++ projects and easily configure dependencies to achieve code hinting accessibility. 27 | * You can use CLion to compile your own C/C++ projects and then PUSH them to your own device for testing, no need to use `mm` anymore. 28 | 29 | For pure use the CMake language has been very good, the project I have been using at work for two years and it is still good to use. 30 | Here are two screenshots. 31 | 1. code jumping. 32 | ![pic](https://www.lili.kim/2018/11/24/android/Use%20CLion%20import%20Android%20code/test.png) 33 | 2. Successful compilation of libcutils.so. 34 | ![2](https://www.lili.kim/2018/11/24/android/Use%20CLion%20import%20Android%20code/test2.png) 35 | 36 | ## Install 37 | ```shell 38 | git clone https://github.com/Ahren-Li/android-cmake-project.git 39 | ``` 40 | ## Dependency 41 | - Complete compiled Android source code. 42 | - For Linux: ${your source path}/prebuilts/clang/host/linux-x86/clang-xxxxxx, determine which version of Clang you are using 43 | - For Windows: requires Android NDK R21+ 44 | 45 | ## Usage 46 | ```shell 47 | cp -r $(path)/android-cmake-project/.idea $(android_source_tree)/ 48 | ln -s $(path)/android-cmake-project/CMakeModule $(android_source_tree)/CMakeModule 49 | ln -s $(path)/android-cmake-project/CMakeLists.txt $(android_source_tree)/CMakeLists.txt 50 | ``` 51 | ### .idea Folders 52 | I pre-configured part of the ignore folder for Clion and they are defined in .idea/misc.xml, which improves the loading speed. 53 | 54 | ### Configure your project environment 55 | Environment configuration path (2 options): 56 | 1. android-cmake-project/CMakeModule/android.env.cmake 57 | 2. touch $(android_source_tree)/android.env.cmake 58 | 59 | | CMake Property | Value | Description | 60 | | ----------------------- | --------- | ----------- | 61 | | TARGET_BOARD_HARDWARE | string | Get the value via `get_build_var` | 62 | | ANDROID_LUNCH | string | Target for `lunch`, no `-user/-userdebug` | 63 | | ANDROID_SDK_VERSION | string | 19-29... | 64 | | ANDROID_TARGET_ARCH | arm/arm64 | The output of `TARGET_ARCH` after lunch | 65 | | ANDROID_ARCH_VARIANT | string | The output of `TARGET_ARCH_VARIANT` after lunch | 66 | | ANDROID_CPU_VARIANT | string | The output of `TARGET_CPU_VARIANT` after lunch | 67 | | ANDROID_ABI | arm64-v8a/armeabi-v7a | Configure CMake to compile 64/32 executables | 68 | | ANDROID_NDK | path | android ndk path | 69 | | ANDROID_CLANG_VERSION | string | clang-4691093(Android p),You can configure it according to your own source code | 70 | 71 | ### Configure project modules 72 | Module configuration path 73 | 1. android-cmake-project/CMakeModule/android.module.cmake 74 | 75 | ```cmake 76 | # Load the dynamic library libsurfaceflinger and its dependencies 77 | parseAndroidMK(libsurfaceflinger ${MK_SHARED}) 78 | # Load the executable init and its dependencies 79 | parseAndroidMK(init ${MK_EXECAB}) 80 | ``` 81 | 82 | Explanation of the second parameter of `parseAndroidMK` 83 | | CMake Property | Description | 84 | | --------------- | ----------- | 85 | | MK_EXECAB | Name of dynamic executable module in Android MK/BP | 86 | | MK_SHARED | Name of dynamic library module in Android MK/BP | 87 | | MK_STATIC | Name of static library module in Android MK/BP | 88 | 89 | ### Configure your custom C/C++ modules 90 | 1. android-cmake-project/CMakeLists.txt has pre-written loading code. 91 | ```cmake 92 | if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/android-test/CMakeLists.txt) 93 | add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/android-test) 94 | endif() 95 | ``` 96 | 2. Create your own `android-test` folder 97 | ```shell 98 | mkdir $(android_source_tree)/android-test 99 | ``` 100 | 3. Refer to this [CMakeList.txt](https://github.com/Ahren-Li/android-cmake-project/blob/automatic/android-test/CMakeLists.txt) to write your own module configuration. 101 | 102 | ### Test Environment 103 | - Android N/O/P/Q source tree 104 | - Ubuntu 16.04/18.04/20.04 105 | - Windows 10 && Android NDK R21 106 | - Clion 2019.3.2 107 | 108 | ## Related Efforts 109 | [AndroidNativeDebug](https://github.com/Ahren-Li/AndroidNativeDebug) 110 | * Clion plugin: Debugging Native programs with Clion and LLDB. 111 | [AndroidCMakeSoong(ing)]() 112 | 113 | ## Maintainers 114 | Ahren Li(liliorg@163.com) 115 | 116 | ## Contributing 117 | Github Push Request. 118 | 119 | ## License 120 | 121 | Copyright [2021] [liliorg@163.com] 122 | 123 | Licensed under the Apache License, Version 2.0 (the "License"); 124 | you may not use this file except in compliance with the License. 125 | You may obtain a copy of the License at 126 | 127 | http://www.apache.org/licenses/LICENSE-2.0 128 | 129 | Unless required by applicable law or agreed to in writing, software 130 | distributed under the License is distributed on an "AS IS" BASIS, 131 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 132 | See the License for the specific language governing permissions and 133 | limitations under the License. -------------------------------------------------------------------------------- /README_zh-CN.md: -------------------------------------------------------------------------------- 1 | # android-cmake-project 2 | 3 | ## 项目背景 4 | 为了使用Clion导入Android Native的C/C++代码,实现代码提示,自定义模块编译。 5 | 6 | 目前支持: 7 | * 自动寻找配置模块的`Android.mk`,`Android.bp`所在路径。 8 | * 自动解析模块路径下的`Android.mk`,`Android.bp`。 9 | * 自动解析模块的源文件和头文件。 10 | * 自动解析模块的依赖,以及依赖的头文件路径。 11 | * 自动解析部分(有些语法复杂的无法解析)C/C++ Flags。 12 | * 通过`Android.mk`,`Android.bp`生成**粗略**的CMakeList.txt。 13 | * 配置了全局的Clang环境,支持在CLion上对自定义C/C++项目进行交叉编译(需要自行编写CMakeList.txt)。 14 | 15 | 已知问题: 16 | * 复杂语法无法解析。 17 | * Android HIDL模块无法正常解析。 18 | * 交叉编译可能无法正常工作。 19 | 20 | 上面的问题可能需要等待我的新项目`AndroidCMakeSoong`才能解决。 21 | 目前还是达到了可以使用的程度: 22 | * 大部分模块能正常解析源文件,头文件大概率也能正常解析,所以对于代码提示很有帮助。 23 | * 依赖部分的头文件也能正常解析,所以对于其他模块的提示也是能做到,最典型的比如`libutils`,`libcutils`。 24 | * 可以自己添加自己C/C++项目,并且可以很容易的配置依赖,达到代码提示无障碍的效果。 25 | * 可以使用CLion编译自己的C/C++项目,再PUSH到自己的设备测试,无需再使用`mm`。 26 | 27 | 对于纯粹的使用CMake语言已经非常不错了,该项目我已经在工作中使用了两年,使用起来还是不错的。 28 | 下面是两个截图: 29 | 1. 代码跳转。 30 | ![pic](https://www.lili.kim/2018/11/24/android/Use%20CLion%20import%20Android%20code/test.png) 31 | 2. libcutils.so 的成功编译。 32 | ![2](https://www.lili.kim/2018/11/24/android/Use%20CLion%20import%20Android%20code/test2.png) 33 | 34 | ## 安装 35 | ```shell 36 | git clone https://github.com/Ahren-Li/android-cmake-project.git 37 | ``` 38 | ## 依赖 39 | - 完整编译完成的Android源码 40 | - 对于Linux: ${你的源码路径}/prebuilts/clang/host/linux-x86/clang-xxxxxx,确定你使用Clang的版本 41 | - 对于Windows: 需要Android NDK R12+ 42 | 43 | ## 使用 44 | ```shell 45 | cp -r $(path)/android-cmake-project/.idea $(android_source_tree)/ 46 | ln -s $(path)/android-cmake-project/CMakeModule $(android_source_tree)/CMakeModule 47 | ln -s $(path)/android-cmake-project/CMakeLists.txt $(android_source_tree)/CMakeLists.txt 48 | ``` 49 | ### .idea文件夹 50 | 我预先为Clion配置好了一部分忽略文件夹,它们定义在.idea/misc.xml,这样可以提高加载速度。 51 | 52 | ### 配置你的项目环境 53 | 环境配置路径(2选1): 54 | 1. android-cmake-project/CMakeModule/android.env.cmake 55 | 2. 新建$(android_source_tree)/android.env.cmake 56 | 57 | | CMake变量 | 值 | description | 58 | | ----------------------- | --------- | ----------- | 59 | | TARGET_BOARD_HARDWARE | 字符串 | 通过`get_build_var`获取值 | 60 | | ANDROID_LUNCH | 字符串 | `lunch`的target,不需要-user/-userdebug | 61 | | ANDROID_SDK_VERSION | 字符串 | 19-29... | 62 | | ANDROID_TARGET_ARCH | arm/arm64 | lunch后输出的`TARGET_ARCH` | 63 | | ANDROID_ARCH_VARIANT | 字符串 | lunch后输出的`TARGET_ARCH_VARIANT` | 64 | | ANDROID_CPU_VARIANT | 字符串 | lunch后输出的`TARGET_CPU_VARIANT` | 65 | | ANDROID_ABI | arm64-v8a/armeabi-v7a | 配置CMake编译64/32可执行程序 | 66 | | ANDROID_NDK | 路径 | android ndk path | 67 | | ANDROID_CLANG_VERSION | 字符串 | clang-4691093(Android p),具体可以根据自己的源码配置 | 68 | 69 | ### 配置项目模块 70 | 模块配置路径 71 | 1. android-cmake-project/CMakeModule/android.module.cmake 72 | 73 | ```cmake 74 | # 加载动态库libsurfaceflinger及其依赖 75 | parseAndroidMK(libsurfaceflinger ${MK_SHARED}) 76 | # 加载可执行程序init及其依赖 77 | parseAndroidMK(init ${MK_EXECAB}) 78 | ``` 79 | 80 | `parseAndroidMK`第二个参数的解释 81 | | CMake变量 | 解释 | 82 | | --------------- | ----------- | 83 | | MK_EXECAB | Android MK/BP 中可执行模块的名字 | 84 | | MK_SHARED | Android MK/BP 中动态库模块的名字 | 85 | | MK_STATIC | Android MK/BP 中静态库模块的名字 | 86 | 87 | ### 配置你自定义C/C++ 模块 88 | 1. android-cmake-project/CMakeLists.txt 已经预先写好了加载代码。 89 | ```cmake 90 | if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/android-test/CMakeLists.txt) 91 | add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/android-test) 92 | endif() 93 | ``` 94 | 2. 新建自己的`android-test`文件夹 95 | ```shell 96 | mkdir $(android_source_tree)/android-test 97 | ``` 98 | 3. 参考这个[CMakeList.txt](https://github.com/Ahren-Li/android-cmake-project/blob/automatic/android-test/CMakeLists.txt)写自己的模块配置。 99 | 100 | ### 测试环境 101 | - Android N/O/P/Q source tree 102 | - Ubuntu 16.04/18.04/20.04 103 | - Windows 10 && Android NDK R21 104 | - Clion 2019.3.2 105 | 106 | ## 相关项目 107 | [AndroidNativeDebug](https://github.com/Ahren-Li/AndroidNativeDebug) 108 | * 使用Clion和LLDB调试Native程序 109 | [AndroidCMakeSoong(进行中)]() 110 | 111 | ## 主要项目负责人 112 | Ahren Li(liliorg@163.com) 113 | 114 | ## 参与贡献方式 115 | github push request. 116 | 117 | ## 开源协议 118 | 119 | Copyright [2021] [liliorg@163.com] 120 | 121 | Licensed under the Apache License, Version 2.0 (the "License"); 122 | you may not use this file except in compliance with the License. 123 | You may obtain a copy of the License at 124 | 125 | http://www.apache.org/licenses/LICENSE-2.0 126 | 127 | Unless required by applicable law or agreed to in writing, software 128 | distributed under the License is distributed on an "AS IS" BASIS, 129 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130 | See the License for the specific language governing permissions and 131 | limitations under the License. -------------------------------------------------------------------------------- /android-test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_executable(test-exec main.c) 3 | 4 | add_library(libtest STATIC test.c) 5 | 6 | target_include_directories(test-exec PUBLIC 7 | include 8 | ${PROJECT_DIR}/external/libpng 9 | ${PROJECT_DIR}/external/libusb/include 10 | ${PROJECT_DIR}/external/zlib 11 | ${PROJECT_DIR}/external/libnl/include 12 | ${PROJECT_DIR}/bionic/libc/include 13 | ${PROJECT_DIR}/system/core/libcutils/include 14 | ) 15 | 16 | target_include_directories(libtest PUBLIC include) 17 | 18 | # aarch64-linux-android-4.9 根据自己的源码配置 19 | # aarch64-linux-android-4.9 Configure according to your own source code 20 | target_compile_options(test-exec PRIVATE 21 | -target aarch64-linux-android 22 | -B${PROJECT_DIR}/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin 23 | ) 24 | 25 | target_link_options(test-exec PRIVATE 26 | -target aarch64-linux-android 27 | -B${PROJECT_DIR}/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin 28 | ) 29 | 30 | target_compile_options(libtinyalsa-vamrs PRIVATE 31 | -target aarch64-linux-android 32 | -B${PROJECT_DIR}/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin 33 | ) 34 | 35 | target_link_options(libtinyalsa-vamrs PRIVATE 36 | -target aarch64-linux-android 37 | -B${PROJECT_DIR}/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin 38 | ) 39 | 40 | target_link_libraries( test-exec PRIVATE libtest) 41 | 42 | target_link_libraries(test-exec PRIVATE 43 | ${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}/obj/STATIC_LIBRARIES/libminuitwrp-vamrs_intermediates/libminuitwrp-vamrs.a 44 | ${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}/obj/STATIC_LIBRARIES/libpixelflinger-vamrs_intermediates/libpixelflinger-vamrs.a 45 | ${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}/obj/STATIC_LIBRARIES/libft2-vamrs_intermediates/libft2-vamrs.a 46 | ${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}/obj/SHARED_LIBRARIES/libnl_intermediates/libnl.so 47 | ${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}/obj/SHARED_LIBRARIES/libpng_intermediates/libpng.so 48 | ${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}/obj/SHARED_LIBRARIES/libusb_intermediates/libusb.so 49 | ${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}/obj/SHARED_LIBRARIES/liblog_intermediates/liblog.so 50 | ${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}/obj/SHARED_LIBRARIES/liblzma_intermediates/liblzma.so 51 | ${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}/obj/SHARED_LIBRARIES/libutils_intermediates/libutils.so 52 | ${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}/obj/SHARED_LIBRARIES/libcutils_intermediates/libcutils.so 53 | ${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}/obj/SHARED_LIBRARIES/libz_intermediates/libz.so 54 | ${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}/obj/SHARED_LIBRARIES/libc++_intermediates/libc++.so 55 | ${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}/obj/SHARED_LIBRARIES/libdl_intermediates/libdl.so 56 | ${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}/obj/SHARED_LIBRARIES/libc_intermediates/libc.so 57 | ${PROJECT_DIR}/out/target/product/${ANDROID_LUNCH}/obj/SHARED_LIBRARIES/libm_intermediates/libm.so 58 | ) -------------------------------------------------------------------------------- /android-test/include/test.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ahren-Li/android-cmake-project/b3297ea3a51da3130caf29cd4892041bbec20a64/android-test/include/test.h -------------------------------------------------------------------------------- /android-test/main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ahren-Li/android-cmake-project/b3297ea3a51da3130caf29cd4892041bbec20a64/android-test/main.c -------------------------------------------------------------------------------- /android-test/test.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ahren-Li/android-cmake-project/b3297ea3a51da3130caf29cd4892041bbec20a64/android-test/test.c --------------------------------------------------------------------------------