cmake: group non-ANSI checks within "if(NOT BUILD_STRICT_C90)"

This commit is contained in:
Hugues Delorme 2015-04-02 09:38:08 +02:00
parent 6d962f7035
commit 35359a2580

View File

@ -43,7 +43,7 @@ test_big_endian(GMIO_HOST_IS_BIG_ENDIAN)
# It must be done before checking of C99 and POSIX features # It must be done before checking of C99 and POSIX features
if(BUILD_STRICT_C90) if(BUILD_STRICT_C90)
if(CMAKE_COMPILER_IS_GNUCC) if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ansi") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ansi -pedantic-errors")
elseif(MSVC) elseif(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Za") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Za")
endif() endif()
@ -54,6 +54,14 @@ set(CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS}")
# Some compilers (like GCC v4.9) don't disable <stdint.h> in STRICT_ANSI mode # Some compilers (like GCC v4.9) don't disable <stdint.h> in STRICT_ANSI mode
check_include_files(stdint.h GMIO_HAVE_STDINT_H) check_include_files(stdint.h GMIO_HAVE_STDINT_H)
# Check non-ANSI available features
if(NOT BUILD_STRICT_C90)
# Check C99 features
check_function_exists(strtof GMIO_HAVE_STRTOF_FUNC)
check_function_exists(powf GMIO_HAVE_POWF_FUNC)
check_include_files(stdbool.h GMIO_HAVE_STDBOOL_H)
# Check POSIX features
check_include_files(sys/types.h GMIO_HAVE_SYS_TYPES_H) check_include_files(sys/types.h GMIO_HAVE_SYS_TYPES_H)
check_include_files(sys/stat.h GMIO_HAVE_SYS_STAT_H) check_include_files(sys/stat.h GMIO_HAVE_SYS_STAT_H)
check_function_exists(fileno GMIO_HAVE_POSIX_FILENO_FUNC) check_function_exists(fileno GMIO_HAVE_POSIX_FILENO_FUNC)
@ -62,25 +70,18 @@ if(WIN32)
check_function_exists(_fstat64 GMIO_HAVE_WIN__FSTAT64_FUNC) check_function_exists(_fstat64 GMIO_HAVE_WIN__FSTAT64_FUNC)
endif() endif()
# Check available C99 and compiler/OS specific features
if(NOT BUILD_STRICT_C90)
check_function_exists(strtof GMIO_HAVE_STRTOF_FUNC)
check_function_exists(powf GMIO_HAVE_POWF_FUNC)
check_include_files(stdbool.h GMIO_HAVE_STDBOOL_H)
# Have BSD-like alloca() function ? # Have BSD-like alloca() function ?
check_c_source_compiles( check_c_source_compiles(
"#include <alloca.h> "#include <alloca.h>
int main() { void* ptr = alloca(256); return 0; }" int main() { void* ptr = alloca(256); return 0; }"
GMIO_HAVE_BSD_ALLOCA_FUNC) GMIO_HAVE_BSD_ALLOCA_FUNC)
if(WIN32)
# Have Win32 _alloca() function ? # Have Win32 _alloca() function ?
if(WIN32)
check_c_source_compiles( check_c_source_compiles(
"#include <malloc.h> "#include <malloc.h>
int main() { void* ptr = _alloca(256); return 0; }" int main() { void* ptr = _alloca(256); return 0; }"
GMIO_HAVE_WIN__ALLOCA_FUNC) GMIO_HAVE_WIN__ALLOCA_FUNC)
endif() # WIN32
endif() endif()
# Have builtin byte swap functions ? # Have builtin byte swap functions ?
@ -99,13 +100,14 @@ elseif(MSVC)
int main() { return (int)_byteswap_ulong(0x11223344); }" int main() { return (int)_byteswap_ulong(0x11223344); }"
GMIO_HAVE_MSVC_BUILTIN_BSWAP_FUNC) GMIO_HAVE_MSVC_BUILTIN_BSWAP_FUNC)
endif() endif()
endif() # !BUILD_STRICT_C90
configure_file(src/gmio_core/config.h.cmake config.h @ONLY) configure_file(src/gmio_core/config.h.cmake config.h @ONLY)
include_directories(${CMAKE_BINARY_DIR}) # For generated "config.h" include_directories(${CMAKE_BINARY_DIR}) # For generated "config.h"
# Specific flags for GCC # Specific flags for GCC
if(CMAKE_COMPILER_IS_GNUCC) if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic-errors -fstrict-aliasing") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstrict-aliasing")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Winline -Wextra -Wstrict-aliasing -Wcast-align -Wlogical-op -Wfloat-equal") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Winline -Wextra -Wstrict-aliasing -Wcast-align -Wlogical-op -Wfloat-equal")
# Force PIC for GCC, see : https://www.gentoo.org/proj/en/base/amd64/howtos/index.xml?part=1&chap=3 # Force PIC for GCC, see : https://www.gentoo.org/proj/en/base/amd64/howtos/index.xml?part=1&chap=3