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_GLES2=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_GLES2=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 # STL version: by default gnustl_static will be used
41 set( BLACKBERRY_USE_STLPORT FALSE CACHE BOOL "Experimental: use stlport_static instead of gnustl_static")
42 mark_as_advanced( BLACKBERRY_USE_STLPORT )
44 # Detect host platform
45 set( TOOL_OS_SUFFIX "" )
46 if( CMAKE_HOST_APPLE )
47 set( BLACKBERRY_NDK_HOST_SYSTEM_NAME "darwin-x86" )
48 elseif( CMAKE_HOST_WIN32 )
49 set( BLACKBERRY_NDK_HOST_SYSTEM_NAME "windows" )
50 set( TOOL_OS_SUFFIX ".exe" )
51 elseif( CMAKE_HOST_UNIX )
52 set(BLACKBERRY_NDK_HOST_SYSTEM_NAME "linux-x86" )
54 message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" )
57 # Specify the cross compiler
58 set( CMAKE_C_COMPILER "$ENV{QNX_HOST}/usr/bin/qcc${TOOL_OS_SUFFIX}" CACHE PATH "gcc" )
59 set( CMAKE_CXX_COMPILER "$ENV{QNX_HOST}/usr/bin/qcc${TOOL_OS_SUFFIX}" CACHE PATH "g++" )
60 set( CMAKE_ASM_COMPILER "$ENV{QNX_HOST}/usr/bin/qcc${TOOL_OS_SUFFIX}" CACHE PATH "Assembler" )
61 if( CMAKE_VERSION VERSION_LESS 2.8.5 )
62 set( CMAKE_ASM_COMPILER_ARG1 "-c" )
65 # There may be a way to make cmake reduce these TODO
66 if( BLACKBERRY_ARCHITECTURE STREQUAL "arm" )
67 set( NEUTRINO_ARCH "v7" )
69 set( NEUTRINO_ARCH "" )
71 set( CMAKE_STRIP "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" )
72 set( CMAKE_AR "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" )
73 set( CMAKE_LINKER "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}${NEUTRINO_ARCH}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" )
74 set( CMAKE_NM "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}${NEUTRINO_ARCH}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" )
75 set( CMAKE_OBJCOPY "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}${NEUTRINO_ARCH}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" )
76 set( CMAKE_OBJDUMP "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}${NEUTRINO_ARCH}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" )
77 set( CMAKE_RANLIB "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" )
81 # find_program( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool )
82 # if( NOT CMAKE_INSTALL_NAME_TOOL )
83 # message( FATAL_ERROR "Could not find install_name_tool, please check your #installation." )
85 # mark_as_advanced( CMAKE_INSTALL_NAME_TOOL )
88 # Setup output directories
89 set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" )
90 set( CMAKE_INSTALL_PREFIX "${BLACKBERRY_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" )
92 if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" )
93 set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" )
95 set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" )
100 list( APPEND BLACKBERRY_SYSTEM_INCLUDE_DIRS "${BLACKBERRY_TARGET_ROOT}/usr/include" )
102 list( APPEND BLACKBERRY_SYSTEM_INCLUDE_DIRS "${BLACKBERRY_TARGET_ROOT}/qnx6/usr/include" )
105 # Flags and preprocessor definitions
106 if( BLACKBERRY_ARCHITECTURE STREQUAL "arm" )
108 set( BLACKBERRY_CC_FLAGS " -V4.4.2,gcc_ntoarmv7le -D__PLAYBOOK__" )
109 set( BLACKBERRY_CXX_FLAGS " -V4.4.2,gcc_ntoarmv7le -Y_gpp -D__PLAYBOOK__" )
111 set( BLACKBERRY_CC_FLAGS " -V4.6.3,gcc_ntoarmv7le -D__QNX__" )
112 set( BLACKBERRY_CXX_FLAGS " -V4.6.3,gcc_ntoarmv7le -Y_gpp -D__QNX__" )
116 set( BLACKBERRY_CC_FLAGS " -V4.4.2,gcc_ntox86 -D__PLAYBOOK__" )
117 set( BLACKBERRY_CXX_FLAGS " -V4.4.2,gcc_ntox86 -Y_gpp -D__PLAYBOOK__" )
119 set( BLACKBERRY_CC_FLAGS " -V4.6.3,gcc_ntox86 -D__QNX__" )
120 set( BLACKBERRY_CXX_FLAGS " -V4.6.3,gcc_ntox86 -Y_gpp -D__QNX__" )
126 set( CMAKE_CXX_FLAGS "${BLACKBERRY_CXX_FLAGS}" )
127 set( CMAKE_C_FLAGS "${BLACKBERRY_CC_FLAGS}" )
128 set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions" )
129 set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions" )
131 # Release and Debug flags
132 if( BLACKBERRY_ARCHITECTURE STREQUAL "arm" )
133 set( CMAKE_CXX_FLAGS_RELEASE "-mthumb -O3" )
134 set( CMAKE_C_FLAGS_RELEASE "-mthumb -O3" )
135 set( CMAKE_CXX_FLAGS_DEBUG "-marm -Os -finline-limit=64" )
136 set( CMAKE_C_FLAGS_DEBUG "-marm -Os -finline-limit=64" )
138 set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i486" )
139 set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i486" )
143 set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags" )
144 set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags" )
145 set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "c++ Release flags" )
146 set( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "c Release flags" )
147 set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "c++ Debug flags" )
148 set( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" CACHE STRING "c Debug flags" )
149 set( CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "linker flags" )
150 SET( CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "" CACHE STRING "linker flags")
151 SET( CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "" CACHE STRING "linker flags")
152 set( CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "linker flags" )
153 set( CMAKE_EXE_LINKER_FLAGS "-lstdc++" CACHE STRING "linker flags" )
156 set( BLACKBERRY_CXX_FLAGS "${BLACKBERRY_CXX_FLAGS}" CACHE INTERNAL "Extra BlackBerry compiler flags")
157 set( BLACKBERRY_LINKER_FLAGS "${BLACKBERRY_LINKER_FLAGS}" CACHE INTERNAL "Extra BlackBerry linker flags")
158 set( CMAKE_CXX_FLAGS "${BLACKBERRY_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" )
159 set( CMAKE_C_FLAGS "${BLACKBERRY_CXX_FLAGS} ${CMAKE_C_FLAGS}" )
161 # Global flags for cmake client scripts to change behavior
162 set( BLACKBERRY True )
163 # Find the Target environment
164 set( CMAKE_FIND_ROOT_PATH "${CMAKE_SOURCE_DIR}" "${BLACKBERRY_TARGET_ROOT}" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share" )
165 # Search for libraries and includes in the ndk toolchain
166 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
167 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
168 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
170 # Macro to find packages on the host OS
171 macro( find_host_package )
172 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
173 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
174 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
175 if( CMAKE_HOST_WIN32 )
178 elseif( CMAKE_HOST_APPLE )
182 find_package( ${ARGN} )
186 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
187 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
188 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
191 # Macro to find programs on the host OS
192 macro( find_host_program )
193 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
194 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
195 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
196 if( CMAKE_HOST_WIN32 )
199 elseif( CMAKE_HOST_APPLE )
203 find_program( ${ARGN} )
207 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
208 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
209 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
212 # We are doing cross compiling, reset the OS information of the Building system