-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
322 lines (301 loc) · 10.9 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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
cmake_minimum_required(VERSION 3.16.3)
project(SdlFramework)
function(config_linux TARGET_NAME)
message("Linux enviroment for " ${TARGET_NAME})
target_compile_definitions(${TARGET_NAME} PRIVATE
USE_OPENGL
_LINUX)
# static, pkg-config --libs sdl2 glew --static --cflags
# target_link_libraries(${TARGET_NAME} #${CMAKE_DL_LIBS} -lGLEW -lSDL2 -Wl,--no-undefined -lm -ldl -lasound -lm -ldl -lpthread -lpulse-simple -lpulse -lX11 -lXext -lXcursor -lXinerama -lXi -lXrandr -lXss -lXxf86vm -lwayland-egl -lwayland-client -lwayland-cursor -lxkbcommon -lpthread -lrt -lGLU -lm -lGL)
target_link_libraries(${TARGET_NAME} # dynamic
SDL2
GLEW
GLU
GL)
endfunction()
function(config_windows TARGET_NAME)
if(MINGW) # if using mingw, automaticlly have this
message("MINGW enviroment for ${TARGET_NAME}, type ${CMAKE_BUILD_TYPE}")
target_compile_definitions(${TARGET_NAME} PRIVATE
USE_OPENGL
_LINUX)
target_link_options(${TARGET_NAME} PRIVATE
-static-libgcc # static link mingw env
-static-libstdc++)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
message("generating debug configuration")
target_compile_definitions(${TARGET_NAME} PRIVATE _DEBUG)
target_compile_options(${TARGET_NAME} PRIVATE -g)
target_link_options(${TARGET_NAME} PRIVATE "-Wl,-subsystem,console")
else()
target_link_options(${TARGET_NAME} PRIVATE "-Wl,-subsystem,windows")
endif()
target_link_libraries(${TARGET_NAME} # static links
-Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive
-Wl,-Bstatic
mingw32
SDL2main
SDL2
glew32
opengl32)
target_link_libraries(${TARGET_NAME} # dynamic links
-Wl,-Bdynamic
dinput8 shell32 setupapi advapi32 uuid version oleaut32 ole32
imm32 winmm gdi32 user32)
else() # msvc, clang-cl
set(SDL2_DIR ${EXTERN_LIB_DIR}/SDL2-2.0.14)
set(GLM_DIR ${EXTERN_LIB_DIR}/glm-0.9.9)
set(GLEW_DIR ${EXTERN_LIB_DIR}/glew-2.1.0)
message("Windows enviroment for " ${TARGET_NAME})
target_compile_definitions(${TARGET_NAME} PRIVATE USE_OPENGL)
target_include_directories(${TARGET_NAME} PRIVATE
${SDL2_DIR}/include
${GLM_DIR}/
${GLEW_DIR}/include)
if(CMAKE_C_COMPILER MATCHES "clang") #can not use directory -DCMAKE_EXE_LINKER_FLAGS, as some example compile test fail
message("using clang to build!")
if(CMAKE_BUILD_TYPE MATCHES "Debug")
target_link_options(${TARGET_NAME} PRIVATE "-Wl,-subsystem:console")
else()
target_link_options(${TARGET_NAME} PRIVATE "-Wl,-subsystem:windows")
endif()
endif()
if(CMAKE_GENERATOR_PLATFORM MATCHES "x64")
message("adding win64 libs to " ${TARGET_NAME})
target_link_directories(${TARGET_NAME} PRIVATE
${SDL2_DIR}/lib/x64
${GLEW_DIR}/lib/Release/x64)
set(SDL2_DLL_PATH ${SDL2_DIR}/lib/x64/SDL2.dll)
message(${SDL2_DLL_PATH}, ${SDL2_DIR})
else() # x86
message("adding win32 libs to " ${TARGET_NAME})
target_link_directories(${TARGET_NAME} PRIVATE
${SDL2_DIR}/lib/x86
${GLEW_DIR}/lib/Release/win32)
set(SDL2_DLL_PATH ${SDL2_DIR}/lib/x86/SDL2.dll)
endif()
target_link_libraries(${TARGET_NAME}
SDL2.lib
SDL2main.lib
glew32s.lib
opengl32.lib)
install(FILES
${SDL2_DLL_PATH}
DESTINATION ${CMAKE_BINARY_DIR}/Release)
install(FILES
${SDL2_DLL_PATH}
DESTINATION ${CMAKE_BINARY_DIR}/Debug)
install(FILES
${SDL2_DLL_PATH}
DESTINATION ${CMAKE_BINARY_DIR}/) # for clang with ninja
endif()
endfunction()
function(config_psv TARGET_NAME)
message("PSV enviroment for " ${TARGET_NAME}
", titleid=" ${VITA_TITLEID}
", version=" ${VITA_VERSION})
include("$ENV{VITASDK}/share/vita.cmake" REQUIRED)
set(VITA_APP_NAME ${TARGET_NAME})
if(NOT DEFINED VITA_TITLEID)
set(VITA_TITLEID "DEVAPPTMP")
endif()
if(NOT DEFINED VITA_VERSION)
set(VITA_VERSION "01.00")
endif()
target_compile_definitions(${TARGET_NAME} PRIVATE
_LINUX
_PSV
)
target_include_directories(${TARGET_NAME} PRIVATE
$ENV{VITASDK}/share/gcc-arm-vita-eabi/samples/common
)
set(SDL_LIBS
stdc++
SDL2_ttf
freetype
png
z
c
SDL2 # must have these functions under SDL2
SceGxm_stub
SceDisplay_stub
SceCtrl_stub
SceAppMgr_stub
SceAppUtil_stub
SceAudio_stub
SceAudioIn_stub
SceSysmodule_stub
SceIofilemgr_stub
SceCommonDialog_stub
SceTouch_stub
SceHid_stub
SceMotion_stub
ScePower_stub
SceProcessmgr_stub
SceMotion_stub
m
)
set(GL_LIBS
vitaGL
SceIme_stub
SceGxm_stub
vitashark
mathneon
SceShaccCg_stub
SceShaccCgExt
SceKernelDmacMgr_stub
taihen_stub
)
if(${TARGET_NAME} MATCHES gl_)
target_compile_definitions(${TARGET_NAME} PRIVATE
USE_OPENGL
)
endif()
target_link_libraries(${TARGET_NAME}
${SDL_LIBS}
${GL_LIBS}
)
vita_create_self(${TARGET_NAME}.self ${TARGET_NAME})
vita_create_vpk(${TARGET_NAME}.vpk ${VITA_TITLEID} ${TARGET_NAME}.self
VERSION ${VITA_VERSION}
NAME ${VITA_APP_NAME}
FILE src/shader/phong.frag assets/phong.frag
FILE src/shader/phong.vert assets/phong.vert
FILE src/shader/debug_light.frag assets/debug_light.frag
FILE src/shader/debug_light.vert assets/debug_light.vert
FILE assets/misuzu.png assets/misuzu.png
FILE assets/psv_icon.png sce_sys/icon0.png
FILE assets/psv_bg.png sce_sys/livearea/contents/bg.png
FILE assets/psv_startup.png sce_sys/livearea/contents/startup.png
FILE assets/psv_template.xml sce_sys/livearea/contents/template.xml
FILE assets/default.ttf default.ttf
)
endfunction()
function(config_web TARGET_NAME)
message("Web enviroment for " ${TARGET_NAME})
# pass flags for emcc
set(EMCC_FLAGS "-sUSE_SDL=2 -o ${TARGET_NAME}.js")
if (${TARGET_NAME} MATCHES gl)
set(EMCC_FLAGS "${EMCC_FLAGS} -sFULL_ES3 -sMIN_WEBGL_VERSION=2")
set(EMCC_FLAGS "${EMCC_FLAGS} -sFORCE_FILESYSTEM --preload-file=${CMAKE_BINARY_DIR}/assets@assets")
target_compile_definitions(${TARGET_NAME} PRIVATE USE_OPENGL)
endif()
set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS ${EMCC_FLAGS})
target_include_directories(${TARGET_NAME} PRIVATE
${PROJECT_SOURCE_DIR}/externlib/glm)
target_compile_definitions(${TARGET_NAME} PRIVATE
_WEB
_LINUX)
target_link_libraries(${TARGET_NAME}
SDL2
GL)
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E
copy ${CMAKE_SOURCE_DIR}/src/example/*.html ${CMAKE_BINARY_DIR})
endfunction()
function(config_platform TARGET_NAME)
# extern lib path
set(EXTERN_LIB_DIR ${PROJECT_SOURCE_DIR}/externlib)
set(STB_DIR ${EXTERN_LIB_DIR}/stb)
# common extern include path
target_include_directories(${TARGET_NAME} PRIVATE ${STB_DIR})
message("system ${CMAKE_SYSTEM_NAME}, toolchain ${CMAKE_TOOLCHAIN_FILE}")
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
config_linux(${TARGET_NAME})
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
config_windows(${TARGET_NAME})
elseif(CMAKE_TOOLCHAIN_FILE MATCHES "vita")
config_psv(${TARGET_NAME})
elseif(CMAKE_SYSTEM_NAME MATCHES "Emscripten")
config_web(${TARGET_NAME})
endif()
endfunction()
function(copy_assets TARGET_NAME)
add_custom_command(TARGET ${TARGET_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E
copy_directory ${CMAKE_SOURCE_DIR}/src/shader ${CMAKE_BINARY_DIR}/assets
COMMAND ${CMAKE_COMMAND} -E
copy_directory ${CMAKE_SOURCE_DIR}/assets ${CMAKE_BINARY_DIR}/assets
COMMAND ${CMAKE_COMMAND} -E
copy_directory ${CMAKE_SOURCE_DIR}/src/shader ${CMAKE_BINARY_DIR}/Release/assets
COMMAND ${CMAKE_COMMAND} -E
copy_directory ${CMAKE_SOURCE_DIR}/assets ${CMAKE_BINARY_DIR}/Release/assets
COMMAND ${CMAKE_COMMAND} -E
copy_directory ${CMAKE_SOURCE_DIR}/src/shader ${CMAKE_BINARY_DIR}/Debug/assets
COMMAND ${CMAKE_COMMAND} -E
copy_directory ${CMAKE_SOURCE_DIR}/assets ${CMAKE_BINARY_DIR}/Debug/assets)
endfunction()
message("This is a simple sdl framework demo")
set(CMAKE_CXX_STANDARD 11)
set(SDL_FRAMEWORK_CODE
src/sdl_util.h
src/sdl_util.c
src/sdl_framework.hpp
src/sdl_framework.cpp
src/sdl_object2d.hpp
src/sdl_object2d.cpp
src/data_types.hpp
src/physics_object.hpp
src/physics_object.cpp)
set(GL_FRAMEWORK_CODE
src/gl_util.h
src/gl_util.c
src/gl_scene.hpp
src/gl_scene.cpp
src/gl_layers.hpp
src/gl_layers.cpp
src/gl_assets.hpp
src/gl_assets.cpp
src/gl_object3d.hpp
src/gl_object3d.cpp)
# simple circle
set(DEMO_NAME circle_one)
add_executable(${DEMO_NAME}
src/example/${DEMO_NAME}.cpp
${SDL_FRAMEWORK_CODE}
${GL_FRAMEWORK_CODE})
target_include_directories(${DEMO_NAME} PRIVATE
${PROJECT_SOURCE_DIR}/src)
config_platform(${DEMO_NAME})
# circle collision
set(DEMO_NAME circle_collision)
add_executable(${DEMO_NAME}
src/example/${DEMO_NAME}.cpp
${SDL_FRAMEWORK_CODE})
target_include_directories(${DEMO_NAME} PRIVATE
${PROJECT_SOURCE_DIR}/src)
config_platform(${DEMO_NAME})
# circle danmaku
set(DEMO_NAME circle_danmaku)
add_executable(${DEMO_NAME}
src/example/${DEMO_NAME}.cpp
${SDL_FRAMEWORK_CODE})
target_include_directories(${DEMO_NAME} PRIVATE
${PROJECT_SOURCE_DIR}/src)
set(VITA_TITLEID "DEVAPP001")
set(VITA_VERSION "01.00")
config_platform(${DEMO_NAME})
# gl pbong demo
set(DEMO_NAME gl_phong_demo)
add_executable(${DEMO_NAME}
src/example/${DEMO_NAME}.cpp
${SDL_FRAMEWORK_CODE}
${GL_FRAMEWORK_CODE})
target_include_directories(${DEMO_NAME} PRIVATE
${PROJECT_SOURCE_DIR}/src)
set(VITA_TITLEID "DEVAPP002")
set(VITA_VERSION "01.00")
copy_assets(${DEMO_NAME})
config_platform(${DEMO_NAME})
# gl shadow demo
set(DEMO_NAME gl_shadow_demo)
add_executable(${DEMO_NAME}
src/example/${DEMO_NAME}.cpp
${SDL_FRAMEWORK_CODE}
${GL_FRAMEWORK_CODE})
target_include_directories(${DEMO_NAME} PRIVATE
${PROJECT_SOURCE_DIR}/src)
set(VITA_TITLEID "DEVAPP003")
set(VITA_VERSION "01.00")
copy_assets(${DEMO_NAME})
config_platform(${DEMO_NAME})