GithubHelp home page GithubHelp logo

android-cmake's Introduction

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;
  2. Value of ANDROID_NDK environment variable;
  3. Search under paths from ANDROID_NDK_SEARCH_PATHS CMake variable;
  4. 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:

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-sections -Wl,--gc-sections);
  • ANDROID_GOLD_LINKER = ON - use gold linker with GCC 4.6 for NDK r8b and newer (only for ARM and x86);
  • ANDROID_NOEXECSTACK = ON - enables or disables stack execution protection code (-Wl,-z,noexecstack);
  • ANDROID_RELRO = ON - Enables RELRO - a memory corruption mitigation technique (-Wl,-z,relro -Wl,-z,now);
  • ANDROID_LIBM_PATH - path to libm.so (set to something like $(TOP)/out/target/product/<product_name>/obj/lib/libm.so) to workaround unresolved sincos.

Fine-tuning CMakeLists.txt for android-cmake

Recognizing Android build

android-cmake defines ANDROID CMake variable which can be used to add Android-specific stuff:

if (ANDROID)
    message(STATUS "Hello from Android build!")
endif()

The recommended way to identify ARM/MIPS/x86 architecture is examining CMAKE_SYSTEM_PROCESSOR which is set to the appropriate value:

  • armv5te - for armeabi ABI
  • armv6 - for armeabi-v6 with VFP ABI
  • armv7-a - for armeabi-v7a, armeabi-v7a with VFPV3 and armeabi-v7a with NEON ABIs
  • aarch64 - for arm64-v8a ABI
  • i686 - for x86 ABI
  • x86_64 - for x86_64 ABI
  • mips - for mips ABI
  • mips64 - for mips64 ABI

Other variables that are set by android-cmake and can be used for the fine-grained build configuration are:

  • NEON - set if target ABI supports Neon;
  • ANDROID_NATIVE_API_LEVEL - native Android API level we are building for (note: Java part of Andoid application can be built for another API level)
  • ANDROID_NDK_RELEASE - version of the Android NDK
  • ANDROID_NDK_HOST_SYSTEM_NAME - "windows", "linux-x86" or "darwin-x86" depending on the host platform
  • ANDROID_RTTI - set if rtti is enabled by the runtime
  • ANDROID_EXCEPTIONS - set if exceptions are enabled by the runtime

Finding packages

When crosscompiling CMake find_* commands are normally expected to find libraries and packages belonging to the same build target. So android-cmake configures CMake to search in Android-specific paths only and ignore your host system locations. So

find_package(ZLIB)

will surely find libz.so within the Android NDK.

However sometimes you need to locate a host package even when cross-compiling. For example you can be searching for your documentation generator. The android-cmake recommends you to use find_host_package and find_host_program macro defined in the android.toolchain.cmake:

find_host_package(Doxygen)
find_host_program(PDFLATEX pdflatex)

However this will break regular builds so instead of wrapping package search into platform-specific logic you can copy the following snippet into your project (put it after your top-level project() command):

# Search packages for host system instead of packages for target system
# in case of cross compilation these macro should be defined by toolchain file
if(NOT COMMAND find_host_package)
  macro(find_host_package)
    find_package(${ARGN})
  endmacro()
endif()
if(NOT COMMAND find_host_program)
  macro(find_host_program)
    find_program(${ARGN})
  endmacro()
endif()

Compiler flags recycling

Make sure to do the following in your scripts:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}")

The flags will be prepopulated with critical flags, so don't loose them. Also be aware that android-cmake also sets configuration-specific compiler and linker flags.

Troubleshooting

Building on Windows

First of all cygwin builds are NOT supported and will not be supported by android-cmake. To build natively on Windows you need a port of make but I recommend http://martine.github.io/ninja/ instead.

To build with Ninja you need:

  • Ensure you are using CMake newer than 2.8.9;
  • Download the latest Ninja from https://github.com/martine/ninja/releases;
  • Put the ninja.exe into your PATH (or add path to ninja.exe to your PATH environment variable);
  • Pass -GNinja to cmake alongside with other arguments (or choose Ninja generator in cmake-gui).
  • Enjoy the fast native multithreaded build :)

But if you still want to stick to old make then:

  • Get a Windows port of GNU Make:
  • Add path to your make.exe to system PATH or always use full path;
  • Pass -G"MinGW Makefiles" and -DCMAKE_MAKE_PROGRAM="<full/path/to/>make.exe"
    • It must be MinGW Makefiles and not Unix Makefiles even if your make.exe is not a MinGW's make.
  • Run make.exe or cmake --build . for single-threaded build.

Projects with assembler files

The android-cmake should correctly handle projects with assembler sources (*.s or *.S). But if you still facing problems with assembler then try to upgrade your CMake to version newer than 2.8.5

Copying

android-cmake is distributed under the terms of BSD 3-Clause License

android-cmake's People

Contributors

abergmeier avatar aichim avatar ethanrublee avatar gjasny avatar paroj avatar rpavlik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-cmake's Issues

How to choose explicitly the GCC version to be used (arch dependent)

Hi,

I wish I can stick to NDK r10d (cf. Android NDK, Revision 10d (December 2014) changelog) defaults for GCC versions:

