-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
150 lines (122 loc) · 3.86 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.14 FATAL_ERROR)
# ---- Project ----
project(
procedural-terrain
VERSION 1.0
LANGUAGES CXX
)
# ---- Include guards ----
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(
FATAL_ERROR
"In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there."
)
endif()
# ---- Add dependencies via CPM ----
# see https://github.com/TheLartians/CPM.cmake for more info
include(cmake/CPM.cmake)
CPMAddPackage("gh:TheLartians/Format.cmake@1.7.0")
# Threads
find_package(Threads REQUIRED)
# OpenGL
find_package(OpenGL)
# Glad: https://github.com/Dav1dde/glad
CPMAddPackage(
NAME glad
GITHUB_REPOSITORY Dav1dde/glad
VERSION 0.1.34
)
# GLM
CPMAddPackage(
NAME glm
GIT_TAG 0.9.9.8
GITHUB_REPOSITORY g-truc/glm
)
# stb
CPMAddPackage(
NAME stb
GITHUB_REPOSITORY nothings/stb
GIT_TAG c9064e317699d2e495f36ba4f9ac037e88ee371a
DOWNLOAD_ONLY YES
)
if(stb_ADDED)
add_library(stb INTERFACE)
target_include_directories(stb INTERFACE ${stb_SOURCE_DIR})
endif()
# SDL2
CPMAddPackage(
NAME SDL2
GITHUB_REPOSITORY libsdl-org/SDL
VERSION 2.0.15
# 2.0.15 hasn't released yet, so let's use a specific commit
GIT_TAG 62a562dea20728726a497b4af49d591a2fa385de
)
# ImGui: https://github.com/ocornut/imgui
CPMAddPackage(
NAME imgui
GIT_REPOSITORY https://github.com/ocornut/imgui
VERSION 1.82
)
if(imgui_ADDED)
set(IMGUI_INCLUDE_DIR ${imgui_SOURCE_DIR}/)
file(GLOB IMGUI_SOURCES ${imgui_SOURCE_DIR}/*.cpp)
file(GLOB IMGUI_HEADERS ${imgui_SOURCE_DIR}/*.h)
add_library(imgui STATIC ${IMGUI_SOURCES})
target_compile_definitions(imgui PRIVATE IMGUI_IMPL_OPENGL_LOADER_GLAD=1)
target_include_directories(imgui PUBLIC ${IMGUI_INCLUDE_DIR})
endif()
# ImGuizmo: https://github.com/ocornut/imgui
CPMAddPackage(
NAME imguizmo
GIT_REPOSITORY https://github.com/CedricGuillemet/ImGuizmo
GIT_TAG f7bbbe39971d9d45816417a70e9b53a0f698c56e
)
if(imguizmo_ADDED)
file(GLOB IMGUIZMO_SOURCES ${imguizmo_SOURCE_DIR}/*.cpp)
file(GLOB IMGUIZMO_HEADERS ${imguizmo_SOURCE_DIR}/*.h)
add_library(imguizmo STATIC ${IMGUIZMO_SOURCES})
target_link_libraries(imguizmo PUBLIC imgui)
target_include_directories(imguizmo PUBLIC ${imguizmo_SOURCE_DIR})
endif()
# Tiny Obj Loader
CPMAddPackage(
NAME tinyobjloader
GIT_REPOSITORY https://github.com/tinyobjloader/tinyobjloader
VERSION 1.0.6
)
# --- Import tools ----
include(cmake/tools.cmake)
# ---- Add source files ----
# Note: globbing sources is considered bad practice as CMake's generators may not detect new files
# automatically. Keep that in mind when changing files, or explicitly mention them here.
file(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h")
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
file(GLOB_RECURSE shaders CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/resources/shaders/*")
# ---- Create executable ----
# list all files that will either be used for compilation or that should show up in the ide of your
# choice
add_executable(
procedural-terrain ${headers} ${sources} ${shaders} ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp
)
set_target_properties(procedural-terrain PROPERTIES CXX_STANDARD 17)
# being a cross-platform target, we enforce standards conformance on MSVC
target_compile_options(procedural-terrain PUBLIC "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive->")
# Link dependencies
target_link_libraries(
procedural-terrain
PUBLIC ${CMAKE_DL_LIBS}
glad
glm
stb
SDL2-static
imgui
imguizmo
tinyobjloader
)
if(FALSE)
target_include_directories(
procedural-terrain PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)
endif()