Skip to content

Commit

Permalink
Fix compilation against GLVND instead of legacy GLX
Browse files Browse the repository at this point in the history
  • Loading branch information
vanfanel committed Jul 27, 2024
1 parent 337b942 commit b8f64c8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cmake/ncine_extra_sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ if(ANGLE_FOUND OR OPENGLES2_FOUND)
list(APPEND SOURCES ${NCINE_SOURCE_DIR}/nCine/Graphics/TextureLoaderPkm.cpp)
elseif(OPENGL_FOUND)
if(TARGET OpenGL::OpenGL)
message(STATUS "Using newer OpenGL::OpenGL target (GLVND)")
message(STATUS "Using OpenGL::OpenGL target (GLVND)")
target_link_libraries(${NCINE_APP} PRIVATE OpenGL::OpenGL)
else()
message(STATUS "Using legacy OpenGL::GL target (GLX)")
target_link_libraries(${NCINE_APP} PRIVATE OpenGL::GL)
endif()
else()
Expand Down
20 changes: 18 additions & 2 deletions cmake/ncine_imported_targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,24 @@ elseif(NOT ANDROID AND NOT NCINE_BUILD_ANDROID) # GCC and LLVM
find_package(GLEW)
endif()
if(NOT NINTENDO_SWITCH)
set(OPENGL_USE_OPENGL ON)
find_package(OpenGL)
# Use pkg-config's pkg_search_module() instead of find_package()
# which isn't reliable for GLVND
find_package(PkgConfig REQUIRED)
pkg_search_module(OPENGL REQUIRED opengl)
# Create import target
add_library(OpenGL::OpenGL INTERFACE IMPORTED)
# Set import target properties
set_target_properties(OpenGL::OpenGL PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${GLVND_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${GLVND_LIBRARIES}"
)

if(OPENGL_FOUND)
message(STATUS "Using modern GLVND for OpenGL")
else()
message(STATUS "Trying to use legacy OpenGL GLX for OpenGL")
find_package(OpenGL)
endif()
endif()
if(NCINE_ARM_PROCESSOR)
include(check_atomic)
Expand Down

0 comments on commit b8f64c8

Please sign in to comment.