1 # ------------------------------------------------------------------------------
2 # BlackBerry CMake toolchain file, for use with the BlackBerry 10 NDK
3 # Requires cmake 2.6.3 or newer (2.8.3 or newer is recommended).
6 # $ source /absolute/path/to/the/bbndk/bbndk-env.sh
9 # $ cmake .. -DCMAKE_TOOLCHAIN_FILE="../blackberry.toolchain.cmake" -DBLACKBERRY_ARCHITECTURE=arm -DFREEGLUT_GLES=ON -DFREEGLUT_BUILD_DEMOS=NO -DCMAKE_VERBOSE_MAKEFILE=TRUE -G "Eclipse CDT4 - Unix Makefiles"
13 # Same as the steps on Linux
16 # > /absolute/path/to/the/bbndk/bbndk-env.bat
19 # > cmake .. -DCMAKE_TOOLCHAIN_FILE="../blackberry.toolchain.cmake" -DBLACKBERRY_ARCHITECTURE=arm -DFREEGLUT_GLES=ON -DFREEGLUT_BUILD_DEMOS=NO -DCMAKE_VERBOSE_MAKEFILE=TRUE -G "Eclipse CDT4 - Unix Makefiles"
23 cmake_minimum_required( VERSION 2.6.3 )
25 if( DEFINED CMAKE_CROSSCOMPILING )
26 # Subsequent toolchain loading is not really needed
30 set( BLACKBERRY_TOOLCHAIN_ROOT "$ENV{QNX_HOST}" )
31 set( BLACKBERRY_TARGET_ROOT "$ENV{QNX_TARGET}" )
32 set( CMAKE_SYSTEM_NAME Linux )
33 set( CMAKE_SYSTEM_VERSION 1 )
36 if( EXISTS "${BLACKBERRY_TARGET_ROOT}/x86/lib/gcc/4.4.2" )
40 # Check for for GCC 4.8.2
41 if( EXISTS "${BLACKBERRY_TARGET_ROOT}/x86/lib/gcc/4.8.2" )
42 set( BB_GCC_482 True )
45 # STL version: by default gnustl_static will be used
46 set( BLACKBERRY_USE_STLPORT FALSE CACHE BOOL "Experimental: use stlport_static instead of gnustl_static")
47 mark_as_advanced( BLACKBERRY_USE_STLPORT )
49 # Detect host platform
50 set( TOOL_OS_SUFFIX "" )
51 if( CMAKE_HOST_APPLE )
52 set( BLACKBERRY_NDK_HOST_SYSTEM_NAME "darwin-x86" )
53 elseif( CMAKE_HOST_WIN32 )
54 set( BLACKBERRY_NDK_HOST_SYSTEM_NAME "windows" )
55 set( TOOL_OS_SUFFIX ".exe" )
56 elseif( CMAKE_HOST_UNIX )
57 set(BLACKBERRY_NDK_HOST_SYSTEM_NAME "linux-x86" )
59 message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" )
62 # Specify the cross compiler
63 set( CMAKE_C_COMPILER "$ENV{QNX_HOST}/usr/bin/qcc${TOOL_OS_SUFFIX}" CACHE PATH "gcc" )
64 set( CMAKE_CXX_COMPILER "$ENV{QNX_HOST}/usr/bin/qcc${TOOL_OS_SUFFIX}" CACHE PATH "g++" )
65 set( CMAKE_ASM_COMPILER "$ENV{QNX_HOST}/usr/bin/qcc${TOOL_OS_SUFFIX}" CACHE PATH "Assembler" )
66 if( CMAKE_VERSION VERSION_LESS 2.8.5 )
67 set( CMAKE_ASM_COMPILER_ARG1 "-c" )
70 # There may be a way to make cmake reduce these TODO
71 if( BLACKBERRY_ARCHITECTURE STREQUAL "arm" )
72 set( NEUTRINO_ARCH "v7" )
74 set( NEUTRINO_ARCH "" )
76 set( CMAKE_STRIP "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" )
77 set( CMAKE_AR "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" )
78 set( CMAKE_LINKER "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}${NEUTRINO_ARCH}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" )
79 set( CMAKE_NM "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}${NEUTRINO_ARCH}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" )
80 set( CMAKE_OBJCOPY "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}${NEUTRINO_ARCH}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" )
81 set( CMAKE_OBJDUMP "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}${NEUTRINO_ARCH}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" )
82 set( CMAKE_RANLIB "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" )
86 # find_program( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool )
87 # if( NOT CMAKE_INSTALL_NAME_TOOL )
88 # message( FATAL_ERROR "Could not find install_name_tool, please check your #installation." )
90 # mark_as_advanced( CMAKE_INSTALL_NAME_TOOL )
93 # Setup output directories
94 set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" )
95 set( CMAKE_INSTALL_PREFIX "${BLACKBERRY_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" )
97 if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" )
98 set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" )
100 set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" )
105 list( APPEND BLACKBERRY_SYSTEM_INCLUDE_DIRS "${BLACKBERRY_TARGET_ROOT}/usr/include" )
107 list( APPEND BLACKBERRY_SYSTEM_INCLUDE_DIRS "${BLACKBERRY_TARGET_ROOT}/qnx6/usr/include" )
110 # Flags and preprocessor definitions
111 set( BB_USING_GCC_482 False )
113 set( BLACKBERRY_COMP_DEF "-D__PLAYBOOK__" )
114 set( BLACKBERRY_COMP_VERSION "4.4.2" )
116 set( BLACKBERRY_COMP_DEF "-D__QNX__" )
117 if( BB_GCC_482 AND BLACKBERRY_USE_GCC_4_8 )
118 set( BLACKBERRY_COMP_VERSION "4.8.2" )
119 set( BB_USING_GCC_482 True )
121 set( BLACKBERRY_COMP_VERSION "4.6.3" )
124 if( BLACKBERRY_ARCHITECTURE STREQUAL "arm" )
125 set( BLACKBERRY_COMP_TARGET "gcc_ntoarmv7le" )
127 set( BLACKBERRY_COMP_TARGET "gcc_ntox86" )
129 set( BLACKBERRY_CXX_COMP_LIB "" )
130 if( BLACKBERRY_DINKUM )
132 if( BB_USING_GCC_482 )
133 set( BLACKBERRY_COMP_TARGET "${BLACKBERRY_COMP_TARGET}_cpp" )
135 set( BLACKBERRY_CXX_COMP_LIB "-Y_cpp" )
139 if( BB_USING_GCC_482 )
140 set( BLACKBERRY_COMP_TARGET "${BLACKBERRY_COMP_TARGET}_gpp" )
142 set( BLACKBERRY_CXX_COMP_LIB "-Y_gpp" )
145 set( BLACKBERRY_CC_FLAGS " -V${BLACKBERRY_COMP_VERSION},${BLACKBERRY_COMP_TARGET} ${BLACKBERRY_COMP_DEF}" )
146 set( BLACKBERRY_CXX_FLAGS " -V${BLACKBERRY_COMP_VERSION},${BLACKBERRY_COMP_TARGET} ${BLACKBERRY_CXX_COMP_LIB} ${BLACKBERRY_COMP_DEF}" )
151 set( CMAKE_CXX_FLAGS "${BLACKBERRY_CXX_FLAGS} -DBLACKBERRY_DINKUM=1" )
152 set( CMAKE_C_FLAGS "${BLACKBERRY_CC_FLAGS} -DBLACKBERRY_DINKUM=1" )
154 set( CMAKE_CXX_FLAGS "${BLACKBERRY_CXX_FLAGS}" )
155 set( CMAKE_C_FLAGS "${BLACKBERRY_CC_FLAGS}" )
157 set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions" )
158 set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions" )
160 # Release and Debug flags
161 if( BLACKBERRY_ARCHITECTURE STREQUAL "arm" )
162 set( CMAKE_CXX_FLAGS_RELEASE "-mthumb -O3" )
163 set( CMAKE_C_FLAGS_RELEASE "-mthumb -O3" )
164 set( CMAKE_CXX_FLAGS_DEBUG "-marm -Os -finline-limit=64" )
165 set( CMAKE_C_FLAGS_DEBUG "-marm -Os -finline-limit=64" )
167 set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i486" )
168 set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i486" )
172 set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags" )
173 set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags" )
174 set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "c++ Release flags" )
175 set( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "c Release flags" )
176 set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "c++ Debug flags" )
177 set( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" CACHE STRING "c Debug flags" )
178 set( CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "linker flags" )
179 SET( CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "" CACHE STRING "linker flags")
180 SET( CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "" CACHE STRING "linker flags")
181 set( CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "linker flags" )
182 set( CMAKE_EXE_LINKER_FLAGS "-lstdc++" CACHE STRING "linker flags" )
185 set( BLACKBERRY_CXX_FLAGS "${BLACKBERRY_CXX_FLAGS}" CACHE INTERNAL "Extra BlackBerry compiler flags")
186 set( BLACKBERRY_LINKER_FLAGS "${BLACKBERRY_LINKER_FLAGS}" CACHE INTERNAL "Extra BlackBerry linker flags")
187 set( CMAKE_CXX_FLAGS "${BLACKBERRY_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" )
188 set( CMAKE_C_FLAGS "${BLACKBERRY_CXX_FLAGS} ${CMAKE_C_FLAGS}" )
190 # Global flags for cmake client scripts to change behavior
191 set( BLACKBERRY True )
192 # Find the Target environment
193 set( CMAKE_FIND_ROOT_PATH "${CMAKE_SOURCE_DIR}" "${BLACKBERRY_TARGET_ROOT}" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share" )
194 # Search for libraries and includes in the ndk toolchain
195 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
196 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
197 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
199 # Macro to find packages on the host OS
200 macro( find_host_package )
201 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
202 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
203 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
204 if( CMAKE_HOST_WIN32 )
207 elseif( CMAKE_HOST_APPLE )
211 find_package( ${ARGN} )
215 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
216 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
217 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
220 # Macro to find programs on the host OS
221 macro( find_host_program )
222 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
223 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
224 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
225 if( CMAKE_HOST_WIN32 )
228 elseif( CMAKE_HOST_APPLE )
232 find_program( ${ARGN} )
236 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
237 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
238 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
241 # We are doing cross compiling, reset the OS information of the Building system