-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
143 lines (109 loc) · 3.94 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
cmake_minimum_required(VERSION 3.5.1)
project(lornock_game)
#
# Vendored code
#
file(GLOB GLAD_INCLUDE_DIRS vendor/glad/include)
file(GLOB GLAD_SOURCES vendor/glad/src/glad.c)
file(GLOB STB_IMAGE_INCLUDE_DIRS vendor/stb)
file(GLOB HANDMADE_MATH_INCLUDE_DIRS vendor/HandmadeMath)
#
# Lornock game code (liblornock.so/lornock.dll)
#
file(GLOB LIB_SOURCES
src/lornock.cpp)
add_library(lornock SHARED
${GLAD_SOURCES}
${LIB_SOURCES})
target_include_directories(lornock PRIVATE
src
${STB_IMAGE_INCLUDE_DIRS}
${HANDMADE_MATH_INCLUDE_DIRS})
#
# Lornock runner (game/game.exe)
#
# Put source files in this glob
file(GLOB GAME_SOURCES
src/sdl_main.cpp
${GLAD_SOURCES})
add_executable(game ${GAME_SOURCES})
include_directories(
src
${GLAD_INCLUDE_DIRS})
#
# Handle assets
#
set(DATA_FILES
data/shaders/default.vert
data/shaders/default.frag
data/shaders/depth.vert
data/shaders/depth.frag
data/shaders/particle.vert
data/shaders/particle.frag
# 2D
data/shaders/rectangle.vert
data/shaders/rectangle.frag
data/shaders/sprite.vert
data/shaders/sprite.frag
data/shaders/text.vert
data/shaders/text.frag
data/font/quicksand_regular.png
data/font/quicksand_regular.fnt
data/font/renogare.png
data/font/renogare.fnt
data/mesh/rock.obj
data/mesh/coal.obj
data/img/particle.png
data/img/particle_color_map_red.png
data/img/particle_color_map_blue.png
data/img/particle_color_map_white.png
data/img/player.png
data/img/rock.png
data/img/rock_albedo.png
data/img/rock_icon.png
data/img/coal_albedo.png
data/img/coal_icon.png
data/img/test.png)
foreach(DATA_FILE ${DATA_FILES})
set(DATA_IN ${CMAKE_CURRENT_SOURCE_DIR}/${DATA_FILE})
set(DATA_OUT ${CMAKE_CURRENT_BINARY_DIR}/${DATA_FILE})
# If the file at DATA_IN does not exist or is changed, copy it into the build directory
configure_file(${DATA_IN} ${DATA_OUT} COPYONLY)
endforeach(DATA_FILE)
# Runs if building for a native platform (currently only Linux)
if ((WIN32 OR (UNIX AND NOT APPLE)) AND NOT EMSCRIPTEN)
# TODO(harrison): figure out exactly what this is for...
if(NOT WIN32)
set(GLAD_LIBRARIES dl)
# We use a bit of a basterdised version of C++11, but it's C++11 no less
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -g -Wall -Werror")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
find_package(SDL2 REQUIRED)
include_directories(game ${SDL2_INCLUDE_DIR})
target_link_libraries(game ${SDL2_LIBRARY}
${GLAD_LIBRARIES})
#[[
# FIXME(harrison): I've disabled Emscripten builds until I get native builds working.
elseif(EMSCRIPTEN)
# Runs if building for Emscripten (web)
# Modified excerpt from https://discourse.libsdl.org/t/sdl2-desktop-bridge-emscripten-questions/22632/2
# Make emscripten output a html page instead of just the javascript (for easier testing).
set(CMAKE_EXECUTABLE_SUFFIX ".html")
# Using SDL2 and SDL2_image
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s USE_SDL_TTF=2 --std=c++11")
# Get SDL2_image to use PNGs
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s SDL2_IMAGE_FORMATS='[\"png\"]'")
# Use O2 optimisation level (makes a .mem file)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O2")
# Use assets folder
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --preload-file assets")
# Another option you can try if having trouble with loading images:
# https://groups.google.com/forum/#!topic/emscripten-discuss/0qxtF7zyG0s
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s STB_IMAGE=1")
# Might need to play around with this if emscripten gives errors saying your program is too big.
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s TOTAL_MEMORY=67108864")
]]
else()
message(FATAL_ERROR "Platform not supported")
endif()