From 1bb098bf44cc13ac0842b113052119770d689fbe Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 7 Oct 2023 18:29:52 +1100 Subject: [PATCH] CMake: WITH_OPENGL_BACKEND=OFF excludes EGL/EPOXY includes & libraries This isn't complete as opensubdiv, hydra & XR still depend on OpenGL. --- intern/ghost/CMakeLists.txt | 18 +++++++++++------ intern/ghost/intern/GHOST_ContextEGL.hh | 4 ++++ intern/ghost/intern/GHOST_ContextVK.hh | 4 ++++ intern/ghost/intern/GHOST_SystemHeadless.hh | 4 ++-- intern/ghost/intern/GHOST_SystemWayland.cc | 20 ++++++++++++++----- intern/wayland_dynload/CMakeLists.txt | 15 +++++++++++--- .../extern/wayland_dynload_API.h | 2 ++ source/blender/gpu/CMakeLists.txt | 13 ++++++++---- source/blender/python/generic/CMakeLists.txt | 13 ++++++++++-- source/blender/python/gpu/CMakeLists.txt | 11 ++++++++-- 10 files changed, 80 insertions(+), 24 deletions(-) diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt index b885d0c4a63..45697b424fc 100644 --- a/intern/ghost/CMakeLists.txt +++ b/intern/ghost/CMakeLists.txt @@ -9,7 +9,6 @@ set(INC ) set(INC_SYS - ${Epoxy_INCLUDE_DIRS} ) set(SRC @@ -72,12 +71,17 @@ set(SRC ) set(LIB - ${Epoxy_LIBRARIES} PRIVATE bf::blenlib PRIVATE bf::dna ) if(WITH_OPENGL_BACKEND) + list(APPEND INC_SYS + ${Epoxy_INCLUDE_DIRS} + ) + list(APPEND LIB + ${Epoxy_LIBRARIES} + ) add_definitions(-DWITH_OPENGL_BACKEND) endif() @@ -521,11 +525,13 @@ elseif(WIN32) endif() if(UNIX AND NOT APPLE) - list(APPEND SRC - intern/GHOST_ContextEGL.cc + if(WITH_OPENGL_BACKEND) + list(APPEND SRC + intern/GHOST_ContextEGL.cc - intern/GHOST_ContextEGL.hh - ) + intern/GHOST_ContextEGL.hh + ) + endif() endif() if(APPLE) diff --git a/intern/ghost/intern/GHOST_ContextEGL.hh b/intern/ghost/intern/GHOST_ContextEGL.hh index bb47a2922c4..f43d37074dc 100644 --- a/intern/ghost/intern/GHOST_ContextEGL.hh +++ b/intern/ghost/intern/GHOST_ContextEGL.hh @@ -8,6 +8,10 @@ #pragma once +#ifndef WITH_OPENGL_BACKEND +# error "ContextEGL requires WITH_OPENGL_BACKEND" +#endif + #include "GHOST_Context.hh" #include "GHOST_System.hh" diff --git a/intern/ghost/intern/GHOST_ContextVK.hh b/intern/ghost/intern/GHOST_ContextVK.hh index 8946f90f228..e9b542b5c0d 100644 --- a/intern/ghost/intern/GHOST_ContextVK.hh +++ b/intern/ghost/intern/GHOST_ContextVK.hh @@ -8,6 +8,10 @@ #pragma once +#ifndef WITH_VULKAN_BACKEND +# error "ContextVK requires WITH_VULKAN_BACKEND" +#endif + #include "GHOST_Context.hh" #ifdef _WIN32 diff --git a/intern/ghost/intern/GHOST_SystemHeadless.hh b/intern/ghost/intern/GHOST_SystemHeadless.hh index 59406ca44f2..9c015580346 100644 --- a/intern/ghost/intern/GHOST_SystemHeadless.hh +++ b/intern/ghost/intern/GHOST_SystemHeadless.hh @@ -14,7 +14,7 @@ #include "GHOST_System.hh" #include "GHOST_WindowNULL.hh" -#ifdef __linux__ +#if defined(WITH_OPENGL_BACKEND) && defined(__linux__) # include "GHOST_ContextEGL.hh" #endif #include "GHOST_ContextNone.hh" @@ -84,7 +84,7 @@ class GHOST_SystemHeadless : public GHOST_System { } GHOST_IContext *createOffscreenContext(GHOST_GPUSettings /*gpuSettings*/) override { -#ifdef __linux__ +#if defined(WITH_OPENGL_BACKEND) && defined(__linux__) GHOST_Context *context; for (int minor = 6; minor >= 3; --minor) { context = new GHOST_ContextEGL((GHOST_System *)this, diff --git a/intern/ghost/intern/GHOST_SystemWayland.cc b/intern/ghost/intern/GHOST_SystemWayland.cc index 4e85f0a65e3..6c05021829d 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cc +++ b/intern/ghost/intern/GHOST_SystemWayland.cc @@ -37,10 +37,12 @@ # include /* For `ghost_wl_dynload_libraries`. */ #endif -#ifdef WITH_GHOST_WAYLAND_DYNLOAD -# include -#endif -#include +#ifdef WITH_OPENGL_BACKEND +# ifdef WITH_GHOST_WAYLAND_DYNLOAD +# include +# endif +# include +#endif /* WITH_OPENGL_BACKEND */ #include #include @@ -7464,7 +7466,11 @@ bool ghost_wl_dynload_libraries_init() if (wayland_dynload_client_init(verbose) && /* `libwayland-client`. */ wayland_dynload_cursor_init(verbose) && /* `libwayland-cursor`. */ - wayland_dynload_egl_init(verbose) /* `libwayland-egl`. */ +# ifdef WITH_OPENGL_BACKEND + wayland_dynload_egl_init(verbose) /* `libwayland-egl`. */ +# else + true +# endif ) { # ifdef WITH_GHOST_WAYLAND_LIBDECOR @@ -7475,7 +7481,9 @@ bool ghost_wl_dynload_libraries_init() wayland_dynload_client_exit(); wayland_dynload_cursor_exit(); +# ifdef WITH_OPENGL_BACKEND wayland_dynload_egl_exit(); +# endif return false; } @@ -7484,7 +7492,9 @@ void ghost_wl_dynload_libraries_exit() { wayland_dynload_client_exit(); wayland_dynload_cursor_exit(); +# ifdef WITH_OPENGL_BACKEND wayland_dynload_egl_exit(); +# endif # ifdef WITH_GHOST_WAYLAND_LIBDECOR wayland_dynload_libdecor_exit(); # endif diff --git a/intern/wayland_dynload/CMakeLists.txt b/intern/wayland_dynload/CMakeLists.txt index 5db155dc9cb..233ec230720 100644 --- a/intern/wayland_dynload/CMakeLists.txt +++ b/intern/wayland_dynload/CMakeLists.txt @@ -11,23 +11,32 @@ set(INC set(INC_SYS ${wayland-client_INCLUDE_DIRS} - ${wayland-egl_INCLUDE_DIRS} ${wayland-cursor_INCLUDE_DIRS} ) set(SRC intern/wayland_dynload_client.c intern/wayland_dynload_cursor.c - intern/wayland_dynload_egl.c intern/wayland_dynload_utils.c extern/wayland_dynload_API.h extern/wayland_dynload_client.h extern/wayland_dynload_cursor.h - extern/wayland_dynload_egl.h intern/wayland_dynload_utils.h ) +if(WITH_OPENGL_BACKEND) + list(APPEND INC_SYS + ${wayland-egl_INCLUDE_DIRS} + ) + list(APPEND SRC + intern/wayland_dynload_egl.c + + extern/wayland_dynload_egl.h + ) + add_definitions(-DWITH_OPENGL_BACKEND) +endif() + if(WITH_GHOST_WAYLAND_LIBDECOR) list(APPEND INC_SYS ${libdecor_INCLUDE_DIRS} diff --git a/intern/wayland_dynload/extern/wayland_dynload_API.h b/intern/wayland_dynload/extern/wayland_dynload_API.h index a5f15e4b8a1..da8b3c4fc60 100644 --- a/intern/wayland_dynload/extern/wayland_dynload_API.h +++ b/intern/wayland_dynload/extern/wayland_dynload_API.h @@ -20,8 +20,10 @@ void wayland_dynload_client_exit(void); bool wayland_dynload_cursor_init(bool verbose); void wayland_dynload_cursor_exit(void); +#ifdef WITH_OPENGL_BACKEND bool wayland_dynload_egl_init(bool verbose); void wayland_dynload_egl_exit(void); +#endif #ifdef WITH_GHOST_WAYLAND_LIBDECOR bool wayland_dynload_libdecor_init(bool verbose); diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index be0c55e59de..c89deb67c2a 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -43,7 +43,6 @@ if(WITH_RENDERDOC) endif() set(INC_SYS - ${Epoxy_INCLUDE_DIRS} ) set(SRC @@ -325,14 +324,20 @@ set(LIB PRIVATE bf::blenlib PRIVATE bf::dna PRIVATE bf::intern::atomic - ${Epoxy_LIBRARIES} PRIVATE bf::intern::guardedalloc ) # Select Backend source based on availability if(WITH_OPENGL_BACKEND) - list(APPEND SRC ${OPENGL_SRC}) - + list(APPEND INC_SYS + ${Epoxy_INCLUDE_DIRS} + ) + list(APPEND SRC + ${OPENGL_SRC} + ) + list(APPEND LIB + ${Epoxy_LIBRARIES} + ) add_definitions(-DWITH_OPENGL_BACKEND) endif() diff --git a/source/blender/python/generic/CMakeLists.txt b/source/blender/python/generic/CMakeLists.txt index 77148216078..6fd75fb46a1 100644 --- a/source/blender/python/generic/CMakeLists.txt +++ b/source/blender/python/generic/CMakeLists.txt @@ -11,7 +11,6 @@ set(INC ) set(INC_SYS - ${Epoxy_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} ) @@ -41,7 +40,6 @@ set(SRC ) set(LIB - ${Epoxy_LIBRARIES} ${PYTHON_LINKFLAGS} ${PYTHON_LIBRARIES} PRIVATE bf::blenlib @@ -49,6 +47,17 @@ set(LIB PRIVATE bf::intern::guardedalloc ) +# NOTE: use irrespective of `WITH_OPENGL_BACKEND` as the `bgl` module uses this for constants. +list(APPEND INC_SYS + ${Epoxy_INCLUDE_DIRS} +) + +if(WITH_OPENGL_BACKEND) + list(APPEND LIB + ${Epoxy_LIBRARIES} + ) +endif() + if(WITH_PYTHON_MODULE) add_definitions(-DWITH_PYTHON_MODULE) endif() diff --git a/source/blender/python/gpu/CMakeLists.txt b/source/blender/python/gpu/CMakeLists.txt index aa15280cad1..868eb1c713c 100644 --- a/source/blender/python/gpu/CMakeLists.txt +++ b/source/blender/python/gpu/CMakeLists.txt @@ -11,7 +11,6 @@ set(INC ) set(INC_SYS - ${Epoxy_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} ) @@ -57,7 +56,6 @@ set(SRC ) set(LIB - ${Epoxy_LIBRARIES} ${PYTHON_LINKFLAGS} ${PYTHON_LIBRARIES} PRIVATE bf::blenlib @@ -65,4 +63,13 @@ set(LIB PRIVATE bf::intern::guardedalloc ) +if(WITH_OPENGL_BACKEND) + list(APPEND INC_SYS + ${Epoxy_INCLUDE_DIRS} + ) + list(APPEND LIB + ${Epoxy_LIBRARIES} + ) +endif() + blender_add_lib(bf_python_gpu "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")