CMakeLists.txt 18.6 KB
Newer Older
1
cmake_minimum_required(VERSION 2.8.5)
2

3 4
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")

5
INCLUDE (GNUInstallDirs)
Eric Anholt's avatar
Eric Anholt committed
6
INCLUDE (CheckCCompilerFlag)
7
INCLUDE (CheckCSourceCompiles)
8
INCLUDE (CheckCXXCompilerFlag)
9
INCLUDE (CheckFunctionExists)
10
INCLUDE (CheckIncludeFile)
11
INCLUDE (FindPkgConfig)
Nicolai Hähnle's avatar
Nicolai Hähnle committed
12

13 14 15 16 17
# http://www.cmake.org/cmake/help/v3.0/policy/CMP0042.html
if (POLICY CMP0042)
	cmake_policy (SET CMP0042 NEW)
endif()

Nicolai Hähnle's avatar
Nicolai Hähnle committed
18 19
project (piglit)

20 21 22
# Require MinGW
if (MSVC)
	message (FATAL_ERROR "Windows builds require MinGW")
23 24
endif ()

Chad Versace's avatar
Chad Versace committed
25
find_package(Threads)
26 27 28 29
find_package(PNG)
if(PNG_FOUND)
	add_definitions(-DPIGLIT_HAS_PNG)
endif(PNG_FOUND)
30
find_package(X11)
31 32 33 34
if(X11_FOUND)
	set(PIGLIT_HAS_X11 True)
	add_definitions(-DPIGLIT_HAS_X11)
endif()
Nicolai Hähnle's avatar
Nicolai Hähnle committed
35

36 37 38 39 40 41
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
	set(PIGLIT_BUILD_GLES_TESTS_DEFAULT ON)
else()
	set(PIGLIT_BUILD_GLES_TESTS_DEFAULT OFF)
endif()

42
option(PIGLIT_BUILD_GL_TESTS "Build tests for OpenGL" ON)
43 44 45
option(PIGLIT_BUILD_GLES1_TESTS "Build tests for OpenGL ES1" ${PIGLIT_BUILD_GLES_TESTS_DEFAULT})
option(PIGLIT_BUILD_GLES2_TESTS "Build tests for OpenGL ES2" ${PIGLIT_BUILD_GLES_TESTS_DEFAULT})
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)
47

48 49 50 51
if(PIGLIT_BUILD_GL_TESTS)
	find_package(OpenGL REQUIRED)
endif()

52 53 54 55 56 57
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
	option(PIGLIT_USE_WAFFLE "Use Waffle in place of GLUT" ON)
else()
	option(PIGLIT_USE_WAFFLE "Use Waffle in place of GLUT" OFF)
endif()

58
if(PIGLIT_USE_WAFFLE)
59
	if (NOT WIN32)
60
		pkg_check_modules(Waffle REQUIRED waffle-1)
61

62
		if(NOT Waffle_FOUND)
63
			message(FATAL_ERROR "Failed to find Waffle. If Waffle "
64 65 66 67
			"is not packaged for your distribution, you can get "
			"it at http://www.waffle-gl.org."
		)
		endif()
68

69 70 71 72 73 74 75 76
		# Check the installed waffle version.
		#
		# We cannot reliably check the version with pkg_check_modules(), but
		# instead must check the version manually as below. The problem is that,
		# if one passes a required version to pkg_check_modules(), CMake
		# validates the required version at most once for the lifetime of the
		# source tree.  If someone changes the required version by editing the
		# CMakeLists, CMake fails to detect the new requirement.
77 78 79 80
		set(Waffle_REQUIRED_VERSION "1.5.0")
		if(Waffle_VERSION VERSION_LESS Waffle_REQUIRED_VERSION)
			message(FATAL_ERROR "Found waffle-${Waffle_VERSION}, but "
			"piglit requires waffle-${Waffle_REQUIRED_VERSION}")
81
		endif()
82
	else ()
83
		find_path(Waffle_INCLUDE_DIRS waffle.h)
84 85
		find_library(Waffle_LDFLAGS waffle-1)
		if(Waffle_INCLUDE_DIRS AND Waffle_LDFLAGS)
86
			set(Waffle_FOUND TRUE)
87 88
		else()
			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 ()
94

95
	add_definitions(-DPIGLIT_USE_WAFFLE)
