Skip to content

Commit

Permalink
Pass c99 to compiler in CMakeLists.txt
Browse files Browse the repository at this point in the history
Fixes #3631

Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
  • Loading branch information
okhowang committed Sep 25, 2020
1 parent 4b5aba8 commit e24e27a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}")

include(CheckCCompilerFlag)

if (NOT CMAKE_VERSION VERSION_LESS 3.1.0)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_EXTENSIONS OFF)
endif ()

if(CMAKE_COMPILER_IS_GNU)
# some warnings we want are not available with old GCC versions
# note: starting with CMake 2.8 we could use CMAKE_C_COMPILER_VERSION
Expand All @@ -175,6 +180,9 @@ if(CMAKE_COMPILER_IS_GNU)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-signedness")
endif()
endif()
if (NOT CMAKE_C_STANDARD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
endif ()
set(CMAKE_C_FLAGS_RELEASE "-O2")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
Expand All @@ -194,6 +202,9 @@ if(CMAKE_COMPILER_IS_CLANG)
set(CMAKE_C_FLAGS_MEMSAN "-fsanitize=memory -O3")
set(CMAKE_C_FLAGS_MEMSANDBG "-fsanitize=memory -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2")
set(CMAKE_C_FLAGS_CHECK "-Os")
if (NOT CMAKE_C_STANDARD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
endif ()
endif(CMAKE_COMPILER_IS_CLANG)

if(CMAKE_COMPILER_IS_IAR)
Expand Down
3 changes: 3 additions & 0 deletions ChangeLog.d/c99.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Changes
* Pass standard c99 to compiler in CMakeLists.txt

0 comments on commit e24e27a

Please sign in to comment.