-
Notifications
You must be signed in to change notification settings - Fork 13
/
CMakeLists.txt
179 lines (164 loc) · 6.53 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
cmake_minimum_required(VERSION 3.25)
include(FetchContent)
project(imgui-glfw-glad-glm VERSION 4.1.0)
set(CMAKE_CXX_STANDARD 17)
set(IGG_COMPONENTS "IMGUI;GLFW;GLAD;GLM" CACHE STRING "The components to import and build")
foreach (comp IN ITEMS ${IGG_COMPONENTS})
set(IMPORT_${comp} ON)
endforeach ()
if (IMPORT_IMGUI)
set(IMPORT_GLAD ON)
set(IMPORT_GLFW ON)
endif ()
if (IMPORT_GLAD)
option(IGG_GLAD_DOWNLOAD "If set to ON the glad gl loader will be generated and downloaded, if OFF the included version (gl4.5/core) will be used" ON)
if (IGG_GLAD_DOWNLOAD)
set(IGG_GLAD_GL_VERSION 4.5 CACHE STRING "The target gl version")
option(IGG_GLAD_GL_CORE "The target gl profile. ON = core profile, OFF = compatibility profile" ON)
if (IGG_GLAD_GL_CORE)
set(GLAD_GL_PROFILE core)
else ()
set(GLAD_GL_PROFILE compatibility)
endif ()
else ()
unset(IGG_GLAD_GL_VERSION CACHE)
unset(IGG_GLAD_GL_CORE CACHE)
endif ()
else ()
unset(IGG_GLAD_DOWNLOAD CACHE)
unset(IGG_GLAD_GL_VERSION CACHE)
unset(IGG_GLAD_GL_CORE CACHE)
endif ()
if (IMPORT_IMGUI)
set(IGG_IMGUI_TAG master CACHE STRING "Defines the imgui version (e.g. master, v1.89.4, v1.89.3, ...")
set(IMPORT_GLFW ON)
else ()
unset(IGG_IMGUI_TAG CACHE)
endif ()
if (IMPORT_GLFW)
set(IGG_GLFW_TAG master CACHE STRING "Defines the glfw version (e.g. master, 3.3.8, 3.3.7, ...) ")
else ()
unset(IGG_GLFW_TAG CACHE)
endif ()
if (IMPORT_GLM)
set(IGG_GLM_TAG master CACHE STRING "Defines the glm version (e.g. master, 0.9.9.8, 0.9.9.7, ...")
else ()
unset(IGG_GLM_TAG CACHE)
endif ()
##############################
# glad #
##############################
if (IMPORT_GLAD)
if (NOT IGG_GLAD_DOWNLOAD)
message(STATUS "Using included version of the glad loader sources (gl 4.5/core) ")
set(glad_SOURCE_DIR glad)
else ()
if ("${glad_INSTALLED_VERSION}" STREQUAL "${IGG_GLAD_GL_VERSION}-${GLAD_GL_PROFILE}")
message(STATUS "Avoiding repeated download of glad gl ${IGG_GLAD_GL_VERSION}/${GLAD_GL_PROFILE}")
set(glad_SOURCE_DIR ${glad_LAST_SOURCE_DIR})
else ()
find_program(IGG_CURL NAMES curl curl.exe)
if (NOT IGG_CURL)
message(STATUS "Could not find curl, using included version of the glad loader sources (gl 4.5/core)")
set(glad_SOURCE_DIR glad)
else ()
execute_process(
COMMAND ${IGG_CURL} -s -D - -X POST -d generator=c&api=egl%3Dnone&api=gl%3D${IGG_GLAD_GL_VERSION}&profile=gl%3D${GLAD_GL_PROFILE}&api=gles1%3Dnone&profile=gles1%3Dcommon&api=gles2%3Dnone&api=glsc2%3Dnone&api=glx%3Dnone&api=vulkan%3Dnone&api=wgl%3Dnone&options=LOADER https://gen.glad.sh/generate
OUTPUT_VARIABLE out
RESULT_VARIABLE res
ERROR_VARIABLE err
)
if (NOT res EQUAL "0")
message(WARNING "${IGG_CURL} returned: " ${res})
if (err)
message(WARNING "Error message: " ${err})
endif ()
message(STATUS "Using included version of the glad loader sources (gl 4.5/core)")
set(glad_SOURCE_DIR glad)
else ()
string(REGEX MATCH "[Ll][Oo][Cc][Aa][Tt][Ii][Oo][Nn]: ([A-Za-z0-9_\\:/\\.]+)" location ${out})
set(location "${CMAKE_MATCH_1}")
if (NOT location OR location STREQUAL "/")
message(WARNING "Could not extract location from http response, using included version of the glad loader sources (gl 4.5/core)")
message(STATUS "Response: " ${out})
set(glad_SOURCE_DIR glad)
else ()
string(REGEX REPLACE "/$" "" location ${location})
string(APPEND location "/glad.zip")
if (NOT ${location} MATCHES "^http")
string(PREPEND location "https://gen.glad.sh")
endif ()
message(STATUS "Downloading glad loader sources for gl${IGG_GLAD_GL_VERSION}/${GLAD_GL_PROFILE} from ${location}")
FetchContent_Declare(
glad
URL ${location}
)
FetchContent_MakeAvailable(glad)
set(glad_INSTALLED_VERSION ${IGG_GLAD_GL_VERSION}-${GLAD_GL_PROFILE} CACHE INTERNAL "")
set(glad_LAST_SOURCE_DIR ${glad_SOURCE_DIR} CACHE INTERNAL "")
endif ()
endif ()
endif ()
endif ()
endif ()
add_library(
glad
${glad_SOURCE_DIR}/src/gl.c
${glad_SOURCE_DIR}/include/glad/gl.h
${glad_SOURCE_DIR}/include/KHR/khrplatform.h
)
target_include_directories(glad PUBLIC ${glad_SOURCE_DIR}/include)
endif ()
if (IMPORT_GLFW)
if (NOT EMSCRIPTEN)
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw.git
GIT_TAG ${IGG_GLFW_TAG}
)
list(APPEND components glfw)
endif ()
endif ()
if (IMPORT_GLM)
FetchContent_Declare(
glm
GIT_REPOSITORY https://github.com/g-truc/glm.git
GIT_TAG ${IGG_GLM_TAG}
)
list(APPEND components glm)
endif ()
if (IMPORT_IMGUI)
FetchContent_Declare(
imgui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG ${IGG_IMGUI_TAG}
)
list(APPEND components imgui)
endif ()
if (components)
FetchContent_MakeAvailable(${components})
endif ()
##############################
# imgui #
##############################
if (IMPORT_IMGUI)
file(GLOB imgui_SRC ${imgui_SOURCE_DIR}/*.cpp ${imgui_SOURCE_DIR}/*.h)
add_library(
imgui
${imgui_SRC}
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.h
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.h
)
target_link_libraries(imgui PUBLIC glad)
if (NOT EMSCRIPTEN)
target_link_libraries(imgui PUBLIC glfw)
endif ()
target_include_directories(
imgui
PUBLIC
${imgui_SOURCE_DIR}
${imgui_SOURCE_DIR}/backends
)
endif ()