forked from anholt/libepoxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
313 lines (291 loc) · 9.87 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
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
cmake_minimum_required(VERSION 3.20)
include(CheckIncludeFile)
set(EPOXY_PROJECT_NAME libepoxy)
set(EPOXY_PROJECT_VERSION 1.5.10)
project(${EPOXY_PROJECT_NAME} VERSION ${EPOXY_PROJECT_VERSION} LANGUAGES C)
set(LIBEPOXY_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(LIBEPOXY_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR})
# meson.build
include(GNUInstallDirs)
set(PACKAGE_NAME ${EPOXY_PROJECT_NAME})
set(PACKAGE_VERSION ${EPOXY_PROJECT_VERSION})
set(PACKAGE_STRING "${PACKAGE_NAME}-${PACKAGE_VERSION}")
set(PACKAGE_DATADIR ${CMAKE_INSTALL_PREFIX})
cmake_path(APPEND PACKAGE_DATADIR ${CMAKE_INSTALL_DATADIR})
set(PACKAGE_LIBDIR ${CMAKE_INSTALL_PREFIX})
cmake_path(APPEND PACKAGE_LIBDIR ${CMAKE_INSTALL_LIBDIR})
set(PACKAGE_LOCALEDIR ${CMAKE_INSTALL_PREFIX})
cmake_path(APPEND PACKAGE_LOCALEDIR ${CMAKE_INSTALL_LOCALEDIR})
set(PACKAGE_LIBEXECDIR ${CMAKE_INSTALL_PREFIX})
cmake_path(APPEND PACKAGE_LOCALEDIR ${CMAKE_INSTALL_LIBEXECDIR})
CHECK_INCLUDE_FILE("KHR/khrplatform.h" HAVE_KHRPLATFORM_H CMAKE_REQUIRED_QUIET)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(EPOXY_ENABLE_GLX "Enable GLX support" OFF)
option(EPOXY_ENABLE_EGL "Enable EGL support" OFF)
option(EPOXY_ENABLE_X11 "Enable X11 support" OFF)
if(NOT WIN32 AND NOT APPLE AND NOT ANDROID AND NOT EMSCRIPTEN)
set(BUILD_GLX ${EPOXY_ENABLE_GLX})
else()
set(BUILD_GLX FALSE)
endif()
if(NOT WIN32 AND NOT APPLE)
set(BUILD_EGL ${EPOXY_ENABLE_EGL})
else()
set(BUILD_EGL FALSE)
endif()
# Remaining platform specific API for GL/GLES are enabled
# depending on the platform we're building for.
if(WIN32)
set(BUILD_WGL ON)
set(EPOXY_HAS_ZNOW YES)
elseif(APPLE)
set(BUILD_WGL OFF)
set(EPOXY_HAS_ZNOW NO)
else()
set(BUILD_WGL OFF)
set(EPOXY_HAS_ZNOW YES)
endif()
if(BUILD_SHARED_LIBS)
add_library(epoxy SHARED)
if(WIN32)
target_compile_definitions(epoxy PRIVATE
DLL_EXPORT
"EPOXY_PUBLIC=__declspec(dllexport) extern"
)
if(NOT MSVC)
target_compile_options(epoxy PRIVATE
-fvisibility=hidden
)
endif()
else()
target_compile_definitions(epoxy PRIVATE
"EPOXY_PUBLIC=__attribute__((visibility(\"default\"))) extern"
)
target_compile_options(epoxy PRIVATE
-fvisibility=hidden
)
endif()
else()
add_library(epoxy STATIC)
endif()
target_compile_features(epoxy PRIVATE c_std_99)
# The inline keyword is only available for C++ in MSVC.
# So we need to use Microsoft specific __inline.
if(WIN32)
if(MSVC)
target_compile_definitions(epoxy PRIVATE
inline=__inline
)
endif()
endif()
find_library(DL_LIB dl)
find_package(OpenGL REQUIRED)
# @todo See if we can remove below.
#if(EGL_FOUND)
# add_library(egl_headers INTERFACE)
# target_include_directories(egl_headers INTERFACE ${EGL_INCLUDE_DIRS})
# target_compile_definitions(egl_headers INTERFACE ${EGL_DEFINITIONS})
#endif()
find_package(X11 CONFIG)
if(X11_FOUND)
add_library(x11_headers INTERFACE)
target_include_directories(x11_headers INTERFACE ${X11_INCLUDE_DIRS})
target_compile_definitions(x11_headers INTERFACE ${X11_DEFINITIONS})
endif()
# GLES v2 and v1 may have pkg-config files, courtesy of downstream
# packagers; let's check those first, and fall back to find_library()
# if we fail
# @todo See if we can remove below.
#find_package(glesv2 CONFIG)
#if(NOT glesv2_FOUND)
# find_library(glesv2_LIB libGLESv2)
#endif()
#
#find_package(glesv1_cm CONFIG)
#if(NOT glesv1_cm_FOUND)
# find_library(glesv1_cm_LIB libGLESv1_CM)
#endif()
# On windows, the DLL has to have all of its functions
# resolved at link time, so we have to link directly against
# opengl32. But that's the only GL provider, anyway.
#if(WIN32)
# find_library(${OPENGL_LIBRARIES} REQUIRED)
#
# find_library(gdi32_dep gdi32 REQUIRED)
#endif()
find_package(Python3 REQUIRED)
if(NOT EXISTS ${LIBEPOXY_BIN_DIR}/include/epoxy)
file(MAKE_DIRECTORY ${LIBEPOXY_BIN_DIR}/include/epoxy)
endif()
if(NOT EXISTS ${LIBEPOXY_BIN_DIR}/src)
file(MAKE_DIRECTORY ${LIBEPOXY_BIN_DIR}/src)
endif()
if(EMSCRIPTEN)
set(LIBEPOXY_EMSCRIPTEN_FLAG --emscripten)
else()
set(LIBEPOXY_EMSCRIPTEN_FLAG --no-emscripten)
endif()
add_custom_command(
OUTPUT ${LIBEPOXY_BIN_DIR}/include/epoxy/gl_generated.h
MAIN_DEPENDENCY ${LIBEPOXY_SRC_DIR}/registry/gl.xml
COMMAND ${Python3_EXECUTABLE}
${LIBEPOXY_SRC_DIR}/src/gen_dispatch.py
--header
--no-source
${LIBEPOXY_EMSCRIPTEN_FLAG}
--outputdir=${LIBEPOXY_BIN_DIR}/include/epoxy
${LIBEPOXY_SRC_DIR}/registry/gl.xml
COMMENT "Generating `gl_generated.h`"
)
add_custom_command(
OUTPUT ${LIBEPOXY_BIN_DIR}/src/gl_generated_dispatch.c
MAIN_DEPENDENCY ${LIBEPOXY_SRC_DIR}/registry/gl.xml
COMMAND ${Python3_EXECUTABLE}
${LIBEPOXY_SRC_DIR}/src/gen_dispatch.py
--source
--no-header
${LIBEPOXY_EMSCRIPTEN_FLAG}
--outputdir=${LIBEPOXY_BIN_DIR}/src
${LIBEPOXY_SRC_DIR}/registry/gl.xml
COMMENT "Generating `gl_generated_dispatch.c`"
)
# include/epoxy/meson.build
# src/meson.build
set(ENABLE_GLX ${BUILD_GLX})
set(ENABLE_EGL ${BUILD_EGL})
set(ENABLE_X11 ${EPOXY_ENABLE_X11})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${LIBEPOXY_BIN_DIR}/include/epoxy/config.h @ONLY)
target_include_directories(epoxy
PUBLIC
${LIBEPOXY_SRC_DIR}/include
${LIBEPOXY_BIN_DIR}/include
${LIBEPOXY_SRC_DIR}/include/epoxy
${LIBEPOXY_BIN_DIR}/include/epoxy
${LIBEPOXY_SRC_DIR}/src)
if(EMSCRIPTEN)
target_sources(epoxy
PRIVATE
${LIBEPOXY_SRC_DIR}/src/dispatch_emscripten.c
)
endif()
target_sources(epoxy
PUBLIC
${LIBEPOXY_SRC_DIR}/include/epoxy/gl.h
)
target_sources(epoxy
PRIVATE
${LIBEPOXY_BIN_DIR}/include/epoxy/config.h
${LIBEPOXY_SRC_DIR}/include/epoxy/common.h
${LIBEPOXY_BIN_DIR}/include/epoxy/gl_generated.h
${LIBEPOXY_SRC_DIR}/src/dispatch_common.h
${LIBEPOXY_SRC_DIR}/src/dispatch_common.c
${LIBEPOXY_BIN_DIR}/src/gl_generated_dispatch.c
)
if(BUILD_EGL)
add_custom_command(
OUTPUT ${LIBEPOXY_BIN_DIR}/include/epoxy/egl_generated.h
MAIN_DEPENDENCY ${LIBEPOXY_SRC_DIR}/registry/egl.xml
COMMAND ${Python3_EXECUTABLE}
${LIBEPOXY_SRC_DIR}/src/gen_dispatch.py
--header
--no-source
--outputdir=${LIBEPOXY_BIN_DIR}/include/epoxy
${LIBEPOXY_SRC_DIR}/registry/egl.xml
COMMENT "Generating `egl_generated.h`"
)
add_custom_command(
OUTPUT ${LIBEPOXY_BIN_DIR}/src/egl_generated_dispatch.c
MAIN_DEPENDENCY ${LIBEPOXY_SRC_DIR}/registry/egl.xml
COMMAND ${Python3_EXECUTABLE}
${LIBEPOXY_SRC_DIR}/src/gen_dispatch.py
--source
--no-header
--outputdir=${LIBEPOXY_BIN_DIR}/src
${LIBEPOXY_SRC_DIR}/registry/egl.xml
COMMENT "Generating `egl_generated_dispatch.c`"
)
target_sources(epoxy PRIVATE
${LIBEPOXY_SRC_DIR}/include/epoxy/egl.h
${LIBEPOXY_BIN_DIR}/include/epoxy/egl_generated.h
${LIBEPOXY_SRC_DIR}/src/dispatch_egl.c
${LIBEPOXY_BIN_DIR}/src/egl_generated_dispatch.c
)
endif()
if(BUILD_GLX)
add_custom_command(
OUTPUT ${LIBEPOXY_BIN_DIR}/include/epoxy/glx_generated.h
MAIN_DEPENDENCY ${LIBEPOXY_SRC_DIR}/registry/glx.xml
COMMAND ${Python3_EXECUTABLE}
${LIBEPOXY_SRC_DIR}/src/gen_dispatch.py
--header
--no-source
--outputdir=${LIBEPOXY_BIN_DIR}/include/epoxy
${LIBEPOXY_SRC_DIR}/registry/glx.xml
COMMENT "Generating `glx_generated.h`"
)
add_custom_command(
OUTPUT ${LIBEPOXY_BIN_DIR}/src/glx_generated_dispatch.c
MAIN_DEPENDENCY ${LIBEPOXY_SRC_DIR}/registry/glx.xml
COMMAND ${Python3_EXECUTABLE}
${LIBEPOXY_SRC_DIR}/src/gen_dispatch.py
--source
--no-header
--outputdir=${LIBEPOXY_BIN_DIR}/src
${LIBEPOXY_SRC_DIR}/registry/glx.xml
COMMENT "Generating `glx_generated_dispatch.c`"
)
target_sources(epoxy PRIVATE
${LIBEPOXY_SRC_DIR}/include/epoxy/glx.h
${LIBEPOXY_BIN_DIR}/include/epoxy/glx_generated.h
${LIBEPOXY_SRC_DIR}/src/dispatch_glx.c
${LIBEPOXY_BIN_DIR}/src/glx_generated_dispatch.c
)
endif()
if(BUILD_WGL)
add_custom_command(
OUTPUT ${LIBEPOXY_BIN_DIR}/include/epoxy/wgl_generated.h
MAIN_DEPENDENCY ${LIBEPOXY_SRC_DIR}/registry/egl.xml
COMMAND ${Python3_EXECUTABLE}
${LIBEPOXY_SRC_DIR}/src/gen_dispatch.py
--header
--no-source
--outputdir=${LIBEPOXY_BIN_DIR}/include/epoxy
${LIBEPOXY_SRC_DIR}/registry/wgl.xml
COMMENT "Generating `wgl_generated.h`"
)
add_custom_command(
OUTPUT ${LIBEPOXY_BIN_DIR}/src/wgl_generated_dispatch.c
MAIN_DEPENDENCY ${LIBEPOXY_SRC_DIR}/registry/wgl.xml
COMMAND ${Python3_EXECUTABLE}
${LIBEPOXY_SRC_DIR}/src/gen_dispatch.py
--source
--no-header
--outputdir=${LIBEPOXY_BIN_DIR}/src
${LIBEPOXY_SRC_DIR}/registry/wgl.xml
COMMENT "Generating `wgl_generated_dispatch.c`"
)
target_sources(epoxy PRIVATE
${LIBEPOXY_SRC_DIR}/include/epoxy/wgl.h
${LIBEPOXY_BIN_DIR}/include/epoxy/wgl_generated.h
${LIBEPOXY_SRC_DIR}/src/dispatch_wgl.c
${LIBEPOXY_BIN_DIR}/src/wgl_generated_dispatch.c
)
endif()
if(UNIX AND NOT APPLE)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_options(epoxy PRIVATE
-Wl,-Bsymbolic-functions
-Wl,-z,relro
)
endif()
endif()
if(WIN32)
target_link_libraries(epoxy PRIVATE OpenGL::GL)
endif()
if(BUILD_X11)
target_link_libraries(epoxy PRIVATE ${x11_headers})
endif()
# @todo See if we can remove below.
#if(BUILD_EGL)
# target_link_libraries(epoxy PRIVATE ${egl_headers})
#endif()