-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
165 lines (144 loc) · 4.72 KB
/
CMakeLists.txt
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
159
160
161
162
163
164
165
cmake_minimum_required(VERSION 3.16)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
project(offscreen)
add_executable(offscreen)
target_compile_options(offscreen PRIVATE "$<$<CONFIG:DEBUG>:-DDEBUG>")
if(APPLE)
set(USE_GLAD_DEFAULT OFF)
else()
set(USE_GLAD_DEFAULT ON)
endif()
option(USE_GLAD "Use GLAD for OpenGL function wrangling" ${USE_GLAD_DEFAULT})
option(ENABLE_GLFW "Enable on-screen rendering using glfw" ON)
set(HAS_GLVND FALSE)
set(HAS_GLX FALSE)
set(HAS_EGL FALSE)
set(HAS_CGL FALSE)
set(HAS_NSOPENGL FALSE)
set(HAS_WGL FALSE)
if(USE_GLAD)
target_compile_definitions(offscreen PRIVATE USE_GLAD)
endif()
find_package(OpenGL REQUIRED)
if(TARGET OpenGL::OpenGL)
# GLVND systems
target_link_libraries(offscreen OpenGL::OpenGL)
set(HAS_GLVND TRUE)
else()
# Non-GLVND systems
target_link_libraries(offscreen OpenGL::GL)
endif()
target_link_libraries(offscreen OpenGL::GLU)
if (OpenGL_EGL_FOUND)
if (TARGET OpenGL::EGL)
# GLVND systems
target_link_libraries(offscreen OpenGL::EGL)
else()
# Non-GLVND systems
target_link_libraries(offscreen ${OPENGL_egl_LIBRARY})
endif()
set(HAS_EGL TRUE)
find_package(GBM)
if (GBM_FOUND)
target_compile_definitions(offscreen PRIVATE HAS_GBM)
target_link_libraries(offscreen GBM::GBM)
endif()
endif()
if(OpenGL_GLX_FOUND)
find_package(X11 REQUIRED)
if(X11_FOUND)
if(TARGET OpenGL::OpenGL)
# For GLVND systems (non-GLVND systems have GLX included in the OpenGL libraries)
target_link_libraries(offscreen OpenGL::GLX)
endif()
set(HAS_GLX TRUE)
target_link_libraries(offscreen X11::X11)
target_compile_definitions(offscreen PRIVATE ENABLE_GLX)
endif()
endif()
if(ENABLE_GLFW)
find_package(glfw3 REQUIRED)
target_link_libraries(offscreen glfw)
target_compile_definitions(offscreen PRIVATE ENABLE_GLFW)
endif()
# Needed for Raspberry pi:
target_link_libraries(offscreen dl)
if(APPLE)
set(HAS_NSOPENGL TRUE)
set(HAS_CGL TRUE)
find_library(COCOA Cocoa)
target_link_libraries(offscreen ${COCOA})
set(SRCS_APPLE
src/OffscreenContextNSOpenGL.mm
src/OffscreenContextCGL.cc
)
endif(APPLE)
if(WIN32)
set(HAS_WGL TRUE)
set(SRCS_WINDOWS src/OffscreenContextWGL.cc)
endif(WIN32)
if(HAS_EGL)
set(SRCS_EGL
src/OffscreenContextEGL.cc
src/egl_utils.cc
)
add_compile_definitions(HAS_EGL)
endif()
if(HAS_GLX)
set(SRCS_GLX
src/OffscreenContextGLX.cc
)
add_compile_definitions(HAS_GLX)
endif()
if(ENABLE_GLFW)
set(SRCS_GLFW src/GLFWContext.cc)
endif()
set(SRCS
src/main.cc
src/CommandLine.cc
src/system-gl.cc
src/OpenGLContext.cc
src/OffscreenContext.cc
src/OffscreenContextFactory.cc
src/FBO.cc
src/render_immediate.cc
src/render_modern_ogl2.cc
src/render_modern_ogl3.cc
${SRCS_GLFW}
${SRCS_EGL}
${SRCS_GLX}
${SRCS_APPLE}
${SRCS_WINDOWS}
)
target_sources(offscreen PRIVATE ${SRCS})
target_include_directories(offscreen PUBLIC "${CMAKE_SOURCE_DIR}/src")
# Using C++17 as my RaspberryPi runs gcc=8.3 which doesn't implement <numbers>
set_property(TARGET offscreen PROPERTY CXX_STANDARD 17)
enable_testing()
add_test(NAME default_run COMMAND offscreen)
add_test(NAME fails_on_empty_context_arg COMMAND offscreen --context)
set_property(TEST fails_on_empty_context_arg PROPERTY WILL_FAIL true)
add_test(NAME will_save_framebuffer COMMAND offscreen -o out.png)
add_test(NAME check_file_exists COMMAND ${CMAKE_COMMAND} -E cat out.png)
set_tests_properties(check_file_exists PROPERTIES DEPENDS will_save_framebuffer)
if(APPLE)
add_test(NAME cgl_opengl2_immediate COMMAND offscreen --context cgl --opengl 2 --mode immediate)
add_test(NAME cgl_opengl2_modern COMMAND offscreen --context cgl --opengl 2 --mode modern)
add_test(NAME cgl_opengl3.2_core COMMAND offscreen --context cgl --opengl 3.2 --profile core)
add_test(NAME nsopengl_opengl2_immediate COMMAND offscreen --context nsopengl --opengl 2 --mode immediate)
add_test(NAME nsopengl_opengl2_modern COMMAND offscreen --context nsopengl --opengl 2 --mode modern)
add_test(NAME nsopengl_opengl3.2_core COMMAND offscreen --context nsopengl --opengl 3.2 --profile core)
endif(APPLE)
message(STATUS " ")
message(STATUS "====================================")
message(STATUS "Build Configuration Summary")
message(STATUS "====================================")
message(STATUS " ")
message(STATUS "GLAD: ${USE_GLAD}")
message(STATUS "GLFW: ${ENABLE_GLFW}")
message(STATUS "Has GLVND: ${HAS_GLVND}")
message(STATUS "GLX: ${HAS_GLX}")
message(STATUS "EGL: ${HAS_EGL}")
message(STATUS "CGL: ${HAS_CGL}")
message(STATUS "NSOpenGL: ${HAS_NSOPENGL}")
message(STATUS "WGL: ${HAS_WGL}")