-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
303 lines (278 loc) · 16.1 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#
# @description Eyedrop
# @about C++ game engine built on Sokol
# @author Stephens Nunnally <@stevinz>
# @license MIT - Copyright (c) 2021 Stephens Nunnally and Scidian Studios
# @source https://github.com/scidian/eyedrop
#
#
cmake_minimum_required(VERSION 3.10)
####################################################################################
# BEFORE COMPILING, set the following options below!
#
# EXPORT_TARGET:
# "auto" Attempt Auto-Detect
# "osx" Apple MacOS defines DROP_TARGET_OSX, DROP_TARGET_APPLE, DROP_MAC_MENU
# "ios" Apple iOS defines DROP_TARGET_IOS, DROP_TARGET_APPLE
# "web" Emscripten defines DROP_TARGET_HTML5
# "android" Google Android defines DROP_TARGET_GOOGLE
# "windows" Microsoft Windows defines DROP_TARGET_WINDOWS
# "linux" Linux defines DROP_TARGET_LINUX
#
# APP_TYPE
# "editor" Eyedrop Editor defines DROP_IMGUI
# "player" Eyedrop Runtime ...does not have ImGui enabled unless DEBUG_MODE is set to "true"
#
# DEBUG_MODE
# "true" defines SOKOL_TRACE_HOOKS, DROP_DEBUG, DROP_IMGUI (turns on ImGui and Sokol Gfx debug menu by default)
# "false"
####################################################################################
#################### Build Options
####################################################################################
##### Standard editor build:
set(EXPORT_TARGET "auto")
set(APP_TYPE "editor")
set(DEBUG_MODE "true")
##### For testing no-gui html5 build:
# set(EXPORT_TARGET "web")
# set(APP_TYPE "player")
# set(DEBUG_MODE "false")
####################################################################################
####################################################################################
#################### Possible Compile Defitions
#
# System
# DROP_TARGET_APPLE ##### True when compiling for either MacOS or iOS
# DROP_TARGET_OSX ##### True when compiling for MacOS
# DROP_TARGET_IOS ##### True when compiling for iOS
# DROP_TARGET_HTML5 ##### True when compiling for Html5 (emscripten)
# DROP_TARGET_GOOGLE ##### True when compiling for Android
# DROP_TARGET_WINDOWS ##### True when compiling for Windows
# DROP_TARGET_LINUX ##### True when compiling for Linux
#
# Sokol
# SOKOL_NO_ENTRY ##### Stops sokol_app from hijacking main()
# SOKOL_TRACE_HOOKS ##### Needed for Sokol Debug Viewer
#
# Sokol Backend, Selects One
# SOKOL_GLCORE33 ##### OpenGL Core 3.3 Backend - MacOS, Windows, Linux, Switch, Playstation
# SOKOL_GLES2 ##### OpenGLES 2.0 Backend - Android, WebAssembly
# SOKOL_GLES3 ##### OpenGLES 3.0 Backend - Android, WebAssembly
# SOKOL_D3D11 ##### DirectX 11 Backend - Windows, XBox
# SOKOL_METAL ##### Metal Backend - MacOS, iOS, tvOS
#
# ImGui
# DROP_IMGUI ##### Signal we want ImGui available to application
# DROP_MAC_MENU ##### Use Mac main menu bar instead of ImGui for main menu
#
# Debug
# DROP_DEBUG ##### Signal we want Sokol Debug Viewer capability
#
####################################################################################
####################################################################################
#################### Program to Build
####################################################################################
##### SELECT DESIRED EXECUTABLE (MAIN)
if (APP_TYPE MATCHES "player")
add_compile_definitions(SOKOL_NO_ENTRY) ##### Stops sokol_app from hijacking main()
file(GLOB_RECURSE MAIN_DIRECTORY_FILES
"player/*.c**"
)
if (EXPORT_TARGET MATCHES "web")
project(player) ##### Project Name for Engine Runtime Only for web
else()
project(Player) ##### Project Name for Engine Runtime Only for all others
endif()
elseif (APP_TYPE MATCHES "editor")
add_compile_definitions(SOKOL_NO_ENTRY) ##### Stops sokol_app from hijacking main()
add_compile_definitions(DROP_IMGUI) ##### Signal we want ImGui available to application
file(GLOB_RECURSE MAIN_DIRECTORY_FILES
"editor/*.c**"
)
if (EXPORT_TARGET MATCHES "web")
project(drop) ##### Project Name for Editor for web
else()
project(Drop) ##### Project Name for Editor for all others
endif()
endif()
####################################################################################
####################################################################################
#################### Target Definitions
####################################################################################
##### DEBUG??
if (DEBUG_MODE MATCHES "true")
add_compile_definitions(SOKOL_TRACE_HOOKS) ##### Needed for Sokol Debug Viewer
add_compile_definitions(DROP_DEBUG) ##### Signal we want Sokol Debug Viewer capability
add_compile_definitions(DROP_IMGUI) ##### Signal we want ImGui available to application
endif()
##### TARGET??
if (EXPORT_TARGET MATCHES "auto")
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(EXPORT_TARGET "osx")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(EXPORT_TARGET "windows")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(EXPORT_TARGET "linux")
endif()
endif()
if (EXPORT_TARGET MATCHES "osx")
add_compile_definitions(DROP_TARGET_APPLE)
add_compile_definitions(DROP_TARGET_OSX)
add_compile_definitions(DROP_MAC_MENU)
add_compile_definitions(SOKOL_GLCORE33) ##### OpenGL Core 3.3 Backend - MacOS, Windows, Linux, Switch, Playstation
#add_compile_definitions(SOKOL_METAL) ##### Metal Backend - MacOS, iOS, tvOS
elseif (EXPORT_TARGET MATCHES "ios")
add_compile_definitions(DROP_TARGET_APPLE)
add_compile_definitions(DROP_TARGET_IOS)
add_compile_definitions(SOKOL_GLCORE33) ##### OpenGL Core 3.3 Backend - MacOS, Windows, Linux, Switch, Playstation
#add_compile_definitions(SOKOL_METAL) ##### Metal Backend - MacOS, iOS, tvOS
elseif (EXPORT_TARGET MATCHES "web")
add_compile_definitions(DROP_TARGET_HTML5)
add_compile_definitions(SOKOL_GLES2) ##### OpenGLES 2.0 Backend - Android, WebAssembly
#add_compile_definitions(SOKOL_GLES3) ##### OpenGLES 3.0 Backend - Android, WebAssembly
#add_compile_definitions(SOKOL_WGPU) ##### WebGL Backend - Next Gen WebAssembly
elseif (EXPORT_TARGET MATCHES "android")
add_compile_definitions(DROP_TARGET_GOOGLE)
add_compile_definitions(SOKOL_GLES3) ##### OpenGLES 3.0 Backend - Android, WebAssembly
elseif (EXPORT_TARGET MATCHES "windows")
add_compile_definitions(DROP_TARGET_WINDOWS)
add_compile_definitions(SOKOL_D3D11) ##### DirectX 11 Backend - Windows, XBox
elseif (EXPORT_TARGET MATCHES "linux")
add_compile_definitions(DROP_TARGET_LINUX)
add_compile_definitions(SOKOL_GLCORE33) ##### OpenGL Core 3.3 Backend - MacOS, Windows, Linux, Switch, Playstation
endif()
####################################################################################
####################################################################################
#################### Files to Include
####################################################################################
##### Include Directories, allows for easy #includes...
include_directories(${CMAKE_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/3rd_party)
##### Glob the files, add the executable
file(GLOB_RECURSE 3RD_PARTY_CODE_FILES "3rd_party/*.c**")
if (EXPORT_TARGET MATCHES "osx")
file(GLOB_RECURSE ENGINE_CODE_FILES "engine/*.c**" "engine/*.mm")
else()
file(GLOB_RECURSE ENGINE_CODE_FILES "engine/*.c**")
endif()
file(GLOB SOURCE_CODE_FILES
${MAIN_DIRECTORY_FILES}
${3RD_PARTY_CODE_FILES}
${ENGINE_CODE_FILES}
"*.c**"
)
add_executable(${PROJECT_NAME} ${SOURCE_CODE_FILES})
####################################################################################
####################################################################################
#################### Pre Build Steps
####################################################################################
##### Change output directory thanks to iCloud constatly backing up builds
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(BUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build.nosync/)
set(EXECUTABLE_OUTPUT_PATH ${BUILD_DIR} CACHE PATH "Build directory" FORCE)
endif()
##### Compile Shaders
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
execute_process (
COMMAND tools/sokol_shdc_bin/osx/./sokol-shdc -i engine/scene3d/shaders/BasicShader.glsl -o engine/scene3d/shaders/BasicShader.glsl.h -l glsl330:glsl100:metal_macos:hlsl4
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endif()
##### Copy 'assets' directory to 'build' directory
add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/assets/output/ $<TARGET_FILE_DIR:${PROJECT_NAME}>/assets/)
####################################################################################
####################################################################################
####################################################################################
# Sokol Gfx Requires Libraries:
# - on macOS with Metal: Cocoa, IOKit, QuartzCore, Metal, MetalKit, Foundation
# - on macOS with GL: Cocoa, IOKit, QuartzCore, OpenGL, Foundation
# - on iOS with Metal: Foundation, UIKit, Metal, MetalKit
# - on iOS with GL: Foundation, UIKit, OpenGLES, GLKit
# - on Linux: X11, Xi, Xcursor, GL, dl, pthread, m(?)
# - on Android: GLESv3, EGL, log, android
# - on Windows: no action needed, libs are defined in-source via pragma-comment-lib
#
# Sokol Audio Requires
# - Windows: WASAPI
# - Linux: ALSA (link with asound)
# - macOS/iOS: CoreAudio (link with AudioToolbox & AVFoundation)
# - emscripten: WebAudio with ScriptProcessorNode
# - Android: OpenSLES (link with OpenSLES)
####################################################################################
if (EXPORT_TARGET MATCHES "osx")
#
# -O# Optimze file size in order: -O0, -O1, -O2, -O3, 0s (size), -0fast (speed)
# -s Strip debug info from binary, saves ~1mb
# -fno-exceptions Turns off "try {} catch {}" blocks, and std::except(), saves ~500kb
# -fobjc-arc MacOS ARC object counting, needed for Sokol
#
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os -std=c99 -fno-exceptions -fobjc-arc -xobjective-c")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -std=c++11 -fno-exceptions")
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Cocoa -framework OpenGL -framework IOKit -framework Foundation")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Metal -framework MetalKit -framework AudioToolbox")
find_library(COCOA_LIBRARY Cocoa REQUIRED)
find_library(IOKIT_LIBRARY IOKit REQUIRED)
find_library(OPENGL_LIBRARY OpenGL REQUIRED)
find_library(FOUNDATION_LIBRARY Foundation REQUIRED)
find_library(METAL_LIBRARY Metal REQUIRED)
find_library(METALKIT_LIBRARY MetalKit REQUIRED)
find_library(AUDIOKIT_LIBRARY AudioToolbox REQUIRED)
message(${COCOA_LIBRARY})
message(${IOKIT_LIBRARY})
message(${OPENGL_LIBRARY})
message(${FOUNDATION_LIBRARY})
message(${METAL_LIBRARY})
message(${METALKIT_LIBRARY})
message(${AUDIOKIT_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${COCOA_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${IOKIT_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${METAL_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${METALKIT_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${AUDIOKIT_LIBRARY})
####################################################################################
elseif (EXPORT_TARGET MATCHES "ios")
### TODO ###
####################################################################################
elseif (EXPORT_TARGET MATCHES "web")
# Flags
# -O# Optimization, file size in order: -O1, -O2, -O3, -Os, -Oz (seems smallest)
# --shell-file <path> Create a html file without emscripten logo and debug shell
# -fno-exceptions Turns off "try {} catch {}" blocks, and std::except(), saves ~500kb
#
set(CMAKE_C_LINK_FLAGS "") # Clear MacOS linker flags
set(CMAKE_CXX_LINK_FLAGS "") # Clear MacOS linker flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Oz -fno-exceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Oz -fno-exceptions --shell-file ../shell_full.html") # -Werror -Wno-error=unused-command-line-argument")
set(CMAKE_C_COMPILER "emcc")
set(CMAKE_CXX_COMPILER "emcc")
set(CMAKE_EXECUTABLE_SUFFIX ".html")
# -s WASM=0 Force javascript (no web assembly, more compatiable, but bigger file size) or
# -s WASM=1 Use web assembly (!!!!! #NOTE: MUST RUN ON WEB SERVER FOR IT TO WORK!!!!!) ('.wast' file is human readable, don't need it!)
# -s ASSERTIONS=1|2 Show errors in javascript console
# -s ALLOW_MEMORY_GROWTH=1 Allow for dynamic memory access
# -s DEMANGLE_SUPPORT=1 Demangle stack traces, that is, emit human-readable C++ function names instead of _ZN.. ones
# -s TOTAL_MEMORY=x Embed larger memory up front (default is 16777216... 33554432, 67108864, 134217728, 268435456
#
# --bind Allows javascript code to call c++ functions
# --closure 1 Turn on Googles closure compiler, reduces code size and improves javascript code
# --memory-init-file 0 Embed the usually external .mem file generated along side .js file
# --preload-file assets/shapes.png Include file in compiled code, allows access to files in simulated local filesystem
# --embed-file assets/shapes.png Embed file in compiled code, also allows access through simulated filesystem (not compatible yet with sokol_app)
#
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-fno-exceptions -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s TOTAL_MEMORY=134217728 -s WASM=1 -std=c++11 --bind")# -s ASSERTIONS=1")
####################################################################################
elseif (EXPORT_TARGET MATCHES "android")
### TODO ###
####################################################################################
elseif (EXPORT_TARGET MATCHES "windows")
### Don't need to do anything for MSVC compiler on Windows ###
####################################################################################
elseif (EXPORT_TARGET MATCHES "linux")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
### TODO ###
endif()