-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
145 lines (116 loc) · 4.56 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
cmake_minimum_required(VERSION 3.16)
project(cardboard_game_engine)
set(CMAKE_EXPORT_COMPILE_COMMANDS on)
set(CARDBOARD_GRAPHICS_TARGET "none" CACHE STRING "Gameengine rendering target")
set(CARDBOARD_WINDOWS_TARGET "none" CACHE STRING "Gameengine resource window target")
# --------------------------------------------------------------------------------
# DEPENDENCIES
# STBI - image loading
add_subdirectory(${PROJECT_SOURCE_DIR}/dep/stbi)
include_directories(${PROJECT_SOURCE_DIR}/dep/stbi)
set(CARDBOARD_DEPENDENCIES_LIBRARIES ${CARDBOARD_DEPENDENCIES_LIBRARIES}
stbi
)
# GLM - fast math
include_directories(${PROJECT_SOURCE_DIR}/dep/glm)
# IMGUI - editor gui
include_directories(${PROJECT_SOURCE_DIR}/dep/imgui)
include_directories(${PROJECT_SOURCE_DIR}/dep/cardboard_imgui)
set(IMGUI_SOURCES ${IMGUI_SOURCES}
${PROJECT_SOURCE_DIR}/dep/imgui/imgui.cpp
${PROJECT_SOURCE_DIR}/dep/imgui/imgui_draw.cpp
${PROJECT_SOURCE_DIR}/dep/imgui/imgui_widgets.cpp
${PROJECT_SOURCE_DIR}/dep/imgui/imgui_demo.cpp
)
if(CARDBOARD_GRAPHICS_TARGET STREQUAL "opengl")
add_compile_definitions(IMGUI_IMPL_OPENGL_LOADER_GLAD)
set(IMGUI_SOURCES ${IMGUI_SOURCES}
${PROJECT_SOURCE_DIR}/dep/imgui/examples/imgui_impl_opengl3.cpp
)
endif()
if(CARDBOARD_WINDOWS_TARGET STREQUAL "glfw")
set(IMGUI_SOURCES ${IMGUI_SOURCES}
${PROJECT_SOURCE_DIR}/dep/imgui/examples/imgui_impl_glfw.cpp
)
endif()
add_library(imgui ${IMGUI_SOURCES})
set(CARDBOARD_DEPENDENCIES_LIBRARIES ${CARDBOARD_DEPENDENCIES_LIBRARIES}
imgui
)
# --------------------------------------------------------------------------------
# TARGETS
# GRAPHICAL
if(CARDBOARD_GRAPHICS_TARGET STREQUAL "opengl")
find_package(OpenGL REQUIRED)
add_subdirectory(${PROJECT_SOURCE_DIR}/dep/glad)
include_directories(${PROJECT_SOURCE_DIR}/dep/glad/include)
set(CARDBOARD_GRAPHICS_LIBRARIES ${CARDBOARD_GRAPHICS_LIBRARIES}
OpenGL::GL
glad
)
set(CARDBOARD_GRAPHICS_SOURCES ${CARDBOARD_GRAPHICS_SOURCES}
${PROJECT_SOURCE_DIR}/src/graphics/opengl/context.cpp
${PROJECT_SOURCE_DIR}/src/graphics/opengl/shader.cpp
${PROJECT_SOURCE_DIR}/src/graphics/opengl/vertex_buffer.cpp
${PROJECT_SOURCE_DIR}/src/graphics/opengl/element_buffer.cpp
${PROJECT_SOURCE_DIR}/src/graphics/opengl/vertex_array.cpp
${PROJECT_SOURCE_DIR}/src/graphics/opengl/quad_renderer.cpp
${PROJECT_SOURCE_DIR}/src/graphics/opengl/texture.cpp
${PROJECT_SOURCE_DIR}/src/graphics/opengl/texture_batch.cpp
)
else()
message(FATAL_ERROR "There was no graphics target specified! ${CARDBOARD_GRAPHICS_TARGET}")
endif()
set(CARDBOARD_GRAPHICS_SOURCES ${CARDBOARD_GRAPHICS_SOURCES}
${PROJECT_SOURCE_DIR}/src/graphics/particle_system.cpp
${PROJECT_SOURCE_DIR}/src/graphics/camera.cpp
)
add_compile_definitions(CARDBOARD_GRAPHICS_TARGET_OPENGL)
# --------------------------------------------------------------------------------
# TARGETS
# WINDOWS
if(CARDBOARD_WINDOWS_TARGET STREQUAL "glfw")
add_subdirectory(${PROJECT_SOURCE_DIR}/dep/glfw)
include_directories(${PROJECT_SOURCE_DIR}/dep/glfw/include)
set(CARDBOARD_WINDOWS_LIBRARIES ${CARDBOARD_WINDOWS_LIBRARIES}
glfw
)
set(CARDBOARD_WINDOWS_SOURCES ${CARDBOARD_WINDOWS_SOURCES}
${PROJECT_SOURCE_DIR}/src/resources/glfw/window.cpp
${PROJECT_SOURCE_DIR}/src/resources/glfw/keyboard.cpp
${PROJECT_SOURCE_DIR}/src/resources/glfw/mouse.cpp
)
else()
message(FATAL_ERROR "There was no windows target specified! ${CARDBOARD_WINDOWS_TARGET}")
endif()
set(CARDBOARD_WINDOWS_SOURCES ${CARDBOARD_WINDOWS_SOURCES}
${PROJECT_SOURCE_DIR}/src/resources/texture_loader.cpp
${PROJECT_SOURCE_DIR}/src/resources/file.cpp
)
add_compile_definitions(CARDBOARD_WINDOWS_TARGET_GLFW)
# --------------------------------------------------------------------------------
# ASSETS
file(COPY ${PROJECT_SOURCE_DIR}/assets DESTINATION ${PROJECT_BINARY_DIR})
# --------------------------------------------------------------------------------
# MAIN EXECUTABLE
include_directories(${PROJECT_SOURCE_DIR}/src)
add_executable(cardboard_game_engine
${PROJECT_SOURCE_DIR}/src/main.cpp
${CARDBOARD_WINDOWS_SOURCES}
${CARDBOARD_GRAPHICS_SOURCES}
${CARDBOARD_DEPENDENCIES_SOURCES}
)
target_link_libraries(cardboard_game_engine
${CARDBOARD_WINDOWS_LIBRARIES}
${CARDBOARD_GRAPHICS_LIBRARIES}
${CARDBOARD_DEPENDENCIES_LIBRARIES}
)
# --------------------------------------------------------------------------------
# MAIN EXECUTABLE
# COMPILER OPTIONS
target_compile_features(cardboard_game_engine PRIVATE cxx_std_17)
if(MSVC)
target_compile_options(cardboard_game_engine PRIVATE /W4 /WX)
else()
target_compile_options(cardboard_game_engine PRIVATE -Wall -Wextra -pedantic -Werror)
endif()