Made GCC 4.8 the default for all 32-bit ABIs. Deprecated GCC 4.6, and will remove it next release. To restore previous behavior, either add NDK_TOOLCHAIN_VERSION=4.6 to ndk-build, or add --toolchain=arm-linux-androideabi-4.6 when executing make-standalone-toolchain.sh on the command line. GCC 4.9 remains the default for 64-bit ABIs.

I didn't succeed using ANDROID_STANDALONE_TOOLCHAIN and didn't see a "version" option made available.
I've also tried using NDK_TOOLCHAIN_VERSION as for ndk-build but didn't worked.
I've seen that all versions of toolchains are detected in the targeted SDK.

Thanks.

Cmake thinks NDK r9b is bad, when it is working

I think mine is related, it detects the latest (r9b) but always thinks that it is bad. When a generate the standalone toolchain from said NDK it works correctly.

CMake Error at cmake/toolchains/Android.toolchain.cmake:700 (message):
Could not find any working toolchain in the NDK. Probably your Android NDK
is broken.
Call Stack (most recent call first):
/opt/local/share/cmake-2.8/Modules/CMakeDetermineSystem.cmake:93 (include)
CMakeLists.txt:11 (project)

(Thank You for an otherwise awesome build script ๐Ÿ‘ )

Error in copyright notice?

Copyright in android.toolchain.cmake reads:
"The name of the copyright holders may be used to endorse or promote..."

Probably supposed to read:
"The name of the copyright holders may NOT be used to endorse or promote..."

Idk if it matters. Just noticed it :)

android-cmake cant find android-ndk-r9 even though its in env

so i found this great little cmake toolchain, but i just cant get it to work with mysql connector c,

ANDROID_NDK_TOOLCHAIN_TOOLS_PREFIX=arm-linux-androideabi
ANDROID_NDK_ROOT=/home/stingray/Qt/android-ndk-r9/
ANDROID_NDK_HOST=Linux-x86
ANDROID_NATIVE_API_LEVEL=android-14
ANDROID_NDK_TOOLCHAIN_PREFIX=arm-linux-androideabi
ANDROID_ABI=armeabi
ANDROID_NDK_PLATFORM=android-18
ANDROID_NDK_TOOLCHAIN_VERSION=4.8
ANDROID_CMAKE=/home/stingray/src/android/r9/r9/android.toolchain.cmake
ANDROID_NDK=/home/stingray/Qt/android-ndk-r9/
ANDROID_STANDALONE_TOOLCHAIN=/usr/arm-linux-androideabi-4.8/

and here comes the output from cmake-gui:
Running cmake version 2.8.10.1
CMake Error at /home/stingray/src/android/r9/android.toolchain.cmake:554 (message):
Could not find neither Android NDK nor Android standalone toolchain.

You should either set an environment variable:

export ANDROID_NDK=~/my-android-ndk

or

export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain

or put the toolchain or NDK in the default path:

sudo ln -s ~/my-android-ndk /opt/android-ndk

sudo ln -s ~/my-android-toolchain /opt/android-toolchain
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/CMakeDetermineSystem.cmake:89 (include)
CMakeLists.txt:99 (PROJECT)

CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file:/home/stingray/src/mysql-connector-c-6.1.1-src/build/CMakeFiles/2.8.10.1/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file:/home/stingray/src/mysql-connector-c-6.1.1-src/build/CMakeFiles/2.8.10.1/CMakeCXXCompiler.cmake
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
Configuring incomplete, errors occurred!

so a little hint on how to use the toolchain would be nice if i missed something?

*find_path* and *find_library* doesn't seem to work

I'm trying to use find_path and find_library to find headers and libraries for local files that I built for android. The path is correct but it doesn't find anything.
Here's an example:

set(LIBUV_ROOT_DIR "[Path to libuv local files]")
find_path(LIBUV_INCLUDE_DIR
     NAMES uv.h
     HINTS ${LIBUV_ROOT_DIR}/include
)

LIBUV_INCLUDE_DIR-Not-Found

do these functions work for android-toolchain ?

AndroidNdkGdb debugging macros broken

