[Piglit] [PATCH] cmake: Target C99.

Roland Scheidegger sroland at vmware.com
Thu Dec 10 07:21:38 PST 2015


Am 10.12.2015 um 12:05 schrieb Jose Fonseca:
> GCC 5.x and 4.x have different defaults, so it's better to explicitly
> specify the target C standard to keep builds consistent.
> ---
>  CMakeLists.txt                | 6 ++++++
>  tests/shaders/shader_runner.c | 4 +---
>  2 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index 4df0202..2da1e6f 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -224,6 +224,12 @@ if (NOT MSVC)
>  		SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
>  	ENDIF (CXX_COMPILER_FLAG_WALL)
>  
> +	# 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 ()
>  	# MSVC does not support C99 variable length arrays
>  	CHECK_C_COMPILER_FLAG("-Werror=vla" C_COMPILER_FLAG_WEVLA)
>  	IF (C_COMPILER_FLAG_WEVLA)
> diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c
> index 12a46de..966abe9 100644
> --- a/tests/shaders/shader_runner.c
> +++ b/tests/shaders/shader_runner.c
> @@ -973,8 +973,6 @@ leave_state(enum states state, const char *line)
>  void
>  process_shader(GLenum target, unsigned num_shaders, GLuint *shaders)
>  {
> -	unsigned i;
> -
>  	if (num_shaders == 0)
>  		return;
>  
> @@ -983,7 +981,7 @@ process_shader(GLenum target, unsigned num_shaders, GLuint *shaders)
>  		glProgramParameteri(prog, GL_PROGRAM_SEPARABLE, GL_TRUE);
>  	}
>  
> -	for (i = 0; i < num_shaders; i++) {
> +	for (unsigned i = 0; i < num_shaders; i++) {
>  		glAttachShader(prog, shaders[i]);
>  	}
>  
> 

This is fine by me. Albeit it seems a bit strange it just happened to
compile in c89 mode so far without this being an explicit requirement.
But I don't have anything against updating that (implicit?) policy to
c99 (minus whatever msvc still doesn't support...), albeit it's
certainly not me who should say what the requirements need to be.

Reviewed-by: Roland Scheidegger <sroland at vmware.com>

Roland



More information about the Piglit mailing list