Merge pull request #12369 from tchaikov/wip-c99

cmake: compile C code with c99

Reviewed-by: Willem Jan Withagen <wjw@digiware.nl>
Reviewed-by: Casey Bodley <cbodley@redhat.com>
This commit is contained in:
Kefu Chai 2016-12-09 01:16:20 +08:00 committed by GitHub
commit fe814e78b9
2 changed files with 16 additions and 7 deletions

View File

@ -123,18 +123,29 @@ endif(no_yasm)
if(CMAKE_VERSION VERSION_LESS "3.1")
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
if(NOT COMPILER_SUPPORTS_CXX11)
message(FATAL_ERROR
"The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
include(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG("-std=gnu99" COMPILER_SUPPORTS_GNU99)
if(NOT COMPILER_SUPPORTS_GNU99)
message(FATAL_ERROR
"The compiler ${CMAKE_C_COMPILER} has no GNU C99 support.")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
else()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 99)
# we use `asm()` to inline assembly, so enable the GNU extension
set(CMAKE_C_EXTENSIONS ON)
set(C_STANDARD_REQUIRED ON)
endif()
## Handle diagnostics color if compiler supports them.
CHECK_C_COMPILER_FLAG("-fdiagnostics-color=always"
COMPILER_SUPPORTS_DIAGNOSTICS_COLOR)

View File

@ -12,8 +12,6 @@
*
*/
#define _XOPEN_SOURCE 500
#include <stdio.h>
#include <string.h>
#include <unistd.h>