Initial version of libomxil-vc4 for RPI3
[platform/adaptation/broadcom/libomxil-vc4.git] / makefiles / cmake / arm-linux.cmake
1 # setup environment for cross compile to arm-linux
2
3 if (DEFINED CMAKE_TOOLCHAIN_FILE)
4 else()
5    message(WARNING
6         "  *********************************************************\n"
7         "  *   CMAKE_TOOLCHAIN_FILE not defined                    *\n"
8         "  *   This is correct for compiling on the Raspberry Pi   *\n"
9         "  *                                                       *\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"
13         "  *                                                       *\n"
14         "  *   Toolchain files are in makefiles/cmake/toolchains.  *\n"
15         "  *********************************************************"
16        )
17 endif()
18
19 # pull in headers for android
20 if(ANDROID)
21     #
22     # work out where android headers and library are
23     #
24
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)
29       
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 ../../../../..
35                   NO_DEFAULT_PATH)
36                 if("${_ANDROID_ROOT}" STREQUAL "_ANDROID_ROOT-NOTFOUND")
37                     set(_ANDROID_ROOT "" CACHE INTERNAL "" FORCE)
38                 endif()
39                 if("${_ANDROID_ROOT}" STREQUAL "")
40             message(FATAL_ERROR "Cannot find android root directory")
41         endif()
42         get_filename_component(ANDROID_ROOT ${_ANDROID_ROOT} ABSOLUTE CACHE)
43         #
44         # top level of cross-compiler target include and lib directory structure
45         #
46         set(ANDROID_NDK_ROOT
47             "${ANDROID_ROOT}/prebuilt/ndk" CACHE INTERNAL "" FORCE)
48         set(ANDROID_BIONIC
49             "${ANDROID_ROOT}/bionic" CACHE INTERNAL "" FORCE)
50         set(ANDROID_LDSCRIPTS
51             "${ANDROID_ROOT}/build/core" CACHE INTERNAL "" FORCE)
52         set(ANDROID_LIBS
53             "${ANDROID_ROOT}/out/target/product/${ANDROID_PRODUCT}/obj/lib"
54             CACHE INTERNAL "" FORCE)
55     endif()
56
57     if("${ANDROID_NDK_ROOT}" STREQUAL "")
58         message(FATAL_ERROR "Cannot find Android NDK root directory")
59     endif()
60     if("${ANDROID_BIONIC}" STREQUAL "")
61         message(FATAL_ERROR "Cannot find Android BIONIC directory")
62     endif()
63     if("${ANDROID_LDSCRIPTS}" STREQUAL "")
64         message(FATAL_ERROR "Cannot find Android LD scripts directory")
65     endif()
66     
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")
68     
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")
73     endif()
74
75     #
76     # add include directories for pthreads
77     #
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)
86     
87
88     #
89     # Pull in Android link options manually
90     #
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")
94
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")
100
101     set(CMAKE_C_STANDARD_LIBRARIES "-llog -lc -lgcc ${ANDROID_CRTEND}" CACHE INTERNAL "" FORCE)
102     
103     set(SHARED "")
104 else()
105     set(SHARED "SHARED")
106 endif()
107
108
109 # All linux systems have sbrk()
110 add_definitions(-D_HAVE_SBRK)
111
112 # pull in declarations of lseek64 and friends
113 add_definitions(-D_LARGEFILE64_SOURCE)
114         
115 # test for glibc malloc debugging extensions
116 try_compile(HAVE_MTRACE
117             ${CMAKE_BINARY_DIR}
118             ${PROJECT_SOURCE_DIR}/makefiles/cmake/srcs/test-mtrace.c
119             OUTPUT_VARIABLE foo)
120
121 # test for existence of execinfo.h header
122 include(CheckIncludeFile)
123 check_include_file(execinfo.h HAVE_EXECINFO_H)
124
125 add_definitions(-DHAVE_CMAKE_CONFIG)
126 configure_file (
127     "makefiles/cmake/cmake_config.h.in"
128     "${PROJECT_BINARY_DIR}/cmake_config.h"
129     )
130