]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: compile C code with c99 12369/head
authorKefu Chai <kchai@redhat.com>
Thu, 8 Dec 2016 01:45:18 +0000 (09:45 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 8 Dec 2016 02:13:49 +0000 (10:13 +0800)
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 <kchai@redhat.com>
src/CMakeLists.txt
src/common/safe_io.c

index c90e2ed7952c5a2f9e555557c97e0a792f46f5f5..670eeb83be024aaee5e1b3f5a50120304b0a68f2 100644 (file)
@@ -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)
 
index a4a31aaba9ad108d996eb8c5819aa24c5c2c7e25..e727542fb416b191a2413f2e618b0329d62da5b3 100644 (file)
@@ -12,8 +12,6 @@
  *
  */
 
-#define _XOPEN_SOURCE 500
-
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>