CMake: make detection of <stdint.h>, <stdbool.h> and strtof() dependent of BUILD_STRICT_C90
This commit is contained in:
parent
3775dca27c
commit
e4dd893ea2
@ -9,37 +9,37 @@ project(gmio C)
|
||||
#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
|
||||
# Options
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries (DLL)" ON)
|
||||
option(BUILD_STRICT_C90 "Build with strict conformance to C90 standard, if disabled, C99 features can be used (eg. fabsf(), strtof(), ...)" ON)
|
||||
option(BUILD_WITH_LIBSTL "Build the libSTL module" ON)
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries (DLL)" ON)
|
||||
option(BUILD_STRICT_C90 "Build with strict conformance to C90 standard. If disabled, C99 features can be used (eg. strtof(), <stdint.h>, ...)" ON)
|
||||
option(BUILD_WITH_LIBSTL "Build the libSTL module" ON)
|
||||
|
||||
# Add core source files
|
||||
file(GLOB ALL_SRC_FILES src/gmio_core/* src/gmio_core/internal/*)
|
||||
set(ALL_SRC_FILES ${ALL_SRC_FILES})
|
||||
|
||||
# Have <stdint.h> ?
|
||||
check_include_files(stdint.h GMIO_HAVE_STDINT_H)
|
||||
|
||||
# Have <stdbool.h> ?
|
||||
check_include_files(stdbool.h GMIO_HAVE_STDBOOL_H)
|
||||
|
||||
# Have strtof() ?
|
||||
if(NOT BUILD_STRICT_C90)
|
||||
check_function_exists(strtof GMIO_HAVE_STRTOF_FUNC)
|
||||
# Have <stdint.h> ?
|
||||
check_include_files(stdint.h GMIO_HAVE_STDINT_H)
|
||||
|
||||
# Have strtof() ?
|
||||
check_function_exists(strtof GMIO_HAVE_STRTOF_FUNC)
|
||||
|
||||
# Have <stdbool.h> ?
|
||||
check_include_files(stdbool.h GMIO_HAVE_STDBOOL_H)
|
||||
endif()
|
||||
|
||||
# Have builtin byte swap functions ?
|
||||
if(CMAKE_COMPILER_IS_GNUCC)
|
||||
# __builtin_bswap16() is missing in x86 GCC version prior to v4.7
|
||||
# See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624
|
||||
check_c_source_compiles("int main() { return (int)__builtin_bswap16(0x1122); }"
|
||||
GMIO_HAVE_GCC_BUILTIN_BSWAP16_FUNC)
|
||||
check_c_source_compiles("int main() { return (int)__builtin_bswap32(0x11223344); }"
|
||||
GMIO_HAVE_GCC_BUILTIN_BSWAP32_FUNC)
|
||||
# __builtin_bswap16() is missing in x86 GCC version prior to v4.7
|
||||
# See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624
|
||||
check_c_source_compiles("int main() { return (int)__builtin_bswap16(0x1122); }"
|
||||
GMIO_HAVE_GCC_BUILTIN_BSWAP16_FUNC)
|
||||
check_c_source_compiles("int main() { return (int)__builtin_bswap32(0x11223344); }"
|
||||
GMIO_HAVE_GCC_BUILTIN_BSWAP32_FUNC)
|
||||
elseif(MSVC)
|
||||
check_c_source_compiles("#include <stdlib.h>
|
||||
int main() { return (int)_byteswap_ulong(0x11223344); }"
|
||||
GMIO_HAVE_MSVC_BUILTIN_BSWAP_FUNC)
|
||||
check_c_source_compiles("#include <stdlib.h>
|
||||
int main() { return (int)_byteswap_ulong(0x11223344); }"
|
||||
GMIO_HAVE_MSVC_BUILTIN_BSWAP_FUNC)
|
||||
endif()
|
||||
|
||||
configure_file(src/gmio_core/config.h.cmake config.h @ONLY)
|
||||
@ -47,24 +47,24 @@ include_directories(${CMAKE_BINARY_DIR}) # For generated "config.h"
|
||||
|
||||
# Specific flags for GCC
|
||||
if(CMAKE_COMPILER_IS_GNUCC)
|
||||
if (BUILD_STRICT_C90)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ansi")
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic-errors -fstrict-aliasing")
|
||||
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
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
if(BUILD_STRICT_C90)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ansi")
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic-errors -fstrict-aliasing")
|
||||
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
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
endif()
|
||||
|
||||
# Specific flags for Visual C++
|
||||
if(MSVC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -TC")
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -TC")
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
add_definitions(-DGMIO_LIB_DLL
|
||||
-DGMIO_LIB_MAKE_DLL)
|
||||
add_definitions(-DGMIO_LIB_DLL
|
||||
-DGMIO_LIB_MAKE_DLL)
|
||||
endif()
|
||||
|
||||
# Declare installs
|
||||
@ -75,13 +75,13 @@ install(FILES ${C_CORE_HEADERS} DESTINATION include/gmio_core)
|
||||
|
||||
# Module libSTL
|
||||
if(BUILD_WITH_LIBSTL)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
add_definitions(-DGMIO_LIBSTL_DLL
|
||||
-DGMIO_LIBSTL_MAKE_DLL)
|
||||
endif()
|
||||
if(BUILD_SHARED_LIBS)
|
||||
add_definitions(-DGMIO_LIBSTL_DLL
|
||||
-DGMIO_LIBSTL_MAKE_DLL)
|
||||
endif()
|
||||
|
||||
file(GLOB ALL_LIBSTL_SRC_FILES src/gmio_stl/* src/gmio_stl/internal/*)
|
||||
set(ALL_SRC_FILES ${ALL_SRC_FILES} ${ALL_LIBSTL_SRC_FILES})
|
||||
file(GLOB ALL_LIBSTL_SRC_FILES src/gmio_stl/* src/gmio_stl/internal/*)
|
||||
set(ALL_SRC_FILES ${ALL_SRC_FILES} ${ALL_LIBSTL_SRC_FILES})
|
||||
|
||||
endif()
|
||||
file(GLOB C_LIBSTL_HEADERS src/gmio_stl/*.h)
|
||||
@ -124,6 +124,9 @@ add_executable(test_internal EXCLUDE_FROM_ALL tests/stream_buffer.c
|
||||
src/gmio_core/stream.c
|
||||
src/gmio_core/internal/ascii_parse.c)
|
||||
add_executable(test_platform EXCLUDE_FROM_ALL tests/test_platform.c)
|
||||
|
||||
add_test(test_internal test_internal)
|
||||
add_test(test_platform test_platform)
|
||||
add_dependencies(check test_internal test_platform)
|
||||
|
||||
add_dependencies(check test_internal
|
||||
test_platform)
|
||||
|
Loading…
Reference in New Issue
Block a user