-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
157 lines (131 loc) · 3.87 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
cmake_minimum_required(VERSION 3.12)
project(blaz)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(OS_LINUX TRUE)
add_compile_definitions(OS_LINUX)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(OS_WINDOWS TRUE)
add_compile_definitions(OS_WINDOWS)
endif()
set(MISC_TARGET_FOLDER "misc")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER ${MISC_TARGET_FOLDER})
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(GRAPHICS_APIS "OpenGL" "D3D11" "Vulkan")
if(NOT GRAPHICS_API)
set(GRAPHICS_API "OpenGL" CACHE STRING "Graphics API" FORCE)
endif()
set_property(CACHE GRAPHICS_API PROPERTY STRINGS ${GRAPHICS_APIS})
option(DEBUG_RENDERER "Debug Renderer" ON)
option(ADDRESS_SANITIZED "Address sanitizer (kinda buggy)" OFF)
if(DEBUG_RENDERER)
add_definitions(-D DEBUG_RENDERER)
endif()
set(COMMON_SOURCES
src/cfgreader.cpp
src/cfgreader.h
src/game.cpp
src/game.h
src/error.h
src/filesystem.h
src/logger.cpp
src/logger.h
src/types.h
src/platform.h
src/my_math.h
src/my_math.cpp
src/color.h
src/color.cpp
src/my_time.h
src/renderer.cpp
src/renderer.h
src/texture.cpp
src/texture.h
src/camera.cpp
src/camera.h
src/node.cpp
src/node.h
src/mesh.cpp
src/mesh.h
src/physics.cpp
src/physics.h
src/memory.h
)
if (EMSCRIPTEN)
add_compile_definitions(EMSCRIPTEN)
set(GRAPHICS_API "WebGL")
endif()
if (GRAPHICS_API STREQUAL "OpenGL")
list(APPEND COMMON_SOURCES src/opengl_loader/opengl_loader.h)
list(APPEND COMMON_SOURCES src/renderer_opengl.cpp)
elseif (GRAPHICS_API STREQUAL "WebGL")
list(APPEND COMMON_SOURCES src/renderer_webgl.cpp)
elseif (GRAPHICS_API STREQUAL "D3D11")
list(APPEND COMMON_SOURCES src/renderer_d3d11.cpp)
elseif (GRAPHICS_API STREQUAL "Vulkan")
list(APPEND COMMON_SOURCES src/vulkan_loader/vulkan_header.h)
list(APPEND COMMON_SOURCES src/vulkan_loader/vulkan_loader.h)
list(APPEND COMMON_SOURCES src/vulkan_loader/vulkan_loader.cpp)
list(APPEND COMMON_SOURCES src/renderer_vulkan.cpp)
endif()
if (EMSCRIPTEN)
set(PLATFORM_SOURCES
src/platform_wasm.cpp
src/filesystem_wasm.cpp
src/my_time_wasm.cpp
)
elseif (OS_WINDOWS)
set(PLATFORM_SOURCES
src/filesystem_win32.cpp
src/utils_win32.cpp
src/utils_win32.h
src/platform_win32.cpp
src/my_time_win32.cpp
src/memory_win32.cpp
)
if (GRAPHICS_API STREQUAL "OpenGL")
list(APPEND COMMON_SOURCES src/opengl_loader/opengl_loader_win32.cpp)
endif()
elseif (OS_LINUX)
set(PLATFORM_SOURCES
src/filesystem_linux.cpp
src/platform_linux.cpp
src/my_time_linux.cpp
)
if (GRAPHICS_API STREQUAL "OpenGL")
list(APPEND COMMON_SOURCES src/opengl_loader/opengl_loader_linux.cpp)
endif()
endif()
file(GLOB SAMPLES
samples/*/CMakeLists.txt
)
add_library(blaz
${COMMON_SOURCES}
${PLATFORM_SOURCES})
target_include_directories(blaz PUBLIC src)
if(ADDRESS_SANITIZED)
target_compile_options(blaz PRIVATE -fsanitize=address)
target_link_options(blaz PRIVATE -fsanitize=address)
endif()
option(UNITY_BUILD "Unity Build" OFF)
if(UNITY_BUILD)
set_target_properties(blaz PROPERTIES UNITY_BUILD ON)
endif()
if (OS_WINDOWS)
target_link_libraries(blaz gdi32 user32)
if (GRAPHICS_API STREQUAL "OpenGL")
target_link_libraries(blaz Opengl32.lib)
endif()
endif()
foreach(SAMPLE ${SAMPLES})
get_filename_component(SAMPLE_DIR ${SAMPLE} DIRECTORY)
add_subdirectory(${SAMPLE_DIR})
endforeach()
file(GLOB TOOL_SOURCES tools/*.cpp)
foreach(TOOL_SOURCE ${TOOL_SOURCES})
get_filename_component(TOOL_NAME ${TOOL_SOURCE} NAME_WE)
add_executable(${TOOL_NAME} ${TOOL_SOURCE})
target_include_directories(${TOOL_NAME} PRIVATE src)
target_link_libraries(${TOOL_NAME} blaz)
endforeach()