# android-cmake
CMake is great, and so is Android. This is a collection of CMake scripts that may be useful to the Android NDK community. It is based on experience from porting OpenCV library to Android: http://opencv.org/platforms/android.html
Main goal is to share these scripts so that devs that use CMake as their build system may easily compile native code for Android.
## TL;DR
cmake -DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake \
-DANDROID_NDK=<ndk_path> \
-DCMAKE_BUILD_TYPE=Release \
-DANDROID_ABI="armeabi-v7a with NEON" \
<source_path>
cmake --build .
One-liner:
cmake -DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake -DANDROID_NDK=<ndk_path> -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI="armeabi-v7a with NEON" <source_path> && cmake --build .
_android-cmake_ will search for your NDK install in the following order:
1. Value of `ANDROID_NDK` CMake variable;
1. Value of `ANDROID_NDK` environment variable;
1. Search under paths from `ANDROID_NDK_SEARCH_PATHS` CMake variable;
1. Search platform specific locations (home folder, Windows "Program Files", etc).
So if you have installed the NDK as `~/android-ndk-r10d` then _android-cmake_ will locate it automatically.
## Getting started
To build a cmake-based C/C++ project for Android you need:
* Android NDK (>= r5) http://developer.android.com/tools/sdk/ndk/index.html
* CMake (>= v2.6.3, >= v2.8.9 recommended) http://www.cmake.org/download
The _android-cmake_ is also capable to build with NDK from AOSP or Linaro Android source tree, but you may be required to manually specify path to `libm` binary to link with.
## Difference from traditional CMake
Folowing the _ndk-build_ the _android-cmake_ supports **only two build targets**:
* `-DCMAKE_BUILD_TYPE=Release`
* `-DCMAKE_BUILD_TYPE=Debug`
So don't even try other targets that can be found in CMake documentation and don't forget to explicitly specify `Release` or `Debug` because CMake builds without a build configuration by default.
## Difference from _ndk-build_
* Latest GCC available in NDK is used as the default compiler;
* `Release` builds with `-O3` instead of `-Os`;
* `Release` builds without debug info (without `-g`) (because _ndk-build_ always creates a stripped version but cmake delays this for `install/strip` target);
* `-fsigned-char` is added to compiler flags to make `char` signed by default as it is on x86/x86_64;
* GCC's stack protector is not used neither in `Debug` nor `Release` configurations;
* No builds for multiple platforms (e.g. building for both arm and x86 require to run cmake twice with different parameters);
* No file level Neon via `.neon` suffix;
The following features of _ndk-build_ are not supported by the _android-cmake_ yet:
* `armeabi-v7a-hard` ABI
* `libc++_static`/`libc++_shared` STL runtime
## Basic options
Similarly to the NDK build system _android-cmake_ allows to select between several compiler toolchains and target platforms. Most of the options can be set either as cmake arguments: `-D<NAME>=<VALUE>` or as environment variables:
* **ANDROID_NDK** - path to the Android NDK. If not set then _android-cmake_ will search for the most recent version of supported NDK in commonly used locations;
* **ANDROID_ABI** - specifies the target Application Binary Interface (ABI). This option nearly matches to the APP_ABI variable used by ndk-build tool from Android NDK. If not specified then set to `armeabi-v7a`. Possible target names are:
* `armeabi` - ARMv5TE based CPU with software floating point operations;
* **`armeabi-v7a`** - ARMv7 based devices with hardware FPU instructions (VFPv3_D16);
* `armeabi-v7a with NEON` - same as armeabi-v7a, but sets NEON as floating-point unit;
* `armeabi-v7a with VFPV3` - same as armeabi-v7a, but sets VFPv3_D32 as floating-point unit;
* `armeabi-v6 with VFP` - tuned for ARMv6 processors having VFP;
* `x86` - IA-32 instruction set
* `mips` - MIPS32 instruction set
* `arm64-v8a` - ARMv8 AArch64 instruction set - only for NDK r10 and newer
* `x86_64` - Intel64 instruction set (r1) - only for NDK r10 and newer
* `mips64` - MIPS64 instruction set (r6) - only for NDK r10 and newer
* **ANDROID_NATIVE_API_LEVEL** - level of android API to build for. Can be set either to full name (example: `android-8`) or a numeric value (example: `17`). The default API level depends on the target ABI:
* `android-8` for ARM;
* `android-9` for x86 and MIPS;
* `android-21` for 64-bit ABIs.
Building for `android-L` is possible only when it is explicitly selected.
* **ANDROID_TOOLCHAIN_NAME** - the name of compiler toolchain to be used. This option allows to select between different GCC and Clang versions. The list of possible values depends on the NDK version and will be printed by toolchain file if an invalid value is set. By default _android-cmake_ selects the most recent version of GCC which can build for specified `ANDROID_ABI`.
Example values are:
* `aarch64-linux-android-4.9`
* `aarch64-linux-android-clang3.5`
* `arm-linux-androideabi-4.8`
* `arm-linux-androideabi-4.9`
* `arm-linux-androideabi-clang3.5`
* `mips64el-linux-android-4.9`
* `mipsel-linux-android-4.8`
* `x86-4.9`
* `x86_64-4.9`
* etc.
* **ANDROID_STL** - the name of C++ runtime to use. The default is `gnustl_static`.
* `none` - do not configure the runtime.
* `system` - use the default minimal system C++ runtime library.
* Implies `-fno-rtti -fno-exceptions`.
* `system_re` - use the default minimal system C++ runtime library.
* Implies `-frtti -fexceptions`.
* `gabi++_static` - use the GAbi++ runtime as a static library.
* Implies `-frtti -fno-exceptions`.
* Available for NDK r7 and newer.
* `gabi++_shared` - use the GAbi++ runtime as a shared library.
* Implies `-frtti -fno-exceptions`.
* Available for NDK r7 and newer.
* `stlport_static` - use the STLport runtime as a static library.
* Implies `-fno-rtti -fno-exceptions` for NDK before r7.
* Implies `-frtti -fno-exceptions` for NDK r7 and newer.
* `stlport_shared` - use the STLport runtime as a shared library.
* Implies `-fno-rtti -fno-exceptions` for NDK before r7.
* Implies `-frtti -fno-exceptions` for NDK r7 and newer.
* **`gnustl_static`** - use the GNU STL as a static library.
* Implies `-frtti -fexceptions`.
* `gnustl_shared` - use the GNU STL as a shared library.
* Implies `-frtti -fno-exceptions`.
* Available for NDK r7b and newer.
* Silently degrades to `gnustl_static` if not available.
* **NDK_CCACHE** - path to `ccache` executable. If not set then initialized from `NDK_CCACHE` environment variable.
## Advanced _android-cmake_ options
Normally _android-cmake_ users are not supposed to touch these variables but they might be useful to workaround some build issues:
* **ANDROID_FORCE_ARM_BUILD** = `OFF` - generate 32-bit ARM instructions instead of Thumb. Applicable only for arm ABIs and is forced to be `ON` for `armeabi-v6 with VFP`;
* **ANDROID_NO_UNDEFINED** = `ON` - show all undefined symbols as linker errors;
* **ANDROID_SO_UNDEFINED** = `OFF` - allow undefined symbols in shared libraries;
* actually it is turned `ON` by default for NDK older than `r7`
* **ANDROID_STL_FORCE_FEATURES** = `ON` - automatically configure rtti and exceptions support based on C++ runtime;
* **ANDROID_NDK_LAYOUT** = `RELEASE` - inner layout of Android NDK, should be detected automatically. Possible values are:
* `RELEASE` - public releases from Google;
* `LINARO` - NDK from Linaro project;
* `ANDROID` - NDK from AOSP.
* **ANDROID_FUNCTION_LEVEL_LINKING** = `ON` - enables saparate putting each function and data items into separate sections and enable garbage collection of unused input sections at link time (`-fdata-sections -ffunction
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
RK3588的硬件编解码库使用 (786个子文件)
astyle 327KB
astylerc 580B
make-Android.bash 2KB
make-Android.bash 2KB
make-Android.bash 2KB
make-Makefiles.bash 559B
make-Makefiles.bash 533B
make-Makefiles.bash 226B
make-Makefiles.bash 190B
build-all.bat 419B
build-all.bat 419B
make-solutions.bat 237B
make-solutions.bat 237B
mpp_astyle.bat 70B
av1_entropymode.c 201KB
hal_h265d_com.c 194KB
hal_h265e_vepu580.c 128KB
hal_av1d_vdpu.c 94KB
av1d_cbs.c 93KB
h264d_init.c 86KB
hal_h264e_vepu580.c 84KB
hal_vp9d_com.c 77KB
h265d_ps.c 74KB
hal_h265e_vepu541.c 74KB
vp9d_parser.c 72KB
h265d_parser.c 67KB
h264d_dpb.c 64KB
hal_h265d_vdpu34x.c 59KB
m2vd_parser.c 55KB
hal_h264e_vepu541.c 54KB
rc_model_v2.c 52KB
hal_h264d_vdpu34x.c 51KB
mpg4d_parser.c 50KB
hal_vp8e_base.c 50KB
utils.c 45KB
hal_h265d_rkv.c 44KB
hal_vp9d_vdpu34x.c 41KB
jpegd_parser.c 40KB
h264e_slice.c 39KB
vp8d_parser.c 38KB
hal_h264d_vdpu2.c 37KB
rc_model_v2_smt.c 37KB
hal_h264d_rkv_reg.c 36KB
hal_avs2d_rkv.c 36KB
av1d_parser.c 36KB
mpi_rc2_test.c 35KB
hal_jpegd_vdpu1.c 35KB
hal_jpegd_vdpu2.c 34KB
h264d_parse.c 34KB
mpi_enc_test.c 33KB
hal_h264d_vdpu1.c 33KB
vepu541_common.c 33KB
h265e_header_gen.c 32KB
hal_jpege_vepu2_v2.c 31KB
hal_h264e_vpu_tbl.c 29KB
h265e_slice.c 29KB
mpp_enc_roi_utils.c 28KB
avsd_parse.c 28KB
mpi_enc_utils.c 28KB
hal_avsd_plus.c 28KB
h265e_dpb.c 28KB
hal_h265e_vepu580_tune.c 27KB
hal_vp9d_rkv.c 26KB
iniparser.c 26KB
avs2d_ps.c 25KB
h264e_api_v2.c 25KB
h264d_sps.c 25KB
hal_h264e_vepu2_v2.c 25KB
hal_h264e_vepu1_v2.c 25KB
vpu_api_test.c 25KB
hal_jpegd_rkv.c 25KB
hal_h264d_vdpu_com.c 25KB
hal_avsd_vdpu2.c 24KB
hal_avsd_vdpu1.c 24KB
hal_vp8e_table.c 24KB
mpi_dec_test.c 24KB
h264d_slice.c 23KB
hal_vp8d_vdpu2.c 23KB
hal_vp8d_vdpu1.c 23KB
avs2d_dpb.c 23KB
hal_jpege_hdr.c 23KB
h264e_dpb.c 22KB
film_grain_noise_table.c 21KB
vcodec_service.c 21KB
hal_h264e_vepu_v2.c 20KB
h264d_api.c 20KB
hal_jpegd_common.c 20KB
mpp_service.c 20KB
avs2d_parse.c 20KB
jpege_api_v2.c 19KB
hal_jpege_vepu1_v2.c 19KB
mpi_dec_multi_test.c 19KB
mpi_dec_utils.c 18KB
hal_vp8e_vepu2_v2.c 18KB
hal_vp8e_vepu1_v2.c 18KB
h265d_parser2_syntax.c 18KB
h265e_ps.c 17KB
h265e_api.c 17KB
h264e_sps.c 17KB
h265e_syntax.c 16KB
共 786 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
- vsd8882023-06-01资源是宝藏资源,实用也是真的实用,感谢大佬分享~
- DIPTE2023-04-26资源不错,对我启发很大,获得了新的灵感,受益匪浅。
道亦无名
- 粉丝: 4964
- 资源: 170
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功