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