brought back the option to build either as "glut" or "freeglut": FREEGLUT_REPLACE_GLUT
[freeglut] / blackberry.toolchain.cmake
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).
4 #
5 #  Usage Linux:
6 #   $ source /absolute/path/to/the/bbndk/bbndk-env.sh
7 #   $ mkdir build
8 #   $ cd build
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"
10 #   $ make -j8
11 #
12 #  Usage Mac:
13 #   Same as the steps on Linux
14 #
15 #  Usage Windows:
16 #   > /absolute/path/to/the/bbndk/bbndk-env.bat
17 #   > mkdir build
18 #   > cd build
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"
20 #   > make -j8
21 #
22
23 cmake_minimum_required( VERSION 2.6.3 )
24
25 if( DEFINED CMAKE_CROSSCOMPILING )
26   # Subsequent toolchain loading is not really needed
27   return()
28 endif()
29
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 )
34
35 # Check for PlayBook
36 if( EXISTS "${BLACKBERRY_TARGET_ROOT}/x86/lib/gcc/4.4.2" )
37   set( PLAYBOOK True )
38 endif()
39
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 )
43 endif()
44
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 )
48
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" )
58 else()
59  message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" )
60 endif()
61
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" )
68 endif()
69
70 # There may be a way to make cmake reduce these TODO
71 if( BLACKBERRY_ARCHITECTURE STREQUAL "arm" )
72  set( NEUTRINO_ARCH "v7" )
73 else()
74  set( NEUTRINO_ARCH "" )
75 endif()
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" )
83
84 # Installer
85 #if( APPLE )
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." )
89 # endif()
90 # mark_as_advanced( CMAKE_INSTALL_NAME_TOOL )
91 # endif()
92
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" )
96
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" )
99 else()
100  set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin"                          CACHE PATH "Output directory for applications" )
101 endif()
102
103 # Includes
104 if( PLAYBOOK )
105  list( APPEND BLACKBERRY_SYSTEM_INCLUDE_DIRS "${BLACKBERRY_TARGET_ROOT}/usr/include" )
106 else()
107  list( APPEND BLACKBERRY_SYSTEM_INCLUDE_DIRS "${BLACKBERRY_TARGET_ROOT}/qnx6/usr/include" )
108 endif()
109
110 # Flags and preprocessor definitions
111 set( BB_USING_GCC_482 False )
112 if( PLAYBOOK )
113   set( BLACKBERRY_COMP_DEF "-D__PLAYBOOK__" )
114   set( BLACKBERRY_COMP_VERSION "4.4.2" )
115 else()
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 )
120   else()
121     set( BLACKBERRY_COMP_VERSION "4.6.3" )
122   endif()
123 endif()
124 if( BLACKBERRY_ARCHITECTURE STREQUAL "arm" )
125   set( BLACKBERRY_COMP_TARGET "gcc_ntoarmv7le" )
126 else()
127   set( BLACKBERRY_COMP_TARGET "gcc_ntox86" )
128 endif()
129 set( BLACKBERRY_CXX_COMP_LIB "" )
130 if( BLACKBERRY_DINKUM )
131   set( DINKUM 1 )
132   if( BB_USING_GCC_482 )
133     set( BLACKBERRY_COMP_TARGET "${BLACKBERRY_COMP_TARGET}_cpp" )
134   else()
135     set( BLACKBERRY_CXX_COMP_LIB "-Y_cpp" )
136   endif()
137 else()
138   set( DINKUM 0 )
139   if( BB_USING_GCC_482 )
140     set( BLACKBERRY_COMP_TARGET "${BLACKBERRY_COMP_TARGET}_gpp" )
141   else()
142     set( BLACKBERRY_CXX_COMP_LIB "-Y_gpp" )
143   endif()
144 endif()
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}" )
147 set( BLACKBERRY 1 )
148
149 # NDK flags
150 if( DINKUM )
151   set( CMAKE_CXX_FLAGS "${BLACKBERRY_CXX_FLAGS} -DBLACKBERRY_DINKUM=1" )
152   set( CMAKE_C_FLAGS "${BLACKBERRY_CC_FLAGS} -DBLACKBERRY_DINKUM=1" )
153 else()
154   set( CMAKE_CXX_FLAGS "${BLACKBERRY_CXX_FLAGS}" )
155   set( CMAKE_C_FLAGS "${BLACKBERRY_CC_FLAGS}" )
156 endif()
157 set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions" )
158 set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions" )
159
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" )
166 else()
167  set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i486" )
168  set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i486" )
169 endif()
170
171 # Cache flags
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" )
183
184 # Finish 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}" )
189
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 )
198
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 )
205   SET( WIN32 1 )
206   SET( UNIX )
207  elseif( CMAKE_HOST_APPLE )
208   SET( APPLE 1 )
209   SET( UNIX )
210  endif()
211  find_package( ${ARGN} )
212  SET( WIN32 )
213  SET( APPLE )
214  SET( UNIX 1 )
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 )
218 endmacro()
219
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 )
226   SET( WIN32 1 )
227   SET( UNIX )
228  elseif( CMAKE_HOST_APPLE )
229   SET( APPLE 1 )
230   SET( UNIX )
231  endif()
232  find_program( ${ARGN} )
233  SET( WIN32 )
234  SET( APPLE )
235  SET( UNIX 1 )
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 )
239 endmacro()
240
241 # We are doing cross compiling, reset the OS information of the Building system
242 UNSET( APPLE )
243 UNSET( WIN32 )
244 UNSET( UNIX )