From a488c5d8ea578e2a53f73c8aa094e0c35d38930c Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 8 Dec 2016 09:45:18 +0800 Subject: [PATCH] cmake: compile C code with c99 so the functions like snprintf() available in C99 are available without defining _XOPEN_SOURCE. and "asm()" is used to inline assembly, so use the GNU's extension instead of C99 standard. Signed-off-by: Kefu Chai --- src/CMakeLists.txt | 12 +++++++++++- src/common/safe_io.c | 2 -- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c90e2ed7952..670eeb83be0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -128,14 +128,24 @@ if(CMAKE_VERSION VERSION_LESS "3.1") "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) diff --git a/src/common/safe_io.c b/src/common/safe_io.c index a4a31aaba9a..e727542fb41 100644 --- a/src/common/safe_io.c +++ b/src/common/safe_io.c @@ -12,8 +12,6 @@ * */ -#define _XOPEN_SOURCE 500 - #include #include #include -- 2.47.3