@@ -104,6 +104,8 @@ set(CMAKE_C_STANDARD 99)
104104set (CMAKE_C_STANDARD_REQUIRED ON )
105105set (CMAKE_C_EXTENSIONS OFF )
106106
107+ include (CheckCCompilerFlag )
108+
107109# Set compiler flags and options.
108110if (MSVC )
109111 message ("Not supported yet!" )
@@ -121,8 +123,27 @@ elseif(UNIX OR MINGW)
121123 set (OPT_DBG "-DNDEBUG" ) # disable assert
122124 endif ()
123125
124- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPT_DBG} -${OPT_LV} -fomit-frame-pointer" )
125- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-unused-function -Wno-pointer-sign -Wno-pointer-to-int-cast" )
126+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPT_DBG} -${OPT_LV} " )
127+ check_c_compiler_flag ("-fomit-frame-pointer" HAS_FLAG_OMIT_FRAME_POINTER )
128+ if (HAS_FLAG_OMIT_FRAME_POINTER)
129+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer" )
130+ endif ()
131+ check_c_compiler_flag ("-Wall" HAS_FLAG_WARNING_ALL )
132+ if (HAS_FLAG_WARNING_ALL)
133+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall" )
134+ endif ()
135+ check_c_compiler_flag ("-Wno-unused-function" HAS_FLAG_NO_UNUSED_FUNCTION )
136+ if (HAS_FLAG_NO_UNUSED_FUNCTION)
137+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function" )
138+ endif ()
139+ check_c_compiler_flag ("-Wno-pointer-sign" HAS_FLAG_NO_POINTER_SIGN )
140+ if (HAS_FLAG_NO_POINTER_SIGN)
141+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-pointer-sign" )
142+ endif ()
143+ check_c_compiler_flag ("-Wno-pointer-to-int-cast" HAS_FLAG_NO_POINTER_INT_CAST )
144+ if (HAS_FLAG_NO_POINTER_INT_CAST)
145+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-pointer-to-int-cast" )
146+ endif ()
126147 if (NOT WIN32 )
127148 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread" )
128149 endif ()
0 commit comments