-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCMakeLists.txt
220 lines (178 loc) · 7.05 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
##########################################
# Edge Classic - CMake Script
##########################################
cmake_minimum_required(VERSION 3.27)
project(
edge-classic
LANGUAGES C CXX
VERSION 0.1.0
)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Rendering Options
# Sokol Renderer
option(EDGE_SOKOL_GL "Sokol GL" OFF)
option(EDGE_SOKOL_GLES3 "Sokol GLES3" OFF)
option(EDGE_SOKOL_D3D11 "Sokol D3D11" OFF)
option(EDGE_LEGACY_GL "Legacy GL Renderer" OFF)
# If the legacy GL renderer has not been selected and
# a Sokol backend is not already specified by CMake params,
# choose a default based on platform
if (NOT EDGE_LEGACY_GL)
if (NOT EDGE_SOKOL_GL AND NOT EDGE_SOKOL_D3D11 AND NOT EDGE_SOKOL_GLES3)
if (WIN32 OR MINGW)
set (EDGE_SOKOL_D3D11 ON)
elseif (EMSCRIPTEN)
set (EDGE_SOKOL_GLES3 ON)
# Unix; Apple will eventually have a Metal backend but it should support
# the level of GL in use by Sokol GFX/GL
else ()
set (EDGE_SOKOL_GL ON)
endif()
endif()
endif()
if (EDGE_SOKOL_GL OR EDGE_SOKOL_GLES3 OR EDGE_SOKOL_D3D11)
set (EDGE_SOKOL ON)
endif()
# Optional Features
option(EDGE_CLASSIC "Enable default features for EDGE-Classic" ON)
# Development
option(EDGE_SANITIZE "Enable code sanitizing" OFF)
option(EDGE_PROFILING "Enable Profiling" OFF)
# memory allocator
option(EDGE_MIMALLOC "Enable mimalloc" ON)
# Enables exhaustive memory checks, see mimalloc CMakeLists.txt for what is enabled
# Memory error logging goes to debug.txt
option(EDGE_MEMORY_CHECK "Enable Memory Checks" OFF)
# If fatal memory checks are enabled, any memory error will be fatal and provide a callstack
option(EDGE_MEMORY_CHECK_FATAL "Enable Fatal Memory Checks" OFF)
include("${CMAKE_SOURCE_DIR}/cmake/EDGEClassic.cmake")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
set(CLANG true)
else()
set(CLANG false)
endif()
if (EMSCRIPTEN)
include("${CMAKE_SOURCE_DIR}/cmake/Emscripten.cmake")
endif()
if (WIN32 OR MINGW)
add_definitions(-D_WIN32_WINNT=0x601)
endif()
if(MSVC)
# Use static C runtime, necessary for mimalloc and also means matching C runtime doesn't need to be on users box
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:Debug>")
if (EDGE_MIMALLOC)
# Override memory allocations to use mimalloc
add_compile_options(/FI${CMAKE_SOURCE_DIR}/libraries/mimalloc/include/mimalloc-override.h)
endif()
endif()
if (MSVC)
# Disable RTTI
string(FIND "${CMAKE_CXX_FLAGS}" "/GR" MSVC_HAS_GR)
if(MSVC_HAS_GR)
string(REGEX REPLACE "/GR" "/GR-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
add_compile_options(/GR-)
endif()
# Disable C++ Exceptions
string(REGEX REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
add_compile_options(/D_HAS_EXCEPTIONS=0)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fp:fast")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast")
if (NOT CLANG)
# get the number of logical cores for parallel build
cmake_host_system_information(RESULT LOGICAL_CORES QUERY NUMBER_OF_LOGICAL_CORES)
math(EXPR COMPILE_CORES "${LOGICAL_CORES} - 1")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP${COMPILE_CORES}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP${COMPILE_CORES}")
endif()
# Disable some very noisy warnings from the MSVC build
# CRT security and POSIX deprecation warnings
add_definitions("-D_CRT_SECURE_NO_WARNINGS /wd4996")
# Loss of precision/data on assignment, requires lots of explicit casting
add_definitions("/wd4244 /wd4267")
# Unreferenced formal parameter, and there are many of these
add_definitions("/wd4100")
# warning level for edge specific source files
set (EDGE_WARNING_LEVEL "/W4")
# To use the sanitizer with MSVC, you will need to either have your Visual Studio
# or Build Tools install in your PATH variable, or copy the appropriate DLL to the program
# folder before launching. The paths and filenames can vary based on your setup,
# but, as an example, for a 64-bit Debug build using MSVC 2022 Build Tools, the path would be
# C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\<version number>\bin\Hostx64\x64
# and the file would be clang_rt.asan_dbg_dynamic-x86_64.dll
if (EDGE_SANITIZE AND MSVC_VERSION GREATER_EQUAL 1929)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fsanitize=address /Oy-")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fsanitize=address /Oy-")
endif()
if (CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++98-compat -Wno-c++98-compat-pedantic")
endif()
set(CMAKE_EXE_LINKER_FLAGS "/SUBSYSTEM:WINDOWS")
else()
if (WIN32 AND CLANG)
add_definitions("-D_CRT_SECURE_NO_WARNINGS")
endif()
# warning level for edge specific source files
set (EDGE_WARNING_LEVEL -Wextra)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fno-exceptions -fno-strict-aliasing")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions -fno-rtti -fno-strict-aliasing")
if (EDGE_SANITIZE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
if (NOT CLANG)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libasan")
endif()
endif()
if (MINGW)
set(CMAKE_EXE_LINKER_FLAGS "-lmingw32 ${CMAKE_EXE_LINKER_FLAGS}")
endif()
endif()
# set some directory values for various situations
if(${CMAKE_SYSTEM} MATCHES "BSD")
include_directories("/usr/local/include")
endif()
if(MINGW OR MSVC OR (WIN32 AND CLANG))
set(SDL2_DIR "${CMAKE_SOURCE_DIR}/libraries/sdl2")
endif()
find_package(SDL2 REQUIRED)
# set certain definitions (if appropriate)
if (APPLE)
include_directories(${SDL2_INCLUDE_DIR})
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" AND APPLE)
add_compile_definitions(APPLE_SILICON)
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" AND APPLE)
add_compile_definitions(NOT_APPLE_SILICON)
endif()
endif()
if (EDGE_SOKOL)
add_definitions(-DEDGE_SOKOL)
if (EDGE_SOKOL_GL)
find_package(OpenGL REQUIRED)
elseif (EDGE_SOKOL_GLES3 AND NOT EMSCRIPTEN)
find_package(OpenGL COMPONENTS GLES3 REQUIRED)
endif()
else()
find_package(OpenGL REQUIRED)
endif()
if (EDGE_CLASSIC)
add_definitions(-DEDGE_CLASSIC)
endif()
if (EDGE_PROFILING)
# these must be defined for all source files
add_compile_definitions(EDGE_PROFILING TRACY_ENABLE)
endif()
if (EDGE_MEMORY_MIMALLOC)
add_compile_definitions(EDGE_MIMALLOC)
if (EDGE_MEMORY_CHECK)
add_compile_definitions(EDGE_MEMORY_CHECK)
if (EDGE_MEMORY_CHECK_FATAL)
add_compile_definitions(EDGE_MEMORY_CHECK_FATAL)
endif()
endif()
endif()
add_subdirectory(libraries)
add_subdirectory(source_files)