CMake 安卓NDK編譯常用語法

2021-10-04 17:39:45 字數 1981 閱讀 8036

鏈結選項

鏈結第三方庫

匯出有符號和無符號庫

cmake_minimum_required(version 3.5)

project(my_project_name)

###常用的內建變數

cmake_c_flags

cmake_cxx_flags

cmake_shared_linker_flags

project_source_dircmake_cxx_compiler_id

android_abi

if("$" strequal "armeabi-v7a" or "$" strequal "armeabi-v7a with neon")

set(android_stl "gnustl_shared")

set(android_toolchain "gcc")

set(strip_path "arm-linux-androideabi")

message("current abi is: $")

elseif ("$" strequal "arm64-v8a")

set(android_stl "c++_shared")

set(android_toolchain "clang")

set(strip_path "aarch64-linux-android")

message("current abi is: $")

else()

message(fatal_error "$ is no support")

endif()

# 設定cmake編譯庫輸出的位置

set(cmake_library_output_directory $/libs/$)

# 設定標頭檔案搜尋路徑

include_directories(

...)# 設定需要編譯的原始檔

file(

glob source_files

...)# 設定庫檔案搜尋路徑

link_directories(

...)

add_library($ shared $)
編譯選項

cmake_ccxx_flags_releasecmake_ccxx_flags_release

-fno-exceptions

-fpic

-o3

-ffunction-sections -fdata-sections

-std=c++11

鏈結選項

cmake_shared_linker_flags

-wl,--gc-sections

-dead-strip

# 設定需要鏈結的庫檔案

target_link_libraries($

...

add_custom_command(target $

post_build

command cp $/libs/$/libmbccore.so $/obj/$/

command $/toolchains/$-4.9/prebuilt/darwin-x86_64/bin/$-strip --strip-all $/libs/$/libmbccore.so

command ditto 其他第三方.so庫 $/libs/$

)

CMake常用語法

cmake 最低版本號要求 cmake minimum required version 2.8 專案資訊 project demo 查詢當前目錄下的所有原始檔,並將名稱儲存到 dir srcs 變數 aux source directory dir srcs 新增標頭檔案搜尋目錄 project ...

cmake常用語法介紹

使用cmake編譯程式 cd path of cmakelist.txt cmake make make install 語法 1.link directories 查詢動態庫路徑,相當於makefile的 l選項,且該方法必須在add library和add executable之前 2.鏈結靜態...

cmake常用語法參考

cmake常用語法參考 利用cmake來構建c 工程是乙個非常方便的選擇,尤其是依賴的庫比較多的時候,或者工程比較大的時候都非常方便,這裡記錄一些cmake常用的語法,key words cmake beijing,2019 code agile pioneer 2.cmake 執行命令 3.cma...