96
	add_definitions(-DWAFFLE_API_VERSION=0x0103)
97 98 99 100
else()
	find_package(GLUT REQUIRED)

	# The 'REQUIRED' above correctly produces an error for
101
	# OpenGL, but there's a bug involving FindGLUT.cmake
102 103 104 105 106 107 108 109 110 111 112
	# that fails to produce the error as of CMake 2.8.5.
	#
	# Instead, CMake keeps going and eventually spams
	# the console with a message for every target that used
	# e.g. the ${GLUT_INCLUDE_DIR} variable. So it
	# prints a line for basically every single test in piglit.
	#
	# Work around the bug and error out quickly here instead.
	if (NOT GLUT_FOUND)
		message(FATAL_ERROR "GLUT library not found")
	endif()
113
endif(PIGLIT_USE_WAFFLE)
114

115 116 117
if(PIGLIT_BUILD_GLES1_TESTS AND NOT PIGLIT_USE_WAFFLE)
	message(FATAL_ERROR "Option PIGLIT_BUILD_GLES1_TESTS requires PIGLIT_USE_WAFFLE")
endif(PIGLIT_BUILD_GLES1_TESTS AND NOT PIGLIT_USE_WAFFLE)
118

119 120 121
if(PIGLIT_BUILD_GLES2_TESTS AND NOT PIGLIT_USE_WAFFLE)
	message(FATAL_ERROR "Option PIGLIT_BUILD_GLES2_TESTS requires PIGLIT_USE_WAFFLE")
endif(PIGLIT_BUILD_GLES2_TESTS AND NOT PIGLIT_USE_WAFFLE)
122

123 124 125 126
if(PIGLIT_BUILD_GLES3_TESTS AND NOT PIGLIT_USE_WAFFLE)
	message(FATAL_ERROR "Option PIGLIT_BUILD_GLES3_TESTS requires PIGLIT_USE_WAFFLE")
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)
130

131
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
132 133 134 135 136 137 138 139
	if(X11_FOUND AND OPENGL_gl_LIBRARY)
		# Assume the system has GLX. In the future, systems may exist
		# with libGL and libX11 but no GLX, but that world hasn't
		# arrived yet.
		set(PIGLIT_HAS_GLX True)
		add_definitions(-DPIGLIT_HAS_GLX)
	endif()

140
	pkg_check_modules(GBM QUIET gbm>=17.1)
141 142 143
	if(GBM_FOUND)
		set(PIGLIT_HAS_GBM True)
		add_definitions(-DPIGLIT_HAS_GBM)
144
		set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${GBM_LIBRARIES})
145 146 147
		CHECK_FUNCTION_EXISTS(gbm_bo_map PIGLIT_HAS_GBM_BO_MAP)
		if (PIGLIT_HAS_GBM_BO_MAP)
			add_definitions(-DPIGLIT_HAS_GBM_BO_MAP)
148
		endif()
149
	endif(GBM_FOUND)
150

151
	pkg_check_modules(WAYLAND QUIET wayland-client wayland-egl)
152 153
	if (WAYLAND_FOUND)
		set(PIGLIT_HAS_WAYLAND True)
154
		add_definitions(-DPIGLIT_HAS_WAYLAND)
155 156 157 158 159 160 161

		FIND_LIBRARY(HAVE_XKBCOMMON NAMES xkbcommon)
		if(NOT HAVE_XKBCOMMON)
			message(FATAL_ERROR "Wayland support requires xkbcommon. "
				"Failed to find xkbcommon library.")
		endif()
		pkg_check_modules(XKBCOMMON QUIET xkbcommon)
162 163
	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 170 171 172 173
ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
	if (PIGLIT_USE_WAFFLE)
		set(PIGLIT_HAS_WGL True)
		add_definitions(-DPIGLIT_HAS_WGL)
	endif()
174
ENDIF()
175

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()
181

182 183 184 185 186 187 188
IF(PIGLIT_HAS_WGL)
	option(PIGLIT_BUILD_WGL_TESTS "Build tests that require WGL" ON)
ELSE()
	option(PIGLIT_BUILD_WGL_TESTS "Build tests that require WGL" OFF)
ENDIF()


