Only add warning and std flags if supported by compiler (cmake) #144

Merged
plicease merged 1 commits from solaris into master 2017-09-24 17:52:49 +00:00
1 changed files with 21 additions and 1 deletions

View File

@ -61,7 +61,27 @@ IF (WIN32)
# Ignore warning C4996: 'strncpy' # Ignore warning C4996: 'strncpy'
ADD_DEFINITIONS("-D_CRT_SECURE_NO_WARNINGS=1") ADD_DEFINITIONS("-D_CRT_SECURE_NO_WARNINGS=1")
ELSE() ELSE()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat=2 -std=gnu99 -O2 -g") INCLUDE(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG("-Wall" COMPILER_HAS_WALL)
IF (COMPILER_HAS_WALL)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
ENDIF()
CHECK_C_COMPILER_FLAG("-Wextra" COMPILER_HAS_WEXTRA)
IF (COMPILER_HAS_WEXTRA)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra")
ENDIF()
CHECK_C_COMPILER_FLAG("-Wformat=2" COMPILER_HAS_WFORMAT)
IF (COMPILER_HAS_WFORMAT)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat=2")
ENDIF()
CHECK_C_COMPILER_FLAG("-std=gnu99" COMPILER_HAS_STD_GNU99)
CHECK_C_COMPILER_FLAG("-std=c99" COMPILER_HAS_STD_C99)
IF (COMPILER_HAS_STD_GNU99)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
ELSEIF (COMPILER_HAS_STD_C99)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
ENDIF()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g")
ENDIF() ENDIF()
INCLUDE_DIRECTORIES(${pkgconf_SOURCE_DIR} ${pkgconf_BINARY_DIR}) INCLUDE_DIRECTORIES(${pkgconf_SOURCE_DIR} ${pkgconf_BINARY_DIR})