-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
247 lines (213 loc) · 9.11 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
# #########################################
# Initial config
# #########################################
set(EXECUTABLE_TARGET_NAME SupergoonWorld)
cmake_minimum_required(VERSION 3.16)
message(STATUS "Starting ${EXECUTABLE_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(${EXECUTABLE_TARGET_NAME} VERSION 0.1.0 LANGUAGES C CXX)
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 GOON_WORLD_FILES src/GoonWorld/*.cpp*)
# #########################################
# Platform specific Project setup
# #########################################
message(STATUS "Changing the platform specific settings")
if(EMSCRIPTEN)
message(STATUS "Configuring Emscripten")
set(CMAKE_EXECUTABLE_SUFFIX ".html")
elseif(APPLE)
if(NOT IOS) # MACOS #
message(STATUS "Configuring Macos")
set(MACOS ON CACHE BOOL "Is Macos")
if(CMAKE_GENERATOR STREQUAL "Xcode")
# message(STATUS "Setting Build to Specific OS type, as libpng cannot handle universal.")
# set(CMAKE_OSX_ARCHITECTURES ${CMAKE_OSX_ARCHITECTURES} CACHE STRING "" FORCE)
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(EMSCRIPTEN)
# #########################################
# Initialize
# #########################################
message(STATUS "Initializing the project")
add_executable(${EXECUTABLE_TARGET_NAME}
${GOON_WORLD_FILES})
set_property(TARGET ${EXECUTABLE_TARGET_NAME} PROPERTY CXX_STANDARD 17)
# #########################################
# 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_MULTITHREADED_SOUND "Adds multithreaded support for sound updates, experimental and has a memory leak somehow" OFF)
option(GOON_BENCHMARKING "Enables benchmarking functions, adds overhead" OFF)
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)
# #########################################
# Set options for child projects.
# #########################################
set(GOON_DEBUG_SOUND ON CACHE BOOL "Builds sound from subdirectory instead of using a made package so we can debug" FORCE)
set(SKIP_INSTALL_ALL ON CACHE BOOL "SKIP INSTALLATION" FORCE)
if(APPLE)
set(libpng_arm_sources
arm/arm_init.c
arm/filter_neon_intrinsics.c
arm/palette_neon_intrinsics.c
arm/filter_neon.S
CACHE STRING "Enable arm sources for apple universal builds, regardless" FORCE)
endif(APPLE)
set(PNG_TESTS OFF CACHE BOOL "Build the libpng tests" FORCE)
# set(PNG_HARDWARE_OPTIMIZATIONS OFF CACHE BOOL "Universal" FORCE)
# set(PNG_ARM_NEON off CACHE BOOL "Build the libpng tests" FORCE)
# set(PNG_ARM_NEON_OPT 0 CACHE BOOL "What" FORCE)
set(PNG_BUILD_ZLIB ON CACHE BOOL "Build the libpng tests" FORCE)
set(PNG_TOOLS OFF CACHE BOOL "Build the libpng tests" FORCE)
set(PNG_SHARED OFF CACHE BOOL "Build the libpng tests" FORCE)
set(GOON_FULL_MACOS_BUILD ${GOON_FULL_MACOS_BUILD} CACHE BOOL "Build the libpng tests" FORCE)
set(GOON_DEBUG_SOUND ${GOON_DEBUG_SOUND} CACHE BOOL "Build from what?" FORCE)
set(PNG_FRAMEWORK OFF CACHE BOOL "Build from what?" FORCE)
# #########################################
# Precompiled headers
# #########################################
if(GOON_BUILD_PCH)
target_precompile_headers(${EXECUTABLE_TARGET_NAME} PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/src/GoonWorld/gnpch.hpp>")
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")
set(EMBUILDER_PATH embuilder)
target_compile_definitions(${EXECUTABLE_TARGET_NAME} PRIVATE -DGN_DEBUG_BUILD)
else()
set(EMBUILDER_PATH /emsdk/upstream/emscripten/embuilder)
target_compile_definitions(${EXECUTABLE_TARGET_NAME} PRIVATE -DGN_RELEASE_BUILD)
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
# #########################################
# Packages And subprojects
# #########################################
add_subdirectory(./external/sg_engine)
# #########################################
# Platform Specific Build settings
# #########################################
if(EMSCRIPTEN)
set_target_properties(${EXECUTABLE_TARGET_NAME} PROPERTIES LINK_FLAGS ${LINK_FLAGS} " -O0 -g -s -sUSE_SDL=2 -sUSE_LIBPNG=1 -sUSE_FREETYPE=1 -sUSE_OGG=1 -sUSE_VORBIS=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(${EXECUTABLE_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(${EXECUTABLE_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
-Wno-unused-parameter
-pthread
)
if(WIN32)
set(FULL_COMPILE_OPTIONS /std:c99)
elseif(EMSCRIPTEN)
# target_compile_options(${EXECUTABLE_TARGET_NAME} PRIVATE -sUSE_SDL_TTF=2)
endif(WIN32)
target_compile_options(${EXECUTABLE_TARGET_NAME} PRIVATE ${FULL_COMPILE_OPTIONS})
# #########################################
# Linking Options
# #########################################
set(LIBRARIES_TO_LINK
SDL2::SDL2main
)
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(${EXECUTABLE_TARGET_NAME} PRIVATE ${LIBRARY})
endif()
endforeach()
target_link_directories(${EXECUTABLE_TARGET_NAME}
PRIVATE
/usr/local/lib
)
target_include_directories(${EXECUTABLE_TARGET_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include/
${CMAKE_CURRENT_SOURCE_DIR}/external/sg_engine/include/
${CMAKE_CURRENT_SOURCE_DIR}/external/sg_physics/include/
${CMAKE_CURRENT_SOURCE_DIR}/external/nlohmann/include/
/usr/local/include
# Freetype cause yeah
/usr/local/include/freetype2) # Add the freetype2 specific include directory
# Tests
target_link_libraries(${EXECUTABLE_TARGET_NAME}
PUBLIC
SupergoonEngine
PRIVATE
)
target_include_directories(${EXECUTABLE_TARGET_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include/
${CMAKE_CURRENT_SOURCE_DIR}/src/GoonWorld/external/include
${CMAKE_CURRENT_SOURCE_DIR}/src/
)
# #########################################
# Install
# #########################################
set(FOLDERS_TO_COPY assets)
if(MSVC OR CMAKE_GENERATOR STREQUAL "Xcode")
set(INSTALL_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>)
else()
set(INSTALL_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif(MSVC OR CMAKE_GENERATOR STREQUAL "Xcode")
install(DIRECTORY ${FOLDERS_TO_COPY}
DESTINATION ${INSTALL_DIR}
COMPONENT assets)