cmake: check all available compiler features even if BUILD_STRICT_C90

This commit is contained in:
Hugues Delorme 2016-03-07 17:09:06 +01:00
parent 43a296656d
commit b6c9518e97

View File

@ -75,7 +75,7 @@ include(TestBigEndian)
test_big_endian(GMIO_HOST_IS_BIG_ENDIAN) test_big_endian(GMIO_HOST_IS_BIG_ENDIAN)
# Adapt C compiler flags to satisfy the GMIO_BUILD_STRICT_C90 option # Adapt C compiler flags to satisfy the GMIO_BUILD_STRICT_C90 option
# It must be done before checking of C99 and POSIX features # It must be done before checking non ANSI features(C99, POSIX, ...)
if(GMIO_BUILD_STRICT_C90) if(GMIO_BUILD_STRICT_C90)
if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE) if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ansi -pedantic-errors") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ansi -pedantic-errors")
@ -97,42 +97,42 @@ endif()
check_type_size("int" GMIO_SIZEOF_INT) check_type_size("int" GMIO_SIZEOF_INT)
check_type_size("long" GMIO_SIZEOF_LONG) check_type_size("long" GMIO_SIZEOF_LONG)
# Check non-ANSI available features # Check availability of a 64b integer type
if(NOT GMIO_BUILD_STRICT_C90) if(GMIO_HAVE_STDINT_H)
# Check availability of a 64b integer type
if(GMIO_HAVE_STDINT_H)
set(CMAKE_REQUIRED_INCLUDES stdint.h) set(CMAKE_REQUIRED_INCLUDES stdint.h)
endif() endif()
check_type_size("int64_t" GMIO_SIZEOF_INT64_T) check_type_size("int64_t" GMIO_SIZEOF_INT64_T)
if(NOT HAVE_GMIO_SIZEOF_INT64_T) if(NOT HAVE_GMIO_SIZEOF_INT64_T)
check_type_size("__int64" GMIO_SIZEOF_MSVC_INT64) check_type_size("__int64" GMIO_SIZEOF_MSVC_INT64)
if(NOT HAVE_GMIO_SIZEOF_MSVC_INT64) if(NOT HAVE_GMIO_SIZEOF_MSVC_INT64)
check_type_size("long long" GMIO_SIZEOF_LONG_LONG) check_type_size("long long" GMIO_SIZEOF_LONG_LONG)
endif() endif()
endif() endif()
set(CMAKE_REQUIRED_INCLUDES) set(CMAKE_REQUIRED_INCLUDES) # Pop changes
if(HAVE_GMIO_SIZEOF_INT64_T) if(HAVE_GMIO_SIZEOF_INT64_T)
set(GMIO_HAVE_INT64_T ${HAVE_GMIO_SIZEOF_INT64_T}) set(GMIO_HAVE_INT64_T ${HAVE_GMIO_SIZEOF_INT64_T})
elseif(HAVE_GMIO_SIZEOF_MSVC_INT64) elseif(HAVE_GMIO_SIZEOF_MSVC_INT64)
set(GMIO_HAVE_MSVC_INT64 ${HAVE_GMIO_SIZEOF_MSVC_INT64}) set(GMIO_HAVE_MSVC_INT64 ${HAVE_GMIO_SIZEOF_MSVC_INT64})
elseif(HAVE_GMIO_SIZEOF_LONG_LONG) elseif(HAVE_GMIO_SIZEOF_LONG_LONG)
set(GMIO_HAVE_LONG_LONG ${HAVE_GMIO_SIZEOF_LONG_LONG}) set(GMIO_HAVE_LONG_LONG ${HAVE_GMIO_SIZEOF_LONG_LONG})
endif() endif()
# Check C99 features # Check C99 features
if(NOT GMIO_BUILD_STRICT_C90)
check_function_exists(strtof GMIO_HAVE_STRTOF_FUNC) check_function_exists(strtof GMIO_HAVE_STRTOF_FUNC)
if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE) if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE)
list(APPEND CMAKE_REQUIRED_LIBRARIES m) # -lm list(APPEND CMAKE_REQUIRED_LIBRARIES m) # -lm
endif() endif()
check_function_exists(powf GMIO_HAVE_POWF_FUNC) check_function_exists(powf GMIO_HAVE_POWF_FUNC)
set(CMAKE_REQUIRED_LIBRARIES) set(CMAKE_REQUIRED_LIBRARIES) # Pop changes
check_include_files(stdbool.h GMIO_HAVE_STDBOOL_H) check_include_files(stdbool.h GMIO_HAVE_STDBOOL_H)
endif()
# Check POSIX features # Check POSIX features
if(UNIX) if(UNIX)
# See: # See:
# http://linux.die.net/man/2/fstat64 # http://linux.die.net/man/2/fstat64
# https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/fstat.2.html # https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/fstat.2.html
@ -145,50 +145,50 @@ if(NOT GMIO_BUILD_STRICT_C90)
list(APPEND CMAKE_REQUIRED_DEFINITIONS list(APPEND CMAKE_REQUIRED_DEFINITIONS
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE=1) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE=1)
endif() endif()
endif() endif()
set(GMIO_HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H}) set(GMIO_HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H})
if(NOT DEFINED HAVE_SYS_TYPES_H) if(NOT DEFINED HAVE_SYS_TYPES_H)
check_include_files(sys/types.h GMIO_HAVE_SYS_TYPES_H) check_include_files(sys/types.h GMIO_HAVE_SYS_TYPES_H)
endif() endif()
set(GMIO_HAVE_SYS_STAT_H ${HAVE_SYS_STAT_H}) set(GMIO_HAVE_SYS_STAT_H ${HAVE_SYS_STAT_H})
if (NOT DEFINED HAVE_SYS_STAT_H) if (NOT DEFINED HAVE_SYS_STAT_H)
check_include_files(sys/stat.h GMIO_HAVE_SYS_STAT_H) check_include_files(sys/stat.h GMIO_HAVE_SYS_STAT_H)
endif() endif()
check_function_exists(fileno GMIO_HAVE_POSIX_FILENO_FUNC) check_function_exists(fileno GMIO_HAVE_POSIX_FILENO_FUNC)
# Have fstat64() ? # Have fstat64() ?
check_c_source_compiles( check_c_source_compiles(
"#include <sys/stat.h> "#include <sys/stat.h>
int main() { fstat64(0, NULL); return 0; }" int main() { fstat64(0, NULL); return 0; }"
GMIO_HAVE_POSIX_FSTAT64_FUNC) GMIO_HAVE_POSIX_FSTAT64_FUNC)
if(WIN32) if(WIN32)
check_function_exists(_fstat64 GMIO_HAVE_WIN__FSTAT64_FUNC) check_function_exists(_fstat64 GMIO_HAVE_WIN__FSTAT64_FUNC)
endif() endif()
# Check size(in bytes) of stat::st_size # Check size(in bytes) of stat::st_size
set(CMAKE_EXTRA_INCLUDE_FILES sys/stat.h) set(CMAKE_EXTRA_INCLUDE_FILES sys/stat.h)
if(GMIO_HAVE_WIN__FSTAT64_FUNC) if(GMIO_HAVE_WIN__FSTAT64_FUNC)
check_type_size("((struct _stat64*)0)->st_size" GMIO_SIZEOF_STRUCT_STAT_ST_SIZE) check_type_size("((struct _stat64*)0)->st_size" GMIO_SIZEOF_STRUCT_STAT_ST_SIZE)
elseif(GMIO_HAVE_POSIX_FSTAT64_FUNC) elseif(GMIO_HAVE_POSIX_FSTAT64_FUNC)
check_type_size("((struct stat64*)0)->st_size" GMIO_SIZEOF_STRUCT_STAT_ST_SIZE) check_type_size("((struct stat64*)0)->st_size" GMIO_SIZEOF_STRUCT_STAT_ST_SIZE)
else() else()
check_type_size("((struct stat*)0)->st_size" GMIO_SIZEOF_STRUCT_STAT_ST_SIZE) check_type_size("((struct stat*)0)->st_size" GMIO_SIZEOF_STRUCT_STAT_ST_SIZE)
endif() endif()
set(CMAKE_EXTRA_INCLUDE_FILES) set(CMAKE_EXTRA_INCLUDE_FILES)
set(CMAKE_REQUIRED_DEFINITIONS) set(CMAKE_REQUIRED_DEFINITIONS)
# Verify large file support # Verify large file support ?
if(GMIO_HAVE_SYS_STAT_H if(GMIO_HAVE_SYS_STAT_H
AND NOT(GMIO_SIZEOF_STRUCT_STAT_ST_SIZE STREQUAL "0") # Not arch-dependent size AND NOT(GMIO_SIZEOF_STRUCT_STAT_ST_SIZE STREQUAL "0") # Not arch-dependent size
AND NOT(GMIO_SIZEOF_STRUCT_STAT_ST_SIZE EQUAL 8)) AND NOT(GMIO_SIZEOF_STRUCT_STAT_ST_SIZE EQUAL 8))
message(WARNING "<sys/stat.h> does not provide 64b variant of fstat(), you may encounter problems with files > 2GB") message(WARNING "<sys/stat.h> does not provide 64b variant of fstat(), you may encounter problems with files > 2GB")
endif() endif()
# Have builtin byte swap functions ? # Have compiler-intrisics bytes wap functions ?
if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE) if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE)
# __builtin_bswap16() is missing in x86 GCC version prior to v4.7 # __builtin_bswap16() is missing in x86 GCC version prior to v4.7
# See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624 # See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624
check_c_source_compiles( check_c_source_compiles(
@ -197,13 +197,12 @@ if(NOT GMIO_BUILD_STRICT_C90)
check_c_source_compiles( check_c_source_compiles(
"int main() { return (int)__builtin_bswap32(0x11223344); }" "int main() { return (int)__builtin_bswap32(0x11223344); }"
GMIO_HAVE_GCC_BUILTIN_BSWAP32_FUNC) GMIO_HAVE_GCC_BUILTIN_BSWAP32_FUNC)
elseif(MSVC) elseif(MSVC)
check_c_source_compiles( check_c_source_compiles(
"#include <stdlib.h> "#include <stdlib.h>
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() # !GMIO_BUILD_STRICT_C90
# Specific flags for GCC-like compilers # Specific flags for GCC-like compilers
if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE) if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE)
@ -283,5 +282,5 @@ endif()
# Examples: # Examples:
# cmake -DCMAKE_INSTALL_PREFIX=gcc-linux64 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_DEBUG_POSTFIX=_d # cmake -DCMAKE_INSTALL_PREFIX=gcc-linux64 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_DEBUG_POSTFIX=_d
# cmake -DCMAKE_INSTALL_PREFIX=gcc-linux64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_RELEASE_POSTFIX=_r # cmake -DCMAKE_INSTALL_PREFIX=gcc-linux64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_RELEASE_POSTFIX=
# make VERBOSE=1 or cmake -DCMAKE_VERBOSE_MAKEFILE=TRUE # make VERBOSE=1 or cmake -DCMAKE_VERBOSE_MAKEFILE=TRUE