I can't seem to get the debugging macros in AndroidNdkGdb working anymore. For one, it uses LIBRARY_OUTPUT_PATH, but that isn't being defined by the toolchain anymore (or I couldn't figure out how).

Also, when hardcoding the LIBRARY_OUTPUT_PATH, I ran into linking issues for executable targets depend on libraries that I have added with android_ndk_gdb_debuggable(libFoo). The linking stage fails due to missing symbols. It's almost like the stripping phase in AndroidNdkGdb has stripped the symbols out.

How to use android_native_app_glue?

My code requires the use of android_native_app_glue wrapper, found in ANDROID_NDK/sources/android. The way it was previously included in Android.mk was by using

LOCAL_STATIC_LIBRARIES := android_native_app_glue

How can I use this in cmake?

ndk r10e, ANROID_ABI=arm64-v8a

hi,
when i try to compile arm64-v8a opencv lib, ubuntu 14.04.
i use cmake-gui and specify cross-compiling toolchain to the android.toolchain.cmake.
and then set ANDROID_NDK=/absolute/path/to/the/android-ndk-r10e, and click configure.
BUT when i try to specity ANDROID_ABI, i can not find arm64-v8a option.
i need help~~~
thanks.

ndk_helper won't compile

I specify API level as 15 and I get the following errors (Using CMake 3.1.1 with NDK r10 generated against Eclipse CDT4 - Ninja). Building on Windows 7:

[15/478] Building CXX object CMakeFiles/ndk_helper.dir/C_/android/android-ndk-r10/sources/android/ndk_helper/gestureDetector.cpp.o
[16/478] Building CXX object CMakeFiles/ndk_helper.dir/C_/android/android-ndk-r10/sources/android/ndk_helper/GLContext.cpp.o
FAILED: C:\android\android-ndk-r10\toolchains\arm-linux-androideabi-4.8\prebuilt\windows-x86_64\bin\arm-linux-androideabi-g++.exe   -DANDROID -fexceptions -frtti -Wno-psabi --sysroot=C:/android/android-ndk-r10/platforms/android-17/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fdata-sections -ffunction-sections -Wa,--noexecstack  -mthumb -fomit-frame-pointer -fno-strict-aliasing -O3 -DNDEBUG -fPIC -isystem C:/android/android-ndk-r10/platforms/android-17/arch-arm/usr/include -isystem C:/android/android-ndk-r10/sources/cxx-stl/gnu-libstdc++/4.8/include -isystem C:/android/android-ndk-r10/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include -isystem C:/android/android-ndk-r10/sources/cxx-stl/gnu-libstdc++/4.8/include/backward -IC:/android/android-ndk-r10/sources/android/cpufeatures -IC:/android/android-ndk-r10/sources/android/native_app_glue -IC:/android/android-ndk-r10/sources/android/ndk_helper -IC:/code/frontend/Core/Artifacts/Android -IC:/code/frontend/Core/Artifacts/PowerVR_SDK/Include    -std=gnu++11 -MMD -MT CMakeFiles/ndk_helper.dir/C_/android/android-ndk-r10/sources/android/ndk_helper/GLContext.cpp.o -MF CMakeFiles/ndk_helper.dir/C_/android/android-ndk-r10/sources/android/ndk_helper/GLContext.cpp.o.d -o CMakeFiles/ndk_helper.dir/C_/android/android-ndk-r10/sources/android/ndk_helper/GLContext.cpp.o -c C:/android/android-ndk-r10/sources/android/ndk_helper/GLContext.cpp
C:/android/android-ndk-r10/sources/android/ndk_helper/GLContext.cpp: In member function 'bool ndk_helper::GLContext::InitEGLSurface()':

C:/android/android-ndk-r10/sources/android/ndk_helper/GLContext.cpp:133:73: error: cannot convert 'ANativeWindow*' to 'EGLNativeWindowType {aka android_native_window_t*}' for argument '3' to 'void* eglCreateWindowSurface(EGLDisplay, EGLConfig, EGLNativeWindowType, const EGLint*)'

     surface_ = eglCreateWindowSurface( display_, config_, window_, NULL );

                                                                         ^

C:/android/android-ndk-r10/sources/android/ndk_helper/GLContext.cpp: In member function 'EGLint ndk_helper::GLContext::Resume(ANativeWindow*)':

C:/android/android-ndk-r10/sources/android/ndk_helper/GLContext.cpp:225:73: error: cannot convert 'ANativeWindow*' to 'EGLNativeWindowType {aka android_native_window_t*}' for argument '3' to 'void* eglCreateWindowSurface(EGLDisplay, EGLConfig, EGLNativeWindowType, const EGLint*)'

     surface_ = eglCreateWindowSurface( display_, config_, window_, NULL );

                                                                         ^

ninja: build stopped: subcommand failed.

I'm calling the following function from android-cmake repository:

android_ndk_import_module_ndk_helper()

cpufeatures and native_app_glue compile fine.

Cmake project builds fine but cannot link to subproject

I'm getting a linking error when building a cmake project for android using these scripts. The project consists in a static library and a binary, linked to it.
Here is the structure of my project :

.
โ”œโ”€โ”€ android_project       <-- Main project, an executable, linked against "assets" static library
โ”‚ย ย  โ”œโ”€โ”€ CMakeLists.txt        <-- "subdirs(src)"
โ”‚ย ย  โ”œโ”€โ”€ include
โ”‚ย ย  โ””โ”€โ”€ src
โ”‚ย ย      โ”œโ”€โ”€ android_project.c
โ”‚ย ย      โ””โ”€โ”€ CMakeLists.txt    <-- see below
โ”œโ”€โ”€ assets            <-- Is a static library
โ”‚ย ย  โ”œโ”€โ”€ CMakeLists.txt        <-- "subdirs(src)"
โ”‚ย ย  โ”œโ”€โ”€ include
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ asset.hpp
โ”‚ย ย  โ””โ”€โ”€ src
โ”‚ย ย      โ”œโ”€โ”€ asset.cpp
โ”‚ย ย      โ””โ”€โ”€ CMakeLists.txt
โ”œโ”€โ”€ cmake
โ”‚ย ย  โ”œโ”€โ”€ android-cmake
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ AndroidNdkGdb.cmake
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ AndroidNdkModules.cmake
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ android.toolchain.cmake
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ ndk_links.md
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ README.md
โ”‚ย ย  โ””โ”€โ”€ modules
โ””โ”€โ”€ CMakeLists.txt        <-- Basic settings (i.e. compilation flags) and "subdirs(android_project, assets)", see below

My ./CMakeLists.txt looks like this ;

cmake_minimum_required(VERSION 2.8)
project(android_project C CXX)

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_COLOR_MAKEFILE ON)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)

