]> git.lizzy.rs Git - nothing.git/blob - CMakeLists.txt
Merge pull request #1042 from tsoding/999
[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.h
134   src/math/pi.h
135   src/math/point.c
136   src/math/point.h
137   src/math/rand.c
138   src/math/rand.h
139   src/math/rect.c
140   src/math/rect.h
141   src/math/triangle.c
142   src/math/triangle.h
143   src/sdl/renderer.c
144   src/sdl/renderer.h
145   src/sdl/texture.h
146   src/sdl/texture.c
147   src/ui/console.c
148   src/ui/console.h
149   src/ui/console_log.c
150   src/ui/console_log.h
151   src/ui/edit_field.c
152   src/ui/edit_field.h
153   src/ui/history.c
154   src/ui/history.h
155   src/ui/list_selector.h
156   src/ui/list_selector.c
157   src/ui/wiggly_text.h
158   src/ui/wiggly_text.c
159   src/ui/slider.h
160   src/ui/slider.c
161   src/game/level_metadata.h
162   src/game/level_metadata.c
163   src/game/level/level_editor.h
164   src/game/level/level_editor.c
165   src/game/level/level_editor/color_picker.h
166   src/game/level/level_editor/color_picker.c
167   src/game/level/level_editor/rect_layer.h
168   src/game/level/level_editor/rect_layer.c
169   src/game/level/level_editor/layer_picker.h
170   src/game/level/level_editor/layer_picker.c
171   src/game/level/level_editor/point_layer.h
172   src/game/level/level_editor/point_layer.c
173   src/game/level/level_editor/player_layer.h
174   src/game/level/level_editor/player_layer.c
175   src/game/level/level_editor/layer.h
176   src/game/level/level_editor/layer.c
177   src/game/level/level_editor/label_layer.c
178   src/game/level/level_editor/label_layer.h
179   src/game/level/level_editor/background_layer.c
180   src/game/level/level_editor/background_layer.h
181   src/game/level/level_editor/undo_history.h
182   src/game/level/level_editor/undo_history.c
183 )
184 target_link_libraries(nothing ${SDL2_LIBRARIES} system ebisp)
185
186 add_executable(repl
187   src/ebisp/repl.c
188   src/ebisp/repl_runtime.c
189   )
190 target_link_libraries(repl ${SDL2_LIBRARIES} system ebisp)
191
192 add_executable(nothing_test
193   test/main.c
194   test/test.h
195   test/tokenizer_suite.h
196   )
197 target_link_libraries(nothing_test ${SDL2_LIBRARIES} system ebisp)
198
199 if(("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang"))
200   set(CMAKE_C_FLAGS
201     "${CMAKE_C_FLAGS} \
202      -Wall \
203      -Werror \
204      -Wextra \
205      -Wconversion \
206      -Wunused \
207      -Wunused-function \
208      -Wunused-label \
209      -Wunused-macros \
210      -Wunused-parameter \
211      -Wunused-value \
212      -Wunused-variable \
213      -Wcast-align \
214      -Wcast-qual \
215      -Wmissing-declarations \
216      -Wredundant-decls \
217      -Wmissing-prototypes \
218      -Wnested-externs \
219      -Wpointer-arith \
220      -Wshadow \
221      -Wstrict-prototypes \
222      -Wwrite-strings \
223      -Wswitch \
224      -Wmissing-field-initializers \
225      -fno-common \
226            -fno-strict-aliasing \
227      -pedantic \
228      -std=c11 \
229      -ggdb \
230      -O3")
231   target_link_libraries(nothing m)
232 elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
233   set(CMAKE_C_FLAGS
234     "${CMAKE_C_FLAGS} \
235     /Wall \
236     /WX \
237     /wd4127 \
238     /wd4201 \
239     /wd4204 \
240     /wd4255 \
241     /wd4389 \
242     /wd4668 \
243     /wd4702 \
244     /wd4710 \
245     /wd4777 \
246     /wd4820 \
247     /wd5045 \
248     /D \"_CRT_SECURE_NO_WARNINGS\"")
249 endif()
250 if(MINGW)
251   target_link_libraries(nothing hid setupapi Imm32 Version winmm)
252 elseif(WIN32)
253   target_link_libraries(nothing Imm32 Version winmm)
254 endif()
255
256 file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test-data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})