]> git.lizzy.rs Git - nothing.git/blob - CMakeLists.txt
Merge pull request #1255 from tsoding/1253
[nothing.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.13)
2 project(nothing)
3
4 set(NOTHING_CI OFF CACHE BOOL "Indicates whether the build is running on CI or not")
5
6 if(WIN32)
7   # do the flags thing first.
8   if(MINGW)
9     add_compile_definitions(SDL_MAIN_HANDLED) # https://stackoverflow.com/a/25089610
10     add_compile_definitions(__USE_MINGW_ANSI_STDIO) # https://github.com/trink/symtseries/issues/49#issuecomment-160843756
11   endif()
12
13   # then try to find SDL2 using normal means (eg. the user may have installed SDL2 using pacman on msys2)
14   # note we don't use REQUIRED here, because it can fail -- in which case we fall back to looking for the 
15   # library "directly" using local files.
16   find_package(SDL2 QUIET)
17   if(NOT SDL2_FOUND)
18     if(MINGW)
19       # Support both 32 and 64 bit builds
20       if (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
21         set(SDL2_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/SDL2/x86_64-w64-mingw32/include/SDL2")
22         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")
23       else()
24         set(SDL2_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/SDL2/i686-w64-mingw32/include/SDL2")
25         set(SDL2_LIBRARIES "${CMAKE_SOURCE_DIR}/SDL2/i686-w64-mingw32/lib/libSDL2.a;${CMAKE_SOURCE_DIR}/SDL2/i686-w64-mingw32/lib/libSDL2main.a")
26       endif()
27     else()
28       set(SDL2_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/SDL2/include")
29
30       # Support both 32 and 64 bit builds
31       if (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
32         set(SDL2_LIBRARIES "${CMAKE_SOURCE_DIR}/SDL2/lib/x64/SDL2.lib;${CMAKE_SOURCE_DIR}/SDL2/lib/x64/SDL2main.lib")
33       else()
34         set(SDL2_LIBRARIES "${CMAKE_SOURCE_DIR}/SDL2/lib/x86/SDL2.lib;${CMAKE_SOURCE_DIR}/SDL2/lib/x86/SDL2main.lib")
35       endif()
36     endif()
37     string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)
38   endif()
39 else()
40   find_package(SDL2 REQUIRED)
41 endif()
42
43 if("${SDL2_LIBRARIES}" STREQUAL "")
44     message(WARNING "SDL2_LIBRARIES wasn't set, manually setting to SDL2::SDL2")
45     set(SDL2_LIBRARIES "SDL2::SDL2")
46 endif()
47
48 include_directories(${CMAKE_BINARY_DIR})
49 include_directories(src/)
50
51 include_directories(${SDL2_INCLUDE_DIRS})
52
53 add_executable(nothing 
54   src/color.h
55   src/color.c
56   src/game.h
57   src/game.c
58   src/game/camera.h
59   src/game/camera.c
60   src/game/level.h
61   src/game/level.c
62   src/game/level/background.h
63   src/game/level/background.c
64   src/game/level/boxes.h
65   src/game/level/boxes.c
66   src/game/level/goals.h
67   src/game/level/goals.c
68   src/game/level/labels.h
69   src/game/level/labels.c
70   src/game/level/lava.h
71   src/game/level/lava.c
72   src/game/level/lava/wavy_rect.h
73   src/game/level/lava/wavy_rect.c
74   src/game/level/platforms.h
75   src/game/level/platforms.c
76   src/game/level/phantom_platforms.h
77   src/game/level/phantom_platforms.c
78   src/game/level/player.h
79   src/game/level/player.c
80   src/game/level/explosion.h
81   src/game/level/explosion.c
82   src/game/level/regions.h
83   src/game/level/regions.c
84   src/game/level/rigid_bodies.h
85   src/game/level/rigid_bodies.c
86   src/game/level/action.h
87   src/game/level_picker.h
88   src/game/level_picker.c
89   src/game/credits.h
90   src/game/credits.c
91   src/game/settings.h
92   src/game/settings.c
93   src/game/sound_samples.h
94   src/game/sound_samples.c
95   src/game/sprite_font.h
96   src/game/sprite_font.c
97   src/main.c
98   src/math/extrema.h
99   src/math/mat3x3.h
100   src/math/pi.h
101   src/math/vec.h
102   src/math/rand.h
103   src/math/rand.c
104   src/math/rect.h
105   src/math/rect.c
106   src/math/triangle.h
107   src/math/triangle.c
108   src/sdl/renderer.h
109   src/sdl/renderer.c
110   src/sdl/texture.h
111   src/sdl/texture.c
112   src/ui/cursor.c
113   src/ui/cursor.h
114   src/ui/console.h
115   src/ui/console.c
116   src/ui/console_log.h
117   src/ui/console_log.c
118   src/ui/edit_field.h
119   src/ui/edit_field.c
120   src/ui/history.h
121   src/ui/history.c
122   src/ui/wiggly_text.h
123   src/ui/wiggly_text.c
124   src/ui/slider.h
125   src/ui/slider.c
126   src/game/level/level_editor.h
127   src/game/level/level_editor.c
128   src/game/level/level_editor/color_picker.h
129   src/game/level/level_editor/color_picker.c
130   src/game/level/level_editor/rect_layer.h
131   src/game/level/level_editor/rect_layer.c
132   src/game/level/level_editor/layer_picker.h
133   src/game/level/level_editor/layer_picker.c
134   src/game/level/level_editor/point_layer.h
135   src/game/level/level_editor/point_layer.c
136   src/game/level/level_editor/player_layer.h
137   src/game/level/level_editor/player_layer.c
138   src/game/level/level_editor/layer.h
139   src/game/level/level_editor/layer.c
140   src/game/level/level_editor/label_layer.h
141   src/game/level/level_editor/label_layer.c
142   src/game/level/level_editor/background_layer.h
143   src/game/level/level_editor/background_layer.c
144   src/game/level/level_editor/undo_history.h
145   src/game/level/level_editor/undo_history.c
146   src/system/log.h
147   src/system/log.c
148   src/system/lt.h
149   src/system/lt_adapters.h
150   src/system/lt_adapters.c
151   src/system/nth_alloc.h
152   src/system/nth_alloc.c
153   src/system/stacktrace.h
154   src/system/stacktrace.c
155   src/system/str.h
156   src/system/str.c
157   src/dynarray.h
158   src/dynarray.c
159   src/system/file.h
160   src/system/file.c
161   src/ring_buffer.h
162   src/ring_buffer.c
163 )
164 target_link_libraries(nothing ${SDL2_LIBRARIES})
165
166 if(WIN32)
167     ADD_CUSTOM_TARGET(link_assets ALL COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/assets ${CMAKE_BINARY_DIR}/assets)
168 else()
169     ADD_CUSTOM_TARGET(link_assets ALL COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/assets ${CMAKE_BINARY_DIR}/assets)
170 endif()
171
172 if(("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang"))
173   set(CMAKE_C_FLAGS
174     "${CMAKE_C_FLAGS} \
175      -Wall \
176      -Wextra \
177      -Wconversion \
178      -Wunused \
179      -Wunused-function \
180      -Wunused-label \
181      -Wunused-macros \
182      -Wunused-parameter \
183      -Wunused-value \
184      -Wunused-variable \
185      -Wcast-align \
186      -Wcast-qual \
187      -Wmissing-declarations \
188      -Wredundant-decls \
189      -Wmissing-prototypes \
190      -Wnested-externs \
191      -Wpointer-arith \
192      -Wshadow \
193      -Wstrict-prototypes \
194      -Wwrite-strings \
195      -Wswitch \
196      -Wmissing-field-initializers \
197      -fno-common \
198      -fno-strict-aliasing \
199      -pedantic \
200      -std=c11 \
201      -ggdb \
202      -O3")
203   if (${NOTHING_CI})
204      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
205   endif()
206   target_link_libraries(nothing m)
207 elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
208   set(CMAKE_C_FLAGS
209     "${CMAKE_C_FLAGS} \
210     /Wall \
211     /wd4127 \
212     /wd4201 \
213     /wd4204 \
214     /wd4255 \
215     /wd4389 \
216     /wd4668 \
217     /wd4702 \
218     /wd4710 \
219     /wd4777 \
220     /wd4820 \
221     /wd5045 \
222     /wd4200 \
223     /wd4706 \
224     /D \"_CRT_SECURE_NO_WARNINGS\"")
225   if (${NOTHING_CI})
226      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
227   endif()
228 endif()
229 if(MINGW)
230   target_link_libraries(nothing hid setupapi Imm32 Version winmm)
231 elseif(WIN32)
232   target_link_libraries(nothing Imm32 Version winmm)
233 endif()