-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCmakeLists.txt
270 lines (232 loc) · 9.25 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
cmake_minimum_required(VERSION 3.15)
project(ToyBox LANGUAGES C CXX OBJC)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_OSX_DEPLOYMENT_TARGET "14.0" CACHE STRING "Minimum OS X deployment version")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(EXTERNAL_DIR ${CMAKE_SOURCE_DIR}/external)
# ========================
# Add External Dependencies
# ========================
add_subdirectory(${EXTERNAL_DIR}/AllocX)
set_target_properties(AllocX PROPERTIES FOLDER "External")
file(GLOB ALLOCX_HEADERS "${EXTERNAL_DIR}/AllocX/include/allocx/*.h")
if(TARGET AllocX)
target_include_directories(AllocX PUBLIC "${EXTERNAL_DIR}/AllocX/include")
target_sources(AllocX PRIVATE ${ALLOCX_HEADERS})
source_group("Header Files" FILES ${ALLOCX_HEADERS})
if(MSVC)
target_compile_definitions(AllocX PRIVATE __STDC_NO_ATOMICS__)
endif()
endif()
add_subdirectory(${EXTERNAL_DIR}/Phyzzy)
set_target_properties(PhyzzyLib PROPERTIES FOLDER "External")
if(MSVC)
target_compile_options(PhyzzyLib PRIVATE /wd4201) # Disable nameless struct warning
endif()
file(GLOB EMBERSCRIPT_SRCS "${EXTERNAL_DIR}/EmberScript/src/*.c")
file(GLOB EMBERSCRIPT_HEADERS "${EXTERNAL_DIR}/EmberScript/include/*.h")
add_library(EmberScriptLib STATIC ${EMBERSCRIPT_SRCS})
target_include_directories(EmberScriptLib PUBLIC "${EXTERNAL_DIR}/EmberScript/include")
set_target_properties(EmberScriptLib PROPERTIES FOLDER "External")
target_sources(EmberScriptLib PRIVATE ${EMBERSCRIPT_HEADERS})
source_group("Header Files" FILES ${EMBERSCRIPT_HEADERS})
if(MSVC)
target_compile_definitions(EmberScriptLib PRIVATE NO_PTHREAD)
endif()
if(APPLE)
find_library(VULKAN_LIBRARY NAMES vulkan HINTS $ENV{VULKAN_SDK}/lib)
find_path(VULKAN_INCLUDE_DIR NAMES vulkan/vulkan.h HINTS $ENV{VULKAN_SDK}/include)
if(VULKAN_LIBRARY AND VULKAN_INCLUDE_DIR)
message(STATUS "Found Vulkan library: ${VULKAN_LIBRARY}")
message(STATUS "Found Vulkan include directory: ${VULKAN_INCLUDE_DIR}")
include_directories(${VULKAN_INCLUDE_DIR})
else()
message(FATAL_ERROR "Vulkan SDK not found. Please install the Vulkan SDK and set VULKAN_SDK environment variable.")
endif()
endif()
add_subdirectory(${EXTERNAL_DIR}/googletest)
if(TARGET gtest)
set_target_properties(gtest PROPERTIES FOLDER "External/GoogleTest")
endif()
if(TARGET gtest_main)
set_target_properties(gtest_main PROPERTIES FOLDER "External/GoogleTest")
endif()
if(TARGET gmock)
set_target_properties(gmock PROPERTIES FOLDER "External/GoogleTest")
endif()
if(TARGET gmock_main)
set_target_properties(gmock_main PROPERTIES FOLDER "External/GoogleTest")
endif()
set(EXTERNAL_LIBS AllocX PhyzzyLib EmberScriptLib)
# ==================================
# Determine Forge libraries directory
# ==================================
if(MSVC)
# On Windows with MSVC, we can determine debug vs release lib directory
set(FORGE_LIB_DIR "${CMAKE_BINARY_DIR}/x64/${CMAKE_BUILD_TYPE}")
# Append OS.lib, Renderer.lib, and SpirvTools.lib from this directory
list(APPEND EXTERNAL_LIBS
"${FORGE_LIB_DIR}/OS.lib"
"${FORGE_LIB_DIR}/Renderer.lib"
"${FORGE_LIB_DIR}/SpirvTools.lib"
)
endif()
# ========================
# Add Engine Modules
# ========================
add_subdirectory(engine/ecs)
add_subdirectory(engine/memory)
add_subdirectory(engine/physics)
add_subdirectory(engine/rendering)
add_subdirectory(engine/scene)
add_subdirectory(engine/scripting)
add_subdirectory(engine/ui)
add_subdirectory(engine/utils)
if(TARGET MemoryModule)
set_target_properties(MemoryModule PROPERTIES FOLDER "Engine/Modules")
endif()
if(TARGET PhysicsModule)
set_target_properties(PhysicsModule PROPERTIES FOLDER "Engine/Modules")
endif()
if(TARGET ScriptingModule)
set_target_properties(ScriptingModule PROPERTIES FOLDER "Engine/Modules")
endif()
if(TARGET DataStructures)
set_target_properties(DataStructures PROPERTIES FOLDER "Engine/Modules")
endif()
add_library(ToyBoxEngine INTERFACE)
target_link_libraries(ToyBoxEngine INTERFACE ${EXTERNAL_LIBS})
target_include_directories(ToyBoxEngine INTERFACE
${EXTERNAL_DIR}/Phyzzy/include
${EXTERNAL_DIR}/AllocX/include
)
add_dependencies(ToyBoxEngine PhyzzyLib EmberScriptLib)
set_target_properties(ToyBoxEngine PROPERTIES FOLDER "Engine")
add_executable(ToyBoxApp main.cpp)
set_target_properties(ToyBoxApp PROPERTIES FOLDER "Applications")
# Include The Forge Common_3 directories
target_include_directories(ToyBoxApp PRIVATE
"${CMAKE_SOURCE_DIR}/external/The-Forge-Toy-Box/Common_3"
"${CMAKE_SOURCE_DIR}/external/The-Forge-Toy-Box/Common_3/Application/Interfaces"
"${CMAKE_SOURCE_DIR}/external/The-Forge-Toy-Box/Common_3/OS/Interfaces"
"${CMAKE_SOURCE_DIR}/external/The-Forge-Toy-Box/Common_3/Graphics/Interfaces"
"${CMAKE_SOURCE_DIR}/external/The-Forge-Toy-Box/Common_3/Resources/ResourceLoader/Interfaces"
"${CMAKE_SOURCE_DIR}/external/The-Forge-Toy-Box/Common_3/Utilities/Interfaces"
"${CMAKE_SOURCE_DIR}/external/The-Forge-Toy-Box/Common_3/Game/Interfaces"
)
if(APPLE)
target_link_libraries(ToyBoxApp PRIVATE ToyBoxEngine ${VULKAN_LIBRARY})
else()
target_link_libraries(ToyBoxApp PRIVATE ToyBoxEngine)
endif()
if(MSVC)
# Add the Xinput library for gamepad functions
target_link_libraries(ToyBoxApp PRIVATE Xinput.lib)
# Add the additional libraries discovered from the The Forge projects:
target_link_libraries(ToyBoxApp PRIVATE
ws2_32.lib
dxcompiler.lib
WinPixEventRuntime.lib
amd_ags_x64.lib
nvapi64.lib
vulkan-1.lib
)
# Add library directories for these external libs if needed
set(TheForgeRoot "${CMAKE_SOURCE_DIR}/external/The-Forge-Toy-Box")
set(TheForgeCommon3 "${TheForgeRoot}/Common_3")
target_link_directories(ToyBoxApp PRIVATE
"${TheForgeCommon3}/Graphics/ThirdParty/OpenSource/ags/ags_lib/lib"
"${TheForgeCommon3}/Graphics/ThirdParty/OpenSource/nvapi/amd64"
"${TheForgeCommon3}/Graphics/ThirdParty/OpenSource/DirectXShaderCompiler/lib/x64"
"${TheForgeCommon3}/Graphics/ThirdParty/OpenSource/winpixeventruntime/bin"
)
endif()
if(APPLE)
set(MACOSX_FRAMEWORKS
"-framework Cocoa"
"-framework IOKit"
"-framework CoreFoundation"
"-framework CoreVideo"
"-framework AudioToolbox"
"-framework AVFoundation"
"-framework Metal"
"-framework QuartzCore"
"-framework CoreGraphics"
"-framework CoreAudio"
"-framework CoreMedia"
"-framework UniformTypeIdentifiers"
)
target_link_libraries(ToyBoxApp PRIVATE ${MACOSX_FRAMEWORKS})
endif()
set_target_properties(ToyBoxApp PROPERTIES LINKER_LANGUAGE CXX)
enable_testing()
add_subdirectory(tests/dynamicstring)
add_subdirectory(tests/hashmap)
add_subdirectory(tests/dynamicarray)
if(TARGET DynamicArrayTests)
set_target_properties(DynamicArrayTests PROPERTIES FOLDER "Tests")
endif()
if(TARGET DynamicStringTests)
set_target_properties(DynamicStringTests PROPERTIES FOLDER "Tests")
endif()
if(TARGET HashMapTests)
set_target_properties(HashMapTests PROPERTIES FOLDER "Tests")
endif()
if(TARGET ALL_BUILD)
set_target_properties(ALL_BUILD PROPERTIES FOLDER "CMake Utilities")
endif()
if(TARGET ZERO_CHECK)
set_target_properties(ZERO_CHECK PROPERTIES FOLDER "CMake Utilities")
endif()
if(TARGET INSTALL)
set_target_properties(INSTALL PROPERTIES FOLDER "CMake Utilities")
endif()
if(TARGET RUN_TESTS)
set_target_properties(RUN_TESTS PROPERTIES FOLDER "CMake Utilities")
endif()
if(TARGET Continuous)
set_target_properties(Continuous PROPERTIES FOLDER "CMake Utilities")
endif()
if(TARGET Nightly)
set_target_properties(Nightly PROPERTIES FOLDER "CMake Utilities")
endif()
if(TARGET NightlyMemoryCheck)
set_target_properties(NightlyMemoryCheck PROPERTIES FOLDER "CMake Utilities")
endif()
# ==================================
# Include External MSProjects for The Forge Libraries
# ==================================
if(MSVC)
set(FORGE_LIBRARIES_DIR "${CMAKE_SOURCE_DIR}/external/The-Forge-Toy-Box/Examples_3/Unit_Tests/PC_Visual_Studio_2019/Libraries")
INCLUDE_EXTERNAL_MSPROJECT(OS
"${FORGE_LIBRARIES_DIR}/OS/OS.vcxproj"
TYPE UTILITY
)
set_target_properties(OS PROPERTIES FOLDER "Engine/TheForge")
INCLUDE_EXTERNAL_MSPROJECT(Renderer
"${FORGE_LIBRARIES_DIR}/Renderer/Renderer.vcxproj"
TYPE UTILITY
)
set_target_properties(Renderer PROPERTIES FOLDER "Engine/TheForge")
INCLUDE_EXTERNAL_MSPROJECT(SpirvTools
"${FORGE_LIBRARIES_DIR}/Tools/SpirvCross.vcxproj"
TYPE UTILITY
)
set_target_properties(SpirvTools PROPERTIES FOLDER "Engine/TheForge")
endif()
if(MSVC)
# Add the dependencies
add_dependencies(Renderer SpirvTools)
add_dependencies(ToyBoxApp OS Renderer SpirvTools)
# Copy WinPixEventRuntime.dll to the output directory
set(PIX_DLL_PATH "${CMAKE_SOURCE_DIR}/external/The-Forge-Toy-Box/Common_3/Graphics/ThirdParty/OpenSource/winpixeventruntime/bin/WinPixEventRuntime.dll")
add_custom_command(TARGET ToyBoxApp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${PIX_DLL_PATH}"
$<TARGET_FILE_DIR:ToyBoxApp>
COMMENT "Copying WinPixEventRuntime.dll to output directory")
endif()