189 190
# Choose to build tests that use dma_buf.
#
191 192
# Piglit's dma_buf utilities require xcb-dri2 to gain DRM authentication.
#
193 194 195
# The presence of libdrm is not sufficient. At least one libdrm_${hardware}
# library is also needed.
#
196 197 198 199
# When building for Intel, libdrm_intel>=2.4.38 is required because support for
# drm-prime arrived in that version.
#
if(LIBDRM_FOUND AND XCB_DRI2_FOUND AND
200 201
   ((LIBDRM_INTEL_VERSION VERSION_GREATER "2.4.37") OR
     PIGLIT_HAS_GBM_BO_MAP))
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
	set(PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID true)
else()
	set(PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID false)
endif()

if(PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID)
	option(PIGLIT_BUILD_DMA_BUF_TESTS "Build tests that use dma_buf" ON)
else()
	option(PIGLIT_BUILD_DMA_BUF_TESTS "Build tests that use dma_buf" OFF)
endif()

# If the users has updated PIGLIT_BUILD_DMA_BUF_TESTS in the CMakeCache, then
# we need to validate it.
if(PIGLIT_BUILD_DMA_BUF_TESTS AND NOT PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID)
	message(FATAL_ERROR
217 218
		"PIGLIT_BUILD_DMA_BUF_TESTS require libdrm, "
		"libdrm_intel>=2.4.38, and xcb-dri2")
219 220
endif()

221
IF(PIGLIT_BUILD_GLX_TESTS)
222 223 224
	pkg_check_modules(GLPROTO REQUIRED glproto)
ENDIF()

225
set(Python_ADDITIONAL_VERSIONS
Dylan Baker's avatar
Dylan Baker committed
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)
230 231 232 233 234 235 236 237 238

# CMake doesn't have a VERSION_GREATER_EQUAL function, at least as of 3.0,
# And mako 1.0.2 contains bug fixes required for python 3.5 to work, so
# the only solution (short of having a series of "OR" statements, is this)
if (PYTHON_VERSION_STRING VERSION_GREATER 3.4.999999)
	find_package(PythonMako 1.0.2 REQUIRED)
else ()
	find_package(PythonMako 0.8.0 REQUIRED)
endif (PYTHON_VERSION_STRING VERSION_GREATER 3.4.999999)
239

240
find_package(bash-completion NO_MODULE)
241

242 243 244 245 246 247
# Default to compiling with debug information (`gcc -g`):
if(NOT CMAKE_BUILD_TYPE)
	SET(CMAKE_BUILD_TYPE Debug CACHE STRING
	"May be one of: None Debug RelWithDebInfo Release MinSizeRel" FORCE)
endif(NOT CMAKE_BUILD_TYPE)

Jose Fonseca's avatar
Jose Fonseca committed
248 249 250 251 252
if (NOT MSVC)
	CHECK_C_COMPILER_FLAG("-Wall" C_COMPILER_FLAG_WALL)
	IF (C_COMPILER_FLAG_WALL)
		SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
	ENDIF (C_COMPILER_FLAG_WALL)
253 254 255 256
	CHECK_CXX_COMPILER_FLAG("-Wall" CXX_COMPILER_FLAG_WALL)
	IF (CXX_COMPILER_FLAG_WALL)
		SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
	ENDIF (CXX_COMPILER_FLAG_WALL)
257

Jose Fonseca's avatar
Jose Fonseca committed
258 259 260 261 262 263
	# Target C99.  GCC's default is gnu11 for 5.0 and newer, gnu89 for
	# older versions.
	check_c_compiler_flag ("-std=gnu99" C_COMPILER_FLAG_STD_GNU99)
	if (C_COMPILER_FLAG_STD_GNU99)
		set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
	endif ()
264
	# MSVC does not support C99 variable length arrays
265 266 267
	CHECK_C_COMPILER_FLAG("-Werror=vla" C_COMPILER_FLAG_WEVLA)
	IF (C_COMPILER_FLAG_WEVLA)
		SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=vla")
268
	ENDIF ()
269 270 271 272 273 274
	# GCC allows void pointer arithmetic, but it is not part of ISO C and
	# in particular MSVC will throw `C2036: 'void *' : unknown size`
	check_c_compiler_flag ("-Werror=pointer-arith" C_COMPILER_FLAG_WEPOINTER_ARITH)
	if (C_COMPILER_FLAG_WEPOINTER_ARITH)
		set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=pointer-arith")
	endif ()
