Adjust sourcize.c to use _snprintf if using MSVC.
[SquirrelJME.git] / nanocoat / cmake / platform.cmake
blob442844612641bcc3f39beb16c8c0c3b72b5935f5
1 # ---------------------------------------------------------------------------
2 # SquirrelJME
3 #     Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
4 # ---------------------------------------------------------------------------
5 # SquirrelJME is under the Mozilla Public License Version 2.0.
6 # See license.mkd for licensing and copyright information.
7 # ---------------------------------------------------------------------------
8 # DESCRIPTION: Platform information
10 # Determine the host platform, if not set
11 if(NOT DEFINED SQUIRRELJME_HOST_PLATFORM)
12         squirreljme_util(platformExePath platform)
13         execute_process(COMMAND "${platformExePath}" "-p"
14                 OUTPUT_VARIABLE SQUIRRELJME_HOST_PLATFORM
15                 ERROR_VARIABLE platformExeIgnore
16                 TIMEOUT 16)
17         execute_process(COMMAND "${platformExePath}" "-a"
18                 OUTPUT_VARIABLE SQUIRRELJME_HOST_ARCH
19                 ERROR_VARIABLE platformExeIgnore
20                 TIMEOUT 16)
21 endif()
23 # Some compile definitions which may shine light on the target platform
24 string(FIND "${COMPILE_DEFINITIONS}" "-D_3DS"
25         SQUIRRELJME_CHECK_CDEF_3DS)
27 # Target architecture
28 if(NOT DEFINED SQUIRRELJME_ARCH)
29         message(STATUS "Input CPU: ${CMAKE_SYSTEM_PROCESSOR}")
31         if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64" OR
32                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "EM64T" OR
33                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR
34                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86-64" OR
35                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "amd64")
36                 set(SQUIRRELJME_ARCH "amd64")
37         elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6k" OR
38                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm32" OR
39                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armel" OR
40                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armbe" OR
41                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm" OR
42                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv5l" OR
43                 "${SQUIRRELJME_CHECK_CDEF_3DS}" GREATER_EQUAL 0)
44                 set(SQUIRRELJME_ARCH "arm32")
45         elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64" OR
46                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64" OR
47                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64_be")
48                 set(SQUIRRELJME_ARCH "arm64")
49         elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i286" OR
50                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "I86" OR
51                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ia16")
52                 set(SQUIRRELJME_ARCH "ia16")
53         elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i386" OR
54                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i486" OR
55                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i586" OR
56                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686" OR
57                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "X86" OR
58                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86" OR
59                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ia32")
60                 set(SQUIRRELJME_ARCH "ia32")
61         elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64" OR
62                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ia64" OR
63                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "Itanium" OR
64                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "Itanic")
65                 set(SQUIRRELJME_ARCH "ia64")
66         elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "mips" OR
67                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "mipsel" OR
68                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "mipseb" OR
69                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "mips32" OR
70                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "mips32el" OR
71                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "mips32eb")
72                 set(SQUIRRELJME_ARCH "mips32")
73         elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "mips64" OR
74                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "mips64el" OR
75                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "mips64eb")
76                 set(SQUIRRELJME_ARCH "mips64")
77         elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc" OR
78                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "powerpc")
79                 set(SQUIRRELJME_ARCH "powerpc32")
80         elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64" OR
81                 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "powerpc64")
82                 set(SQUIRRELJME_ARCH "powerpc64")
83         else()
84                 set(SQUIRRELJME_ARCH "${SQUIRRELJME_HOST_ARCH}")
85         endif()
86 endif()
88 # Determine the platform we are targeting
89 # https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_NAME.html
90 if(NOT DEFINED SQUIRRELJME_PLATFORM)
91         message(STATUS "Input Platform: ${CMAKE_SYSTEM_NAME}")
93         if("${SQUIRRELJME_CHECK_CDEF_3DS}" GREATER_EQUAL 0)
94                 set(SQUIRRELJME_PLATFORM "3ds")
95         elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "BeOS")
96                 set(SQUIRRELJME_PLATFORM "beos")
97         elseif(BSD OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
98                 CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR
99                 CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
100                 set(SQUIRRELJME_PLATFORM "bsd")
101         elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN" OR
102                 "${CMAKE_SYSTEM_NAME}" STREQUAL "MSYS2")
103                 set(SQUIRRELJME_PLATFORM "cygwin")
104         elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "DOS")
105                 set(SQUIRRELJME_PLATFORM "dos")
106         elseif(EMSCRIPTEN OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten")
107                 set(SQUIRRELJME_PLATFORM "emscripten")
108         elseif(LINUX OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
109                 set(SQUIRRELJME_PLATFORM "linux")
110         elseif(APPLE OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
111                 set(SQUIRRELJME_PLATFORM "macosx")
112         elseif(WIN32 OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
113                 if("${SQUIRRELJME_ARCH}" STREQUAL "ia16")
114                         set(SQUIRRELJME_PLATFORM "win16")
115                 else()
116                         set(SQUIRRELJME_PLATFORM "win32")
117                 endif()
118         elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsCE")
119                 set(SQUIRRELJME_PLATFORM "wince")
120         elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Generic")
121                 set(SQUIRRELJME_PLATFORM "unknown")
122         else()
123                 set(SQUIRRELJME_PLATFORM "${SQUIRRELJME_HOST_PLATFORM}")
124         endif()
125 endif()
127 if (NOT "${SQUIRRELJME_HOST_PLATFORM}" STREQUAL "${SQUIRRELJME_PLATFORM}" OR
128         NOT "${SQUIRRELJME_HOST_ARCH}" STREQUAL "${SQUIRRELJME_ARCH}")
129         set(SQUIRRELJME_IS_CROSS_COMPILE YES)
130 else()
131         set(SQUIRRELJME_IS_CROSS_COMPILE NO)
132 endif()
134 # It's a UNIX system! I know this!
135 if(SQUIRRELJME_PLATFORM STREQUAL "bsd" OR
136         SQUIRRELJME_PLATFORM STREQUAL "linux" OR
137         SQUIRRELJME_PLATFORM STREQUAL "macosx")
138         set(SQUIRRELJME_IS_UNIX YES)
139 else()
140         set(SQUIRRELJME_IS_UNIX NO)
141 endif()
143 # It's a Windows system? Must be another flavor of UNIX!
144 if(SQUIRRELJME_HOST_PLATFORM STREQUAL "win16" OR
145         SQUIRRELJME_HOST_PLATFORM STREQUAL "win32" OR
146         SQUIRRELJME_HOST_PLATFORM STREQUAL "wince")
147         set(SQUIRRELJME_IS_WINDOWS YES)
148 else()
149         set(SQUIRRELJME_IS_WINDOWS NO)
150 endif()
152 # Is this RetroArch? Any kind of RetroArch build?
153 if(RETROARCH OR ENV{RETROARCH} OR
154         LIBRETRO_STATIC OR ENV{LIBRETRO_STATIC} OR
155         LIBRETRO_SUFFIX OR ENV{LIBRETRO_SUFFIX} OR
156         ENV{LIBRETRO})
157         set(SQUIRRELJME_IS_LIBRETRO YES)
158 else()
159         set(SQUIRRELJME_IS_LIBRETRO NO)
160 endif()
162 # Debug
163 message(STATUS "Host: ${SQUIRRELJME_HOST_PLATFORM}/${SQUIRRELJME_HOST_ARCH}")
164 message(STATUS "Target: ${SQUIRRELJME_PLATFORM}/${SQUIRRELJME_ARCH}")
165 message(STATUS "Cross Compiled? ${SQUIRRELJME_IS_CROSS_COMPILE}")
166 message(STATUS "Is UNIX? ${SQUIRRELJME_IS_UNIX}")
167 message(STATUS "Is Windows? ${SQUIRRELJME_IS_WINDOWS}")
168 message(STATUS "Is libretro? ${SQUIRRELJME_IS_LIBRETRO}")
170 # Options
171 ## Dynamic libraries?
172 if("${SQUIRRELJME_PLATFORM}" STREQUAL "dos" OR
173         "${SQUIRRELJME_PLATFORM}" STREQUAL "emscripten" OR
174         "${SQUIRRELJME_PLATFORM}" STREQUAL "palmos" OR
175         "${SQUIRRELJME_PLATFORM}" STREQUAL "wince" OR
176         LIBRETRO_STATIC OR ENV{LIBRETRO_STATIC})
177         set(SQUIRRELJME_ENABLE_DYLIB_DEFAULT OFF)
178 else()
179         set(SQUIRRELJME_ENABLE_DYLIB_DEFAULT ON)
180 endif()
182 ## Enable LUA?
183 if("${SQUIRRELJME_PLATFORM}" STREQUAL "dos" OR
184         "${SQUIRRELJME_PLATFORM}" STREQUAL "classicmac" OR
185         "${SQUIRRELJME_PLATFORM}" STREQUAL "emscripten" OR
186         "${SQUIRRELJME_PLATFORM}" STREQUAL "palmos" OR
187         "${SQUIRRELJME_PLATFORM}" STREQUAL "wince" OR
188         "${SQUIRRELJME_ARCH}" STREQUAL "ia16")
189         set(SQUIRRELJME_ENABLE_LUA_DEFAULT OFF)
190 else()
191         set(SQUIRRELJME_ENABLE_LUA_DEFAULT ON)
192 endif()
194 ## Netscape JRI Interface?
195 if(SQUIRRELJME_ENABLE_DYLIB_DEFAULT AND
196         ("${SQUIRRELJME_PLATFORM}" STREQUAL "classicmac" OR
197         "${SQUIRRELJME_PLATFORM}" STREQUAL "win16"))
198         set(SQUIRRELJME_ENABLE_FRONTEND_JRI_DEFAULT ON)
199 else()
200         set(SQUIRRELJME_ENABLE_FRONTEND_JRI_DEFAULT OFF)
201 endif()
203 ## LibRetro?
204 if("${SQUIRRELJME_ARCH}" STREQUAL "ia16" OR
205         "${SQUIRRELJME_PLATFORM}" STREQUAL "classicmac" OR
206         "${SQUIRRELJME_PLATFORM}" STREQUAL "palmos" OR
207         "${SQUIRRELJME_PLATFORM}" STREQUAL "win16" OR
208         "${SQUIRRELJME_PLATFORM}" STREQUAL "wince")
209         set(SQUIRRELJME_ENABLE_FRONTEND_LIBRETRO_DEFAULT OFF)
210 else()
211         set(SQUIRRELJME_ENABLE_FRONTEND_LIBRETRO_DEFAULT ON)
212 endif()
214 ## Testing?
215 if(SQUIRRELJME_IS_CROSS_COMPILE OR
216         ${CMAKE_VERSION} VERSION_LESS_EQUAL "3.12")
217         set(SQUIRRELJME_ENABLE_TESTING_DEFAULT OFF)
218 else()
219         set(SQUIRRELJME_ENABLE_TESTING_DEFAULT ON)
220 endif()
222 ## FPIC?
223 if(FALSE)
224         set(SQUIRRELJME_ENABLE_FPIC_DEFAULT OFF)
225 else()
226         set(SQUIRRELJME_ENABLE_FPIC_DEFAULT ON)
227 endif()
229 # Option flags which are available
230 option(SQUIRRELJME_ENABLE_DYLIB "Enable Dynamic Libraries"
231         ${SQUIRRELJME_ENABLE_DYLIB_DEFAULT})
232 option(SQUIRRELJME_ENABLE_FPIC "Enable FPIC"
233         ${SQUIRRELJME_ENABLE_FPIC_DEFAULT})
234 option(SQUIRRELJME_ENABLE_FRONTEND_JRI "Enable Front End: JRI"
235         ${SQUIRRELJME_ENABLE_FRONTEND_JRI_DEFAULT})
236 option(SQUIRRELJME_ENABLE_FRONTEND_LIBRETRO "Enable Front End: LibRetro"
237         ${SQUIRRELJME_ENABLE_FRONTEND_LIBRETRO_DEFAULT})
238 option(SQUIRRELJME_ENABLE_LUA "Enable Lua"
239         ${SQUIRRELJME_ENABLE_LUA_DEFAULT})
240 option(SQUIRRELJME_ENABLE_TESTING "Enable Host System Tests"
241         ${SQUIRRELJME_ENABLE_TESTING_DEFAULT})
243 # Verbose these
244 message(STATUS "ENABLE_DYLIB: ${SQUIRRELJME_ENABLE_DYLIB}")
245 message(STATUS "ENABLE_FPIC: ${SQUIRRELJME_ENABLE_FPIC}")
246 message(STATUS "ENABLE_FRONTEND_JRI: ${SQUIRRELJME_ENABLE_FRONTEND_JRI}")
247 message(STATUS "ENABLE_FRONTEND_LIBRETRO: ${SQUIRRELJME_ENABLE_FRONTEND_LIBRETRO}")
248 message(STATUS "ENABLE_LUA: ${SQUIRRELJME_ENABLE_LUA}")
249 message(STATUS "ENABLE_TESTING: ${SQUIRRELJME_ENABLE_TESTING}")