summaryrefslogtreecommitdiff
path: root/Tests/FindOpenGL/Test/CMakeLists.txt
blob: 7c805c0c5ff38f926a1a2d31180a8a72006ac66f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
cmake_minimum_required(VERSION 3.10)
cmake_policy(SET CMP0072 NEW)
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()

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.
  get_target_property(iface_libs OpenGL::EGL INTERFACE_LINK_LIBRARIES)
  if(iface_libs 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()

find_package(OpenGL COMPONENTS GLES2)
if(OpenGL_GLES2_FOUND)
  add_executable(test_comp_gles2 main_gles2.c)
  target_link_libraries(test_comp_gles2 PRIVATE OpenGL::GLES2)
  add_test(NAME test_comp_gles2 COMMAND test_comp_gles2)
  # GLES2-only code should not link to OpenGL
  get_target_property(iface_libs test_comp_gles2 LINK_LIBRARIES)
  if(iface_libs MATCHES "OpenGL::OpenGL")
    message(FATAL_ERROR "GLES2-only code links to OpenGL!")
  endif()
endif()

# GLES2 and EGL together.
find_package(OpenGL COMPONENTS GLES2 EGL)
if(OpenGL_GLES2_FOUND AND OpenGL_EGL_FOUND)
  add_executable(test_comp_gles2_egl main_gles2.c)
  target_link_libraries(test_comp_gles2_egl PRIVATE OpenGL::GLES2
                        OpenGL::EGL)
  add_test(NAME test_comp_gles2_egl COMMAND test_comp_gles2_egl)
  # GLES2-EGL-only code should not link to OpenGL or GLX
  get_target_property(iface_libs test_comp_gles2_egl LINK_LIBRARIES)
  if(iface_libs MATCHES "OpenGL::OpenGL")
    message(FATAL_ERROR "GLES2-only code links to OpenGL!")
  endif()
  if(iface_libs MATCHES "GLX")
    message(FATAL_ERROR "GLES2-EGL-only code links to GLX!")
  endif()
endif()

# GLES2 and GLX together.
find_package(OpenGL COMPONENTS GLES2 GLX)
if(OpenGL_GLES2_FOUND AND OpenGL_GLX_FOUND)
  add_executable(test_comp_gles2_glx main_gles2.c)
  target_link_libraries(test_comp_gles2_glx PRIVATE OpenGL::GLES2
                        OpenGL::GLX)
  add_test(NAME test_comp_gles2_glx COMMAND test_comp_gles2_glx)
  # GLES2-GLX-only code should not link to OpenGL or EGL
  get_target_property(iface_libs test_comp_gles2_glx LINK_LIBRARIES)
  if(iface_libs MATCHES "OpenGL::OpenGL")
    message(FATAL_ERROR "GLES2-only code links to OpenGL!")
  endif()
  if(iface_libs MATCHES "EGL")
    message(FATAL_ERROR "GLES2-GLX-only code links to EGL!")
  endif()
endif()

find_package(OpenGL COMPONENTS GLES3)
if(OpenGL_GLES3_FOUND)
  add_executable(test_comp_gles3 main_gles3.c)
  target_link_libraries(test_comp_gles3 PRIVATE OpenGL::GLES3)
  add_test(NAME test_comp_gles3 COMMAND test_comp_gles3)
  # GLES3-only code should not link to OpenGL.
  get_target_property(iface_libs test_comp_gles3 LINK_LIBRARIES)
  if(iface_libs MATCHES "OpenGL::OpenGL")
    message(FATAL_ERROR "GLES3-only code links to OpenGL!")
  endif()
endif()

# GLES3 and EGL together.
find_package(OpenGL COMPONENTS GLES3 EGL)
if(OpenGL_GLES3_FOUND AND OpenGL_EGL_FOUND)
  add_executable(test_comp_gles3_egl main_gles3.c)
  target_link_libraries(test_comp_gles3_egl PRIVATE OpenGL::GLES3
                        OpenGL::EGL)
  add_test(NAME test_comp_gles3_egl COMMAND test_comp_gles3_egl)
  # GLES3-EGL-only code should not link to OpenGL or GLX
  get_target_property(iface_libs test_comp_gles3_egl LINK_LIBRARIES)
  if(iface_libs MATCHES "OpenGL::OpenGL")
    message(FATAL_ERROR "GLES3-only code links to OpenGL!")
  endif()
  if(iface_libs MATCHES "GLX")
    message(FATAL_ERROR "GLES3-EGL-only code links to GLX!")
  endif()
endif()

# GLES3 and GLX together.
find_package(OpenGL COMPONENTS GLES3 GLX)
if(OpenGL_GLES3_FOUND AND OpenGL_GLX_FOUND)
  add_executable(test_comp_gles3_glx main_gles3.c)
  target_link_libraries(test_comp_gles3_glx PRIVATE OpenGL::GLES3
                        OpenGL::GLX)
  add_test(NAME test_comp_gles3_glx COMMAND test_comp_gles3_glx)
  # GLESr-GLX-only code should not link to OpenGL or EGL
  get_target_property(iface_libs test_comp_gles3_glx LINK_LIBRARIES)
  if(iface_libs MATCHES "OpenGL::OpenGL")
    message(FATAL_ERROR "GLES3-only code links to OpenGL!")
  endif()
  if(iface_libs MATCHES "EGL")
    message(FATAL_ERROR "GLES3-GLX-only code links to EGL!")
  endif()
endif()