glx_arb_create_context: Fix build against older GL headers.
[piglit.git] / CMakeLists.txt
blobb416cacb207c698055f2f97683edd17a5368a458
1 cmake_minimum_required(VERSION 3.2)
3 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
5 INCLUDE (GNUInstallDirs)
6 INCLUDE (CheckCCompilerFlag)
7 INCLUDE (CheckCSourceCompiles)
8 INCLUDE (CheckCXXCompilerFlag)
9 INCLUDE (CheckFunctionExists)
10 INCLUDE (CheckIncludeFile)
11 INCLUDE (FindPkgConfig)
13 # http://www.cmake.org/cmake/help/v3.0/policy/CMP0042.html
14 if (POLICY CMP0042)
15         cmake_policy (SET CMP0042 NEW)
16 endif()
18 if (POLICY CMP0072)
19         cmake_policy (SET CMP0072 OLD)
20 endif()
22 project (piglit)
24 # Require MinGW
25 if (MSVC)
26         message (FATAL_ERROR "Windows builds require MinGW")
27 endif ()
29 find_package(Threads)
30 find_package(PNG)
31 if(PNG_FOUND)
32         add_definitions(-DPIGLIT_HAS_PNG)
33 endif(PNG_FOUND)
34 find_package(X11)
35 if(X11_FOUND)
36         set(PIGLIT_HAS_X11 True)
37         add_definitions(-DPIGLIT_HAS_X11)
38 endif()
40 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
41         set(PIGLIT_BUILD_GLES_TESTS_DEFAULT ON)
42 else()
43         set(PIGLIT_BUILD_GLES_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)
52 if(PIGLIT_BUILD_GL_TESTS)
53         find_package(OpenGL REQUIRED)
54 endif()
56 if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
57         option(PIGLIT_USE_WAFFLE "Use Waffle in place of GLUT" ON)
58 else()
59         option(PIGLIT_USE_WAFFLE "Use Waffle in place of GLUT" OFF)
60 endif()
62 if(PIGLIT_USE_WAFFLE)
63         if (NOT WIN32)
64                 pkg_check_modules(Waffle REQUIRED waffle-1)
66                 if(NOT Waffle_FOUND)
67                         message(FATAL_ERROR "Failed to find Waffle. If Waffle "
68                         "is not packaged for your distribution, you can get "
69                         "it at http://www.waffle-gl.org."
70                 )
71                 endif()
73                 # Check the installed waffle version.
74                 #
75                 # We cannot reliably check the version with pkg_check_modules(), but
76                 # instead must check the version manually as below. The problem is that,
77                 # if one passes a required version to pkg_check_modules(), CMake
78                 # validates the required version at most once for the lifetime of the
79                 # source tree.  If someone changes the required version by editing the
80                 # CMakeLists, CMake fails to detect the new requirement.
81                 set(Waffle_REQUIRED_VERSION "1.5.0")
82                 if(Waffle_VERSION VERSION_LESS Waffle_REQUIRED_VERSION)
83                         message(FATAL_ERROR "Found waffle-${Waffle_VERSION}, but "
84                         "piglit requires waffle-${Waffle_REQUIRED_VERSION}")
85                 endif()
86         else ()
87                 find_path(Waffle_INCLUDE_DIRS waffle.h)
88                 find_library(Waffle_LDFLAGS waffle-1)
89                 if(Waffle_INCLUDE_DIRS AND Waffle_LDFLAGS)
90                         set(Waffle_FOUND TRUE)
91                 else()
92                         message(FATAL_ERROR "Failed to find Waffle. Get and build Waffle from "
93                                 "http://www.waffle-gl.org and set Waffle_INCLUDE_DIRS and "
94                                 "Waffle_LDFLAGS variables accordingly."
95                         )
96                 endif()
97         endif ()
99         add_definitions(-DPIGLIT_USE_WAFFLE)
100         add_definitions(-DWAFFLE_API_VERSION=0x0103)
101 else()
102         find_package(GLUT REQUIRED)
104         # The 'REQUIRED' above correctly produces an error for
105         # OpenGL, but there's a bug involving FindGLUT.cmake
106         # that fails to produce the error as of CMake 2.8.5.
107         #
108         # Instead, CMake keeps going and eventually spams
109         # the console with a message for every target that used
110         # e.g. the ${GLUT_INCLUDE_DIR} variable. So it
111         # prints a line for basically every single test in piglit.
112         #
113         # Work around the bug and error out quickly here instead.
114         if (NOT GLUT_FOUND)
115                 message(FATAL_ERROR "GLUT library not found")
116         endif()
117 endif(PIGLIT_USE_WAFFLE)
119 if(PIGLIT_BUILD_GLES1_TESTS AND NOT PIGLIT_USE_WAFFLE)
120         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES1_TESTS requires PIGLIT_USE_WAFFLE")
121 endif(PIGLIT_BUILD_GLES1_TESTS AND NOT PIGLIT_USE_WAFFLE)
123 if(PIGLIT_BUILD_GLES2_TESTS AND NOT PIGLIT_USE_WAFFLE)
124         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES2_TESTS requires PIGLIT_USE_WAFFLE")
125 endif(PIGLIT_BUILD_GLES2_TESTS AND NOT PIGLIT_USE_WAFFLE)
127 if(PIGLIT_BUILD_GLES3_TESTS AND NOT PIGLIT_USE_WAFFLE)
128         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES3_TESTS requires PIGLIT_USE_WAFFLE")
129 endif(PIGLIT_BUILD_GLES3_TESTS AND NOT PIGLIT_USE_WAFFLE)
131 if(PIGLIT_BUILD_CL_TESTS)
132         find_package(OpenCL REQUIRED)
133 endif(PIGLIT_BUILD_CL_TESTS)
135 IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
136         if(X11_FOUND AND OPENGL_gl_LIBRARY)
137                 # Assume the system has GLX. In the future, systems may exist
138                 # with libGL and libX11 but no GLX, but that world hasn't
139                 # arrived yet.
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         endif(GBM_FOUND)
155         pkg_check_modules(WAYLAND QUIET wayland-client)
156         if (WAYLAND_FOUND)
157                 set(PIGLIT_HAS_WAYLAND True)
158                 add_definitions(-DPIGLIT_HAS_WAYLAND)
160                 FIND_LIBRARY(HAVE_XKBCOMMON NAMES xkbcommon)
161                 if(NOT HAVE_XKBCOMMON)
162                         message(FATAL_ERROR "Wayland support requires xkbcommon. "
163                                 "Failed to find xkbcommon library.")
164                 endif()
165                 pkg_check_modules(XKBCOMMON QUIET xkbcommon)
166         endif()
168         pkg_check_modules(LIBDRM QUIET libdrm)
169         pkg_check_modules(LIBDRM_INTEL QUIET libdrm_intel)
170         pkg_check_modules(XCB QUIET xcb)
171         pkg_check_modules(XCB_DRI2 QUIET xcb-dri2)
172         pkg_check_modules(GLPROTO QUIET glproto)
173 ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
174         if (PIGLIT_USE_WAFFLE)
175                 set(PIGLIT_HAS_WGL True)
176                 add_definitions(-DPIGLIT_HAS_WGL)
177         endif()
178 ENDIF()
180 IF(PIGLIT_HAS_GLX)
181         option(PIGLIT_BUILD_GLX_TESTS "Build tests that require GLX" ON)
182 ELSE()
183         option(PIGLIT_BUILD_GLX_TESTS "Build tests that require GLX" OFF)
184 ENDIF()
186 IF(PIGLIT_HAS_WGL)
187         option(PIGLIT_BUILD_WGL_TESTS "Build tests that require WGL" ON)
188 ELSE()
189         option(PIGLIT_BUILD_WGL_TESTS "Build tests that require WGL" OFF)
190 ENDIF()
193 # Choose to build tests that use dma_buf.
195 # Piglit's dma_buf utilities require xcb-dri2 to gain DRM authentication.
197 # The presence of libdrm is not sufficient. At least one libdrm_${hardware}
198 # library is also needed.
200 # When building for Intel, libdrm_intel>=2.4.38 is required because support for
201 # drm-prime arrived in that version.
203 if(LIBDRM_FOUND AND XCB_DRI2_FOUND AND
204    ((LIBDRM_INTEL_VERSION VERSION_GREATER "2.4.37") OR
205      PIGLIT_HAS_GBM_BO_MAP))
206         set(PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID true)
207 else()
208         set(PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID false)
209 endif()
211 if(PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID)
212         option(PIGLIT_BUILD_DMA_BUF_TESTS "Build tests that use dma_buf" ON)
213 else()
214         option(PIGLIT_BUILD_DMA_BUF_TESTS "Build tests that use dma_buf" OFF)
215 endif()
217 # If the users has updated PIGLIT_BUILD_DMA_BUF_TESTS in the CMakeCache, then
218 # we need to validate it.
219 if(PIGLIT_BUILD_DMA_BUF_TESTS AND NOT PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID)
220         message(FATAL_ERROR
221                 "PIGLIT_BUILD_DMA_BUF_TESTS require libdrm, "
222                 "libdrm_intel>=2.4.38, and xcb-dri2")
223 endif()
225 IF(PIGLIT_BUILD_GLX_TESTS)
226         pkg_check_modules(GLPROTO REQUIRED glproto)
227 ENDIF()
229 set(Python_ADDITIONAL_VERSIONS
230     3.7 3.6 3.5 3.4 2.7)
231 find_package(PythonInterp REQUIRED)
232 find_package(PythonSix 1.5.2 REQUIRED)
233 find_package(PythonNumpy 1.7.0 REQUIRED)
235 # CMake doesn't have a VERSION_GREATER_EQUAL function, at least as of 3.0,
236 # And mako 1.0.2 contains bug fixes required for python 3.5 to work, so
237 # the only solution (short of having a series of "OR" statements, is this)
238 if (PYTHON_VERSION_STRING VERSION_GREATER 3.4.999999)
239         find_package(PythonMako 1.0.2 REQUIRED)
240 else ()
241         find_package(PythonMako 0.8.0 REQUIRED)
242 endif (PYTHON_VERSION_STRING VERSION_GREATER 3.4.999999)
244 find_package(bash-completion NO_MODULE)
246 # Default to compiling with debug information (`gcc -g`):
247 if(NOT CMAKE_BUILD_TYPE)
248         SET(CMAKE_BUILD_TYPE Debug CACHE STRING
249         "May be one of: None Debug RelWithDebInfo Release MinSizeRel" FORCE)
250 endif(NOT CMAKE_BUILD_TYPE)
252 if (NOT MSVC)
253         CHECK_C_COMPILER_FLAG("-Wall" C_COMPILER_FLAG_WALL)
254         IF (C_COMPILER_FLAG_WALL)
255                 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
256         ENDIF (C_COMPILER_FLAG_WALL)
257         CHECK_CXX_COMPILER_FLAG("-Wall" CXX_COMPILER_FLAG_WALL)
258         IF (CXX_COMPILER_FLAG_WALL)
259                 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
260         ENDIF (CXX_COMPILER_FLAG_WALL)
262         # Target C99.  GCC's default is gnu11 for 5.0 and newer, gnu89 for
263         # older versions.
264         check_c_compiler_flag ("-std=gnu99" C_COMPILER_FLAG_STD_GNU99)
265         if (C_COMPILER_FLAG_STD_GNU99)
266                 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
267         endif ()
268         # MSVC does not support C99 variable length arrays
269         CHECK_C_COMPILER_FLAG("-Werror=vla" C_COMPILER_FLAG_WEVLA)
270         IF (C_COMPILER_FLAG_WEVLA)
271                 SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=vla")
272         ENDIF ()
273         # GCC allows void pointer arithmetic, but it is not part of ISO C and
274         # in particular MSVC will throw `C2036: 'void *' : unknown size`
275         check_c_compiler_flag ("-Werror=pointer-arith" C_COMPILER_FLAG_WEPOINTER_ARITH)
276         if (C_COMPILER_FLAG_WEPOINTER_ARITH)
277                 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=pointer-arith")
278         endif ()
279         # MSVC only supports C99 variadic macros.  It doesn't support the
280         # non-standard GNU named variadic macro syntax that's documented in
281         # https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html
282         #
283         # XXX: on older GCC version this option has no effect unless -Wpedantic
284         # is set, but this should be fixed on future GCC versions, per
285         # https://gcc.gnu.org/ml/gcc-patches/2014-04/msg01459.html
286         check_c_compiler_flag ("-Werror=variadic-macros" C_COMPILER_FLAG_WVARIADIC_MACROS)
287         if (C_COMPILER_FLAG_WVARIADIC_MACROS)
288                 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=variadic-macros")
289         endif ()
291         CHECK_CXX_COMPILER_FLAG("-Wno-narrowing" CXX_COMPILER_FLAG_WNO_NARROWING)
292         IF (CXX_COMPILER_FLAG_WNO_NARROWING)
293                 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
294         ENDIF (CXX_COMPILER_FLAG_WNO_NARROWING)
295 else ()
296         # Adjust warnings
297         add_definitions (-W3)
298         add_definitions (-wd4018) # signed/unsigned mismatch
299         add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
300         add_definitions (-wd4305) # truncation from 'type1' to 'type2'
301         add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
303         add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
304         add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
305 endif ()
307 if (MINGW)
308         # Match MSVC default stack size
309         set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,1048576")
311         # Avoid depending on MinGW runtime DLLs
312         check_cxx_compiler_flag (-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
313         if (HAVE_STATIC_LIBGCC_FLAG)
314                 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
315                 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
316                 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libgcc")
317         endif ()
318         check_cxx_compiler_flag (-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG)
319         if (HAVE_STATIC_LIBSTDCXX_FLAG)
320                 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
321                 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
322                 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++")
323         endif ()
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         # Define M_PI and others
350         add_definitions (-D_USE_MATH_DEFINES)
351 endif (WIN32)
353 if (APPLE)
354         # Don't warn about using deprecated OpenGL/GLUT functions.
355         # TODO: It would be nice to silence just the deprecation macros from
356         # OpenGLAvailability.h as opposed to all deprecated functions.
357         set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
358         set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
359 endif ()
361 if (OPENGL_FOUND)
362         if (APPLE)
363                 find_path(GLEXT_INCLUDE_DIR
364                         NAMES OpenGL/glext.h
365                         PATHS ${OPENGL_INCLUDE_DIR}
366                         DOC "Include for OpenGL/glext.h on OSX"
367                 )
368         else (APPLE)
369                 find_path(GLEXT_INCLUDE_DIR
370                         NAMES GL/glext.h
371                         PATHS ${OPENGL_INCLUDE_DIR}
372                         DOC "Include for GL/glext.h"
373                 )
374         endif (APPLE)
375 endif()
377 if(CMAKE_USE_PTHREADS_INIT)
378         set(PIGLIT_HAS_PTHREADS true)
379         add_definitions(-DPIGLIT_HAS_PTHREADS)
380 endif()
382 FIND_LIBRARY(HAVE_LIBRT NAMES rt)
383 if(HAVE_LIBRT)
384         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt)
385 endif()
387 check_c_source_compiles(
388         "
389         #define _POSIX_C_SOURCE 199309L
390         #include <time.h>
391         int main() { return clock_gettime(CLOCK_MONOTONIC, NULL); }
392         "
393         PIGLIT_HAS_POSIX_CLOCK_MONOTONIC
396 if(PIGLIT_HAS_PTHREADS AND PIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
397         check_c_source_compiles(
398                 "
399                 #include <signal.h>
400                 #include <time.h>
401                 static void timeout(union sigval val) { }
402                 int main() {
403                         struct sigevent sev = {
404                                 .sigev_notify = SIGEV_THREAD,
405                                 .sigev_notify_function = timeout,
406                         };
407                         timer_t timerid;
408                         return timer_create(CLOCK_MONOTONIC, &sev, &timerid);
409                 }
410                 "
411                 PIGLIT_HAS_POSIX_TIMER_NOTIFY_THREAD
412         )
413 endif()
415 set(CMAKE_REQUIRED_LIBRARIES)
417 if(PIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
418         add_definitions(-DPIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
419 endif()
421 if(PIGLIT_HAS_POSIX_TIMER_NOTIFY_THREAD)
422         add_definitions(-DPIGLIT_HAS_POSIX_TIMER_NOTIFY_THREAD)
423 endif()
425 if(GBM_FOUND)
426 FIND_LIBRARY(HAVE_LIBCACA NAMES caca)
427 if(HAVE_LIBCACA)
428         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} caca)
429         add_definitions(-DPIGLIT_HAS_LIBCACA)
430 endif(HAVE_LIBCACA)
431 endif(GBM_FOUND)
433 if(PIGLIT_USE_WAFFLE AND ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
434         pkg_check_modules(EGL egl>=11.0)
435 endif()
437 if(EGL_FOUND)
438         add_definitions(-DPIGLIT_HAS_EGL)
439         include_directories(${EGL_INCLUDE_DIRS})
440         add_definitions (${EGL_CFLAGS_OTHER})
441 endif()
443 if(PIGLIT_BUILD_GLES1_TESTS AND NOT EGL_FOUND)
444         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES1_TESTS requires EGL. "
445                             "Failed to find EGL library.")
446 endif()
448 if(PIGLIT_BUILD_GLES2_TESTS AND NOT EGL_FOUND)
449         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES2_TESTS requires EGL. "
450                             "Failed to find EGL library.")
451 endif()
453 if(PIGLIT_BUILD_GLES3_TESTS AND NOT EGL_FOUND)
454         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES3_TESTS requires EGL. "
455                             "Failed to find EGL library.")
456 endif()
458 # Put all executables into the bin subdirectory
459 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${piglit_BINARY_DIR}/bin)
460 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${piglit_BINARY_DIR}/lib)
462 # Do the same for MSVC, regardless of the build type. This only works correctly
463 # for CMake 2.8.1 and above.
464 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${piglit_BINARY_DIR}/bin)
465 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${piglit_BINARY_DIR}/bin)
466 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${piglit_BINARY_DIR}/bin)
467 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${piglit_BINARY_DIR}/bin)
469 check_function_exists(asprintf  HAVE_ASPRINTF)
470 check_function_exists(ffs       HAVE_FFS)
471 check_function_exists(strchrnul HAVE_STRCHRNUL)
472 check_function_exists(strndup   HAVE_STRNDUP)
473 if(NOT MINGW)
474 check_function_exists(fopen_s   HAVE_FOPEN_S)
475 endif()
476 check_function_exists(setrlimit HAVE_SETRLIMIT)
478 check_include_file(sys/time.h  HAVE_SYS_TIME_H)
479 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
480 check_include_file(sys/resource.h  HAVE_SYS_RESOURCE_H)
481 check_include_file(sys/stat.h  HAVE_SYS_STAT_H)
482 check_include_file(unistd.h    HAVE_UNISTD_H)
483 check_include_file(fcntl.h     HAVE_FCNTL_H)
484 check_include_file(linux/sync_file.h HAVE_LINUX_SYNC_FILE_H)
486 if(DEFINED PIGLIT_INSTALL_VERSION)
487         set(PIGLIT_INSTALL_VERSION_SUFFIX
488             "-${PIGLIT_INSTALL_VERSION}")
489 else()
490         set(PIGLIT_INSTALL_VERSION_SUFFIX "")
491 endif()
492 set(PIGLIT_INSTALL_LIBDIR
493     "${CMAKE_INSTALL_LIBDIR}/piglit${PIGLIT_INSTALL_VERSION_SUFFIX}")
494 if(NOT IS_ABSOLUTE ${PIGLIT_INSTALL_LIBDIR})
495         set(PIGLIT_INSTALL_FULL_LIBDIR "${CMAKE_INSTALL_PREFIX}/${PIGLIT_INSTALL_LIBDIR}")
496 else()
497         set(PIGLIT_INSTALL_FULL_LIBDIR "${PIGLIT_INSTALL_LIBDIR}")
498 endif()
500 SET(CMAKE_INSTALL_RPATH "${PIGLIT_INSTALL_FULL_LIBDIR}/lib")
502 configure_file(
503         "${piglit_SOURCE_DIR}/tests/util/config.h.in"
504         "${piglit_BINARY_DIR}/tests/util/config.h"
507 include(cmake/piglit_util.cmake)
508 include(cmake/piglit_dispatch.cmake)
510 include_directories(src)
511 add_subdirectory(cmake/target_api)
512 add_subdirectory(generated_tests)
515 ##############################################################################
516 # Packaging
518 install (
519         FILES
520                 COPYING
521                 README.md
522                 RELEASE
523         DESTINATION share/doc/piglit${PIGLIT_INSTALL_VERSION_SUFFIX}
526 install (
527         DIRECTORY framework
528         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
529         FILES_MATCHING PATTERN "*.py"
532 install (
533         DIRECTORY templates
534         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
537 install (
538         DIRECTORY tests
539         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
540         FILES_MATCHING REGEX ".*\\.(xml|xml.gz|py|program_test|shader_test|shader_source|frag|vert|geom|tesc|tese|comp|ktx|cl|txt|inc|vk_shader_test)$"
541         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
544 install (
545         DIRECTORY ${CMAKE_BINARY_DIR}/tests
546         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
547         FILES_MATCHING REGEX ".*\\.xml.gz"
550 install (
551         DIRECTORY ${CMAKE_BINARY_DIR}/generated_tests
552         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
553         FILES_MATCHING REGEX ".*\\.(shader_test|program_test|frag|vert|geom|tesc|tese|comp|cl|txt|vk_shader_test)$"
554         REGEX "CMakeFiles|CMakeLists" EXCLUDE
557 install (
558         DIRECTORY generated_tests
559         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
560         FILES_MATCHING REGEX ".*\\.inc$"
561         REGEX "CMakeFiles|CMakeLists" EXCLUDE
564 if (BASH_COMPLETION_FOUND)
565         install(
566                 FILES completions/bash/piglit
567                 DESTINATION ${CMAKE_INSTALL_PREFIX}/${BASH_COMPLETION_COMPLETIONSDIR}/
568         )
569 endif (BASH_COMPLETION_FOUND)
571 if (WIN32)
572         set (PYTHON_SUFFIX ".py")
573 else ()
574         set (PYTHON_SUFFIX "")
575 endif ()
576 install (
577         PROGRAMS piglit RENAME piglit${PIGLIT_INSTALL_VERSION_SUFFIX}${PYTHON_SUFFIX}
578         DESTINATION ${CMAKE_INSTALL_BINDIR}
582 set (CPACK_PACKAGE_VERSION_MAJOR "1")
583 set (CPACK_PACKAGE_VERSION_MINOR "0")
585 # Use current date in YYYYMMDD format as patch number
586 execute_process (
587         COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
588         OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
591 # cpack mistakenly detects Mingw-w64 as win32
592 if (MINGW)
593         if (CMAKE_SIZEOF_VOID_P EQUAL 8)
594                 set (CPACK_SYSTEM_NAME win64)
595         endif ()
596 endif ()
598 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
599 if (WIN32)
600         set (CPACK_GENERATOR "ZIP")
601 else ()
602         set (CPACK_GENERATOR "TBZ2")
603 endif ()
605 include(CPack)