@@ -214,40 +214,49 @@ if (MATPLOTPP_BUILD_EXPERIMENTAL_OPENGL_BACKEND)
214
214
# The biggest con of the OpenGL backend is that it cannot open a window
215
215
# in another thread. All it can do is get in the middle of the render
216
216
# loop and draw the plot.
217
- find_package (OpenGL REQUIRED )
217
+ find_package (OpenGL )
218
218
219
219
# https://github.com/Dav1dde/glad
220
- find_package (GLAD QUIET )
221
- if (NOT GLAD_FOUND AND NOT TARGET glad )
222
- # Use CPM only if not found, to avoid ODR violations
223
- # find_package(GLAD REQUIRE) would suffice if it worked well
224
- FetchContent_Declare (glad GIT_REPOSITORY https://github.com/Dav1dde/glad.git GIT_TAG df8e9e16110b305479a875399cee13daa0ccadd9 )
225
- FetchContent_MakeAvailable (glad )
226
- else ()
227
- # FindGLAD does not usually create a target, so we create an interface target
228
- if (NOT TARGET glad )
229
- add_library (glad INTERFACE )
230
- target_include_directories (glad INTERFACE ${GLAD_INCLUDE_PATH} )
231
- target_link_libraries (glad INTERFACE ${GLAD_LIBRARIES} )
232
- endif ()
233
- endif ()
220
+ find_package (glad CONFIG )
221
+ if (NOT glad_FOUND )
222
+ find_package (GLAD QUIET )
223
+ if (NOT GLAD_FOUND AND NOT TARGET glad )
224
+ # Use CPM only if not found, to avoid ODR violations
225
+ # find_package(GLAD REQUIRE) would suffice if it worked well
226
+ FetchContent_Declare (glad GIT_REPOSITORY https://github.com/Dav1dde/glad.git GIT_TAG df8e9e16110b305479a875399cee13daa0ccadd9 )
227
+ FetchContent_MakeAvailable (glad )
228
+ else ()
229
+ if (TARGET glad )
230
+ add_library (glad::glad ALIAS glad )
231
+ endif ()
232
+ if (NOT TARGET glad::glad )
233
+ # FindGLAD does not usually create a target, so we create an interface target
234
+ add_library (glad::glad INTERFACE )
235
+ target_include_directories (glad::glad INTERFACE ${GLAD_INCLUDE_PATH} )
236
+ target_link_libraries (glad::glad INTERFACE ${GLAD_LIBRARIES} )
237
+ endif ()
238
+ endif ()
239
+ endif ()
234
240
235
241
# https://github.com/glfw/glfw
236
- find_package (glfw3 QUIET )
237
- if (NOT GLFW3_FOUND AND NOT TARGET glfw )
238
- # Use CPM only if not found, to avoid ODR violations
239
- # find_package(glfw3 REQUIRE) would suffice if it worked well
240
- FetchContent_Declare (glfw3 GIT_REPOSITORY https://github.com/glfw/glfw.git GIT_TAG 3.3.2 )
241
- FetchContent_MakeAvailable (glfw3 )
242
- endif ()
242
+ find_package (glfw3 CONFIG )
243
+ if (NOT glfw3_FOUND )
244
+ find_package (glfw3 QUIET )
245
+ if (NOT GLFW3_FOUND AND NOT TARGET glfw )
246
+ # Use CPM only if not found, to avoid ODR violations
247
+ # find_package(glfw3 REQUIRE) would suffice if it worked well
248
+ FetchContent_Declare (glfw3 GIT_REPOSITORY https://github.com/glfw/glfw.git GIT_TAG 3.3.2 )
249
+ FetchContent_MakeAvailable (glfw3 )
250
+ endif ()
251
+ endif ()
243
252
244
253
add_library (matplot_opengl
245
254
backend/opengl_embed.h
246
255
backend/opengl_embed.cpp
247
256
backend/opengl.h
248
257
backend/opengl.cpp
249
258
)
250
- target_link_libraries (matplot_opengl PUBLIC matplot glad glfw ${CMAKE_DL_LIBS} )
259
+ target_link_libraries (matplot_opengl PUBLIC matplot glad::glad glfw ${CMAKE_DL_LIBS} )
251
260
252
261
list (APPEND TARGETS matplot_opengl )
253
262
endif ()
0 commit comments