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