set(CMAKE_CXX_FLAGS "-v -std=c++11 -pedantic -Wall -Weffc++ -Wcast-align ")
set(CMAKE_CXX_FLAGS_DEBUG "-g")

set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/bin/")

subdirs(${PROJECT_NAME} assets)

My ./androidproject/src/CMakeLists.txt looks like this :

set(CMAKE_VERBOSE_MAKEFILE ON)

include_directories(${${PROJECT_NAME}_SOURCE_DIR}/android_project/include)

file(GLOB android_project_SRCS *.cpp *.c)

add_executable(${PROJECT_NAME} ${android_project_SRCS})
target_link_libraries(${PROJECT_NAME} assets)

I build my project :

mkdir build && cd build

cmake -DCMAKE_TOOLCHAIN_FILE=./cmake/android-cmake/android.toolchain.cmake -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-clang3.6 -DANDROID_NDK=/opt/android-ndk-r10e -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI="armeabi-v7a" ..
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/android_project/build

make
/usr/bin/cmake -H/tmp/android_project -B/tmp/android_project/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /tmp/android_project/build/CMakeFiles /tmp/android_project/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/tmp/android_project/build'
make -f assets/src/CMakeFiles/assets.dir/build.make assets/src/CMakeFiles/assets.dir/depend
make[2]: Entering directory `/tmp/android_project/build'
cd /tmp/android_project/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /tmp/android_project /tmp/android_project/assets/src /tmp/android_project/build /tmp/android_project/build/assets/src /tmp/android_project/build/assets/src/CMakeFiles/assets.dir/DependInfo.cmake --color=
Scanning dependencies of target assets
make[2]: Leaving directory `/tmp/android_project/build'
make -f assets/src/CMakeFiles/assets.dir/build.make assets/src/CMakeFiles/assets.dir/build
make[2]: Entering directory `/tmp/android_project/build'
/usr/bin/cmake -E cmake_progress_report /tmp/android_project/build/CMakeFiles 2
[ 50%] Building CXX object assets/src/CMakeFiles/assets.dir/asset.cpp.o
cd /tmp/android_project/build/assets/src && /opt/android-ndk-r10e/toolchains/llvm-3.6/prebuilt/linux-x86_64/bin/clang++   -DANDROID -v -std=c++11 -pedantic -Wall -Weffc++ -Wcast-align  -mthumb -fomit-frame-pointer -fno-strict-aliasing -O3 -DNDEBUG -isystem /opt/android-ndk-r10e/platforms/android-8/arch-arm/usr/include -isystem /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/include -isystem /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include -isystem /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/include/backward -I/tmp/android_project/assets/include    -o CMakeFiles/assets.dir/asset.cpp.o -c /tmp/android_project/assets/src/asset.cpp
clang version 3.6 
Target: x86_64-pc-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.1
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Candidate multilib: .;@m64
Selected multilib: .;@m64
clang: warning: argument unused during compilation: '-mthumb'
 "/opt/android-ndk-r10e/toolchains/llvm-3.6/prebuilt/linux-x86_64/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -disable-free -main-file-name asset.cpp -mrelocation-model static -mthread-model posix -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -target-linker-version 2.24 -momit-leaf-frame-pointer -v -dwarf-column-info -coverage-file /tmp/android_project/build/assets/src/CMakeFiles/assets.dir/asset.cpp.o -resource-dir /opt/android-ndk-r10e/toolchains/llvm-3.6/prebuilt/linux-x86_64/bin/../lib/clang/3.6 -isystem /opt/android-ndk-r10e/platforms/android-8/arch-arm/usr/include -isystem /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/include -isystem /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include -isystem /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/include/backward -D ANDROID -D NDEBUG -I /tmp/android_project/assets/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/x86_64-linux-gnu/c++/4.8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/x86_64-linux-gnu/c++/4.8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/backward -internal-isystem /usr/local/include -internal-isystem /opt/android-ndk-r10e/toolchains/llvm-3.6/prebuilt/linux-x86_64/bin/../lib/clang/3.6/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wall -Weffc++ -Wcast-align -pedantic -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /tmp/android_project/build/assets/src -ferror-limit 19 -fmessage-length 237 -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o CMakeFiles/assets.dir/asset.cpp.o -x c++ /tmp/android_project/assets/src/asset.cpp
clang -cc1 version 3.6 based upon LLVM 3.6 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/include"
ignoring duplicate directory "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/x86_64-linux-gnu/c++/4.8"
#include "..." search starts here:
#include <...> search starts here:
 /tmp/android_project/assets/include
 /opt/android-ndk-r10e/platforms/android-8/arch-arm/usr/include
 /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/include
 /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include
 /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/include/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8
 /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/x86_64-linux-gnu/c++/4.8
 /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/backward
 /usr/local/include
 /opt/android-ndk-r10e/toolchains/llvm-3.6/prebuilt/linux-x86_64/bin/../lib/clang/3.6/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
Linking CXX static library libassets.a
cd /tmp/android_project/build/assets/src && /usr/bin/cmake -P CMakeFiles/assets.dir/cmake_clean_target.cmake
cd /tmp/android_project/build/assets/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/assets.dir/link.txt --verbose=1
/opt/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc-ar cr libassets.a  CMakeFiles/assets.dir/asset.cpp.o
/opt/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ranlib libassets.a
make[2]: Leaving directory `/tmp/android_project/build'
/usr/bin/cmake -E cmake_progress_report /tmp/android_project/build/CMakeFiles  2
[ 50%] Built target assets
make -f android_project/src/CMakeFiles/android_project.dir/build.make android_project/src/CMakeFiles/android_project.dir/depend
make[2]: Entering directory `/tmp/android_project/build'
cd /tmp/android_project/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /tmp/android_project /tmp/android_project/android_project/src /tmp/android_project/build /tmp/android_project/build/android_project/src /tmp/android_project/build/android_project/src/CMakeFiles/android_project.dir/DependInfo.cmake --color=
Scanning dependencies of target android_project
make[2]: Leaving directory `/tmp/android_project/build'
make -f android_project/src/CMakeFiles/android_project.dir/build.make android_project/src/CMakeFiles/android_project.dir/build
make[2]: Entering directory `/tmp/android_project/build'
/usr/bin/cmake -E cmake_progress_report /tmp/android_project/build/CMakeFiles 1
[100%] Building C object android_project/src/CMakeFiles/android_project.dir/android_project.c.o
cd /tmp/android_project/build/android_project/src && /opt/android-ndk-r10e/toolchains/llvm-3.6/prebuilt/linux-x86_64/bin/clang  -DANDROID -fexceptions -fpic -gcc-toolchain /opt/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64 -target armv7-none-linux-androideabi -Qunused-arguments --sysroot=/opt/android-ndk-r10e/platforms/android-8/arch-arm -funwind-tables -fsigned-char -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fdata-sections -ffunction-sections -Xclang -mnoexecstack  -mthumb -fomit-frame-pointer -fno-strict-aliasing -O3 -DNDEBUG -isystem /opt/android-ndk-r10e/platforms/android-8/arch-arm/usr/include -isystem /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/include -isystem /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include -isystem /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/include/backward -I/tmp/android_project/android_project/include    -o CMakeFiles/android_project.dir/android_project.c.o   -c /tmp/android_project/android_project/src/android_project.c
Linking CXX executable ../../bin/android_project
cd /tmp/android_project/build/android_project/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/android_project.dir/link.txt --verbose=1
/opt/android-ndk-r10e/toolchains/llvm-3.6/prebuilt/linux-x86_64/bin/clang  -v -std=c++11 -pedantic -Wall -Weffc++ -Wcast-align  -mthumb -fomit-frame-pointer -fno-strict-aliasing -O3 -DNDEBUG   -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,-z,nocopyreloc CMakeFiles/android_project.dir/android_project.c.o -o ../../bin/android_project  -L/libs/armeabi-v7a -rdynamic ../../assets/src/libassets.a  "/opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/libgnustl_static.a" "/opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/libsupc++.a" -lm
clang version 3.6 
Target: x86_64-pc-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.1
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/usr/bin/ld" -export-dynamic -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o ../../bin/android_project /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.8/crtbegin.o -L/libs/armeabi-v7a -L/usr/lib/gcc/x86_64-linux-gnu/4.8 -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.. -L/opt/android-ndk-r10e/toolchains/llvm-3.6/prebuilt/linux-x86_64/bin/../lib -L/lib -L/usr/lib --fix-cortex-a8 --no-undefined --gc-sections -z noexecstack -z relro -z now -z nocopyreloc CMakeFiles/android_project.dir/android_project.c.o ../../assets/src/libassets.a /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/libgnustl_static.a /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/libsupc++.a -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
/usr/bin/ld: unrecognized option '--fix-cortex-a8'
/usr/bin/ld: use the --help option for usage information
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/android_project] Error 1
make[2]: Leaving directory `/tmp/android_project/build'
make[1]: *** [android_project/src/CMakeFiles/android_project.dir/all] Error 2
make[1]: Leaving directory `/tmp/android_project/build'
make: *** [all] Error 2

The project builds and links without problem natively (i.e. using the host system's clang for x86_64). I also tried with another ANDROID_TOOLCHAIN_NAME (arm gcc) without success.

From what I understand, it is the system linker (/usr/bin/ld) that is called at the end. Should not it be the toolchain's linker (/opt/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld) ?

When I print the value of ${CMAKE_LINKER}, i get the right value (/opt/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld), in both the root CMakeLists.txt and android_project/src/CMakeLists.txt.

Since my project is rather small and its architecture quite classic, there might be something I am doing something wrong. But I cannot figure what.

Anyone got pointers or suggestions regarding this error ?

Simple example ?

Is there a really simple example somewhere ?

There are some on the net, but so far seem to be a bit out of date.

Switch between clang and gcc

I currently don't see any way to switch between clang or gcc. The NDK comes bundled with both compilers. This is a fantastic cmake plugin by the way thanks for sharing!

CLANG prefered over GCC as of r11b

As of r11b. GCC is deprecated and CLANG is the preferred compiler.
The default compiler should be updated to use CLANG by default as well.

From the release notes for NDK r11b:
"We strongly recommend switching to Clang"
"GCC in the NDK is now deprecated in favor of Clang"

This issue depends on #81

Search for standalone toolchain first

Currently, ANDROID_NDK has priority over ANDROID_STANDALONE_TOOLCHAIN. As far as I know, there are two main environment setups that NDK devs use :

  1. Regular (as untarred) toolchain
  2. Standalone toolchain for building and installing private libs into + Regular toolchain on the side out of necessity (for e.g building with Qt for Android)

For people like me who prefer option 2, regular NDK priority over standalone is an inconvenience, due to private installed libs not being found in regular NDK paths, which would be solved by inverting this priority. This inversion does not affect people (probably the majority) who use option 1.

ARM64 relocation error due to default linker flags

Hi,

it seems that the default linker flags breaks the ARM 64 build available since NDK r10 (cf. PR 23).

set( CMAKE_EXE_LINKER_FLAGS    "-Wl,-z,nocopyreloc"      CACHE STRING "executable linker flags" )

should be replaced with

set( CMAKE_EXE_LINKER_FLAGS    ""      CACHE STRING "executable linker flags" )

It fixes the relocation/link issue on ARM64 and had no incidence on other architectures.
Maybe it should be defined according to current architecture and disabled only for ARM64?

Android NDK related post https://groups.google.com/forum/#!topic/android-ndk/-ajpz2E-BEE + extracted project https://bitbucket.org/opatry/ndk10_armv8a_bug

NDK r11 does not work due to toolchain restructure

They have changed the way LLVM is structured in NDK r11. The llvm directory is no longer prefixed with a version number such as llvm-3.5. It's just llvm now. There is only 1 version of Clang (3.8).

As such, it does not detect the clang tooling as available option for ANDROID_TOOLCHAIN_NAME.

Problem building with Crystax 10.1.0 and add-rendermanager branch

I get the following error when trying to build. It looks from the code like maybe the first element in the + operation is empty, making the overall expression be +0 rather than 0+0 or some other number +0.

CMake Error at /home/taylorr/sensics/src/OSVR-Android-Build/android-cmake/android.toolchain.cmake:429 (math):
math cannot parse the expression: "+0": syntax error, unexpected exp_PLUS,
expecting exp_OPENPARENT or exp_NUMBER (1)
Call Stack (most recent call first):
/usr/share/cmake-3.2/Modules/CMakeDetermineSystem.cmake:98 (include)
CMakeLists.txt:2 (project)

This was not an issue with bbfa867, which is what I started out using to develop a RenderManager port.

how to compile source for android using CMake

i am trying to compile poco for android using CMake , i am using CMake 3.5.2 and Android CMake

https://github.com/taka-no-me/android-cmake

C:\Program Files (x86)\CMake\bin>cmake -DCMAKE_TOOLCHAIN_FILE="E:\ndk\android-cm
ake-master\android.toolchain.cmake" -DANDROID_NDK="D:\android-ndk-r10e" -DCMAKE_
BUILD_TYPE=Release -DANDROID_ABI="armeabi" "E:\ndk\poco-1.7.3" && cmake --build


i am getting following error 

> CMake Error at CMakeLists.txt:11 (project):
>   CMAKE_SYSTEM_NAME is 'Android' but 'NVIDIA Nsight Tegra Visual Studio
>   Edition' is not installed.
> 
> 
> -- Configuring incomplete, errors occurred!
> See also "C:/Program Files (x86)/CMake/bin/CMakeFiles/CMakeOutput.log".


can anyone please suggest a proper roadmap to compile it for android , i hunt over a net a lot but couldnt find anything

A missing sysroot in ANDROID_LINKER_FLAGS

While linking shared library, linkers print error that can't find standard libraries (dl, libc, libm). Reason is a missing sysroot in ANDROID_LINKER_FLAGS. Just I replaced 1326 line in android.toolchain.cmake and all was begins works correctly. I replaced this line by that content:

set( ANDROID_LINKER_FLAGS "--sysroot=${ANDROID_SYSROOT}" )

Building boost

I'm trying to build boost for Android and so far I've tried 1.45.0, 1.49.0 and 1.54.0 with no success. Just wondering if anyone has tried doing something like this before?

The original Google android-cmake supported 1.45.0.

Build mutliple abi's with one cmake file

This is more of a question rather than a feature request maybe. I am trying to build a shared library for ARM/X86/MIPS all at the same time. I can see how to do this manually very easily. Create multiple build folders and run "cmake .." in them with appropriate toolchain parameters. Is there any way I can generate these folders easily from cmake?

error: unknown target CPU 'armv7-a'

Hi,

I have a very simple script:
export ANDROID_NDK=/android-ndk-r8e
cmake -DCMAKE_TOOLCHAIN_FILE=
/android-cmake/android.toolchain.cmake

everything works fine at this point but trying to run make I always receive the same error:
error: unknown target CPU 'armv7-a'

I have tried different toolchains using ANDROID_TOOLCHAIN_NAME, but the error is always the same.

Any ideas what could be wrong?

Thanks!

error when selecting gnustl_shared

If I pass -DANDROID_STL=gnustl_shared to cmake, I get an error during configuration like so:

Error copying file (if different) from "/home/user/Dev/env/sys/android-toolchain-arm/arm-linux-androideabi/lib/armv7-a/libgnustl_shared.so" to "/libgnustl_shared.so".
CMake Error at /home/user/Downloads/build/android-cmake/android.toolchain.cmake:1138 (message):
Failed copying of
/home/user/Dev/env/sys/android-toolchain-arm/arm-linux-androideabi/lib/armv7-a/libgnustl_shared.so
to the /libgnustl_shared.so

It seems like the variable LIBRARY_OUTPUT_PATH is empty when this is called [line 1138]. If I copy the block of code responsible for copying libgnustl_shared to after where output directories are setup (line 1546) the error goes away... I don't know if this breaks anything else or if I'm doing something else wrong to generate the error in the first place.

STL include dirs for standalone toolchain

The STL include directories get set wrongly for standalone toolchain.

I've got:

  • android.toolchain.cmake from commit fd1f705 (2013-04-19)
  • NDK r8e
  • standalone toolchain made with the make-standalone-toolchain.sh script from the above NDK version

I don't know if the toolchain structure has changed or what but at least currently the C++ headers are in the root of the toolchain directory. The android.toolchain.cmake seems to look for them from the ${ANDROID_TOOLCHAIN_MACHINE_NAME} subdirectory. With the below patch I get the correct include directories set.

diff --git a/android.toolchain.cmake b/android.toolchain.cmake
index d7f09c7..2e550c0 100644
--- a/android.toolchain.cmake
+++ b/android.toolchain.cmake
@@ -970,7 +970,7 @@ if( BUILD_WITH_STANDALONE_TOOLCHAIN )
  set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" )

  if( NOT ANDROID_STL STREQUAL "none" )
-  set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}" )
+  set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/include/c++/${ANDROID_COMPILER_VERSION}" )
   if( ARMEABI_V7A AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" )
    list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" )
   elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" )

Can we remove "-fdata-sections -ffunction-sections"

See here: http://sourceforge.net/p/log4cplus/mailman/message/31286406/

What steps will reproduce the problem?

  1. Compile logcplus 1.2 in Andriod using cmake
  2. Choose the Release version(Debug works fine)
  3. encounter error log4cplus::internal::__emutls_t._ZN9log4cplus8internal3ptdE causes a section type conflict

What is the expected output? What do you see instead?

Should works fine for release version.

What version of the product are you using? On what operating system?

I'm using mac to cross compile the log4cplus for android, and ndk using is android-ndk-r9d, toolchain is arm-linux-androideabi-g++ (GCC) 4.6 20120106 (prerelease)

Please provide any additional information below.

How to generate android project on Windows without using Tegra?

Hi, I want to use only android ndk & sdk for build, but don't want to install Tegra Studio. I'll just not be able to install it on CI server. Is it possible?

I tried to comment CMAKE_SYSTEM_NAME Android and was able to generate Visual Studio project, but it fails to build. For some reason it still uses VS's linker instead of linker from NDK. I've check CMakeCache.txt and it points to NDK linker:

CMAKE_LINKER:PATH=C:/Users/aln/android-ndk-r10d/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-ld.exe

Could you please suggest anything?

Add support for NDK/toolchains cloned from git

Hi,

While trying to integrate apitrace [1], a user of android.toolchain.cmake, into FirefoxOS [2] I stumbled to the following issue:

The directories layout in http://dl.google.com/android/ndk/android-ndk-r8-linux-x86.tar.bz2 is different than the one in git://android.git.linaro.org/platform/prebuilt and apparently android.toolchain.cmake only supports the former (or maybe I failed to provide the proper cmake options?).

I created a simple patch for android.toolchain.cmake (as is provided in the apitrace project) [3] to recognize the directory structure from git when ANDROID_NDK is specified.

Would be nice to have that functionality in android-cmake itself.

[1] https://github.com/apitrace/apitrace
[2] https://bugzilla.mozilla.org/show_bug.cgi?id=831147
[3] vasild/apitrace@91e28b5

on Mac 64-bit OS X, with a 64-bit NDK, ANDROID_NDK_HOST_X64 must be set explicitly

On Mac 64-bit OS X, with a 64-bit NDK, if ANDROID_NDK_HOST_X64 is not set explicitly, cmake fails on line 702. The reason is that CMAKE_HOST_SYSTEM_PROCESSOR=i386.

It could be enough to add a Mac section to the instructions, but I see no risk in looking for "darwin-x86_64" and "darwin-x86" even if the script cannot detect the 64-bit host.

Compiling Eigen on mac os 10.9.4

Eigen, in common-libs/build.sh errors with:

gfortran: error: unrecognized command line option '-rdynamic'

gfortran comes from gcc package in homebrew

$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/4.9.1/libexec/gcc/x86_64-apple-darwin13.3.0/4.9.1/lto-wrapper
Target: x86_64-apple-darwin13.3.0
Configured with: ../configure --build=x86_64-apple-darwin13.3.0 --prefix=/usr/local/Cellar/gcc/4.9.1 --enable-languages=c,c++,objc,obj-c++,fortran,java --program-suffix=-4.9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-cloog=/usr/local/opt/cloog --with-isl=/usr/local/opt/isl --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --disable-werror --with-pkgversion='Homebrew gcc 4.9.1 --with-all-languages' --with-bugurl=https://github.com/Homebrew/homebrew/issues --enable-plugin --disable-nls --with-ecj-jar=/usr/local/opt/ecj/share/java/ecj.jar --enable-multilib
Thread model: posix
gcc version 4.9.1 (Homebrew gcc 4.9.1 --with-all-languages) 

-fsigned-char breaks binary compatibility on ARM

android.toolchain.cmake adds -fsigned-char to the build options (line 1237), but ARM is using unsigned chars by default. This breaks library calls, e.g. as described here:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47275

I am running into exactly the problem described in the above bug report with Apitrace on ARM Android. I'll report the issue to Apitrace too, but I don't think it can do much when the build tool unconditionally sets an incompatible ABI.

Problem with static compilation

this is my config:
cmake -DANDROID_ABI="armeabi-v7a with NEON" -DANDROID_NATIVE_API_LEVEL=android-22

/media/Data/android/android-ndk-r10d/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld: error: /media/Data/android/android-ndk-r10d/platforms/android-21/arch-arm/usr/lib/libc.a(new.o): multiple definition of 'operator delete(void*)'
/media/Data/android/android-ndk-r10d/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld: /media/Data/android/android-ndk-r10d/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/libgnustl_static.a(del_op.o): previous definition here

If I switch to stlport_static I get this error:
/tmp/ndk-user/tmp/build-stlport/ndk/sources/cxx-stl/gabi++/src/fatal_error.cc:65: error: undefined reference to 'dlopen'
/tmp/ndk-user/tmp/build-stlport/ndk/sources/cxx-stl/gabi++/src/fatal_error.cc:68: error: undefined reference to 'dlsym'
/tmp/ndk-user/tmp/build-stlport/ndk/sources/cxx-stl/gabi++/src/fatal_error.cc:72: error: undefined reference to 'dlclose'

what this basically means is that I can't use any stl without having some kind of weird errors.

cmake 3.6.0 not compatible with android-cmake with Ninja on Windows

Getting the following when trying to use android-cmake with cmake 3.6.0 and ninja on Windows:

RUNNING: cmake --version
cmake version 3.6.0

CMake suite maintained and supported by Kitware (kitware.com/cmake).
RUNNING: cmake -DCMAKE_TOOLCHAIN_FILE=cmake/android/android.toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DANDROID_NATIVE_API_LEVEL=21 -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 -DTREAT_WARNINGS_AS_ERRORS=1 -G Ninja G:\Hp3d-HR-dev
CMake Deprecation Warning at G:/Program Files/CMake/share/cmake-3.6/Modules/CMakeForceCompiler.cmake:79 (message):
  The CMAKE_FORCE_C_COMPILER macro is deprecated.  Instead just set
  CMAKE_C_COMPILER and allow CMake to identify the compiler.
Call Stack (most recent call first):
  cmake/android/android.toolchain.cmake:1129 (CMAKE_FORCE_C_COMPILER)
  G:/Program Files/CMake/share/cmake-3.6/Modules/CMakeDetermineSystem.cmake:98 (include)
  CMakeLists.txt:4 (PROJECT)


CMake Deprecation Warning at G:/Program Files/CMake/share/cmake-3.6/Modules/CMakeForceCompiler.cmake:93 (message):
  The CMAKE_FORCE_CXX_COMPILER macro is deprecated.  Instead just set
  CMAKE_CXX_COMPILER and allow CMake to identify the compiler.
Call Stack (most recent call first):
  cmake/android/android.toolchain.cmake:1141 (CMAKE_FORCE_CXX_COMPILER)
  G:/Program Files/CMake/share/cmake-3.6/Modules/CMakeDetermineSystem.cmake:98 (include)
  CMakeLists.txt:4 (PROJECT)


CMake Error at cmake/android/android.toolchain.cmake:1622 (enable_language):
  Language 'C' is currently being enabled.  Recursive call not allowed.
Call Stack (most recent call first):
  G:/Program Files/CMake/share/cmake-3.6/Modules/CMakeDetermineSystem.cmake:98 (include)
  CMakeLists.txt:4 (PROJECT)


-- Configuring incomplete, errors occurred!
Traceback (most recent call last):
  File "buildLib\build.py", line 708, in <module>
  File "buildLib\build.py", line 95, in Main
  File "buildLib\build.py", line 205, in RunCMake
  File "G:\Hp3d-HR-dev\scripts\buildLib\cmd.py", line 28, in Run
    raise(RuntimeError('ERROR (%i) running command: %s' % (ret, cmdLine)))
RuntimeError: ERROR (1) running command: cmake -DCMAKE_TOOLCHAIN_FILE=cmake/android/android.toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DANDROID_NATIVE_API_LEVEL=21 -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 -DTREAT_WARNINGS_AS_ERRORS=1 -G Ninja G:\Hp3d-HR-dev

BUILD STEP FAILED: Running CMake

Unable to find shared_ptr

I am trying to use Android-cmake to build a c++ library (openMVG) for Android.

Altough cmake can find the c++ compiler ("Checking for c++11 compiler - available"), cmake cannot find the shared_ptr ("CMake Error at third_party/ceres-solver/CMakeLists.txt:503 (MESSAGE):
Unable to find shared_ptr"). Do you have an idea how I can solve this problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.