From: Kefu Chai Date: Thu, 8 Dec 2016 01:45:18 +0000 (+0800) Subject: cmake: compile C code with c99 X-Git-Tag: v11.1.0~25^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F12369%2Fhead;p=ceph.git 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 --- 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