-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
288 lines (244 loc) · 9.18 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
# #########################################
# Initial config
# #########################################
set(LIBRARY_TARGET_NAME SupergoonEngine)
cmake_minimum_required(VERSION 3.16)
message(STATUS "Starting ${LIBRARY_TARGET_NAME} project initialization")
# set(CMAKE_EXPORT_COMPILE_COMMANDS 1) # This exports a file that clangd can use so that we know what compile/include flags so that we can use clangd language server properly with our cmake attributes.
include(FindPkgConfig)
project(${LIBRARY_TARGET_NAME} VERSION 0.1.0 LANGUAGES C)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# Adding PIC to enable linux builds test
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# #########################################
# File globbing
# #########################################
message(STATUS "Getting all files for cmake..")
file(GLOB_RECURSE ENGINE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/GoonEngine/*.c* ${CMAKE_CURRENT_SOURCE_DIR}/src/GoonPhysics/*.c*)
# #########################################
# Platform specific Project setup
# #########################################
message(STATUS "Changing the platform specific settings")
if(APPLE)
if(NOT IOS) # MACOS #
message(STATUS "Configuring Macos")
set(MACOS ON)
if(CMAKE_GENERATOR STREQUAL "Xcode")
# message(STATUS "Setting Build to Universal Binary")
# set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "" FORCE)
endif(CMAKE_GENERATOR STREQUAL "Xcode")
else()
# IOS
endif(NOT IOS)
elseif(WIN32)
message(STATUS "Configuring Windows")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} /c/cmake)
elseif(UNIX AND NOT APPLE)
message(STATUS "Configuring Linux")
set(LINUX ON)
endif(APPLE)
# Subdirectory things
# We want to skip installing freetype,etc, this is a var in their CMAKE file
set(SKIP_INSTALL_ALL ON)
# Don't build the png tests
set(PNG_TESTS OFF)
# #########################################
# Initialize
# #########################################
message(STATUS "Initializing the project")
message(STATUS "Adding subdirectories for engine")
# if(LINUX)
add_library(${LIBRARY_TARGET_NAME}
STATIC
${ENGINE_FILES}
)
# else()
# add_library(${LIBRARY_TARGET_NAME}
# SHARED
# ${ENGINE_FILES}
# )
# endif(LINUX)
set_property(TARGET ${LIBRARY_TARGET_NAME} PROPERTY C_STANDARD 11)
# find_package(PkgConfig REQUIRED)
find_package(ZLIB)
include(CTest)
# #########################################
# Options
# #########################################
option(CMAKE_DEBUG_VARIABLES "Runs a debug on all variables for troubleshooting" ON)
option(GOON_BUILD_PCH "Uses a PCH file to try and speed up compilation" ON)
option(GOON_DEBUG_SOUND "Builds sound from subdirectory instead of using a made package so we can debug" ON)
option(GOON_BUILD_TESTING "Should we enable testing with ctest" OFF)
set(BUILD_TESTING GOON_BUILD_TESTING) # Set the cmake variable build_testing to our option
# option(GOON_FULL_MACOS_BUILD "Full builds of all libraries, used for runners mostly, and passed in to override." OFF)
# #########################################
# Precompiled headers
# #########################################
if(GOON_BUILD_PCH)
message(STATUS "Setting up PCH, mac needs objc")
target_precompile_headers(${LIBRARY_TARGET_NAME} PRIVATE
"$<$<COMPILE_LANGUAGE:C>:${CMAKE_CURRENT_SOURCE_DIR}/include/GoonEngine/gnpch.h>")
endif(GOON_BUILD_PCH)
# #########################################
# Build Type specific setup
# #########################################
# If we are debug, we should use the local path, otherwise use the location of embuilder from the docker image
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(${LIBRARY_TARGET_NAME} PRIVATE -DGN_DEBUG_BUILD)
else()
target_compile_definitions(${LIBRARY_TARGET_NAME} PRIVATE -DGN_RELEASE_BUILD)
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
# #########################################
# Packages
# #########################################
# Have both of these already built, and then we find them.
# These should be added via subdir if not FULL BUILD
message("Going to do the thing.. macos is ${MACOS} and GOON_FULL_MACOS_BUILD is ${GOON_FULL_MACOS_BUILD}")
if(MACOS AND NOT GOON_FULL_MACOS_BUILD)
find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main)
find_library(LIB_PNG
REQUIRED
PATH_SUFFIXES .a
NAMES libpng png.a png.dll libpng.a
HINTS /usr/local/lib /c/cmake/lib)
find_library(LIB_FREETYPE
REQUIRED
PATH_SUFFIXES .a
NAMES libfreetype.a libfreetype.dll freetype.a freetype.dll freetype libfreetype
HINTS /usr/local/lib /c/cmake/lib)
add_subdirectory(./external/sg_sound)
else()
# Windows doesn't have zlib by default.
if(WIN32)
add_subdirectory(./external/zlib)
endif(WIN32)
if(NOT EMSCRIPTEN)
add_subdirectory(./external/freetype)
add_subdirectory(./external/libpng)
endif(NOT EMSCRIPTEN)
add_subdirectory(./external/sg_sound)
endif(MACOS AND NOT GOON_FULL_MACOS_BUILD)
# #########################################
# Platform Specific Build settings
# #########################################
message("Going to do the thing.. emscripten is is ${EMSCRIPTEN} and GOON_FULL_MACOS_BUILD is ${GOON_FULL_MACOS_BUILD}")
if(EMSCRIPTEN)
set_target_properties(${EXECUTABLE_TARGET_NAME} PROPERTIES LINK_FLAGS ${LINK_FLAGS} " -O0 -g -s SAFE_HEAP=2 -s STACK_OVERFLOW_CHECK=1 -sUSE_LIBPNG=1 -sUSE_FREETYPE=1 --preload-file ${CMAKE_SOURCE_DIR}/assets@/assets")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s 'DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[\"$autoResumeAudioContext\",\"$dynCall\"]'")
endif(EMSCRIPTEN)
# #########################################
# Compile Definitions
# #########################################
# Platform-specific compile definitions
target_compile_definitions(${LIBRARY_TARGET_NAME} PRIVATE
$<$<BOOL:${APPLE}>: -DGN_PLATFORM_MACOS>
$<$<BOOL:${WIN32}>: -DGN_PLATFORM_WINDOWS>
$<$<BOOL:${EMSCRIPTEN}>: -DGN_PLATFORM_EMSCRIPTEN>
$<$<BOOL:${LINUX}>: -DGN_PLATFORM_LINUX>
)
# Other compile definitions
target_compile_definitions(${LIBRARY_TARGET_NAME} PRIVATE
$<$<BOOL:${GOON_MULTITHREADED_SOUND}>: -DGN_MULTITHREADED>
$<$<BOOL:${GOON_DEBUG_LUA}>: -DGN_DEBUG_LUA>
$<$<BOOL:${GOON_BENCHMARKING}>: -DGN_BENCHMARKING_ENABLED>
)
# #########################################
# Debug
# #########################################
if(CMAKE_DEBUG_VARIABLES)
message(STATUS "Exporting debug")
get_cmake_property(_variableNames VARIABLES)
list(SORT _variableNames)
foreach(_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
endif(CMAKE_DEBUG_VARIABLES)
# #########################################
# Compile Options
# #########################################
set(FULL_COMPILE_OPTIONS
-Wall
-Wextra
-Wpedantic
-Wdeprecated
-Wno-newline-eof
-Wno-strict-prototypes
-Wno-sign-compare
-pthread
)
if(WIN32)
set(FULL_COMPILE_OPTIONS /std:c99)
elseif(EMSCRIPTEN)
target_compile_options(${EXECUTABLE_TARGET_NAME} PRIVATE -sUSE_LIBPNG=1 -sUSE_FREETYPE=1)
endif(WIN32)
target_compile_options(${LIBRARY_TARGET_NAME} PRIVATE ${FULL_COMPILE_OPTIONS})
# #########################################
# Linking Options
# #########################################
# set(LIBRARIES_TO_LINK
# SDL2::SDL2-static
# ZLIB::ZLIB
# freetype
# png
# supergoonSound::supergoonSound
# supergoonSound
# ${LIB_PNG}
# )
# foreach(LIBRARY ${LIBRARIES_TO_LINK})
# # Check if the target exists, if we are building it then we should link to it.
# if(TARGET ${LIBRARY})
# target_link_libraries(${LIBRARY_TARGET_NAME} PUBLIC ${LIBRARY})
# endif()
# endforeach()
if(EMSCRIPTEN OR(MACOS AND NOT GOON_FULL_MACOS_BUILD))
set(PNG_LIB_NAME png)
else()
set(PNG_LIB_NAME png_static)
endif(EMSCRIPTEN OR(MACOS AND NOT GOON_FULL_MACOS_BUILD))
target_link_libraries(${LIBRARY_TARGET_NAME}
PUBLIC
supergoonSound
freetype
${PNG_LIB_NAME}
${LIB_PNG}
${LIB_FREETYPE}
# testing
${LIB_VORBISFILE}
${LIB_VORBIS}
${LIB_OGG}
${OGG_LIBRARIES}
PRIVATE
)
if(NOT EMSCRIPTEN)
target_link_libraries(${LIBRARY_TARGET_NAME}
PUBLIC
SDL2::SDL2-static
vorbis vorbisenc vorbisfile ogg
)
endif(NOT EMSCRIPTEN)
target_link_directories(${LIBRARY_TARGET_NAME}
PRIVATE
/usr/local/lib
)
# libpng bs
add_compile_options(
"$<$<COMPILE_LANGUAGE:C>: -DPNG_ARM_NEON_OPT=0>"
"$<$<COMPILE_LANGUAGE:CXX>: -DPNG_ARM_NEON_OPT=0>"
)
target_include_directories(${LIBRARY_TARGET_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include/
${CMAKE_CURRENT_SOURCE_DIR}/external/freetype/include/
/usr/local/include
# Need both when not building (using emscripten)
/emsdk/upstream/emscripten/cache/sysroot/include
${CMAKE_CURRENT_SOURCE_DIR}/external/freetype/include/freetype/
${CMAKE_CURRENT_SOURCE_DIR}/external/libpng
${CMAKE_CURRENT_SOURCE_DIR}/external/
external/sg_sound/src/
${CMAKE_CURRENT_BINARY_DIR}/external/sg_engine/exteral/libpng
# Freetype cause yeah
/usr/local/include/freetype2) # Add the freetype2 specific include directory