275 276 277 278 279 280 281 282 283 284 285
	# MSVC only supports C99 variadic macros.  It doesn't support the
	# non-standard GNU named variadic macro syntax that's documented in
	# https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html
	#
	# XXX: on older GCC version this option has no effect unless -Wpedantic
	# is set, but this should be fixed on future GCC versions, per
	# https://gcc.gnu.org/ml/gcc-patches/2014-04/msg01459.html
	check_c_compiler_flag ("-Werror=variadic-macros" C_COMPILER_FLAG_WVARIADIC_MACROS)
	if (C_COMPILER_FLAG_WVARIADIC_MACROS)
		set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=variadic-macros")
	endif ()
286 287 288 289 290

	CHECK_CXX_COMPILER_FLAG("-Wno-narrowing" CXX_COMPILER_FLAG_WNO_NARROWING)
	IF (CXX_COMPILER_FLAG_WNO_NARROWING)
		SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
	ENDIF (CXX_COMPILER_FLAG_WNO_NARROWING)
291
else ()
292 293 294 295 296 297
	# Adjust warnings
	add_definitions (-W3)
	add_definitions (-wd4018) # signed/unsigned mismatch
	add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
	add_definitions (-wd4305) # truncation from 'type1' to 'type2'
	add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
298 299 300 301

	add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
	add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
endif ()
Eric Anholt's avatar
Eric Anholt committed
302

303
if (MINGW)
304 305 306
	# Match MSVC default stack size
	set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,1048576")

