]> git.lizzy.rs Git - nothing.git/blob - CMakeLists.txt
Merge pull request #1026 from tsoding/1010
[nothing.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.2)
2 project(nothing)
3
4 if(WIN32)
5   if(MINGW)
6     add_compile_definitions(SDL_MAIN_HANDLED) # https://stackoverflow.com/a/25089610
7     add_compile_definitions(__USE_MINGW_ANSI_STDIO) # https://github.com/trink/symtseries/issues/49#issuecomment-160843756
8     # Support both 32 and 64 bit builds
9     if (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
10       set(SDL2_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/SDL2/x86_64-w64-mingw32/include/SDL2")
11       set(SDL2_LIBRARIES "${CMAKE_SOURCE_DIR}/SDL2/x86_64-w64-mingw32/lib/libSDL2.a;${CMAKE_SOURCE_DIR}/SDL2/x86_64-w64-mingw32/lib/libSDL2main.a")
12     else()
13       set(SDL2_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/SDL2/i686-w64-mingw32/include/SDL2")
14       set(SDL2_LIBRARIES "${CMAKE_SOURCE_DIR}/SDL2/i686-w64-mingw32/lib/libSDL2.a;${CMAKE_SOURCE_DIR}/SDL2/i686-w64-mingw32/lib/libSDL2main.a")
15     endif()
16           
17   else()
18     set(SDL2_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/SDL2/include")
19
20     # Support both 32 and 64 bit builds
21     if (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
22       set(SDL2_LIBRARIES "${CMAKE_SOURCE_DIR}/SDL2/lib/x64/SDL2.lib;${CMAKE_SOURCE_DIR}/SDL2/lib/x64/SDL2main.lib")
23     else()
24       set(SDL2_LIBRARIES "${CMAKE_SOURCE_DIR}/SDL2/lib/x86/SDL2.lib;${CMAKE_SOURCE_DIR}/SDL2/lib/x86/SDL2main.lib")
25     endif()
26
27   endif()
28   string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)
29   
30 else()
31   find_package(SDL2 REQUIRED)
32 endif()
33
34 if("${SDL2_LIBRARIES}" STREQUAL "")
35     message(WARNING "SDL2_LIBRARIES wasn't set, manually setting to SDL2::SDL2")
36     set(SDL2_LIBRARIES "SDL2::SDL2")
37 endif()
38
39 include_directories(${CMAKE_BINARY_DIR})
40 include_directories(src/)
41
42 include_directories(${SDL2_INCLUDE_DIRS})
43
44 add_library(system STATIC
45   src/system/line_stream.c
46   src/system/line_stream.h
47   src/system/log.c
48   src/system/log.h
49   src/system/log_script.c
50   src/system/log_script.h
51   src/system/lt.h
52   src/system/lt_adapters.h
53   src/system/lt_adapters.c
54   src/system/nth_alloc.c
55   src/system/nth_alloc.h
56   src/system/stacktrace.c
57   src/system/stacktrace.h
58   src/system/str.c
59   src/system/str.h
60   src/dynarray.h
61   src/dynarray.c
62   src/hashset.h
63   src/hashset.c
64   src/system/file.h
65   src/system/file.c
66   )
67
68 add_library(ebisp STATIC
69   src/ebisp/builtins.c
70   src/ebisp/builtins.h
71   src/ebisp/expr.c
72   src/ebisp/expr.h
73   src/ebisp/gc.c
74   src/ebisp/gc.h
75   src/ebisp/interpreter.c
76   src/ebisp/interpreter.h
77   src/ebisp/parser.c
78   src/ebisp/parser.h
79   src/ebisp/scope.c
80   src/ebisp/scope.h
81   src/ebisp/std.c
82   src/ebisp/std.h
83   src/ebisp/tokenizer.c
84   src/ebisp/tokenizer.h
85   )
86 target_link_libraries(ebisp system)
87
88 add_executable(nothing 
89   src/broadcast.c
90   src/broadcast.h
91   src/color.c
92   src/color.h
93   src/game.c
94   src/game.h
95   src/game/camera.c
96   src/game/camera.h
97   src/game/level.c
98   src/game/level.h
99   src/game/level/background.c
100   src/game/level/background.h
101   src/game/level/boxes.c
102   src/game/level/boxes.h
103   src/game/level/goals.c
104   src/game/level/goals.h
105   src/game/level/labels.c
106   src/game/level/labels.h
107   src/game/level/lava.c
108   src/game/level/lava.h
109   src/game/level/lava/wavy_rect.c
110   src/game/level/lava/wavy_rect.h
111   src/game/level/platforms.c
112   src/game/level/platforms.h
113   src/game/level/player.c
114   src/game/level/player.h
115   src/game/level/explosion.c
116   src/game/level/explosion.h
117   src/game/level/regions.c
118   src/game/level/regions.h
119   src/game/level/rigid_bodies.c
120   src/game/level/rigid_bodies.h
121   src/game/level/script.c
122   src/game/level/script.h
123   src/game/level_picker.c
124   src/game/level_picker.h
125   src/game/level_folder.h
126   src/game/level_folder.c
127   src/game/sound_samples.c
128   src/game/sound_samples.h
129   src/game/sprite_font.c
130   src/game/sprite_font.h
131   src/main.c
132   src/math/extrema.h
133   src/math/mat3x3.c
134   src/math/mat3x3.h
135   src/math/pi.h
136   src/math/point.c
137   src/math/point.h
138   src/math/rand.c
139   src/math/rand.h
140   src/math/rect.c
141   src/math/rect.h
142   src/math/triangle.c
143   src/math/triangle.h
144   src/sdl/renderer.c
145   src/sdl/renderer.h
146   src/sdl/texture.h
147   src/sdl/texture.c
148   src/ui/console.c
149   src/ui/console.h
150   src/ui/console_log.c
151   src/ui/console_log.h
152   src/ui/edit_field.c
153   src/ui/edit_field.h
154   src/ui/history.c
155   src/ui/history.h
156   src/ui/list_selector.h
157   src/ui/list_selector.c
158   src/ui/wiggly_text.h
159   src/ui/wiggly_text.c
160   src/ui/slider.h
161   src/ui/slider.c
162   src/game/level_metadata.h
163   src/game/level_metadata.c
164   src/game/level/level_editor.h
165   src/game/level/level_editor.c
166   src/game/level/level_editor/color_picker.h
167   src/game/level/level_editor/color_picker.c
168   src/game/level/level_editor/rect_layer.h
169   src/game/level/level_editor/rect_layer.c
170   src/game/level/level_editor/layer_picker.h
171   src/game/level/level_editor/layer_picker.c
172   src/game/level/level_editor/point_layer.h
173   src/game/level/level_editor/point_layer.c
174   src/game/level/level_editor/player_layer.h
175   src/game/level/level_editor/player_layer.c
176   src/game/level/level_editor/layer.h
177   src/game/level/level_editor/layer.c
178   src/game/level/level_editor/label_layer.c
179   src/game/level/level_editor/label_layer.h
180   src/game/level/level_editor/background_layer.c
181   src/game/level/level_editor/background_layer.h
182   src/game/level/level_editor/undo_history.h
183   src/game/level/level_editor/undo_history.c
184 )
185 target_link_libraries(nothing ${SDL2_LIBRARIES} system ebisp)
186
187 add_executable(repl
188   src/ebisp/repl.c
189   src/ebisp/repl_runtime.c
190   )
191 target_link_libraries(repl ${SDL2_LIBRARIES} system ebisp)
192
193 add_executable(nothing_test
194   test/main.c
195   test/test.h
196   test/tokenizer_suite.h
197   )
198 target_link_libraries(nothing_test ${SDL2_LIBRARIES} system ebisp)
199
200 if(("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang"))
201   set(CMAKE_C_FLAGS
202     "${CMAKE_C_FLAGS} \
203      -Wall \
204      -Werror \
205      -Wextra \
206      -Wconversion \
207      -Wunused \
208      -Wunused-function \
209      -Wunused-label \
210      -Wunused-macros \
211      -Wunused-parameter \
212      -Wunused-value \
213      -Wunused-variable \
214      -Wcast-align \
215      -Wcast-qual \
216      -Wmissing-declarations \
217      -Wredundant-decls \
218      -Wmissing-prototypes \
219      -Wnested-externs \
220      -Wpointer-arith \
221      -Wshadow \
222      -Wstrict-prototypes \
223      -Wwrite-strings \
224      -Wswitch \
225      -Wmissing-field-initializers \
226      -fno-common \
227            -fno-strict-aliasing \
228      -pedantic \
229      -std=c11 \
230      -ggdb \
231      -O3")
232   target_link_libraries(nothing m)
233 elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
234   set(CMAKE_C_FLAGS
235     "${CMAKE_C_FLAGS} \
236     /Wall \
237     /WX \
238     /wd4127 \
239     /wd4201 \
240     /wd4204 \
241     /wd4255 \
242     /wd4389 \
243     /wd4668 \
244     /wd4702 \
245     /wd4710 \
246     /wd4777 \
247     /wd4820 \
248     /wd5045 \
249     /D \"_CRT_SECURE_NO_WARNINGS\"")
250 endif()
251 if(MINGW)
252   target_link_libraries(nothing hid setupapi Imm32 Version winmm)
253 elseif(WIN32)
254   target_link_libraries(nothing Imm32 Version winmm)
255 endif()
256
257 file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test-data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})