aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: e9a1932ff08d2fcd090f30d953e3745778a0e174 (plain)
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
cmake_minimum_required(VERSION 3.13)
project(ProjectBrussel LANGUAGES C CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

include(cmake/Exceptions.cmake)
include(cmake/RTTI.cmake)
include(cmake/Win32Subsystem.cmake)

find_package(OpenGL REQUIRED)
add_subdirectory(3rdparty/glfw)
add_subdirectory(3rdparty/glm)
add_subdirectory(3rdparty/imgui)
add_subdirectory(3rdparty/imguicolortextedit)
add_subdirectory(3rdparty/tracy)

# ==============================================================================
# Layer 10 (standalone, throw-into-the-buildsystem style)

file(GLOB_RECURSE 10-common_SOURCES
	source/10-common/*.c
	source/10-common/*.cpp
)
add_library(10-common OBJECT ${10-common_SOURCES})

set_target_properties(10-common PROPERTIES
	CXX_STANDARD 20
	CXX_STANDARD_REQUIRED ON
	CXX_EXTENSIONS OFF

	# Many files include platform headers, we don't want to leak them - it's just simpler to disable unity build for everything
	UNITY_BUILD OFF
)

target_include_directories(10-common PUBLIC source/10-common)
target_link_libraries(10-common PUBLIC
	# External dependencies
	${CONAN_LIBS}
	glm::glm
)

# ==============================================================================
# Layer 20 (building tools)

file(GLOB_RECURSE 20-codegen-runtime_SOURCES
	source/20-codegen-runtime/*.c
	source/20-codegen-runtime/*.cpp
)
add_library(20-codegen-runtime OBJECT ${20-codegen-runtime_SOURCES})

set_target_properties(20-codegen-runtime PROPERTIES
	CXX_STANDARD 20
	CXX_STANDARD_REQUIRED ON
	CXX_EXTENSIONS OFF
)

target_include_directories(20-codegen-runtime PUBLIC source/20-codegen-runtime)
target_link_libraries(20-codegen-runtime PUBLIC
	# External dependencies
	${CONAN_LIBS}

	# Project internal components
	10-common
)

# NOTE: delibrately not recursive, because this target can contain non-source files with .cpp extensions in the folder
file(GLOB 20-codegen-compiler_SOURCES
	source/20-codegen-compiler/*.c
	source/20-codegen-compiler/*.cpp
)
add_executable(20-codegen-compiler ${20-codegen-compiler_SOURCES})

set_target_properties(20-codegen-compiler PROPERTIES	
	CXX_STANDARD 20
	CXX_STANDARD_REQUIRED ON
	CXX_EXTENSIONS OFF
)

target_link_libraries(20-codegen-compiler PRIVATE
	# External dependencies
	${CONAN_LIBS}

	# Project internal components
	10-common
)

target_flag_exceptions(20-codegen-compiler ON)
target_flag_rtti(20-codegen-compiler OFF)

option(BRUSSEL_CODEGEN_DEBUG_PRINT "Enable debug printing in the code generator or not." OFF)
if(BRUSSEL_CODEGEN_DEBUG_PRINT)
	target_compile_definitions(codegen PRIVATE CODEGEN_DEBUG_PRINT=1)
endif()

# ==============================================================================
# Layer 30 (final products)

function(add_projectized_executable)
	# Add a library target
	#
	# Arguments
	#   TARGET_NAME
	#   TARGET_SOURCE_DIR
	#   EXTRA_SOURCES
	#   ENABLE_CODEGEN

	set(one_value_args TARGET_NAME TARGET_SOURCE_DIR ENABLE_CODEGEN)
	set(multi_value_args EXTRA_SOURCES)
	cmake_parse_arguments(arg "" "${one_value_args}" "${multi_value_args}" ${ARGN})

	file(GLOB_RECURSE var_HEADERS
		${arg_TARGET_SOURCE_DIR}/*.h
		${arg_TARGET_SOURCE_DIR}/*.hh
		${arg_TARGET_SOURCE_DIR}/*.hpp
	)
	file(GLOB_RECURSE var_SOURCES
		${arg_TARGET_SOURCE_DIR}/*.c
		${arg_TARGET_SOURCE_DIR}/*.cc
		${arg_TARGET_SOURCE_DIR}/*.cpp
	)
	add_executable(${arg_TARGET_NAME}
		${var_SOURCES}
		${arg_EXTRA_SOURCES}
	)

	target_include_directories(${arg_TARGET_NAME} PRIVATE
		${arg_TARGET_SOURCE_DIR}
	)

	target_link_libraries(${arg_TARGET_NAME} PRIVATE
		10-common
	)

	set_target_properties(${arg_TARGET_NAME} PROPERTIES
		CXX_STANDARD 20
		CXX_STANDARD_REQUIRED ON
		CXX_EXTENSIONS OFF
	)

	if(arg_ENABLE_CODEGEN)
		set(var_OUTPUT_DIR ${CMAKE_BINARY_DIR}/generated/${arg_TARGET_NAME})
		target_include_directories(${arg_TARGET_NAME} PRIVATE ${var_OUTPUT_DIR})
		target_link_libraries(${arg_TARGET_NAME} PRIVATE 20-codegen-runtime)

		foreach(var_HEADER IN LISTS var_HEADERS)
			get_filename_component(var_HEADER_ABS "${var_HEADER}" ABSOLUTE)
			get_filename_component(var_HEADER_NAME "${var_HEADER}" NAME_WLE)

			# Things that are included by other TUs
			set(var_OUTPUT_HEADERS
				${var_OUTPUT_DIR}/generated/${var_HEADER_NAME}.gh.inl
				${var_OUTPUT_DIR}/generated/${var_HEADER_NAME}.gs.inl
			)

			# Things that needs to be compiled
			# NOTE: we need at least one of this to make sure the target is rebuilt if the generated files changes
			set(var_OUTPUT_SOURCES
				${var_OUTPUT_DIR}/generated/${var_HEADER_NAME}.gs.cpp
			)

			# Generate the files
			add_custom_command(
				OUTPUT ${var_OUTPUT_HEADERS} ${var_OUTPUT_SOURCES}
				COMMAND 20-codegen-compiler ${var_OUTPUT_DIR}/generated single:${var_HEADER}
				DEPENDS ${var_HEADER}
			)

			# Add generated TUs to the target
			target_sources(${arg_TARGET_NAME} PRIVATE ${var_OUTPUT_SOURCES})
		endforeach()
	endif()
endfunction()

add_projectized_executable(
	TARGET_NAME 30-game
	TARGET_SOURCE_DIR source/30-game/
	ENABLE_CODEGEN ON
)

set_source_files_properties(
	source/main.cpp
TARGET_DIRECTORY 30-game
PROPERTIES
	SKIP_UNITY_BUILD_INCLUSION ON
)

set_target_properties(30-game PROPERTIES
	UNITY_BUILD_MODE BATCH
	UNITY_BUILD_UNIQUE_ID "ProjectBrussel_UNITY_ID"
)

target_compile_definitions(30-game PRIVATE
	RAPIDJSON_HAS_STDSTRING=1
	IMGUI_DISABLE_OBSOLETE_FUNCTIONS
)

target_link_libraries(30-game PRIVATE
	# External dependencies
	${CONAN_LIBS}
	OpenGL::GL
	glfw
	glm::glm
	imgui
	ImGuiColorTextEdit
	tracy

	# Project internal components
)

target_flag_exceptions(30-game ON)
target_flag_rtti(30-game ON)
target_use_windows_subsystem(30-game)

option(BRUSSEL_ENABLE_PROFILING "Whether profiling support is enabled or not." OFF)
if(BRUSSEL_ENABLE_PROFILING)
	target_compile_definitions(30-game
	PRIVATE
		TRACY_ENABLE
	)
endif()

option(BRUSSEL_ENABLE_DEV_ENC "Enable dev environment features or not." ON)
if(BRUSSEL_ENABLE_DEV_ENC)
	target_compile_definitions(30-game
	PRIVATE
		BRUSSEL_DEV_ENV=1
	)
endif()

option(BRUSSEL_ENABLE_EDITOR "Enable editor support or not." ON)
if(BRUSSEL_ENABLE_EDITOR)
	target_compile_definitions(30-game
	PRIVATE
		BRUSSEL_ENABLE_EDITOR=1
	)
endif()

option(BRUSSEL_ENABLE_ASAN "Enable AddressSanitizer or not." OFF)
if(BRUSSEL_ENABLE_ASAN)
	target_compile_options(30-game
	PRIVATE
		-fsanitize=address
		-fno-omit-frame-pointer
	)
	target_link_options(30-game
	PRIVATE
		-fsanitize=address
		-fno-omit-frame-pointer
	)
endif()