cl: Initialize device_config
[piglit.git] / CMakeLists.txt
blobd169fb481d852db7ffb86c1ae22ee2f46f8fe12d
1 cmake_minimum_required(VERSION 3.4...3.28)
3 if (POLICY CMP0072)
4         cmake_policy (SET CMP0072 OLD)
5 endif()
6 if (POLICY CMP0148)
7         cmake_policy (SET CMP0148 OLD)
8 endif()
10 project (piglit)
12 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
14 INCLUDE (GNUInstallDirs)
15 INCLUDE (CheckCCompilerFlag)
16 INCLUDE (CheckCSourceCompiles)
17 INCLUDE (CheckCXXCompilerFlag)
18 INCLUDE (CheckFunctionExists)
19 INCLUDE (CheckSymbolExists)
20 INCLUDE (CheckIncludeFile)
21 INCLUDE (FindPkgConfig)
23 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
25 if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
26         set(DEFAULT_EGL ON)
27         set(DEFAULT_GLX ON)
28         set(DEFAULT_WGL OFF)
30         set(DEFAULT_WAFFLE ON)
32         set(DEFAULT_GBM ON)
33         set(DEFAULT_WAYLAND ON)
34         set(DEFAULT_X11 ON)
36         set(DEFAULT_GLES_TESTS_BUILD ON)
37         set(DEFAULT_VK_TESTS_BUILD ON)
38 elseif(APPLE)
39         set(DEFAULT_EGL OFF)
40         set(DEFAULT_GLX OFF)
41         set(DEFAULT_WGL OFF)
43         set(DEFAULT_WAFFLE OFF)
45         set(DEFAULT_GBM OFF)
46         set(DEFAULT_WAYLAND OFF)
47         set(DEFAULT_X11 OFF)
49         set(DEFAULT_GLES_TESTS_BUILD OFF)
50         set(DEFAULT_VK_TESTS_BUILD OFF)
51 elseif(WIN32)
52         set(DEFAULT_EGL OFF)
53         set(DEFAULT_GLX OFF)
54         set(DEFAULT_WGL ON)
56         set(DEFAULT_WAFFLE OFF)
58         set(DEFAULT_GBM OFF)
59         set(DEFAULT_WAYLAND OFF)
60         set(DEFAULT_X11 OFF)
62         set(DEFAULT_GLES_TESTS_BUILD OFF)
63         set(DEFAULT_VK_TESTS_BUILD OFF)
64 else()
65         message(FATAL_ERROR "Unsupported platform")
66 endif()
68 option(PIGLIT_SSE2 "Build with SSE2 support on 32-bit x86 architecture" ON)
70 option(PIGLIT_USE_WAFFLE "Use Waffle in place of GLUT" ${DEFAULT_WAFFLE})
72 option(PIGLIT_USE_GBM "Use GBM" ${DEFAULT_GBM})
73 option(PIGLIT_USE_WAYLAND "Use Wayland" ${DEFAULT_WAYLAND})
74 option(PIGLIT_USE_X11 "Use X11" ${DEFAULT_X11})
76 option(PIGLIT_BUILD_EGL_TESTS "Build tests that require EGL" ${DEFAULT_EGL})
77 option(PIGLIT_BUILD_GLX_TESTS "Build tests that require GLX" ${DEFAULT_GLX})
78 option(PIGLIT_BUILD_WGL_TESTS "Build tests that require WGL" ${DEFAULT_WGL})
80 option(PIGLIT_BUILD_GL_TESTS "Build tests for OpenGL" ON)
81 option(PIGLIT_BUILD_GLES1_TESTS "Build tests for OpenGL ES1" ${DEFAULT_GLES_TESTS_BUILD})
82 option(PIGLIT_BUILD_GLES2_TESTS "Build tests for OpenGL ES2" ${DEFAULT_GLES_TESTS_BUILD})
83 option(PIGLIT_BUILD_GLES3_TESTS "Build tests for OpenGL ES3" ${DEFAULT_GLES_TESTS_BUILD})
84 option(PIGLIT_BUILD_CL_TESTS "Build tests for OpenCL" OFF)
85 option(PIGLIT_BUILD_VK_TESTS "Build tests for Vulkan" ${DEFAULT_VK_TESTS_BUILD})
87 option(PIGLIT_BUILD_DMA_BUF_TESTS "Build tests that use dma_buf" ${DEFAULT_GBM})
90 find_package(Threads)
91 find_package(PNG)
92 if(PNG_FOUND)
93         add_definitions(-DPIGLIT_HAS_PNG)
94 endif(PNG_FOUND)
96 if(PIGLIT_BUILD_GLX_TESTS AND NOT PIGLIT_USE_X11)
97         message(FATAL_ERROR "X11 has to be enabled for GLX to build")
98 endif()
100 if(PIGLIT_BUILD_DMA_BUF_TESTS AND NOT PIGLIT_USE_GBM)
101         message(FATAL_ERROR "PIGLIT_BUILD_DMA_BUF_TESTS require GBM")
102 endif()
104 if(PIGLIT_BUILD_EGL_TESTS AND NOT PIGLIT_USE_WAFFLE)
105         message(FATAL_ERROR "Waffle has to be enabled for EGL tests to build")
106 endif()
108 if(PIGLIT_USE_X11)
109         find_package(X11 REQUIRED)
110         set(PIGLIT_HAS_X11 True)
111         add_definitions(-DPIGLIT_HAS_X11)
112 endif()
114 if(PIGLIT_BUILD_GL_TESTS)
115         find_package(OpenGL REQUIRED)
116 endif()
118 if(PIGLIT_USE_WAFFLE)
119         if (NOT WIN32)
120                 pkg_check_modules(Waffle REQUIRED waffle-1)
122                 if(NOT Waffle_FOUND)
123                         message(FATAL_ERROR "Failed to find Waffle. If Waffle "
124                         "is not packaged for your distribution, you can get "
125                         "it at https://gitlab.freedesktop.org/mesa/waffle."
126                 )
127                 endif()
129                 # Check the installed waffle version.
130                 #
131                 # We cannot reliably check the version with pkg_check_modules(), but
132                 # instead must check the version manually as below. The problem is that,
133                 # if one passes a required version to pkg_check_modules(), CMake
134                 # validates the required version at most once for the lifetime of the
135                 # source tree.  If someone changes the required version by editing the
136                 # CMakeLists, CMake fails to detect the new requirement.
137                 set(Waffle_REQUIRED_VERSION "1.6.0")
138                 if(Waffle_VERSION VERSION_LESS Waffle_REQUIRED_VERSION)
139                         message(FATAL_ERROR "Found waffle-${Waffle_VERSION}, but "
140                         "piglit requires waffle-${Waffle_REQUIRED_VERSION}")
141                 endif()
142         else ()
143                 find_path(Waffle_INCLUDE_DIRS waffle.h)
144                 find_library(Waffle_LDFLAGS waffle-1)
145                 if(Waffle_INCLUDE_DIRS AND Waffle_LDFLAGS)
146                         set(Waffle_FOUND TRUE)
147                 else()
148                         message(FATAL_ERROR "Failed to find Waffle. Get and build Waffle from "
149                                 "https://gitlab.freedesktop.org/mesa/waffle and set "
150                                 "Waffle_INCLUDE_DIRS and Waffle_LDFLAGS variables accordingly."
151                         )
152                 endif()
153         endif ()
155         add_definitions(-DPIGLIT_USE_WAFFLE)
156         add_definitions(-DWAFFLE_API_VERSION=0x0103)
157 else()
158         find_package(GLUT REQUIRED)
159 endif(PIGLIT_USE_WAFFLE)
161 if(PIGLIT_BUILD_GLES1_TESTS AND (NOT PIGLIT_USE_WAFFLE OR NOT PIGLIT_BUILD_EGL_TESTS))
162         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES1_TESTS requires EGL and PIGLIT_USE_WAFFLE")
163 endif()
164 if(PIGLIT_BUILD_GLES2_TESTS AND (NOT PIGLIT_USE_WAFFLE OR NOT PIGLIT_BUILD_EGL_TESTS))
165         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES2_TESTS requires EGL and PIGLIT_USE_WAFFLE")
166 endif()
167 if(PIGLIT_BUILD_GLES3_TESTS AND (NOT PIGLIT_USE_WAFFLE OR NOT PIGLIT_BUILD_EGL_TESTS))
168         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES3_TESTS requires EGL and PIGLIT_USE_WAFFLE")
169 endif()
171 if(PIGLIT_BUILD_CL_TESTS)
172         find_package(OpenCL 1.2 REQUIRED)
173 endif(PIGLIT_BUILD_CL_TESTS)
176 if(PIGLIT_USE_GBM)
177         pkg_check_modules(GBM REQUIRED gbm>=17.1)
178         set(PIGLIT_HAS_GBM True)
179         add_definitions(-DPIGLIT_HAS_GBM)
180         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${GBM_LIBRARIES})
181         set(CMAKE_REQUIRED_LINK_OPTIONS ${GBM_LDFLAGS})
182         include_directories(${GBM_INCLUDE_DIRS})
184         CHECK_FUNCTION_EXISTS(gbm_bo_map PIGLIT_HAS_GBM_BO_MAP)
185         if (PIGLIT_HAS_GBM_BO_MAP)
186                 add_definitions(-DPIGLIT_HAS_GBM_BO_MAP)
187         endif()
189         CHECK_FUNCTION_EXISTS(gbm_bo_get_fd_for_plane PIGLIT_HAS_GBM_BO_GET_FD_FOR_PLANE)
190         if (PIGLIT_HAS_GBM_BO_GET_FD_FOR_PLANE)
191                 add_definitions(-DPIGLIT_HAS_GBM_BO_GET_FD_FOR_PLANE)
192         endif()
193 endif()
195 if(PIGLIT_USE_WAYLAND)
196         pkg_check_modules(WAYLAND REQUIRED wayland-client)
197         set(PIGLIT_HAS_WAYLAND True)
198         add_definitions(-DPIGLIT_HAS_WAYLAND)
199         include_directories(${WAYLAND_INCLUDE_DIRS})
201         FIND_LIBRARY(HAVE_XKBCOMMON NAMES xkbcommon)
202         if(NOT HAVE_XKBCOMMON)
203                 message(FATAL_ERROR "Wayland support requires xkbcommon. "
204                         "Failed to find xkbcommon library.")
205         endif()
206         pkg_check_modules(XKBCOMMON QUIET xkbcommon)
208         pkg_check_modules(WaylandProtocols REQUIRED wayland-protocols>=1.24)
209         pkg_get_variable(WaylandProtocols_DATADIR wayland-protocols pkgdatadir)
210         if (NOT WaylandProtocols_DATADIR)
211                 message(FATAL_ERROR "Failed to find wayland-protocols XML path")
212         endif()
214         pkg_check_modules(WaylandScanner REQUIRED wayland-scanner)
215         pkg_get_variable(WaylandScannerPath wayland-scanner wayland_scanner)
216         if (NOT WaylandScannerPath)
217                 message(FATAL_ERROR "Failed to find wayland-scanner path from pkg-config")
218         endif()
219         add_executable(WaylandScannerExe IMPORTED)
220         set_property(TARGET WaylandScannerExe PROPERTY IMPORTED_LOCATION ${WaylandScannerPath})
221 endif()
223 if(PIGLIT_USE_X11 AND OPENGL_gl_LIBRARY AND PIGLIT_BUILD_GLX_TESTS)
224         set(PIGLIT_HAS_GLX True)
225         add_definitions(-DPIGLIT_HAS_GLX)
226 endif()
228 if(PIGLIT_BUILD_WGL_TESTS)
229         set(PIGLIT_HAS_WGL True)
230         add_definitions(-DPIGLIT_HAS_WGL)
231 endif()
233 IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
234         pkg_check_modules(LIBDRM QUIET libdrm)
235         pkg_check_modules(XCB QUIET xcb)
236         pkg_check_modules(XCB_DRI2 QUIET xcb-dri2)
237         pkg_check_modules(GLPROTO QUIET glproto)
238         pkg_check_modules(LIBVULKAN QUIET vulkan)
239 ENDIF()
241 if(LIBDRM_FOUND)
242         if(LIBDRM_VERSION VERSION_GREATER "2.4.109")
243                 set(PIGLIT_HAS_DRM_GET_DEVICE_BY_DEVID true)
244         else()
245                 set(PIGLIT_HAS_DRM_GET_DEVICE_BY_DEVID false)
246         endif()
247 endif()
249 if(PIGLIT_BUILD_VK_TESTS)
250         if (NOT LIBVULKAN_FOUND)
251                 message(FATAL_ERROR "libvulkan required by vulkan tests not found")
252         endif()
254         find_program(GLSLANG_VALIDATOR NAMES glslangValidator)
256         if (NOT GLSLANG_VALIDATOR)
257                 message(FATAL_ERROR "glslangValidator required by vulkan tests not found")
258         endif()
259 endif(PIGLIT_BUILD_VK_TESTS)
261 # Choose to build tests that use dma_buf.
263 # Piglit's dma_buf utilities require xcb-dri2 to gain DRM authentication, and
264 # gbm_bo_map() to be available for generating dma_bufs, and libdrm for fourcc
265 # definitions.
267 if(PIGLIT_BUILD_DMA_BUF_TESTS)
268         if(PIGLIT_HAS_GBM_BO_MAP AND LIBDRM_FOUND AND LIBDRM_VERSION VERSION_GREATER "2.4.97" AND XCB_DRI2_FOUND)
269                 set(PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID true)
270         else()
271                 message(FATAL_ERROR
272                         "PIGLIT_BUILD_DMA_BUF_TESTS require libdrm, "
273                         "gbm_bo_map(), libdrm>=2.4.98 and xcb-dri2")
274                 set(PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID false)
275         endif()
276 endif()
278 IF(PIGLIT_BUILD_GLX_TESTS)
279         pkg_check_modules(GLPROTO REQUIRED glproto)
280 ENDIF()
282 if (NOT Python_ADDITIONAL_VERSIONS)
283         set(Python_ADDITIONAL_VERSIONS 3.12 3.11 3.10 3.9 3.8 3.7 3.6)
284 endif()
285 find_package(PythonInterp REQUIRED)
286 find_package(PythonNumpy 1.7.0 REQUIRED)
287 find_package(PythonMako 1.0.2 REQUIRED)
289 pkg_search_module(BASH_COMPLETION bash-completion)
291 # Default to compiling with debug information (`gcc -g`):
292 if(NOT CMAKE_BUILD_TYPE)
293         SET(CMAKE_BUILD_TYPE Debug CACHE STRING
294         "May be one of: None Debug RelWithDebInfo Release MinSizeRel" FORCE)
295 endif(NOT CMAKE_BUILD_TYPE)
297 if (NOT MSVC)
298         if (PIGLIT_SSE2 AND CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)")
299                 # enables SSE2 and precision used on x86-64 by default
300                 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -mfpmath=sse")
301                 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -mfpmath=sse")
302         else()
303                 # degrade performance a bit, but enforce required precision
304                 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffloat-store")
305                 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffloat-store")
306         endif()
307         CHECK_C_COMPILER_FLAG("-Wall" C_COMPILER_FLAG_WALL)
308         IF (C_COMPILER_FLAG_WALL)
309                 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
310         ENDIF (C_COMPILER_FLAG_WALL)
311         CHECK_CXX_COMPILER_FLAG("-Wall" CXX_COMPILER_FLAG_WALL)
312         IF (CXX_COMPILER_FLAG_WALL)
313                 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
314         ENDIF (CXX_COMPILER_FLAG_WALL)
316         # Target C99.  GCC's default is gnu11 for 5.0 and newer, gnu89 for
317         # older versions.
318         check_c_compiler_flag ("-std=gnu99" C_COMPILER_FLAG_STD_GNU99)
319         if (C_COMPILER_FLAG_STD_GNU99)
320                 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
321         endif ()
322         # MSVC does not support C99 variable length arrays
323         CHECK_C_COMPILER_FLAG("-Werror=vla" C_COMPILER_FLAG_WEVLA)
324         IF (C_COMPILER_FLAG_WEVLA)
325                 SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=vla")
326         ENDIF ()
327         # GCC allows void pointer arithmetic, but it is not part of ISO C and
328         # in particular MSVC will throw `C2036: 'void *' : unknown size`
329         check_c_compiler_flag ("-Werror=pointer-arith" C_COMPILER_FLAG_WEPOINTER_ARITH)
330         if (C_COMPILER_FLAG_WEPOINTER_ARITH)
331                 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=pointer-arith")
332         endif ()
333         # MSVC only supports C99 variadic macros.  It doesn't support the
334         # non-standard GNU named variadic macro syntax that's documented in
335         # https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html
336         #
337         # XXX: on older GCC version this option has no effect unless -Wpedantic
338         # is set, but this should be fixed on future GCC versions, per
339         # https://gcc.gnu.org/ml/gcc-patches/2014-04/msg01459.html
340         check_c_compiler_flag ("-Werror=variadic-macros" C_COMPILER_FLAG_WVARIADIC_MACROS)
341         if (C_COMPILER_FLAG_WVARIADIC_MACROS)
342                 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=variadic-macros")
343         endif ()
345         CHECK_CXX_COMPILER_FLAG("-Wno-narrowing" CXX_COMPILER_FLAG_WNO_NARROWING)
346         IF (CXX_COMPILER_FLAG_WNO_NARROWING)
347                 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
348         ENDIF (CXX_COMPILER_FLAG_WNO_NARROWING)
349 else ()
350         # Adjust warnings
351         add_definitions (-W3)
352         add_definitions (-wd4018) # signed/unsigned mismatch
353         add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
354         add_definitions (-wd4305) # truncation from 'type1' to 'type2'
355         add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
357         add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
358         add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
359 endif ()
361 if (MINGW)
362         # Match MSVC default stack size
363         set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,1048576")
364 endif ()
366 if (${CMAKE_C_COMPILER_ID} STREQUAL "SunPro")
367         # Use C++ to link C files.
368         # http://developers.sun.com/solaris/articles/mixing.html#linking
369         # Modified rule from Modules/CMakeCInformation.cmake.
370         set (CMAKE_C_LINK_EXECUTABLE
371                 "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
372 endif()
374 # Always enable GNU C extensions.  Non-GNU platforms will need to
375 # define wrappers for them.
376 add_definitions(-D_GNU_SOURCE)
378 if (WIN32)
379         # MSVC & MinGW only define & use APIENTRY
380         add_definitions (-DGLAPIENTRY=__stdcall)
382         # Avoid namespace pollution when including windows.h
383         # http://support.microsoft.com/kb/166474
384         add_definitions (-DWIN32_LEAN_AND_MEAN=1)
386         # Don't define min/max macros
387         add_definitions (-DNOMINMAX)
389         # Even more no min/max macros
390         add_definitions (-D_CRT_DECLARE_NONSTDC_NAMES=0)
392         # Define M_PI and others
393         add_definitions (-D_USE_MATH_DEFINES)
394 endif (WIN32)
396 if (APPLE)
397         # Don't warn about using deprecated OpenGL/GLUT functions.
398         # TODO: It would be nice to silence just the deprecation macros from
399         # OpenGLAvailability.h as opposed to all deprecated functions.
400         set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
401         set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
402 endif ()
404 if (PIGLIT_BUILD_GL_TESTS)
405         if (APPLE)
406                 find_path(GLEXT_INCLUDE_DIR
407                         NAMES OpenGL/glext.h
408                         PATHS ${OPENGL_INCLUDE_DIR}
409                         DOC "Include for OpenGL/glext.h on OSX"
410                 )
411         else()
412                 find_path(GLEXT_INCLUDE_DIR
413                         NAMES GL/glext.h
414                         PATHS ${OPENGL_INCLUDE_DIR}
415                         DOC "Include for GL/glext.h"
416                 )
417         endif()
418 endif()
420 if(CMAKE_USE_PTHREADS_INIT)
421         set(PIGLIT_HAS_PTHREADS true)
422         add_definitions(-DPIGLIT_HAS_PTHREADS)
423 endif()
425 FIND_LIBRARY(HAVE_LIBRT NAMES rt)
426 if(HAVE_LIBRT)
427         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt)
428 endif()
430 check_c_source_compiles(
431         "
432         #define _POSIX_C_SOURCE 199309L
433         #include <time.h>
434         int main() { return clock_gettime(CLOCK_MONOTONIC, NULL); }
435         "
436         PIGLIT_HAS_POSIX_CLOCK_MONOTONIC
439 if(PIGLIT_HAS_PTHREADS AND PIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
440         check_c_source_compiles(
441                 "
442                 #include <signal.h>
443                 #include <time.h>
444                 static void timeout(union sigval val) { }
445                 int main() {
446                         struct sigevent sev = {
447                                 .sigev_notify = SIGEV_THREAD,
448                                 .sigev_notify_function = timeout,
449                         };
450                         timer_t timerid;
451                         return timer_create(CLOCK_MONOTONIC, &sev, &timerid);
452                 }
453                 "
454                 PIGLIT_HAS_POSIX_TIMER_NOTIFY_THREAD
455         )
456 endif()
458 set(CMAKE_REQUIRED_LIBRARIES)
460 if(PIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
461         add_definitions(-DPIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
462 endif()
464 if(PIGLIT_HAS_POSIX_TIMER_NOTIFY_THREAD)
465         add_definitions(-DPIGLIT_HAS_POSIX_TIMER_NOTIFY_THREAD)
466 endif()
468 if(GBM_FOUND)
469         FIND_LIBRARY(HAVE_LIBCACA NAMES caca)
470         if(HAVE_LIBCACA)
471                 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} caca)
472                 add_definitions(-DPIGLIT_HAS_LIBCACA)
473         endif(HAVE_LIBCACA)
474 endif(GBM_FOUND)
476 if(PIGLIT_BUILD_EGL_TESTS)
477         pkg_check_modules(EGL REQUIRED egl)
478         set(PIGLIT_HAS_EGL True)
479         add_definitions(-DPIGLIT_HAS_EGL)
480         include_directories(${EGL_INCLUDE_DIRS})
481         add_definitions (${EGL_CFLAGS_OTHER})
482 endif()
484 # Put all executables into the bin subdirectory
485 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${piglit_BINARY_DIR}/bin)
486 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${piglit_BINARY_DIR}/lib)
488 # Do the same for MSVC, regardless of the build type. This only works correctly
489 # for CMake 2.8.1 and above.
490 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${piglit_BINARY_DIR}/bin)
491 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${piglit_BINARY_DIR}/bin)
492 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${piglit_BINARY_DIR}/bin)
493 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${piglit_BINARY_DIR}/bin)
495 check_function_exists(asprintf  HAVE_ASPRINTF)
496 check_function_exists(ffs       HAVE_FFS)
497 check_function_exists(strchrnul HAVE_STRCHRNUL)
498 check_function_exists(strndup   HAVE_STRNDUP)
499 if(NOT MINGW)
500         check_function_exists(fopen_s   HAVE_FOPEN_S)
501 endif()
502 check_function_exists(setrlimit HAVE_SETRLIMIT)
504 check_symbol_exists(htobe32 "endian.h" HAVE_HTOBE32)
505 check_symbol_exists(htole16 "endian.h" HAVE_HTOLE16)
506 check_symbol_exists(htole32 "endian.h" HAVE_HTOLE32)
507 check_symbol_exists(htole64 "endian.h" HAVE_HTOLE64)
509 check_include_file(sys/time.h  HAVE_SYS_TIME_H)
510 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
511 check_include_file(sys/resource.h  HAVE_SYS_RESOURCE_H)
512 check_include_file(sys/stat.h  HAVE_SYS_STAT_H)
513 check_include_file(unistd.h    HAVE_UNISTD_H)
514 check_include_file(fcntl.h     HAVE_FCNTL_H)
515 check_include_file(linux/sync_file.h HAVE_LINUX_SYNC_FILE_H)
516 check_include_file(endian.h    HAVE_ENDIAN_H)
517 check_include_file(libgen.h    HAVE_LIBGEN_H)
519 if(DEFINED PIGLIT_INSTALL_VERSION)
520         set(PIGLIT_INSTALL_VERSION_SUFFIX
521             "-${PIGLIT_INSTALL_VERSION}")
522 else()
523         set(PIGLIT_INSTALL_VERSION_SUFFIX "")
524 endif()
525 set(PIGLIT_INSTALL_LIBDIR
526     "${CMAKE_INSTALL_LIBDIR}/piglit${PIGLIT_INSTALL_VERSION_SUFFIX}")
527 if(NOT IS_ABSOLUTE ${PIGLIT_INSTALL_LIBDIR})
528         set(PIGLIT_INSTALL_FULL_LIBDIR "${CMAKE_INSTALL_PREFIX}/${PIGLIT_INSTALL_LIBDIR}")
529 else()
530         set(PIGLIT_INSTALL_FULL_LIBDIR "${PIGLIT_INSTALL_LIBDIR}")
531 endif()
533 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
534         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--enable-new-dtags")
535 endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
537 SET(CMAKE_INSTALL_RPATH "${PIGLIT_INSTALL_FULL_LIBDIR}/lib")
539 configure_file(
540         "${piglit_SOURCE_DIR}/tests/util/config.h.in"
541         "${piglit_BINARY_DIR}/tests/util/config.h"
544 include(cmake/piglit_util.cmake)
545 include(cmake/piglit_dispatch.cmake)
547 include_directories(src)
548 add_subdirectory(cmake/target_api)
549 add_subdirectory(generated_tests)
550 add_subdirectory(replayer)
553 ##############################################################################
554 # Packaging
556 install (
557         FILES
558                 COPYING
559                 README.md
560                 RELEASE
561         DESTINATION share/doc/piglit${PIGLIT_INSTALL_VERSION_SUFFIX}
564 install (
565         DIRECTORY framework
566         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
567         FILES_MATCHING PATTERN "*.py"
570 install (
571         DIRECTORY templates
572         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
575 install (
576         DIRECTORY tests
577         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
578         FILES_MATCHING REGEX ".*\\.(xml|xml.gz|py|program_test|shader_test|shader_source|frag|vert|geom|tesc|tese|comp|spv|ktx|cl|txt|inc|vk_shader_test)$"
579         REGEX "CMakeFiles|CMakeLists|serializer.py|opengl.py|cl.py|quick_gl.py|glslparser.py|shader.py|quick_shader.py|no_error.py|llvmpipe_gl.py|sanity.py" EXCLUDE
582 install (
583         DIRECTORY ${CMAKE_BINARY_DIR}/tests
584         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
585         FILES_MATCHING REGEX ".*\\.xml.gz"
588 install (
589         DIRECTORY ${CMAKE_BINARY_DIR}/generated_tests
590         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
591         FILES_MATCHING REGEX ".*\\.(shader_test|program_test|frag|vert|geom|tesc|tese|comp|cl|txt|vk_shader_test)$"
592         REGEX "CMakeFiles|CMakeLists" EXCLUDE
595 install (
596         DIRECTORY generated_tests
597         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
598         FILES_MATCHING REGEX ".*\\.inc$"
599         REGEX "CMakeFiles|CMakeLists" EXCLUDE
602 if (BASH_COMPLETION_FOUND)
603         pkg_get_variable(BASH_COMPLETION_COMPLETIONSDIR bash-completion completionsdir)
605         if(NOT "${BASH_COMPLETION_PREFIX}" STREQUAL "${CMAKE_INSTALL_PREFIX}")
606                 string(REGEX REPLACE "^${BASH_COMPLETION_PREFIX}" "${CMAKE_INSTALL_PREFIX}" COMP_DIR ${BASH_COMPLETION_COMPLETIONSDIR})
607                 set(BASH_COMPLETION_COMPLETIONSDIR ${COMP_DIR})
608                 unset(COMP_DIR)
609         endif()
611         install(
612                 FILES completions/bash/piglit
613                 DESTINATION ${BASH_COMPLETION_COMPLETIONSDIR}
614         )
615 endif (BASH_COMPLETION_FOUND)
617 if (WIN32)
618         set (PYTHON_SUFFIX ".py")
619 else ()
620         set (PYTHON_SUFFIX "")
621 endif ()
622 install (
623         PROGRAMS piglit RENAME piglit${PIGLIT_INSTALL_VERSION_SUFFIX}${PYTHON_SUFFIX}
624         DESTINATION ${CMAKE_INSTALL_BINDIR}
627 # Install MinGW runtime DLLs
628 if (MINGW)
629         if (CMAKE_SIZEOF_VOID_P EQUAL 8)
630                 set (LIBGCC_DLL_NAME libgcc_s_seh-1.dll)
631         else ()
632                 set (LIBGCC_DLL_NAME libgcc_s_sjlj-1.dll)
633         endif ()
634         execute_process (
635                 COMMAND ${CMAKE_C_COMPILER} -print-file-name=${LIBGCC_DLL_NAME}
636                 OUTPUT_STRIP_TRAILING_WHITESPACE
637                 OUTPUT_VARIABLE LIBGCC_DLL
638         )
639         execute_process (
640                 COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=libstdc++-6.dll
641                 OUTPUT_STRIP_TRAILING_WHITESPACE
642                 OUTPUT_VARIABLE LIBSTDCXX_DLL
643         )
644         if (EXISTS ${LIBGCC_DLL})
645                 message (STATUS "Found libgcc DLL: ${LIBGCC_DLL}")
646                 install (FILES ${LIBGCC_DLL} DESTINATION ${PIGLIT_INSTALL_LIBDIR}/bin)
647         endif ()
648         if (EXISTS ${LIBSTDCXX_DLL})
649                 message (STATUS "Found libstdc++ DLL: ${LIBSTDCXX_DLL}")
650                 install (FILES ${LIBSTDCXX_DLL} DESTINATION ${PIGLIT_INSTALL_LIBDIR}/bin)
651         endif ()
652 endif ()
654 # Install Waffle DLL if specified
655 if (WIN32 AND Waffle_DLL)
656         install (FILES ${Waffle_DLL} DESTINATION ${PIGLIT_INSTALL_LIBDIR}/bin)
657 endif ()
660 set (CPACK_PACKAGE_VERSION_MAJOR "1")
661 set (CPACK_PACKAGE_VERSION_MINOR "0")
663 # Use current date in YYYYMMDD format as patch number
664 execute_process (
665         COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
666         OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
669 # cpack mistakenly detects Mingw-w64 as win32
670 if (MINGW)
671         if (CMAKE_SIZEOF_VOID_P EQUAL 8)
672                 set (CPACK_SYSTEM_NAME win64)
673         endif ()
674 endif ()
676 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
677 if (WIN32)
678         set (CPACK_GENERATOR "7Z")
679         set (CPACK_STRIP_FILES ON)
680 else ()
681         set (CPACK_GENERATOR "TBZ2")
682 endif ()
684 include(CPack)