-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
150 lines (127 loc) · 4.3 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
cmake_minimum_required(VERSION 3.21)
if(PROJECT_IS_TOP_LEVEL)
message("Engine is a main project - some additional flags will be available")
# force Debug build type if nothing else has been provided
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "" FORCE)
endif()
endif()
option(COMPILE_PLAYGROUND "Compile engine's playground" OFF)
option(DRAW_DEBUG "Draw debug info, such as hitboxes" OFF)
option(WITH_IMGUI "Compile engine with imgui support" OFF)
# set project name and version
project(engine
LANGUAGES CXX
VERSION 0.1
)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Prefer new GLVND over OLD
set(OpenGL_GL_PREFERENCE GLVND)
add_library(engine STATIC
engine/raybuff.cpp
engine/raybuff.hpp
engine/formatters.hpp
engine/node.cpp
engine/node.hpp
engine/scene.cpp
engine/scene.hpp
engine/core.cpp
engine/core.hpp
engine/mapgen.hpp
engine/quadtree.hpp
engine/settings.cpp
engine/settings.hpp
engine/sound.hpp
engine/sprite.cpp
engine/sprite.hpp
engine/text.cpp
engine/text.hpp
engine/observer.hpp
engine/ui/components.cpp
engine/ui/components.hpp
engine/ui/ui.cpp
engine/ui/ui.hpp
engine/ui/observers.cpp
engine/ui/observers.hpp
engine/utility.cpp
engine/utility.hpp
engine/storage.cpp
engine/storage.hpp
engine/tasks.hpp
)
if(WITH_IMGUI)
target_sources(engine PUBLIC
# engine/imgui.cpp
engine/imgui.hpp
)
endif()
target_include_directories(engine PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>"
"$<INSTALL_INTERFACE:${PROJECT_SOURCE_DIR}/engine>"
)
# Disable warnings about vsprintf being deprecated on windows
if(CMAKE_SYSTEM_NAME STREQUAL "Windows" OR MINGW)
target_compile_definitions(engine PRIVATE
_CRT_SECURE_NO_WARNINGS
)
endif()
# Draw debug info if specific flag has been received
# I hope this won't eat previous target_compile_definitions statement.
if(DRAW_DEBUG)
target_compile_definitions(engine PRIVATE
"DRAW_DEBUG"
)
endif()
if(PROJECT_IS_TOP_LEVEL)
target_compile_options(engine PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:-Wall -Wextra -Wpedantic -Werror -Wextra-semi -Wsuggest-override -Wno-missing-field-initializers>
$<$<CXX_COMPILER_ID:MSVC>:/Wall /w34263 /w34266>
)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif()
# If building with debug - enable sanitizer for hard-to-debug moments
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-fsanitize=address,undefined)
add_link_options(-fsanitize=address,undefined)
endif()
# Setup raylib
add_subdirectory("${PROJECT_SOURCE_DIR}/dependencies/raylib")
target_link_libraries(engine raylib)
target_include_directories(engine PUBLIC ${raylib_INCLUDE_DIRS})
# Setup imgui, if enabled
if(WITH_IMGUI)
add_subdirectory("${PROJECT_SOURCE_DIR}/dependencies/imgui")
target_link_libraries(engine imgui)
target_include_directories(engine PUBLIC ${imgui_INCLUDE_DIRS})
add_subdirectory("${PROJECT_SOURCE_DIR}/dependencies/rlimgui")
target_link_libraries(engine rlimgui)
target_include_directories(engine PUBLIC ${rlimgui_INCLUDE_DIRS})
endif()
# Setup fmt
add_subdirectory("${PROJECT_SOURCE_DIR}/dependencies/fmt")
target_link_libraries(engine fmt)
target_include_directories(engine PUBLIC ${fmt_INCLUDE_DIRS})
# Setup spdlog
add_subdirectory("${PROJECT_SOURCE_DIR}/dependencies/spdlog")
target_link_libraries(engine spdlog)
target_include_directories(engine PUBLIC ${spdlog_INCLUDE_DIRS})
# Setup tomlplusplus
add_subdirectory("${PROJECT_SOURCE_DIR}/dependencies/tomlplusplus")
target_link_libraries(engine tomlplusplus::tomlplusplus)
target_include_directories(engine PUBLIC ${tomlplusplus_INCLUDE_DIRS})
if(PROJECT_IS_TOP_LEVEL)
add_custom_target(compile_commands
WORKING_DIRECTORY ${CMAKE_BUILD_DIR}
BYPRODUCTS ${CMAKE_SOURCE_DIR}/compile_commands.json
COMMAND cp -f ./compile_commands.json ${CMAKE_SOURCE_DIR}/compile_commands.json
VERBATIM)
add_custom_target(format
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND find engine \( -name '*.cpp' -o -name '*.hpp' \) -exec clang-format -style=file -i {} \;
VERBATIM)
endif()
if(COMPILE_PLAYGROUND)
add_subdirectory(playground)
endif()