Updated toolchain so that it does a more exact check if this is for PlayBook or Black...
[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_GLES2=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_GLES2=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 # 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 )
43
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" )
53 else()
54  message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" )
55 endif()
56
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" )
63 endif()
64
65 # There may be a way to make cmake reduce these TODO
66 if( BLACKBERRY_ARCHITECTURE STREQUAL "arm" )
67  set( NEUTRINO_ARCH "v7" )
68 else()
69  set( NEUTRINO_ARCH "" )
70 endif()
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" )
78
79 # Installer
80 #if( APPLE )
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." )
84 # endif()
85 # mark_as_advanced( CMAKE_INSTALL_NAME_TOOL )
86 # endif()
87
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" )
91
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" )
94 else()
95  set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin"                          CACHE PATH "Output directory for applications" )
96 endif()
97
98 # Includes
99 if( PLAYBOOK )
100  list( APPEND BLACKBERRY_SYSTEM_INCLUDE_DIRS "${BLACKBERRY_TARGET_ROOT}/usr/include" )
101 else()
102  list( APPEND BLACKBERRY_SYSTEM_INCLUDE_DIRS "${BLACKBERRY_TARGET_ROOT}/qnx6/usr/include" )
103 endif()
104
105 # Flags and preprocessor definitions
106 if( BLACKBERRY_ARCHITECTURE STREQUAL "arm" )
107  if( PLAYBOOK )
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__" )
110  else()
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__" )
113  endif()
114 else()
115  if( PLAYBOOK )
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__" )
118  else()
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__" )
121  endif()
122 endif()
123 set( BLACKBERRY 1 )
124
125 # NDK flags
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" )
130
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" )
137 else()
138  set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i486" )
139  set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i486" )
140 endif()
141
142 # Cache flags
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" )
154
155 # Finish 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}" )
160
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 )
169
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 )
176   SET( WIN32 1 )
177   SET( UNIX )
178  elseif( CMAKE_HOST_APPLE )
179   SET( APPLE 1 )
180   SET( UNIX )
181  endif()
182  find_package( ${ARGN} )
183  SET( WIN32 )
184  SET( APPLE )
185  SET( UNIX 1 )
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 )
189 endmacro()
190
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 )
197   SET( WIN32 1 )
198   SET( UNIX )
199  elseif( CMAKE_HOST_APPLE )
200   SET( APPLE 1 )
201   SET( UNIX )
202  endif()
203  find_program( ${ARGN} )
204  SET( WIN32 )
205  SET( APPLE )
206  SET( UNIX 1 )
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 )
210 endmacro()
211
212 # We are doing cross compiling, reset the OS information of the Building system
213 UNSET( APPLE )
214 UNSET( WIN32 )
215 UNSET( UNIX )