Skip to content

Commit

Permalink
change cmake setup to use auto option
Browse files Browse the repository at this point in the history
  • Loading branch information
nmwsharp committed Mar 25, 2024
1 parent 53016e7 commit 02c1023
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cmake_policy(SET CMP0054 NEW) # don't implicitly dereference inside if()
# Backend
set(POLYSCOPE_BACKEND_OPENGL3_GLFW "ON" CACHE BOOL "Enable openGL3_glfw backend")
set(POLYSCOPE_BACKEND_OPENGL_MOCK "ON" CACHE BOOL "Enable openGL_mock backend")
set(POLYSCOPE_BACKEND_OPENGL3_EGL "OFF" CACHE BOOL "Enable openGL3_egl backend") # disable EGL by default, for now
set(POLYSCOPE_BACKEND_OPENGL3_EGL "AUTO" CACHE STRING "Enable openGL3_egl backend") # 'AUTO' means "if we're on linux and EGL.h is available"

### Do anything needed for dependencies and bring their stuff in to scope
add_subdirectory(deps)
Expand Down
36 changes: 33 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,43 @@ if("${POLYSCOPE_BACKEND_OPENGL3_GLFW}")
add_definitions(-DPOLYSCOPE_BACKEND_OPENGL3_GLFW_ENABLED)
endif()

## some logic to decide whether or not EGL is available and whether we want to build with it
include(CheckIncludeFileCXX)
CHECK_INCLUDE_FILE_CXX("EGL/egl.h" HAVE_EGL_LIB)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(IS_LINUX TRUE)
else()
set(IS_LINUX FALSE)
endif()

if(POLYSCOPE_BACKEND_OPENGL3_EGL STREQUAL "AUTO")
if(IS_LINUX AND HAVE_EGL_LIB) # "AUTO" policy: only enable if we're on linux and EGL libs seem to be present
set(POLYSCOPE_BACKEND_OPENGL3_EGL ON)
else()
set(POLYSCOPE_BACKEND_OPENGL3_EGL OFF)
endif()
elseif(POLYSCOPE_BACKEND_OPENGL3_EGL) # if "TRUE" (or "ON" or "YES" etc etc)
# sanity check that we can actually use the EGL backend
if(NOT IS_LINUX)
message(FATAL_ERROR "EGL backend is only supported on linux. Disable it with POLYSCOPE_BACKEND_OPENGL3_EGL=False")
endif()
if(NOT HAVE_EGL_LIB)
message(FATAL_ERROR "EGL backend requires EGL headers, but 'EGL/egl.h' was not found. On Ubuntu, try 'apt-get install libegl1-mesa-dev'")
endif()

# we should be good-to-go for EGL

else()
# nothing to do, already disabled
endif()




if("${POLYSCOPE_BACKEND_OPENGL3_EGL}")
message("Polyscope backend openGL3_egl enabled")

# this only supports headless rendering, and as of Mar 2024 headless rendering seems to only be available on nvidia drivers.
#
# This adds an additional requirement for EGL.h headers, get them on Ubuntu & friends via
# sudo apt-get install libegl1-mesa-dev

list(APPEND BACKEND_HEADERS
${INCLUDE_ROOT}render/opengl/gl_engine_egl.h
Expand Down

0 comments on commit 02c1023

Please sign in to comment.