307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
	# Avoid depending on MinGW runtime DLLs
	check_cxx_compiler_flag (-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
	if (HAVE_STATIC_LIBGCC_FLAG)
		set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
		set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
		set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libgcc")
	endif ()
	check_cxx_compiler_flag (-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG)
	if (HAVE_STATIC_LIBSTDCXX_FLAG)
		set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
		set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
		set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++")
	endif ()
endif ()

322 323 324 325 326 327 328 329
if (${CMAKE_C_COMPILER_ID} STREQUAL "SunPro")
	# Use C++ to link C files.
	# http://developers.sun.com/solaris/articles/mixing.html#linking
	# Modified rule from Modules/CMakeCInformation.cmake.
	set (CMAKE_C_LINK_EXECUTABLE
		"<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
endif()

330 331 332 333
# Always enable GNU C extensions.  Non-GNU platforms will need to
# define wrappers for them.
add_definitions(-D_GNU_SOURCE)

334 335 336
if (WIN32)
	# MSVC & MinGW only define & use APIENTRY
	add_definitions (-DGLAPIENTRY=__stdcall)
337

338 339
	# Avoid namespace pollution when including windows.h
	# http://support.microsoft.com/kb/166474
340 341
	add_definitions (-DWIN32_LEAN_AND_MEAN=1)

342 343
	# Don't define min/max macros
	add_definitions (-DNOMINMAX)
344 345 346

	# Define M_PI and others
	add_definitions (-D_USE_MATH_DEFINES)
347 348
endif (WIN32)

349
if (APPLE)
350
	# Don't warn about using deprecated OpenGL/GLUT functions.
351 352 353 354 355 356
	# TODO: It would be nice to silence just the deprecation macros from
	# OpenGLAvailability.h as opposed to all deprecated functions.
	set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
	set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
endif ()

357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
if (OPENGL_FOUND)
	if (APPLE)
		find_path(GLEXT_INCLUDE_DIR
			NAMES OpenGL/glext.h
			PATHS ${OPENGL_INCLUDE_DIR}
			DOC "Include for OpenGL/glext.h on OSX"
		)
	else (APPLE)
		find_path(GLEXT_INCLUDE_DIR
			NAMES GL/glext.h
			PATHS ${OPENGL_INCLUDE_DIR}
			DOC "Include for GL/glext.h"
		)
	endif (APPLE)
endif()
372

373 374 375 376 377
if(CMAKE_USE_PTHREADS_INIT)
	set(PIGLIT_HAS_PTHREADS true)
	add_definitions(-DPIGLIT_HAS_PTHREADS)
endif()

378 379
FIND_LIBRARY(HAVE_LIBRT NAMES rt)
if(HAVE_LIBRT)
380
	set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt)
381
endif()
382

383 384 385 386 387 388 389 390
check_c_source_compiles(
	"
	#define _POSIX_C_SOURCE 199309L
	#include <time.h>
	int main() { return clock_gettime(CLOCK_MONOTONIC, NULL); }
	"
	PIGLIT_HAS_POSIX_CLOCK_MONOTONIC
)
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410

if(PIGLIT_HAS_PTHREADS AND PIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
	check_c_source_compiles(
		"
		#include <signal.h>
		#include <time.h>
		static void timeout(union sigval val) { }
		int main() {
			struct sigevent sev = {
				.sigev_notify = SIGEV_THREAD,
				.sigev_notify_function = timeout,
			};
			timer_t timerid;
			return timer_create(CLOCK_MONOTONIC, &sev, &timerid);
		}
		"
		PIGLIT_HAS_POSIX_TIMER_NOTIFY_THREAD
	)
endif()

411 412 413
set(CMAKE_REQUIRED_LIBRARIES)

if(PIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
414
	add_definitions(-DPIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
415 416
endif()

417 418
if(PIGLIT_HAS_POSIX_TIMER_NOTIFY_THREAD)
	add_definitions(-DPIGLIT_HAS_POSIX_TIMER_NOTIFY_THREAD)
Chad Versace's avatar
Chad Versace committed
419 420
endif()

421 422 423 424 425 426 427 428
if(GBM_FOUND)
FIND_LIBRARY(HAVE_LIBCACA NAMES caca)
if(HAVE_LIBCACA)
	set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} caca)
	add_definitions(-DPIGLIT_HAS_LIBCACA)
endif(HAVE_LIBCACA)
endif(GBM_FOUND)

429
if(PIGLIT_USE_WAFFLE AND ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
Vinson Lee's avatar
Vinson Lee committed
430
	pkg_check_modules(EGL egl>=11.0)
431
endif()
432

433 434 435
if(EGL_FOUND)
	add_definitions(-DPIGLIT_HAS_EGL)
	include_directories(${EGL_INCLUDE_DIRS})
436
	add_definitions (${EGL_CFLAGS_OTHER})
437 438
endif()

439
if(PIGLIT_BUILD_GLES1_TESTS AND NOT EGL_FOUND)
440 441 442 443
	message(FATAL_ERROR "Option PIGLIT_BUILD_GLES1_TESTS requires EGL. "
			    "Failed to find EGL library.")
endif()

444
if(PIGLIT_BUILD_GLES2_TESTS AND NOT EGL_FOUND)
445 446 447 448
	message(FATAL_ERROR "Option PIGLIT_BUILD_GLES2_TESTS requires EGL. "
			    "Failed to find EGL library.")
endif()

449
if(PIGLIT_BUILD_GLES3_TESTS AND NOT EGL_FOUND)
450 451 452 453
	message(FATAL_ERROR "Option PIGLIT_BUILD_GLES3_TESTS requires EGL. "
			    "Failed to find EGL library.")
endif()

454 455 456 457 458 459 460 461 462 463
# Put all executables into the bin subdirectory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${piglit_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${piglit_BINARY_DIR}/lib)

# Do the same for MSVC, regardless of the build type. This only works correctly
# for CMake 2.8.1 and above.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${piglit_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${piglit_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${piglit_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${piglit_BINARY_DIR}/bin)
464

Vinson Lee's avatar
Vinson Lee committed
465
check_function_exists(asprintf  HAVE_ASPRINTF)
Vinson Lee's avatar
Vinson Lee committed
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)
473

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 478 479
check_include_file(sys/stat.h  HAVE_SYS_STAT_H)
check_include_file(unistd.h    HAVE_UNISTD_H)
check_include_file(fcntl.h     HAVE_FCNTL_H)
480
check_include_file(linux/sync_file.h HAVE_LINUX_SYNC_FILE_H)
481

482 483 484 485 486 487
if(DEFINED PIGLIT_INSTALL_VERSION)
	set(PIGLIT_INSTALL_VERSION_SUFFIX
	    "-${PIGLIT_INSTALL_VERSION}")
else()
	set(PIGLIT_INSTALL_VERSION_SUFFIX "")
endif()
488
set(PIGLIT_INSTALL_LIBDIR
489
    "${CMAKE_INSTALL_LIBDIR}/piglit${PIGLIT_INSTALL_VERSION_SUFFIX}")
490 491 492 493 494 495 496 497
if(NOT IS_ABSOLUTE ${PIGLIT_INSTALL_LIBDIR})
	set(PIGLIT_INSTALL_FULL_LIBDIR "${CMAKE_INSTALL_PREFIX}/${PIGLIT_INSTALL_LIBDIR}")
else()
	set(PIGLIT_INSTALL_FULL_LIBDIR "${PIGLIT_INSTALL_LIBDIR}")
endif()

SET(CMAKE_INSTALL_RPATH "${PIGLIT_INSTALL_FULL_LIBDIR}/lib")

498 499
configure_file(
	"${piglit_SOURCE_DIR}/tests/util/config.h.in"
500
	"${piglit_BINARY_DIR}/tests/util/config.h"
501
)
502

503
include(cmake/piglit_util.cmake)
504 505
include(cmake/piglit_dispatch.cmake)

506
include_directories(src)
507
add_subdirectory(cmake/target_api)
508
add_subdirectory(generated_tests)
509 510 511 512 513 514 515 516 517 518


##############################################################################
# Packaging

install (
	FILES
		COPYING
		README
		RELEASE
519
	DESTINATION share/doc/piglit${PIGLIT_INSTALL_VERSION_SUFFIX}
520 521 522 523
)

install (
	DIRECTORY framework
524
	DESTINATION ${PIGLIT_INSTALL_LIBDIR}
525 526 527
	FILES_MATCHING PATTERN "*.py"
)

528
install (
529
	DIRECTORY templates
530
	DESTINATION ${PIGLIT_INSTALL_LIBDIR}
531 532
)

533 534
install (
	DIRECTORY tests
535
	DESTINATION ${PIGLIT_INSTALL_LIBDIR}
536
	FILES_MATCHING REGEX ".*\\.(xml|xml.gz|py|program_test|shader_test|frag|vert|geom|tesc|tese|comp|ktx|cl|txt|inc)$"
537 538 539 540 541 542
	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
)

install (
	DIRECTORY ${CMAKE_BINARY_DIR}/tests
	DESTINATION ${PIGLIT_INSTALL_LIBDIR}
543
	FILES_MATCHING REGEX ".*\\.xml.gz"
544 545 546
)

install (
547
	DIRECTORY ${CMAKE_BINARY_DIR}/generated_tests
548
	DESTINATION ${PIGLIT_INSTALL_LIBDIR}
549
	FILES_MATCHING REGEX ".*\\.(shader_test|program_test|frag|vert|geom|tesc|tese|comp|cl|txt)$"
550
	REGEX "CMakeFiles|CMakeLists" EXCLUDE
551 552
)

553 554 555 556 557 558 559
install (
	DIRECTORY generated_tests
	DESTINATION ${PIGLIT_INSTALL_LIBDIR}
	FILES_MATCHING REGEX ".*\\.inc$"
	REGEX "CMakeFiles|CMakeLists" EXCLUDE
)

560 561 562 563 564 565 566
if (BASH_COMPLETION_FOUND)
	install(
		FILES completions/bash/piglit
		DESTINATION ${CMAKE_INSTALL_PREFIX}/${BASH_COMPLETION_COMPLETIONSDIR}/
	)
endif (BASH_COMPLETION_FOUND)

567 568 569 570 571
if (WIN32)
	set (PYTHON_SUFFIX ".py")
else ()
	set (PYTHON_SUFFIX "")
endif ()
572
install (
573
	PROGRAMS piglit RENAME piglit${PIGLIT_INSTALL_VERSION_SUFFIX}${PYTHON_SUFFIX}
574 575 576
	DESTINATION ${CMAKE_INSTALL_BINDIR}
)

577 578 579 580 581 582

set (CPACK_PACKAGE_VERSION_MAJOR "1")
set (CPACK_PACKAGE_VERSION_MINOR "0")

# Use current date in YYYYMMDD format as patch number
execute_process (
583
	COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
	OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
)

# cpack mistakenly detects Mingw-w64 as win32
if (MINGW)
	if (CMAKE_SIZEOF_VOID_P EQUAL 8)
		set (CPACK_SYSTEM_NAME win64)
	endif ()
endif ()

# See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
if (WIN32)
	set (CPACK_GENERATOR "ZIP")
else ()
	set (CPACK_GENERATOR "TBZ2")
endif ()

include(CPack)