add new indexing test with dynamic indexing of integer vector
[piglit.git] / CMakeLists.txt
blob4259ec8327077a237e42caf58aa3721445d0375d
1 cmake_minimum_required(VERSION 2.8.5)
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 project (piglit)
20 # Require MinGW
21 if (MSVC)
22         message (FATAL_ERROR "Windows builds require MinGW")
23 endif ()
25 find_package(Threads)
26 find_package(PNG)
27 if(PNG_FOUND)
28         add_definitions(-DPIGLIT_HAS_PNG)
29 endif(PNG_FOUND)
30 find_package(X11)
31 if(X11_FOUND)
32         set(PIGLIT_HAS_X11 True)
33         add_definitions(-DPIGLIT_HAS_X11)
34 endif()
36 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
37         set(PIGLIT_BUILD_GLES_TESTS_DEFAULT ON)
38 else()
39         set(PIGLIT_BUILD_GLES_TESTS_DEFAULT OFF)
40 endif()
42 option(PIGLIT_BUILD_GL_TESTS "Build tests for OpenGL" ON)
43 option(PIGLIT_BUILD_GLES1_TESTS "Build tests for OpenGL ES1" ${PIGLIT_BUILD_GLES_TESTS_DEFAULT})
44 option(PIGLIT_BUILD_GLES2_TESTS "Build tests for OpenGL ES2" ${PIGLIT_BUILD_GLES_TESTS_DEFAULT})
45 option(PIGLIT_BUILD_GLES3_TESTS "Build tests for OpenGL ES3" ${PIGLIT_BUILD_GLES_TESTS_DEFAULT})
46 option(PIGLIT_BUILD_CL_TESTS "Build tests for OpenCL" OFF)
48 if(PIGLIT_BUILD_GL_TESTS)
49         find_package(OpenGL REQUIRED)
50 endif()
52 if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
53         option(PIGLIT_USE_WAFFLE "Use Waffle in place of GLUT" ON)
54 else()
55         option(PIGLIT_USE_WAFFLE "Use Waffle in place of GLUT" OFF)
56 endif()
58 if(PIGLIT_USE_WAFFLE)
59         if (NOT WIN32)
60                 pkg_check_modules(Waffle REQUIRED waffle-1)
62                 if(NOT Waffle_FOUND)
63                         message(FATAL_ERROR "Failed to find Waffle. If Waffle "
64                         "is not packaged for your distribution, you can get "
65                         "it at http://www.waffle-gl.org."
66                 )
67                 endif()
69                 # Check the installed waffle version.
70                 #
71                 # We cannot reliably check the version with pkg_check_modules(), but
72                 # instead must check the version manually as below. The problem is that,
73                 # if one passes a required version to pkg_check_modules(), CMake
74                 # validates the required version at most once for the lifetime of the
75                 # source tree.  If someone changes the required version by editing the
76                 # CMakeLists, CMake fails to detect the new requirement.
77                 set(Waffle_REQUIRED_VERSION "1.5.0")
78                 if(Waffle_VERSION VERSION_LESS Waffle_REQUIRED_VERSION)
79                         message(FATAL_ERROR "Found waffle-${Waffle_VERSION}, but "
80                         "piglit requires waffle-${Waffle_REQUIRED_VERSION}")
81                 endif()
82         else ()
83                 find_path(Waffle_INCLUDE_DIRS waffle.h)
84                 find_library(Waffle_LDFLAGS waffle-1)
85                 if(Waffle_INCLUDE_DIRS AND Waffle_LDFLAGS)
86                         set(Waffle_FOUND TRUE)
87                 else()
88                         message(FATAL_ERROR "Failed to find Waffle. Get and build Waffle from "
89                                 "http://www.waffle-gl.org and set Waffle_INCLUDE_DIRS and "
90                                 "Waffle_LDFLAGS variables accordingly."
91                         )
92                 endif()
93         endif ()
95         add_definitions(-DPIGLIT_USE_WAFFLE)
96         add_definitions(-DWAFFLE_API_VERSION=0x0103)
97 else()
98         find_package(GLUT REQUIRED)
100         # The 'REQUIRED' above correctly produces an error for
101         # OpenGL, but there's a bug involving FindGLUT.cmake
102         # that fails to produce the error as of CMake 2.8.5.
103         #
104         # Instead, CMake keeps going and eventually spams
105         # the console with a message for every target that used
106         # e.g. the ${GLUT_INCLUDE_DIR} variable. So it
107         # prints a line for basically every single test in piglit.
108         #
109         # Work around the bug and error out quickly here instead.
110         if (NOT GLUT_FOUND)
111                 message(FATAL_ERROR "GLUT library not found")
112         endif()
113 endif(PIGLIT_USE_WAFFLE)
115 if(PIGLIT_BUILD_GLES1_TESTS AND NOT PIGLIT_USE_WAFFLE)
116         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES1_TESTS requires PIGLIT_USE_WAFFLE")
117 endif(PIGLIT_BUILD_GLES1_TESTS AND NOT PIGLIT_USE_WAFFLE)
119 if(PIGLIT_BUILD_GLES2_TESTS AND NOT PIGLIT_USE_WAFFLE)
120         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES2_TESTS requires PIGLIT_USE_WAFFLE")
121 endif(PIGLIT_BUILD_GLES2_TESTS AND NOT PIGLIT_USE_WAFFLE)
123 if(PIGLIT_BUILD_GLES3_TESTS AND NOT PIGLIT_USE_WAFFLE)
124         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES3_TESTS requires PIGLIT_USE_WAFFLE")
125 endif(PIGLIT_BUILD_GLES3_TESTS AND NOT PIGLIT_USE_WAFFLE)
127 if(PIGLIT_BUILD_CL_TESTS)
128         find_package(OpenCL REQUIRED)
129 endif(PIGLIT_BUILD_CL_TESTS)
131 IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
132         if(X11_FOUND AND OPENGL_gl_LIBRARY)
133                 # Assume the system has GLX. In the future, systems may exist
134                 # with libGL and libX11 but no GLX, but that world hasn't
135                 # arrived yet.
136                 set(PIGLIT_HAS_GLX True)
137                 add_definitions(-DPIGLIT_HAS_GLX)
138         endif()
140         pkg_check_modules(GBM QUIET gbm>=17.1)
141         if(GBM_FOUND)
142                 set(PIGLIT_HAS_GBM True)
143                 add_definitions(-DPIGLIT_HAS_GBM)
144                 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${GBM_LIBRARIES})
145                 CHECK_FUNCTION_EXISTS(gbm_bo_map PIGLIT_HAS_GBM_BO_MAP)
146                 if (PIGLIT_HAS_GBM_BO_MAP)
147                         add_definitions(-DPIGLIT_HAS_GBM_BO_MAP)
148                 endif()
149         endif(GBM_FOUND)
151         pkg_check_modules(WAYLAND QUIET wayland-client wayland-egl)
152         if (WAYLAND_FOUND)
153                 set(PIGLIT_HAS_WAYLAND True)
154                 add_definitions(-DPIGLIT_HAS_WAYLAND)
156                 FIND_LIBRARY(HAVE_XKBCOMMON NAMES xkbcommon)
157                 if(NOT HAVE_XKBCOMMON)
158                         message(FATAL_ERROR "Wayland support requires xkbcommon. "
159                                 "Failed to find xkbcommon library.")
160                 endif()
161                 pkg_check_modules(XKBCOMMON QUIET xkbcommon)
162         endif()
164         pkg_check_modules(LIBDRM QUIET libdrm)
165         pkg_check_modules(LIBDRM_INTEL QUIET libdrm_intel)
166         pkg_check_modules(XCB QUIET xcb)
167         pkg_check_modules(XCB_DRI2 QUIET xcb-dri2)
168         pkg_check_modules(GLPROTO QUIET glproto)
169 ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
170         if (PIGLIT_USE_WAFFLE)
171                 set(PIGLIT_HAS_WGL True)
172                 add_definitions(-DPIGLIT_HAS_WGL)
173         endif()
174 ENDIF()
176 IF(PIGLIT_HAS_GLX)
177         option(PIGLIT_BUILD_GLX_TESTS "Build tests that require GLX" ON)
178 ELSE()
179         option(PIGLIT_BUILD_GLX_TESTS "Build tests that require GLX" OFF)
180 ENDIF()
182 IF(PIGLIT_HAS_WGL)
183         option(PIGLIT_BUILD_WGL_TESTS "Build tests that require WGL" ON)
184 ELSE()
185         option(PIGLIT_BUILD_WGL_TESTS "Build tests that require WGL" OFF)
186 ENDIF()
189 # Choose to build tests that use dma_buf.
191 # Piglit's dma_buf utilities require xcb-dri2 to gain DRM authentication.
193 # The presence of libdrm is not sufficient. At least one libdrm_${hardware}
194 # library is also needed.
196 # When building for Intel, libdrm_intel>=2.4.38 is required because support for
197 # drm-prime arrived in that version.
199 if(LIBDRM_FOUND AND XCB_DRI2_FOUND AND
200    ((LIBDRM_INTEL_VERSION VERSION_GREATER "2.4.37") OR
201      PIGLIT_HAS_GBM_BO_MAP))
202         set(PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID true)
203 else()
204         set(PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID false)
205 endif()
207 if(PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID)
208         option(PIGLIT_BUILD_DMA_BUF_TESTS "Build tests that use dma_buf" ON)
209 else()
210         option(PIGLIT_BUILD_DMA_BUF_TESTS "Build tests that use dma_buf" OFF)
211 endif()
213 # If the users has updated PIGLIT_BUILD_DMA_BUF_TESTS in the CMakeCache, then
214 # we need to validate it.
215 if(PIGLIT_BUILD_DMA_BUF_TESTS AND NOT PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID)
216         message(FATAL_ERROR
217                 "PIGLIT_BUILD_DMA_BUF_TESTS require libdrm, "
218                 "libdrm_intel>=2.4.38, and xcb-dri2")
219 endif()
221 IF(PIGLIT_BUILD_GLX_TESTS)
222         pkg_check_modules(GLPROTO REQUIRED glproto)
223 ENDIF()
225 set(Python_ADDITIONAL_VERSIONS
226     3.6 3.5 3.4 3.3 2.7)
227 find_package(PythonInterp REQUIRED)
228 find_package(PythonSix 1.5.2 REQUIRED)
229 find_package(PythonNumpy 1.7.0 REQUIRED)
231 # CMake doesn't have a VERSION_GREATER_EQUAL function, at least as of 3.0,
232 # And mako 1.0.2 contains bug fixes required for python 3.5 to work, so
233 # the only solution (short of having a series of "OR" statements, is this)
234 if (PYTHON_VERSION_STRING VERSION_GREATER 3.4.999999)
235         find_package(PythonMako 1.0.2 REQUIRED)
236 else ()
237         find_package(PythonMako 0.8.0 REQUIRED)
238 endif (PYTHON_VERSION_STRING VERSION_GREATER 3.4.999999)
240 find_package(bash-completion NO_MODULE)
242 # Default to compiling with debug information (`gcc -g`):
243 if(NOT CMAKE_BUILD_TYPE)
244         SET(CMAKE_BUILD_TYPE Debug CACHE STRING
245         "May be one of: None Debug RelWithDebInfo Release MinSizeRel" FORCE)
246 endif(NOT CMAKE_BUILD_TYPE)
248 if (NOT MSVC)
249         CHECK_C_COMPILER_FLAG("-Wall" C_COMPILER_FLAG_WALL)
250         IF (C_COMPILER_FLAG_WALL)
251                 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
252         ENDIF (C_COMPILER_FLAG_WALL)
253         CHECK_CXX_COMPILER_FLAG("-Wall" CXX_COMPILER_FLAG_WALL)
254         IF (CXX_COMPILER_FLAG_WALL)
255                 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
256         ENDIF (CXX_COMPILER_FLAG_WALL)
258         # Target C99.  GCC's default is gnu11 for 5.0 and newer, gnu89 for
259         # older versions.
260         check_c_compiler_flag ("-std=gnu99" C_COMPILER_FLAG_STD_GNU99)
261         if (C_COMPILER_FLAG_STD_GNU99)
262                 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
263         endif ()
264         # MSVC does not support C99 variable length arrays
265         CHECK_C_COMPILER_FLAG("-Werror=vla" C_COMPILER_FLAG_WEVLA)
266         IF (C_COMPILER_FLAG_WEVLA)
267                 SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=vla")
268         ENDIF ()
269         # GCC allows void pointer arithmetic, but it is not part of ISO C and
270         # in particular MSVC will throw `C2036: 'void *' : unknown size`
271         check_c_compiler_flag ("-Werror=pointer-arith" C_COMPILER_FLAG_WEPOINTER_ARITH)
272         if (C_COMPILER_FLAG_WEPOINTER_ARITH)
273                 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=pointer-arith")
274         endif ()
275         # MSVC only supports C99 variadic macros.  It doesn't support the
276         # non-standard GNU named variadic macro syntax that's documented in
277         # https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html
278         #
279         # XXX: on older GCC version this option has no effect unless -Wpedantic
280         # is set, but this should be fixed on future GCC versions, per
281         # https://gcc.gnu.org/ml/gcc-patches/2014-04/msg01459.html
282         check_c_compiler_flag ("-Werror=variadic-macros" C_COMPILER_FLAG_WVARIADIC_MACROS)
283         if (C_COMPILER_FLAG_WVARIADIC_MACROS)
284                 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=variadic-macros")
285         endif ()
287         CHECK_CXX_COMPILER_FLAG("-Wno-narrowing" CXX_COMPILER_FLAG_WNO_NARROWING)
288         IF (CXX_COMPILER_FLAG_WNO_NARROWING)
289                 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
290         ENDIF (CXX_COMPILER_FLAG_WNO_NARROWING)
291 else ()
292         # Adjust warnings
293         add_definitions (-W3)
294         add_definitions (-wd4018) # signed/unsigned mismatch
295         add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
296         add_definitions (-wd4305) # truncation from 'type1' to 'type2'
297         add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
299         add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
300         add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
301 endif ()
303 if (MINGW)
304         # Match MSVC default stack size
305         set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,1048576")
307         # Avoid depending on MinGW runtime DLLs
308         check_cxx_compiler_flag (-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
309         if (HAVE_STATIC_LIBGCC_FLAG)
310                 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
311                 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
312                 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libgcc")
313         endif ()
314         check_cxx_compiler_flag (-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG)
315         if (HAVE_STATIC_LIBSTDCXX_FLAG)
316                 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
317                 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
318                 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++")
319         endif ()
320 endif ()
322 if (${CMAKE_C_COMPILER_ID} STREQUAL "SunPro")
323         # Use C++ to link C files.
324         # http://developers.sun.com/solaris/articles/mixing.html#linking
325         # Modified rule from Modules/CMakeCInformation.cmake.
326         set (CMAKE_C_LINK_EXECUTABLE
327                 "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
328 endif()
330 # Always enable GNU C extensions.  Non-GNU platforms will need to
331 # define wrappers for them.
332 add_definitions(-D_GNU_SOURCE)
334 if (WIN32)
335         # MSVC & MinGW only define & use APIENTRY
336         add_definitions (-DGLAPIENTRY=__stdcall)
338         # Avoid namespace pollution when including windows.h
339         # http://support.microsoft.com/kb/166474
340         add_definitions (-DWIN32_LEAN_AND_MEAN=1)
342         # Don't define min/max macros
343         add_definitions (-DNOMINMAX)
345         # Define M_PI and others
346         add_definitions (-D_USE_MATH_DEFINES)
347 endif (WIN32)
349 if (APPLE)
350         # Don't warn about using deprecated OpenGL/GLUT functions.
351         # TODO: It would be nice to silence just the deprecation macros from
352         # OpenGLAvailability.h as opposed to all deprecated functions.
353         set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
354         set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
355 endif ()
357 if (OPENGL_FOUND)
358         if (APPLE)
359                 find_path(GLEXT_INCLUDE_DIR
360                         NAMES OpenGL/glext.h
361                         PATHS ${OPENGL_INCLUDE_DIR}
362                         DOC "Include for OpenGL/glext.h on OSX"
363                 )
364         else (APPLE)
365                 find_path(GLEXT_INCLUDE_DIR
366                         NAMES GL/glext.h
367                         PATHS ${OPENGL_INCLUDE_DIR}
368                         DOC "Include for GL/glext.h"
369                 )
370         endif (APPLE)
371 endif()
373 if(CMAKE_USE_PTHREADS_INIT)
374         set(PIGLIT_HAS_PTHREADS true)
375         add_definitions(-DPIGLIT_HAS_PTHREADS)
376 endif()
378 FIND_LIBRARY(HAVE_LIBRT NAMES rt)
379 if(HAVE_LIBRT)
380         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt)
381 endif()
383 check_c_source_compiles(
384         "
385         #define _POSIX_C_SOURCE 199309L
386         #include <time.h>
387         int main() { return clock_gettime(CLOCK_MONOTONIC, NULL); }
388         "
389         PIGLIT_HAS_POSIX_CLOCK_MONOTONIC
392 if(PIGLIT_HAS_PTHREADS AND PIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
393         check_c_source_compiles(
394                 "
395                 #include <signal.h>
396                 #include <time.h>
397                 static void timeout(union sigval val) { }
398                 int main() {
399                         struct sigevent sev = {
400                                 .sigev_notify = SIGEV_THREAD,
401                                 .sigev_notify_function = timeout,
402                         };
403                         timer_t timerid;
404                         return timer_create(CLOCK_MONOTONIC, &sev, &timerid);
405                 }
406                 "
407                 PIGLIT_HAS_POSIX_TIMER_NOTIFY_THREAD
408         )
409 endif()
411 set(CMAKE_REQUIRED_LIBRARIES)
413 if(PIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
414         add_definitions(-DPIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
415 endif()
417 if(PIGLIT_HAS_POSIX_TIMER_NOTIFY_THREAD)
418         add_definitions(-DPIGLIT_HAS_POSIX_TIMER_NOTIFY_THREAD)
419 endif()
421 if(GBM_FOUND)
422 FIND_LIBRARY(HAVE_LIBCACA NAMES caca)
423 if(HAVE_LIBCACA)
424         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} caca)
425         add_definitions(-DPIGLIT_HAS_LIBCACA)
426 endif(HAVE_LIBCACA)
427 endif(GBM_FOUND)
429 if(PIGLIT_USE_WAFFLE AND ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
430         pkg_check_modules(EGL egl>=11.0)
431 endif()
433 if(EGL_FOUND)
434         add_definitions(-DPIGLIT_HAS_EGL)
435         include_directories(${EGL_INCLUDE_DIRS})
436         add_definitions (${EGL_CFLAGS_OTHER})
437 endif()
439 if(PIGLIT_BUILD_GLES1_TESTS AND NOT EGL_FOUND)
440         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES1_TESTS requires EGL. "
441                             "Failed to find EGL library.")
442 endif()
444 if(PIGLIT_BUILD_GLES2_TESTS AND NOT EGL_FOUND)
445         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES2_TESTS requires EGL. "
446                             "Failed to find EGL library.")
447 endif()
449 if(PIGLIT_BUILD_GLES3_TESTS AND NOT EGL_FOUND)
450         message(FATAL_ERROR "Option PIGLIT_BUILD_GLES3_TESTS requires EGL. "
451                             "Failed to find EGL library.")
452 endif()
454 # Put all executables into the bin subdirectory
455 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${piglit_BINARY_DIR}/bin)
456 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${piglit_BINARY_DIR}/lib)
458 # Do the same for MSVC, regardless of the build type. This only works correctly
459 # for CMake 2.8.1 and above.
460 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${piglit_BINARY_DIR}/bin)
461 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${piglit_BINARY_DIR}/bin)
462 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${piglit_BINARY_DIR}/bin)
463 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${piglit_BINARY_DIR}/bin)
465 check_function_exists(asprintf  HAVE_ASPRINTF)
466 check_function_exists(ffs       HAVE_FFS)
467 check_function_exists(strchrnul HAVE_STRCHRNUL)
468 check_function_exists(strndup   HAVE_STRNDUP)
469 if(NOT MINGW)
470 check_function_exists(fopen_s   HAVE_FOPEN_S)
471 endif()
472 check_function_exists(setrlimit HAVE_SETRLIMIT)
474 check_include_file(sys/time.h  HAVE_SYS_TIME_H)
475 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
476 check_include_file(sys/resource.h  HAVE_SYS_RESOURCE_H)
477 check_include_file(sys/stat.h  HAVE_SYS_STAT_H)
478 check_include_file(unistd.h    HAVE_UNISTD_H)
479 check_include_file(fcntl.h     HAVE_FCNTL_H)
480 check_include_file(linux/sync_file.h HAVE_LINUX_SYNC_FILE_H)
482 if(DEFINED PIGLIT_INSTALL_VERSION)
483         set(PIGLIT_INSTALL_VERSION_SUFFIX
484             "-${PIGLIT_INSTALL_VERSION}")
485 else()
486         set(PIGLIT_INSTALL_VERSION_SUFFIX "")
487 endif()
488 set(PIGLIT_INSTALL_LIBDIR
489     "${CMAKE_INSTALL_LIBDIR}/piglit${PIGLIT_INSTALL_VERSION_SUFFIX}")
490 if(NOT IS_ABSOLUTE ${PIGLIT_INSTALL_LIBDIR})
491         set(PIGLIT_INSTALL_FULL_LIBDIR "${CMAKE_INSTALL_PREFIX}/${PIGLIT_INSTALL_LIBDIR}")
492 else()
493         set(PIGLIT_INSTALL_FULL_LIBDIR "${PIGLIT_INSTALL_LIBDIR}")
494 endif()
496 SET(CMAKE_INSTALL_RPATH "${PIGLIT_INSTALL_FULL_LIBDIR}/lib")
498 configure_file(
499         "${piglit_SOURCE_DIR}/tests/util/config.h.in"
500         "${piglit_BINARY_DIR}/tests/util/config.h"
503 include(cmake/piglit_util.cmake)
504 include(cmake/piglit_dispatch.cmake)
506 include_directories(src)
507 add_subdirectory(cmake/target_api)
508 add_subdirectory(generated_tests)
511 ##############################################################################
512 # Packaging
514 install (
515         FILES
516                 COPYING
517                 README
518                 RELEASE
519         DESTINATION share/doc/piglit${PIGLIT_INSTALL_VERSION_SUFFIX}
522 install (
523         DIRECTORY framework
524         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
525         FILES_MATCHING PATTERN "*.py"
528 install (
529         DIRECTORY templates
530         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
533 install (
534         DIRECTORY tests
535         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
536         FILES_MATCHING REGEX ".*\\.(py|program_test|shader_test|frag|vert|geom|tesc|tese|comp|ktx|cl|txt|inc)$"
537         REGEX "CMakeFiles|CMakeLists" EXCLUDE
540 install (
541         DIRECTORY ${CMAKE_BINARY_DIR}/generated_tests
542         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
543         FILES_MATCHING REGEX ".*\\.(shader_test|program_test|frag|vert|geom|tesc|tese|comp|cl|txt)$"
544         REGEX "CMakeFiles|CMakeLists" EXCLUDE
547 install (
548         DIRECTORY generated_tests
549         DESTINATION ${PIGLIT_INSTALL_LIBDIR}
550         FILES_MATCHING REGEX ".*\\.inc$"
551         REGEX "CMakeFiles|CMakeLists" EXCLUDE
554 if (BASH_COMPLETION_FOUND)
555         install(
556                 FILES completions/bash/piglit
557                 DESTINATION ${CMAKE_INSTALL_PREFIX}/${BASH_COMPLETION_COMPLETIONSDIR}/
558         )
559 endif (BASH_COMPLETION_FOUND)
561 if (WIN32)
562         set (PYTHON_SUFFIX ".py")
563 else ()
564         set (PYTHON_SUFFIX "")
565 endif ()
566 install (
567         PROGRAMS piglit RENAME piglit${PIGLIT_INSTALL_VERSION_SUFFIX}${PYTHON_SUFFIX}
568         DESTINATION ${CMAKE_INSTALL_BINDIR}
572 set (CPACK_PACKAGE_VERSION_MAJOR "1")
573 set (CPACK_PACKAGE_VERSION_MINOR "0")
575 # Use current date in YYYYMMDD format as patch number
576 execute_process (
577         COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
578         OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
581 # cpack mistakenly detects Mingw-w64 as win32
582 if (MINGW)
583         if (CMAKE_SIZEOF_VOID_P EQUAL 8)
584                 set (CPACK_SYSTEM_NAME win64)
585         endif ()
586 endif ()
588 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
589 if (WIN32)
590         set (CPACK_GENERATOR "ZIP")
591 else ()
592         set (CPACK_GENERATOR "TBZ2")
593 endif ()
595 include(CPack)