arb_occlusion_query: execute test even if no query bits
[piglit.git] / CMakeLists.txt
blob9adb9b3186ad8d8ce19f140c99b415a1d35d6900
1 cmake_minimum_required(VERSION 3.2)
3 # http://www.cmake.org/cmake/help/v3.0/policy/CMP0042.html
4 if (POLICY CMP0042)
5         cmake_policy (SET CMP0042 NEW)
6 endif()
8 if (POLICY CMP0072)
9         cmake_policy (SET CMP0072 OLD)
10 endif()
12 project (piglit)
14 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
16 INCLUDE (GNUInstallDirs)
17 INCLUDE (CheckCCompilerFlag)
18 INCLUDE (CheckCSourceCompiles)
19 INCLUDE (CheckCXXCompilerFlag)
20 INCLUDE (CheckFunctionExists)
21 INCLUDE (CheckSymbolExists)
22 INCLUDE (CheckIncludeFile)
23 INCLUDE (FindPkgConfig)
25 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
27 find_package(Threads)
28 find_package(PNG)
29 if(PNG_FOUND)
30         add_definitions(-DPIGLIT_HAS_PNG)
31 endif(PNG_FOUND)
32 find_package(X11)
33 if(X11_FOUND)
34         set(PIGLIT_HAS_X11 True)
35         add_definitions(-DPIGLIT_HAS_X11)
36 endif()
38 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
39         set(PIGLIT_BUILD_GLES_TESTS_DEFAULT ON)
40         set(PIGLIT_BUILD_VK_TESTS_DEFAULT ON)
41 else()
42         set(PIGLIT_BUILD_GLES_TESTS_DEFAULT OFF)
43         set(PIGLIT_BUILD_VK_TESTS_DEFAULT OFF)
44 endif()
46 option(PIGLIT_BUILD_GL_TESTS "Build tests for OpenGL" ON)
47 option(PIGLIT_BUILD_GLES1_TESTS "Build tests for OpenGL ES1" ${PIGLIT_BUILD_GLES_TESTS_DEFAULT})
48 option(PIGLIT_BUILD_GLES2_TESTS "Build tests for OpenGL ES2" ${PIGLIT_BUILD_GLES_TESTS_DEFAULT})
49 option(PIGLIT_BUILD_GLES3_TESTS "Build tests for OpenGL ES3" ${PIGLIT_BUILD_GLES_TESTS_DEFAULT})
50 option(PIGLIT_BUILD_CL_TESTS "Build tests for OpenCL" OFF)
51 option(PIGLIT_BUILD_VK_TESTS "Build tests for Vulkan" ${PIGLIT_BUILD_VK_TESTS_DEFAULT})
53 if(PIGLIT_BUILD_GL_TESTS)
54         find_package(OpenGL REQUIRED)
55 endif()
57 if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
58         option(PIGLIT_USE_WAFFLE "Use Waffle in place of GLUT" ON)
59 else()
60         option(PIGLIT_USE_WAFFLE "Use Waffle in place of GLUT" OFF)
61 endif()
63 if(PIGLIT_USE_WAFFLE)
64         if (NOT WIN32)
65                 pkg_check_modules(Waffle REQUIRED waffle-1)
67                 if(NOT Waffle_FOUND)
68                         message(FATAL_ERROR "Failed to find Waffle. If Waffle "
69                         "is not packaged for your distribution, you can get "
70                         "it at https://gitlab.freedesktop.org/mesa/waffle."
71                 )
72                 endif()
74                 # Check the installed waffle version.
75                 #
76                 # We cannot reliably check the version with pkg_check_modules(), but
77                 # instead must check the version manually as below. The problem is that,
78                 # if one passes a required version to pkg_check_modules(), CMake
79                 # validates the required version at most once for the lifetime of the
80                 # source tree.  If someone changes the required version by editing the
81                 # CMakeLists, CMake fails to detect the new requirement.
82                 set(Waffle_REQUIRED_VERSION "1.6.0")
83                 if(Waffle_VERSION VERSION_LESS Waffle_REQUIRED_VERSION)
84                         message(FATAL_ERROR "Found waffle-${Waffle_VERSION}, but "
85                         "piglit requires waffle-${Waffle_REQUIRED_VERSION}")
86                 endif()
87         else ()
88                 find_path(Waffle_INCLUDE_DIRS waffle.h)
89                 find_library(Waffle_LDFLAGS waffle-1)
90                 if(Waffle_INCLUDE_DIRS AND Waffle_LDFLAGS)
91                         set(Waffle_FOUND TRUE)
92                 else()
93                         message(FATAL_ERROR "Failed to find Waffle. Get and build Waffle from "
94                                 "https://gitlab.freedesktop.org/mesa/waffle and set "
95                                 "Waffle_INCLUDE_DIRS and Waffle_LDFLAGS variables accordingly."
96                         )
97                 endif()
98         endif ()
100         add_definitions(-DPIGLIT_USE_WAFFLE)
101         add_definitions(-DWAFFLE_API_VERSION=0x0103)
102 else()
103         find_package(GLUT REQUIRED)
105         # The 'REQUIRED' above correctly produces an error for
106         # OpenGL, but there's a bug involving FindGLUT.cmake
107         # that fails to produce the error as of CMake 2.8.5.
108         #
109         # Instead, CMake keeps going and eventually spams
110         # the console with a message for every target that used
111         # e.g. the ${GLUT_INCLUDE_DIR} variable. So it
112         # prints a line for basically every single test in piglit.
113         #
114         # Work around the bug and error out quickly here instead.
115         if (NOT GLUT_FOUND)
116                 message(FATAL_ERROR "GLUT library not found")
117         endif()
118 endif(PIGLIT_USE_WAFFLE)
120 if(PIGLIT_BUILD_GLES1_TESTS AND NOT PIGLIT_USE_WAFFLE)
121         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES1_TESTS requires PIGLIT_USE_WAFFLE")
122 endif(PIGLIT_BUILD_GLES1_TESTS AND NOT PIGLIT_USE_WAFFLE)
124 if(PIGLIT_BUILD_GLES2_TESTS AND NOT PIGLIT_USE_WAFFLE)
125         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES2_TESTS requires PIGLIT_USE_WAFFLE")
126 endif(PIGLIT_BUILD_GLES2_TESTS AND NOT PIGLIT_USE_WAFFLE)
128 if(PIGLIT_BUILD_GLES3_TESTS AND NOT PIGLIT_USE_WAFFLE)
129         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES3_TESTS requires PIGLIT_USE_WAFFLE")
130 endif(PIGLIT_BUILD_GLES3_TESTS AND NOT PIGLIT_USE_WAFFLE)
132 if(PIGLIT_BUILD_CL_TESTS)
133         find_package(OpenCL 1.2 REQUIRED)
134 endif(PIGLIT_BUILD_CL_TESTS)
136 IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
137         if(X11_FOUND AND OPENGL_gl_LIBRARY AND PIGLIT_BUILD_GLX_TESTS)
138                 set(PIGLIT_HAS_GLX True)
139                 add_definitions(-DPIGLIT_HAS_GLX)
140         endif()
142         pkg_check_modules(GBM QUIET gbm>=17.1)
143         if(GBM_FOUND)
144                 set(PIGLIT_HAS_GBM True)
145                 add_definitions(-DPIGLIT_HAS_GBM)
146                 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${GBM_LIBRARIES})
147                 CHECK_FUNCTION_EXISTS(gbm_bo_map PIGLIT_HAS_GBM_BO_MAP)
148                 if (PIGLIT_HAS_GBM_BO_MAP)
149                         add_definitions(-DPIGLIT_HAS_GBM_BO_MAP)
150                 endif()
151                 CHECK_FUNCTION_EXISTS(gbm_bo_get_fd_for_plane PIGLIT_HAS_GBM_BO_GET_FD_FOR_PLANE)
152                 if (PIGLIT_HAS_GBM_BO_GET_FD_FOR_PLANE)
153                         add_definitions(-DPIGLIT_HAS_GBM_BO_GET_FD_FOR_PLANE)
154                 endif()
155         endif(GBM_FOUND)
157         pkg_check_modules(WAYLAND QUIET wayland-client)
158         if (WAYLAND_FOUND)
159                 set(PIGLIT_HAS_WAYLAND True)
160                 add_definitions(-DPIGLIT_HAS_WAYLAND)
162                 FIND_LIBRARY(HAVE_XKBCOMMON NAMES xkbcommon)
163                 if(NOT HAVE_XKBCOMMON)
164                         message(FATAL_ERROR "Wayland support requires xkbcommon. "
165                                 "Failed to find xkbcommon library.")
166                 endif()
167                 pkg_check_modules(XKBCOMMON QUIET xkbcommon)
168         endif()
170         pkg_check_modules(LIBDRM QUIET libdrm)
171         pkg_check_modules(XCB QUIET xcb)
172         pkg_check_modules(XCB_DRI2 QUIET xcb-dri2)
173         pkg_check_modules(GLPROTO QUIET glproto)
174         pkg_check_modules(LIBVULKAN QUIET vulkan)
175 ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
176         if (PIGLIT_USE_WAFFLE)
177                 set(PIGLIT_HAS_WGL True)
178                 add_definitions(-DPIGLIT_HAS_WGL)
179         endif()
180 ENDIF()
182 if(PIGLIT_BUILD_VK_TESTS)
184 if (NOT LIBVULKAN_FOUND)
185         message(FATAL_ERROR "libvulkan required by vulkan tests not found")
186 endif()
188 find_program(GLSLANG_VALIDATOR NAMES glslangValidator)
190 if (NOT GLSLANG_VALIDATOR)
191         message(FATAL_ERROR "glslangValidator required by vulkan tests not found")
192 endif()
194 endif(PIGLIT_BUILD_VK_TESTS)
196 IF(PIGLIT_HAS_GLX)
197         option(PIGLIT_BUILD_GLX_TESTS "Build tests that require GLX" ON)
198 ELSE()
199         option(PIGLIT_BUILD_GLX_TESTS "Build tests that require GLX" OFF)
200 ENDIF()
202 IF(PIGLIT_HAS_WGL)
203         option(PIGLIT_BUILD_WGL_TESTS "Build tests that require WGL" ON)
204 ELSE()
205         option(PIGLIT_BUILD_WGL_TESTS "Build tests that require WGL" OFF)
206 ENDIF()
209 # Choose to build tests that use dma_buf.
211 # Piglit's dma_buf utilities require xcb-dri2 to gain DRM authentication, and
212 # gbm_bo_map() to be available for generating dma_bufs, and libdrm for fourcc
213 # definitions.
215 if(LIBDRM_FOUND AND LIBDRM_VERSION VERSION_GREATER "2.4.97" AND XCB_DRI2_FOUND AND PIGLIT_HAS_GBM_BO_MAP)
216         set(PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID true)
217 else()
218         set(PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID false)
219 endif()
221 if(PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID)
222         option(PIGLIT_BUILD_DMA_BUF_TESTS "Build tests that use dma_buf" ON)
223 else()
224         option(PIGLIT_BUILD_DMA_BUF_TESTS "Build tests that use dma_buf" OFF)
225 endif()
227 # If the users has updated PIGLIT_BUILD_DMA_BUF_TESTS in the CMakeCache, then
228 # we need to validate it.
229 if(PIGLIT_BUILD_DMA_BUF_TESTS AND NOT PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID)
230         message(FATAL_ERROR
231                 "PIGLIT_BUILD_DMA_BUF_TESTS require libdrm, "
232                 "gbm_bo_map(), libdrm>=2.4.98 and xcb-dri2")
233 endif()
235 IF(PIGLIT_BUILD_GLX_TESTS)
236         pkg_check_modules(GLPROTO REQUIRED glproto)
237 ENDIF()
239 if (NOT Python_ADDITIONAL_VERSIONS)
240         set(Python_ADDITIONAL_VERSIONS 3.11 3.10 3.9 3.8 3.7 3.6)
241 endif()
242 find_package(PythonInterp REQUIRED)
243 find_package(PythonNumpy 1.7.0 REQUIRED)
244 find_package(PythonMako 1.0.2 REQUIRED)
246 find_package(bash-completion NO_MODULE)
248 # Default to compiling with debug information (`gcc -g`):
249 if(NOT CMAKE_BUILD_TYPE)
250         SET(CMAKE_BUILD_TYPE Debug CACHE STRING
251         "May be one of: None Debug RelWithDebInfo Release MinSizeRel" FORCE)
252 endif(NOT CMAKE_BUILD_TYPE)
254 if (NOT MSVC)
255         CHECK_C_COMPILER_FLAG("-Wall" C_COMPILER_FLAG_WALL)
256         IF (C_COMPILER_FLAG_WALL)
257                 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
258         ENDIF (C_COMPILER_FLAG_WALL)
259         CHECK_CXX_COMPILER_FLAG("-Wall" CXX_COMPILER_FLAG_WALL)
260         IF (CXX_COMPILER_FLAG_WALL)
261                 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
262         ENDIF (CXX_COMPILER_FLAG_WALL)
264         # Target C99.  GCC's default is gnu11 for 5.0 and newer, gnu89 for
265         # older versions.
266         check_c_compiler_flag ("-std=gnu99" C_COMPILER_FLAG_STD_GNU99)
267         if (C_COMPILER_FLAG_STD_GNU99)
268                 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
269         endif ()
270         # MSVC does not support C99 variable length arrays
271         CHECK_C_COMPILER_FLAG("-Werror=vla" C_COMPILER_FLAG_WEVLA)
272         IF (C_COMPILER_FLAG_WEVLA)
273                 SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=vla")
274         ENDIF ()
275         # GCC allows void pointer arithmetic, but it is not part of ISO C and
276         # in particular MSVC will throw `C2036: 'void *' : unknown size`
277         check_c_compiler_flag ("-Werror=pointer-arith" C_COMPILER_FLAG_WEPOINTER_ARITH)
278         if (C_COMPILER_FLAG_WEPOINTER_ARITH)
279                 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=pointer-arith")
280         endif ()
281         # MSVC only supports C99 variadic macros.  It doesn't support the
282         # non-standard GNU named variadic macro syntax that's documented in
283         # https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html
284         #
285         # XXX: on older GCC version this option has no effect unless -Wpedantic
286         # is set, but this should be fixed on future GCC versions, per
287         # https://gcc.gnu.org/ml/gcc-patches/2014-04/msg01459.html
288         check_c_compiler_flag ("-Werror=variadic-macros" C_COMPILER_FLAG_WVARIADIC_MACROS)
289         if (C_COMPILER_FLAG_WVARIADIC_MACROS)
290                 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=variadic-macros")
291         endif ()
293         CHECK_CXX_COMPILER_FLAG("-Wno-narrowing" CXX_COMPILER_FLAG_WNO_NARROWING)
294         IF (CXX_COMPILER_FLAG_WNO_NARROWING)
295                 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
296         ENDIF (CXX_COMPILER_FLAG_WNO_NARROWING)
297 else ()
298         # Adjust warnings
299         add_definitions (-W3)
300         add_definitions (-wd4018) # signed/unsigned mismatch
301         add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
302         add_definitions (-wd4305) # truncation from 'type1' to 'type2'
303         add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
305         add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
306         add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
307 endif ()
309 if (MINGW)
310         # Match MSVC default stack size
311         set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,1048576")
312 endif ()
314 if (${CMAKE_C_COMPILER_ID} STREQUAL "SunPro")
315         # Use C++ to link C files.
316         # http://developers.sun.com/solaris/articles/mixing.html#linking
317         # Modified rule from Modules/CMakeCInformation.cmake.
318         set (CMAKE_C_LINK_EXECUTABLE
319                 "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
320 endif()
322 # Always enable GNU C extensions.  Non-GNU platforms will need to
323 # define wrappers for them.
324 add_definitions(-D_GNU_SOURCE)
326 if (WIN32)
327         # MSVC & MinGW only define & use APIENTRY
328         add_definitions (-DGLAPIENTRY=__stdcall)
330         # Avoid namespace pollution when including windows.h
331         # http://support.microsoft.com/kb/166474
332         add_definitions (-DWIN32_LEAN_AND_MEAN=1)
334         # Don't define min/max macros
335         add_definitions (-DNOMINMAX)
337         # Even more no min/max macros
338         add_definitions (-D_CRT_DECLARE_NONSTDC_NAMES=0)
340         # Define M_PI and others
341         add_definitions (-D_USE_MATH_DEFINES)
342 endif (WIN32)
344 if (APPLE)
345         # Don't warn about using deprecated OpenGL/GLUT functions.
346         # TODO: It would be nice to silence just the deprecation macros from
347         # OpenGLAvailability.h as opposed to all deprecated functions.
348         set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
349         set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
350 endif ()
352 if (OPENGL_FOUND)
353         if (APPLE)
354                 find_path(GLEXT_INCLUDE_DIR
355                         NAMES OpenGL/glext.h
356                         PATHS ${OPENGL_INCLUDE_DIR}
357                         DOC "Include for OpenGL/glext.h on OSX"
358                 )
359         else (APPLE)
360                 find_path(GLEXT_INCLUDE_DIR
361                         NAMES GL/glext.h
362                         PATHS ${OPENGL_INCLUDE_DIR}
363                         DOC "Include for GL/glext.h"
364                 )
365         endif (APPLE)
366 endif()
368 if(CMAKE_USE_PTHREADS_INIT)
369         set(PIGLIT_HAS_PTHREADS true)
370         add_definitions(-DPIGLIT_HAS_PTHREADS)
371 endif()
373 FIND_LIBRARY(HAVE_LIBRT NAMES rt)
374 if(HAVE_LIBRT)
375         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt)
376 endif()
378 check_c_source_compiles(
379         "
380         #define _POSIX_C_SOURCE 199309L
381         #include <time.h>
382         int main() { return clock_gettime(CLOCK_MONOTONIC, NULL); }
383         "
384         PIGLIT_HAS_POSIX_CLOCK_MONOTONIC
387 if(PIGLIT_HAS_PTHREADS AND PIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
388         check_c_source_compiles(
389                 "
390                 #include <signal.h>
391                 #include <time.h>
392                 static void timeout(union sigval val) { }
393                 int main() {
394                         struct sigevent sev = {
395                                 .sigev_notify = SIGEV_THREAD,
396                                 .sigev_notify_function = timeout,
397                         };
398                         timer_t timerid;
399                         return timer_create(CLOCK_MONOTONIC, &sev, &timerid);
400                 }
401                 "
402                 PIGLIT_HAS_POSIX_TIMER_NOTIFY_THREAD
403         )
404 endif()
406 set(CMAKE_REQUIRED_LIBRARIES)
408 if(PIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
409         add_definitions(-DPIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
410 endif()
412 if(PIGLIT_HAS_POSIX_TIMER_NOTIFY_THREAD)
413         add_definitions(-DPIGLIT_HAS_POSIX_TIMER_NOTIFY_THREAD)
414 endif()
416 if(GBM_FOUND)
417 FIND_LIBRARY(HAVE_LIBCACA NAMES caca)
418 if(HAVE_LIBCACA)
419         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} caca)
420         add_definitions(-DPIGLIT_HAS_LIBCACA)
421 endif(HAVE_LIBCACA)
422 endif(GBM_FOUND)
424 if(PIGLIT_USE_WAFFLE AND ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
425         pkg_check_modules(EGL egl)
426 endif()
428 if(EGL_FOUND)
429         set(PIGLIT_HAS_EGL True)
430         add_definitions(-DPIGLIT_HAS_EGL)
431         include_directories(${EGL_INCLUDE_DIRS})
432         add_definitions (${EGL_CFLAGS_OTHER})
433 endif()
435 if(PIGLIT_BUILD_GLES1_TESTS AND NOT EGL_FOUND)
436         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES1_TESTS requires EGL. "
437                             "Failed to find EGL library.")
438 endif()
440 if(PIGLIT_BUILD_GLES2_TESTS AND NOT EGL_FOUND)
441         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES2_TESTS requires EGL. "
442                             "Failed to find EGL library.")
443 endif()
445 if(PIGLIT_BUILD_GLES3_TESTS AND NOT EGL_FOUND)
446         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES3_TESTS requires EGL. "
447                             "Failed to find EGL library.")
448 endif()
450 # Put all executables into the bin subdirectory
451 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${piglit_BINARY_DIR}/bin)
452 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${piglit_BINARY_DIR}/lib)
454 # Do the same for MSVC, regardless of the build type. This only works correctly
455 # for CMake 2.8.1 and above.
456 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${piglit_BINARY_DIR}/bin)
457 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${piglit_BINARY_DIR}/bin)
458 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${piglit_BINARY_DIR}/bin)
459 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${piglit_BINARY_DIR}/bin)
461 check_function_exists(asprintf  HAVE_ASPRINTF)
462 check_function_exists(ffs       HAVE_FFS)
463 check_function_exists(strchrnul HAVE_STRCHRNUL)
464 check_function_exists(strndup   HAVE_STRNDUP)
465 if(NOT MINGW)
466 check_function_exists(fopen_s   HAVE_FOPEN_S)
467 endif()
468 check_function_exists(setrlimit HAVE_SETRLIMIT)
470 check_symbol_exists(htobe32 "endian.h" HAVE_HTOBE32)
471 check_symbol_exists(htole16 "endian.h" HAVE_HTOLE16)
472 check_symbol_exists(htole32 "endian.h" HAVE_HTOLE32)
473 check_symbol_exists(htole64 "endian.h" HAVE_HTOLE64)
475 check_include_file(sys/time.h  HAVE_SYS_TIME_H)
476 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
477 check_include_file(sys/resource.h  HAVE_SYS_RESOURCE_H)
478 check_include_file(sys/stat.h  HAVE_SYS_STAT_H)
479 check_include_file(unistd.h    HAVE_UNISTD_H)
480 check_include_file(fcntl.h     HAVE_FCNTL_H)
481 check_include_file(linux/sync_file.h HAVE_LINUX_SYNC_FILE_H)
482 check_include_file(endian.h    HAVE_ENDIAN_H)
484 if(DEFINED PIGLIT_INSTALL_VERSION)
485         set(PIGLIT_INSTALL_VERSION_SUFFIX
486             "-${PIGLIT_INSTALL_VERSION}")
487 else()
488         set(PIGLIT_INSTALL_VERSION_SUFFIX "")
489 endif()
490 set(PIGLIT_INSTALL_LIBDIR
491     "${CMAKE_INSTALL_LIBDIR}/piglit${PIGLIT_INSTALL_VERSION_SUFFIX}")
492 if(NOT IS_ABSOLUTE ${PIGLIT_INSTALL_LIBDIR})
493         set(PIGLIT_INSTALL_FULL_LIBDIR "${CMAKE_INSTALL_PREFIX}/${PIGLIT_INSTALL_LIBDIR}")
494 else()
495         set(PIGLIT_INSTALL_FULL_LIBDIR "${PIGLIT_INSTALL_LIBDIR}")
496 endif()
498 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
499   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--enable-new-dtags")
500 endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
502 SET(CMAKE_INSTALL_RPATH "${PIGLIT_INSTALL_FULL_LIBDIR}/lib")
504 configure_file(
505         "${piglit_SOURCE_DIR}/tests/util/config.h.in"
506         "${piglit_BINARY_DIR}/tests/util/config.h"
509 include(cmake/piglit_util.cmake)
510 include(cmake/piglit_dispatch.cmake)
512 include_directories(src)
513 add_subdirectory(cmake/target_api)
514 add_subdirectory(generated_tests)
515 add_subdirectory(replayer)
518 ##############################################################################
519 # Packaging
521 install (
522         FILES
523                 COPYING
524                 README.md
525                 RELEASE
526         DESTINATION share/doc/piglit${PIGLIT_INSTALL_VERSION_SUFFIX}
529 install (
530         DIRECTORY framework
531         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
532         FILES_MATCHING PATTERN "*.py"
535 install (
536         DIRECTORY templates
537         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
540 install (
541         DIRECTORY tests
542         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
543         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)$"
544         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
547 install (
548         DIRECTORY ${CMAKE_BINARY_DIR}/tests
549         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
550         FILES_MATCHING REGEX ".*\\.xml.gz"
553 install (
554         DIRECTORY ${CMAKE_BINARY_DIR}/generated_tests
555         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
556         FILES_MATCHING REGEX ".*\\.(shader_test|program_test|frag|vert|geom|tesc|tese|comp|cl|txt|vk_shader_test)$"
557         REGEX "CMakeFiles|CMakeLists" EXCLUDE
560 install (
561         DIRECTORY generated_tests
562         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
563         FILES_MATCHING REGEX ".*\\.inc$"
564         REGEX "CMakeFiles|CMakeLists" EXCLUDE
567 if (BASH_COMPLETION_FOUND)
568         install(
569                 FILES completions/bash/piglit
570                 DESTINATION ${CMAKE_INSTALL_PREFIX}/${BASH_COMPLETION_COMPLETIONSDIR}/
571         )
572 endif (BASH_COMPLETION_FOUND)
574 if (WIN32)
575         set (PYTHON_SUFFIX ".py")
576 else ()
577         set (PYTHON_SUFFIX "")
578 endif ()
579 install (
580         PROGRAMS piglit RENAME piglit${PIGLIT_INSTALL_VERSION_SUFFIX}${PYTHON_SUFFIX}
581         DESTINATION ${CMAKE_INSTALL_BINDIR}
584 # Install MinGW runtime DLLs
585 if (MINGW)
586         if (CMAKE_SIZEOF_VOID_P EQUAL 8)
587                 set (LIBGCC_DLL_NAME libgcc_s_seh-1.dll)
588         else ()
589                 set (LIBGCC_DLL_NAME libgcc_s_sjlj-1.dll)
590         endif ()
591         execute_process (
592                 COMMAND ${CMAKE_C_COMPILER} -print-file-name=${LIBGCC_DLL_NAME}
593                 OUTPUT_STRIP_TRAILING_WHITESPACE
594                 OUTPUT_VARIABLE LIBGCC_DLL
595         )
596         execute_process (
597                 COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=libstdc++-6.dll
598                 OUTPUT_STRIP_TRAILING_WHITESPACE
599                 OUTPUT_VARIABLE LIBSTDCXX_DLL
600         )
601         if (EXISTS ${LIBGCC_DLL})
602                 message (STATUS "Found libgcc DLL: ${LIBGCC_DLL}")
603                 install (FILES ${LIBGCC_DLL} DESTINATION ${PIGLIT_INSTALL_LIBDIR}/bin)
604         endif ()
605         if (EXISTS ${LIBSTDCXX_DLL})
606                 message (STATUS "Found libstdc++ DLL: ${LIBSTDCXX_DLL}")
607                 install (FILES ${LIBSTDCXX_DLL} DESTINATION ${PIGLIT_INSTALL_LIBDIR}/bin)
608         endif ()
609 endif ()
611 # Install Waffle DLL if specified
612 if (WIN32 AND Waffle_DLL)
613         install (FILES ${Waffle_DLL} DESTINATION ${PIGLIT_INSTALL_LIBDIR}/bin)
614 endif ()
617 set (CPACK_PACKAGE_VERSION_MAJOR "1")
618 set (CPACK_PACKAGE_VERSION_MINOR "0")
620 # Use current date in YYYYMMDD format as patch number
621 execute_process (
622         COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
623         OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
626 # cpack mistakenly detects Mingw-w64 as win32
627 if (MINGW)
628         if (CMAKE_SIZEOF_VOID_P EQUAL 8)
629                 set (CPACK_SYSTEM_NAME win64)
630         endif ()
631 endif ()
633 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
634 if (WIN32)
635         set (CPACK_GENERATOR "7Z")
636         set (CPACK_STRIP_FILES ON)
637 else ()
638         set (CPACK_GENERATOR "TBZ2")
639 endif ()
641 include(CPack)