Commit e2e8a690 authored by Tom Fogal's avatar Tom Fogal Committed by Brad King

FindOpenGL: Add support for GLVND on Linux

Find GLVND components if available.  Add `GLX` and `EGL` options for
COMPONENTS that allow requesting these libraries explicitly.  Introduce
new import targets for these windowing-system-specific libraries.

On a GLVND system, populate the legacy `OPENGL_LIBRARIES` variable and
the `OpenGL::GL` target using the `OpenGL` and `GLX` components.  On
non-GLVND systems, continue to use the legacy `GL` library and simply do
not provide the GLVND components.  Application code can choose to adapt
based on the availability of GLVND components as imported targets.
parent eae3765b
......@@ -76,6 +76,7 @@ The following individuals and institutions are among the Contributors:
* Nicolas Bock <nicolasbock@gmail.com>
* Nicolas Despres <nicolas.despres@gmail.com>
* Nikita Krupen'ko <krnekit@gmail.com>
* NVIDIA Corporation <www.nvidia.com>
* OpenGamma Ltd. <opengamma.com>
* Per Øyvind Karlsen <peroyvind@mandriva.org>
* Peter Collingbourne <peter@pcc.me.uk>
......
FindOpenGL-glvnd
----------------
* The :module:`FindOpenGL` module gained support for GLVND on Linux.
This diff is collapsed.
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMake_TEST_FindOpenGL_VND)
set(_vnd_testing TRUE)
else()
set(_vnd_testing FALSE)
endif()
add_test(NAME FindOpenGL.Test COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
......@@ -6,5 +12,6 @@ add_test(NAME FindOpenGL.Test COMMAND
${build_generator_args}
--build-project TestFindOpenGL
--build-options ${build_options}
-DOpenGL_TEST_VND=${_vnd_testing}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
cmake_minimum_required(VERSION 3.7)
cmake_minimum_required(VERSION 3.9)
project(TestFindOpenGL C)
include(CTest)
find_package(OpenGL REQUIRED)
# import target for GLU
add_executable(test_tgt main.c)
target_link_libraries(test_tgt OpenGL::GLU)
add_test(NAME test_tgt COMMAND test_tgt)
# OPENGL_LIBRARIES should be whatever libraries are needed to link.
add_executable(test_var main.c)
target_include_directories(test_var PRIVATE ${OPENGL_INGLUDE_DIRS})
target_link_libraries(test_var PRIVATE ${OPENGL_LIBRARIES})
add_test(NAME test_var COMMAND test_var)
# VND support adds an ::OpenGL import target. This can be used for OpenGL-only
# code (code that does not manipulate contexts, like our 'main.c'). Without
# VND, ::GL can be used for both context and non-context OpenGL code.
if(OpenGL_TEST_VND)
add_executable(test_comp_none main.c)
target_link_libraries(test_comp_none PRIVATE OpenGL::OpenGL)
add_test(NAME test_comp_none COMMAND test_comp_none)
else()
add_executable(test_comp_none main.c)
target_link_libraries(test_comp_none PRIVATE OpenGL::GL)
add_test(NAME test_comp_none COMMAND test_comp_none)
endif()
# GLX
if(OpenGL_TEST_VND)
find_package(OpenGL REQUIRED COMPONENTS OpenGL GLX)
add_executable(test_comp_glx main.c)
target_link_libraries(test_comp_glx PRIVATE OpenGL::OpenGL OpenGL::GLX)
add_test(NAME test_comp_glx COMMAND test_comp_glx)
else()
# non-VND systems won't have it, but an optional search for GLX should still
# be okay.
find_package(OpenGL COMPONENTS GLX)
add_executable(test_comp_glx_novnd main.c)
target_link_libraries(test_comp_glx_novnd PRIVATE OpenGL::GL)
add_test(NAME test_comp_glx_novnd COMMAND test_comp_glx_novnd)
endif()
# EGL is only available on Linux+GLVND at present.
if(OpenGL_TEST_VND)
find_package(OpenGL COMPONENTS OpenGL EGL)
if(OpenGL_EGL_FOUND)
add_executable(test_comp_egl main.c)
target_link_libraries(test_comp_egl PRIVATE OpenGL::OpenGL OpenGL::EGL)
add_test(NAME test_comp_egl COMMAND test_comp_egl)
# EGL-only code should not link to GLX.
execute_process(COMMAND ldd test_comp_egl
OUTPUT_VARIABLE LDD_OUT
ERROR_VARIABLE LDD_ERR)
if("${LDD_OUT}" MATCHES "GLX")
message(FATAL_ERROR "EGL-only code links to GLX!")
endif()
endif()
# all three COMPONENTS together.
find_package(OpenGL COMPONENTS OpenGL EGL GLX)
if(OpenGL_EGL_FOUND AND OpenGL_GLX_FOUND)
add_executable(test_comp_both main.c)
target_link_libraries(test_comp_both PRIVATE OpenGL::OpenGL OpenGL::EGL
OpenGL::GLX)
add_test(NAME test_comp_both COMMAND test_comp_both)
endif()
endif()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment