diff --git a/cmake/ncine_extra_sources.cmake b/cmake/ncine_extra_sources.cmake index 75b54697..b573dd90 100644 --- a/cmake/ncine_extra_sources.cmake +++ b/cmake/ncine_extra_sources.cmake @@ -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() diff --git a/cmake/ncine_imported_targets.cmake b/cmake/ncine_imported_targets.cmake index e5b7909c..55c2821f 100644 --- a/cmake/ncine_imported_targets.cmake +++ b/cmake/ncine_imported_targets.cmake @@ -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)