1 # setup environment for cross compile to arm-linux
3 if (DEFINED CMAKE_TOOLCHAIN_FILE)
6 " *********************************************************\n"
7 " * CMAKE_TOOLCHAIN_FILE not defined *\n"
8 " * This is correct for compiling on the Raspberry Pi *\n"
10 " * If you are cross-compiling on some other machine *\n"
11 " * then DELETE the build directory and re-run with: *\n"
12 " * -DCMAKE_TOOLCHAIN_FILE=toolchain_file.cmake *\n"
14 " * Toolchain files are in makefiles/cmake/toolchains. *\n"
15 " *********************************************************"
19 # pull in headers for android
22 # work out where android headers and library are
25 set(ANDROID_NDK_ROOT $ENV{ANDROID_NDK_ROOT} CACHE INTERNAL "" FORCE)
26 set(ANDROID_LIBS $ENV{ANDROID_LIBS} CACHE INTERNAL "" FORCE)
27 set(ANDROID_BIONIC $ENV{ANDROID_BIONIC} CACHE INTERNAL "" FORCE)
28 set(ANDROID_LDSCRIPTS $ENV{ANDROID_LDSCRIPTS} CACHE INTERNAL "" FORCE)
30 if("${ANDROID_NDK_ROOT}" STREQUAL "")
31 find_program(ANDROID_COMPILER arm-eabi-gcc)
32 get_filename_component(ANDROID_BIN ${ANDROID_COMPILER} PATH CACHE)
33 find_path(_ANDROID_ROOT Makefile PATHS ${ANDROID_BIN}
34 PATH_SUFFIXES ../../../../..
36 if("${_ANDROID_ROOT}" STREQUAL "_ANDROID_ROOT-NOTFOUND")
37 set(_ANDROID_ROOT "" CACHE INTERNAL "" FORCE)
39 if("${_ANDROID_ROOT}" STREQUAL "")
40 message(FATAL_ERROR "Cannot find android root directory")
42 get_filename_component(ANDROID_ROOT ${_ANDROID_ROOT} ABSOLUTE CACHE)
44 # top level of cross-compiler target include and lib directory structure
47 "${ANDROID_ROOT}/prebuilt/ndk" CACHE INTERNAL "" FORCE)
49 "${ANDROID_ROOT}/bionic" CACHE INTERNAL "" FORCE)
51 "${ANDROID_ROOT}/build/core" CACHE INTERNAL "" FORCE)
53 "${ANDROID_ROOT}/out/target/product/${ANDROID_PRODUCT}/obj/lib"
54 CACHE INTERNAL "" FORCE)
57 if("${ANDROID_NDK_ROOT}" STREQUAL "")
58 message(FATAL_ERROR "Cannot find Android NDK root directory")
60 if("${ANDROID_BIONIC}" STREQUAL "")
61 message(FATAL_ERROR "Cannot find Android BIONIC directory")
63 if("${ANDROID_LDSCRIPTS}" STREQUAL "")
64 message(FATAL_ERROR "Cannot find Android LD scripts directory")
67 set(CMAKE_SYSTEM_PREFIX_PATH "${ANDROID_NDK_ROOT}/android-ndk-r${ANDROID_NDK_RELEASE}/platforms/android-${ANDROID_NDK_PLATFORM}/arch-${CMAKE_SYSTEM_PROCESSOR}/usr")
69 if("${ANDROID_LIBS}" STREQUAL "")
70 set(ANDROID_LIBS "${CMAKE_SYSTEM_PREFIX_PATH}/lib"
71 CACHE INTERNAL "" FORCE)
72 # message(FATAL_ERROR "Cannot find android libraries")
76 # add include directories for pthreads
78 include_directories("${CMAKE_SYSTEM_PREFIX_PATH}/include" BEFORE SYSTEM)
79 include_directories("${ANDROID_BIONIC}/libc/include" BEFORE SYSTEM)
80 include_directories("${ANDROID_BIONIC}/libc/include/arch-arm/include" BEFORE SYSTEM)
81 include_directories("${ANDROID_BIONIC}/libc/kernel/arch-arm" BEFORE SYSTEM)
82 include_directories("${ANDROID_BIONIC}/libc/kernel/common" BEFORE SYSTEM)
83 include_directories("${ANDROID_BIONIC}/libm/include" BEFORE SYSTEM)
84 include_directories("${ANDROID_BIONIC}/libm/include/arch/arm" BEFORE SYSTEM)
85 include_directories("${ANDROID_BIONIC}/libstdc++/include" BEFORE SYSTEM)
89 # Pull in Android link options manually
91 set(ANDROID_CRTBEGIN "${ANDROID_LIBS}/crtbegin_dynamic.o")
92 set(ANDROID_CRTEND "${ANDROID_LIBS}/crtend_android.o")
93 set(CMAKE_SHARED_LINKER_FLAGS "-nostdlib ${ANDROID_CRTBEGIN} -Wl,-Bdynamic -Wl,-T${ANDROID_LDSCRIPTS}/armelf.x")
95 link_directories(${ANDROID_LIBS})
96 set(CMAKE_EXE_LINKER_FLAGS "-nostdlib ${ANDROID_CRTBEGIN} -nostdlib -Wl,-z,noexecstack")
97 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-dynamic-linker,/system/bin/linker -Wl,-rpath,${CMAKE_INSTALL_PREFIX}/lib")
98 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-T${ANDROID_LDSCRIPTS}/armelf.x -Wl,--gc-sections")
99 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,nocopyreloc -Wl,-z,noexecstack -Wl,--fix-cortex-a8 -Wl,--no-undefined")
101 set(CMAKE_C_STANDARD_LIBRARIES "-llog -lc -lgcc ${ANDROID_CRTEND}" CACHE INTERNAL "" FORCE)
109 # All linux systems have sbrk()
110 add_definitions(-D_HAVE_SBRK)
112 # pull in declarations of lseek64 and friends
113 add_definitions(-D_LARGEFILE64_SOURCE)
115 # test for glibc malloc debugging extensions
116 try_compile(HAVE_MTRACE
118 ${PROJECT_SOURCE_DIR}/makefiles/cmake/srcs/test-mtrace.c
121 # test for existence of execinfo.h header
122 include(CheckIncludeFile)
123 check_include_file(execinfo.h HAVE_EXECINFO_H)
125 add_definitions(-DHAVE_CMAKE_CONFIG)
127 "makefiles/cmake/cmake_config.h.in"
128 "${PROJECT_BINARY_DIR}/cmake_config.h"