2015-03-03 00:38:33 +08:00
|
|
|
#############################################################################
|
2016-07-05 18:46:22 +08:00
|
|
|
## Copyright (c) 2016, Fougue Ltd. <http://www.fougue.pro>
|
|
|
|
## All rights reserved.
|
|
|
|
##
|
|
|
|
## Redistribution and use in source and binary forms, with or without
|
|
|
|
## modification, are permitted provided that the following conditions
|
|
|
|
## are met:
|
|
|
|
##
|
|
|
|
## 1. Redistributions of source code must retain the above copyright
|
|
|
|
## notice, this list of conditions and the following disclaimer.
|
|
|
|
##
|
|
|
|
## 2. Redistributions in binary form must reproduce the above
|
|
|
|
## copyright notice, this list of conditions and the following
|
|
|
|
## disclaimer in the documentation and/or other materials provided
|
|
|
|
## with the distribution.
|
|
|
|
##
|
|
|
|
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2015-03-03 00:38:33 +08:00
|
|
|
#############################################################################
|
|
|
|
|
2015-03-30 22:37:47 +08:00
|
|
|
cmake_minimum_required(VERSION 2.8)
|
2014-01-24 00:24:50 +08:00
|
|
|
|
2013-02-21 21:37:42 +08:00
|
|
|
include(CheckIncludeFiles)
|
2014-01-24 00:24:50 +08:00
|
|
|
include(CheckFunctionExists)
|
2016-06-08 17:00:54 +08:00
|
|
|
include(CheckSymbolExists)
|
2014-01-24 00:24:50 +08:00
|
|
|
include(CheckCSourceCompiles)
|
2015-04-03 21:22:47 +08:00
|
|
|
include(CheckTypeSize)
|
2015-09-02 18:08:14 +08:00
|
|
|
include(CMakeDependentOption)
|
2013-02-21 21:37:42 +08:00
|
|
|
|
2015-09-01 23:01:38 +08:00
|
|
|
project(gmio)
|
2015-05-28 00:57:00 +08:00
|
|
|
set(GMIO_VERSION_MAJOR 0)
|
2016-11-29 16:55:13 +08:00
|
|
|
set(GMIO_VERSION_MINOR 4)
|
|
|
|
set(GMIO_VERSION_PATCH 0)
|
2015-05-28 00:57:00 +08:00
|
|
|
set(GMIO_VERSION
|
|
|
|
${GMIO_VERSION_MAJOR}.${GMIO_VERSION_MINOR}.${GMIO_VERSION_PATCH})
|
2013-02-21 21:37:42 +08:00
|
|
|
|
2015-09-25 00:16:08 +08:00
|
|
|
# C Compiler detection
|
|
|
|
if(CMAKE_C_COMPILER MATCHES ".*clang")
|
2015-09-09 23:13:12 +08:00
|
|
|
set(CMAKE_COMPILER_IS_CLANG 1)
|
|
|
|
endif ()
|
|
|
|
|
2015-09-25 00:16:08 +08:00
|
|
|
if(CMAKE_C_COMPILER MATCHES "tcc")
|
|
|
|
set(CMAKE_COMPILER_IS_TCC 1) # TinyCC
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_COMPILER_IS_GNUCC
|
|
|
|
OR CMAKE_COMPILER_IS_CLANG
|
|
|
|
OR CMAKE_COMPILER_IS_TCC)
|
|
|
|
set(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE 1) # Compatible with GNUCC options
|
|
|
|
endif()
|
|
|
|
|
2016-01-13 17:55:59 +08:00
|
|
|
# Build type
|
|
|
|
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
|
|
|
|
if(CMAKE_BUILD_TYPE_LOWER MATCHES "debug")
|
|
|
|
set(GMIO_DEBUG_BUILD 1)
|
|
|
|
else()
|
|
|
|
set(GMIO_DEBUG_BUILD 0)
|
|
|
|
endif()
|
|
|
|
|
2015-09-02 00:20:31 +08:00
|
|
|
# Options
|
|
|
|
option(GMIO_BUILD_STRICT_C90 "Build gmio library(and tests) with strict conformance to C90 standard" OFF)
|
|
|
|
option(GMIO_BUILD_SHARED_LIBS "Build gmio as a shared library (DLL)" OFF)
|
|
|
|
option(GMIO_BUILD_BENCHMARKS "Build performance benchmarks for the gmio library" OFF)
|
2016-06-30 16:39:45 +08:00
|
|
|
option(GMIO_BUILD_EXAMPLES "Build gmio examples" OFF)
|
2015-09-02 18:08:14 +08:00
|
|
|
option(GMIO_BUILD_TESTS_FAKE_SUPPORT "Build tests/fake_support target" OFF)
|
2015-09-25 00:16:08 +08:00
|
|
|
if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE)
|
2015-09-09 23:13:12 +08:00
|
|
|
option(GMIO_BUILD_TESTS_COVERAGE "Instrument testing code with code coverage" OFF)
|
|
|
|
endif()
|
2015-06-29 18:26:47 +08:00
|
|
|
|
2016-06-08 17:00:54 +08:00
|
|
|
# Declare variable GMIO_STR2FLOAT_LIB(library for string-to-float conversion)
|
|
|
|
# - std:
|
|
|
|
# C standard library functions(eg strtod())
|
2016-06-16 00:05:51 +08:00
|
|
|
# - irrlicht_fast_atof:
|
2016-06-08 17:00:54 +08:00
|
|
|
# fast_atof() function of Irrlicht project
|
|
|
|
# - google_doubleconversion:
|
|
|
|
# Google's doubleconversion functions, note that this implies C++
|
|
|
|
# fastness: std < google_doubleconversion < irrlicht_fast_atof
|
|
|
|
# robustness: irrlicht_fast_atof < google_doubleconversion <= std
|
|
|
|
set(GMIO_STR2FLOAT_LIB "irrlicht_fast_atof" CACHE STRING "String->float library to use")
|
|
|
|
set_property(CACHE GMIO_STR2FLOAT_LIB
|
|
|
|
PROPERTY STRINGS std irrlicht_fast_atof google_doubleconversion)
|
|
|
|
|
|
|
|
if(GMIO_STR2FLOAT_LIB MATCHES "std")
|
|
|
|
set(GMIO_STR2FLOAT_LIBCODE 0)
|
|
|
|
elseif(GMIO_STR2FLOAT_LIB MATCHES "irrlicht_fast_atof")
|
|
|
|
set(GMIO_STR2FLOAT_LIBCODE 1)
|
|
|
|
elseif(GMIO_STR2FLOAT_LIB MATCHES "google_doubleconversion")
|
|
|
|
set(GMIO_STR2FLOAT_LIBCODE 2)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Declare variable GMIO_FLOAT2STR_LIB(library for float-to-string conversion)
|
|
|
|
# - std:
|
|
|
|
# C standard library functions(eg snprintf())
|
|
|
|
# - google_doubleconversion:
|
|
|
|
# Google's doubleconversion functions, note that this implies C++
|
|
|
|
# fastness: std < google_doubleconversion
|
|
|
|
# robustness: google_doubleconversion <= std
|
|
|
|
set(GMIO_FLOAT2STR_LIB "std" CACHE STRING "Float->string library to use")
|
|
|
|
set_property(CACHE GMIO_FLOAT2STR_LIB
|
|
|
|
PROPERTY STRINGS std google_doubleconversion)
|
|
|
|
|
|
|
|
if(GMIO_FLOAT2STR_LIB MATCHES "std")
|
|
|
|
set(GMIO_FLOAT2STR_LIBCODE 0)
|
|
|
|
elseif(GMIO_FLOAT2STR_LIB MATCHES "google_doubleconversion")
|
|
|
|
set(GMIO_FLOAT2STR_LIBCODE 2)
|
|
|
|
endif()
|
|
|
|
|
2015-03-04 00:18:15 +08:00
|
|
|
# Find bit size of the target architecture
|
2015-03-03 17:27:39 +08:00
|
|
|
math(EXPR GMIO_TARGET_ARCH_BIT_SIZE "8 * ${CMAKE_SIZEOF_VOID_P}")
|
2015-11-06 19:40:57 +08:00
|
|
|
message(STATUS "GMIO_TARGET_ARCH_BIT_SIZE = ${GMIO_TARGET_ARCH_BIT_SIZE}")
|
2015-03-03 17:27:39 +08:00
|
|
|
|
2015-03-20 15:53:20 +08:00
|
|
|
# Test if host's architecture is big-endian
|
|
|
|
include(TestBigEndian)
|
|
|
|
test_big_endian(GMIO_HOST_IS_BIG_ENDIAN)
|
|
|
|
|
2015-08-12 05:57:57 +08:00
|
|
|
# Adapt C compiler flags to satisfy the GMIO_BUILD_STRICT_C90 option
|
2016-03-08 00:09:06 +08:00
|
|
|
# It must be done before checking non ANSI features(C99, POSIX, ...)
|
2015-08-12 05:57:57 +08:00
|
|
|
if(GMIO_BUILD_STRICT_C90)
|
2015-09-25 00:16:08 +08:00
|
|
|
if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE)
|
2015-04-02 15:38:08 +08:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ansi -pedantic-errors")
|
2015-04-01 21:39:00 +08:00
|
|
|
elseif(MSVC)
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Za")
|
|
|
|
endif()
|
|
|
|
endif()
|
2014-01-24 00:24:50 +08:00
|
|
|
|
2015-04-01 21:39:00 +08:00
|
|
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS}")
|
2014-11-11 01:31:44 +08:00
|
|
|
|
2015-12-04 17:36:27 +08:00
|
|
|
# Some compilers (like GCC v4.9) don't disable <stdint.h> in C90 mode
|
2015-04-01 21:39:00 +08:00
|
|
|
check_include_files(stdint.h GMIO_HAVE_STDINT_H)
|
2015-03-26 19:04:17 +08:00
|
|
|
|
2015-11-20 00:43:07 +08:00
|
|
|
# Find size of short, int and long types
|
2015-12-04 17:36:27 +08:00
|
|
|
set(GMIO_SIZEOF_SHORT ${CMAKE_SIZEOF_UNSIGNED_SHORT})
|
|
|
|
if (NOT DEFINED HAVE_CMAKE_SIZEOF_UNSIGNED_SHORT)
|
|
|
|
check_type_size("short" GMIO_SIZEOF_SHORT)
|
|
|
|
endif()
|
2015-11-20 00:43:07 +08:00
|
|
|
check_type_size("int" GMIO_SIZEOF_INT)
|
|
|
|
check_type_size("long" GMIO_SIZEOF_LONG)
|
|
|
|
|
2016-03-08 00:09:06 +08:00
|
|
|
# Check availability of a 64b integer type
|
|
|
|
if(GMIO_HAVE_STDINT_H)
|
|
|
|
set(CMAKE_REQUIRED_INCLUDES stdint.h)
|
|
|
|
endif()
|
|
|
|
check_type_size("int64_t" GMIO_SIZEOF_INT64_T)
|
|
|
|
if(NOT HAVE_GMIO_SIZEOF_INT64_T)
|
|
|
|
check_type_size("__int64" GMIO_SIZEOF_MSVC_INT64)
|
|
|
|
if(NOT HAVE_GMIO_SIZEOF_MSVC_INT64)
|
|
|
|
check_type_size("long long" GMIO_SIZEOF_LONG_LONG)
|
2015-11-06 19:40:57 +08:00
|
|
|
endif()
|
2016-03-08 00:09:06 +08:00
|
|
|
endif()
|
|
|
|
set(CMAKE_REQUIRED_INCLUDES) # Pop changes
|
|
|
|
|
|
|
|
if(HAVE_GMIO_SIZEOF_INT64_T)
|
|
|
|
set(GMIO_HAVE_INT64_T ${HAVE_GMIO_SIZEOF_INT64_T})
|
|
|
|
elseif(HAVE_GMIO_SIZEOF_MSVC_INT64)
|
|
|
|
set(GMIO_HAVE_MSVC_INT64 ${HAVE_GMIO_SIZEOF_MSVC_INT64})
|
|
|
|
elseif(HAVE_GMIO_SIZEOF_LONG_LONG)
|
|
|
|
set(GMIO_HAVE_LONG_LONG ${HAVE_GMIO_SIZEOF_LONG_LONG})
|
|
|
|
endif()
|
2015-11-06 19:40:57 +08:00
|
|
|
|
2016-03-08 00:09:06 +08:00
|
|
|
# Check C99 features
|
|
|
|
if(NOT GMIO_BUILD_STRICT_C90)
|
2015-09-25 00:16:08 +08:00
|
|
|
if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE)
|
2015-04-04 05:58:58 +08:00
|
|
|
list(APPEND CMAKE_REQUIRED_LIBRARIES m) # -lm
|
|
|
|
endif()
|
2016-03-15 00:02:30 +08:00
|
|
|
check_function_exists(powf GMIO_HAVE_POWF_FUNC)
|
|
|
|
check_function_exists(sqrtf GMIO_HAVE_SQRTF_FUNC)
|
2016-06-08 17:00:54 +08:00
|
|
|
check_function_exists(strtof GMIO_HAVE_STRTOF_FUNC)
|
|
|
|
check_symbol_exists(isfinite math.h GMIO_HAVE_ISFINITE_MACRO)
|
|
|
|
check_symbol_exists(isnan math.h GMIO_HAVE_ISNAN_MACRO)
|
2016-03-08 00:09:06 +08:00
|
|
|
set(CMAKE_REQUIRED_LIBRARIES) # Pop changes
|
2015-04-04 05:58:58 +08:00
|
|
|
|
2015-04-01 21:39:00 +08:00
|
|
|
check_include_files(stdbool.h GMIO_HAVE_STDBOOL_H)
|
2016-03-09 00:28:43 +08:00
|
|
|
|
|
|
|
check_function_exists(snprintf GMIO_HAVE_SNPRINTF_FUNC)
|
|
|
|
if(WIN32 AND NOT GMIO_HAVE_SNPRINTF_FUNC)
|
|
|
|
check_function_exists(_snprintf GMIO_HAVE_WIN__SNPRINTF_FUNC)
|
|
|
|
endif()
|
2016-03-10 22:23:01 +08:00
|
|
|
|
|
|
|
check_function_exists(vsnprintf GMIO_HAVE_VSNPRINTF_FUNC)
|
|
|
|
if(WIN32 AND NOT GMIO_HAVE_VSNPRINTF_FUNC)
|
|
|
|
check_function_exists(_vsnprintf GMIO_HAVE_WIN__VSNPRINTF_FUNC)
|
|
|
|
endif()
|
2016-03-08 00:09:06 +08:00
|
|
|
endif()
|
2015-03-30 22:37:47 +08:00
|
|
|
|
2016-03-08 00:09:06 +08:00
|
|
|
# Check POSIX features
|
|
|
|
if(UNIX)
|
|
|
|
# See:
|
|
|
|
# http://linux.die.net/man/2/fstat64
|
|
|
|
# https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/fstat.2.html
|
|
|
|
# https://www.gnu.org/software/libc/manual/html_mono/libc.html#Feature-Test-Macros
|
|
|
|
if(APPLE)
|
|
|
|
add_definitions(-D_DARWIN_USE_64_BIT_INODE)
|
|
|
|
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_DARWIN_USE_64_BIT_INODE)
|
|
|
|
else()
|
|
|
|
add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE=1)
|
|
|
|
list(APPEND CMAKE_REQUIRED_DEFINITIONS
|
|
|
|
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE=1)
|
2015-04-03 21:12:58 +08:00
|
|
|
endif()
|
2016-03-08 00:09:06 +08:00
|
|
|
endif()
|
2015-04-03 21:12:58 +08:00
|
|
|
|
2016-03-08 00:09:06 +08:00
|
|
|
set(GMIO_HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H})
|
|
|
|
if(NOT DEFINED HAVE_SYS_TYPES_H)
|
|
|
|
check_include_files(sys/types.h GMIO_HAVE_SYS_TYPES_H)
|
|
|
|
endif()
|
2015-12-04 17:36:27 +08:00
|
|
|
|
2016-03-08 00:09:06 +08:00
|
|
|
set(GMIO_HAVE_SYS_STAT_H ${HAVE_SYS_STAT_H})
|
|
|
|
if (NOT DEFINED HAVE_SYS_STAT_H)
|
|
|
|
check_include_files(sys/stat.h GMIO_HAVE_SYS_STAT_H)
|
|
|
|
endif()
|
2015-12-04 17:36:27 +08:00
|
|
|
|
2016-03-08 00:09:06 +08:00
|
|
|
check_function_exists(fileno GMIO_HAVE_POSIX_FILENO_FUNC)
|
2015-12-04 17:36:27 +08:00
|
|
|
|
2016-03-08 00:09:06 +08:00
|
|
|
# Have fstat64() ?
|
|
|
|
check_c_source_compiles(
|
|
|
|
"#include <sys/stat.h>
|
|
|
|
int main() { fstat64(0, NULL); return 0; }"
|
|
|
|
GMIO_HAVE_POSIX_FSTAT64_FUNC)
|
|
|
|
if(WIN32)
|
|
|
|
check_function_exists(_fstat64 GMIO_HAVE_WIN__FSTAT64_FUNC)
|
|
|
|
endif()
|
2015-04-02 15:38:08 +08:00
|
|
|
|
2016-03-08 00:09:06 +08:00
|
|
|
# Check size(in bytes) of stat::st_size
|
|
|
|
set(CMAKE_EXTRA_INCLUDE_FILES sys/stat.h)
|
|
|
|
if(GMIO_HAVE_WIN__FSTAT64_FUNC)
|
|
|
|
check_type_size("((struct _stat64*)0)->st_size" GMIO_SIZEOF_STRUCT_STAT_ST_SIZE)
|
|
|
|
elseif(GMIO_HAVE_POSIX_FSTAT64_FUNC)
|
|
|
|
check_type_size("((struct stat64*)0)->st_size" GMIO_SIZEOF_STRUCT_STAT_ST_SIZE)
|
|
|
|
else()
|
|
|
|
check_type_size("((struct stat*)0)->st_size" GMIO_SIZEOF_STRUCT_STAT_ST_SIZE)
|
|
|
|
endif()
|
|
|
|
set(CMAKE_EXTRA_INCLUDE_FILES)
|
|
|
|
set(CMAKE_REQUIRED_DEFINITIONS)
|
|
|
|
|
|
|
|
# Verify large file support ?
|
|
|
|
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 EQUAL 8))
|
|
|
|
message(WARNING "<sys/stat.h> does not provide 64b variant of fstat(), you may encounter problems with files > 2GB")
|
|
|
|
endif()
|
2015-03-30 22:37:47 +08:00
|
|
|
|
2016-06-08 17:00:54 +08:00
|
|
|
# Have compiler-intrisics byte swap functions ?
|
2016-03-08 00:09:06 +08:00
|
|
|
if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE)
|
|
|
|
# __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)
|
|
|
|
endif()
|
2013-02-21 21:37:42 +08:00
|
|
|
|
2015-09-25 00:16:08 +08:00
|
|
|
# Specific flags for GCC-like compilers
|
|
|
|
if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE)
|
2015-04-02 15:38:08 +08:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstrict-aliasing")
|
2015-04-10 21:10:33 +08:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wstrict-aliasing")
|
2015-06-29 22:32:00 +08:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-align -Wfloat-equal")
|
2015-11-04 01:09:25 +08:00
|
|
|
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Winline")
|
2015-06-29 22:32:00 +08:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCC)
|
2015-11-04 01:09:25 +08:00
|
|
|
# Undefined behavior sanitizer(ubsan), requires GCC >= v4.9
|
|
|
|
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
|
2015-06-29 22:32:00 +08:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wlogical-op")
|
|
|
|
else()
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wlogical-op-parentheses")
|
|
|
|
endif()
|
2015-04-03 17:15:57 +08:00
|
|
|
|
2015-12-04 19:48:00 +08:00
|
|
|
# Disable warnings -Wno-missing-braces -Wno-missing-field-initializers
|
|
|
|
# in case GCC wrongly warns about universal zero initializer {0}
|
|
|
|
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
|
|
|
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS} -Werror=missing-braces")
|
|
|
|
check_c_source_compiles(
|
|
|
|
"struct data { char array[128]; };
|
|
|
|
int main() {
|
|
|
|
struct data d = {0};
|
|
|
|
return d.array[0];
|
|
|
|
}"
|
|
|
|
GMIO_GCC_DOESNT_WARN_UNIVERSAL_0_INITIALIZER)
|
|
|
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS}") # Restore CMAKE_REQUIRED_FLAGS
|
|
|
|
if (NOT GMIO_GCC_DOESNT_WARN_UNIVERSAL_0_INITIALIZER)
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-braces -Wno-missing-field-initializers")
|
|
|
|
endif()
|
2015-03-04 00:18:15 +08:00
|
|
|
|
2015-11-04 01:09:25 +08:00
|
|
|
# Force PIC for GCC
|
|
|
|
# See https://www.gentoo.org/proj/en/base/amd64/howtos/index.xml?part=1&chap=3
|
2014-11-19 16:38:24 +08:00
|
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
2013-02-21 21:37:42 +08:00
|
|
|
endif()
|
|
|
|
|
2016-02-12 18:45:46 +08:00
|
|
|
# Specific flags for Clang
|
|
|
|
if(CMAKE_COMPILER_IS_CLANG)
|
|
|
|
# Clang on apple-darwin13.4.0 wrongly reports many unused functions
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
|
|
|
|
endif()
|
|
|
|
|
2013-02-21 21:37:42 +08:00
|
|
|
# Specific flags for Visual C++
|
|
|
|
if(MSVC)
|
2015-03-03 23:27:02 +08:00
|
|
|
# Treat all files a C source files
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /TC")
|
2015-03-04 00:18:15 +08:00
|
|
|
|
2015-03-03 23:27:02 +08:00
|
|
|
# Set warning level to /W4
|
|
|
|
string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
|
2016-07-05 17:20:51 +08:00
|
|
|
|
|
|
|
# Set warning level to /Wall
|
|
|
|
#string(REGEX REPLACE "/W[0-9]" "/Wall" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
|
|
|
|
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4255 /wd4710 /wd4711 /wd4820")
|
|
|
|
|
|
|
|
# Enable static analysis
|
2015-03-18 23:27:43 +08:00
|
|
|
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /analyze")
|
2016-02-05 19:21:29 +08:00
|
|
|
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Oi /Qvec-report:2")
|
2015-03-04 00:18:15 +08:00
|
|
|
|
2016-07-05 17:20:51 +08:00
|
|
|
# Treat some warnings as errors
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4133")
|
2016-09-21 15:03:39 +08:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4013")
|
2015-03-13 18:05:51 +08:00
|
|
|
|
2015-03-03 23:27:02 +08:00
|
|
|
# Enable /Zc:strictStrings when msvc_ver > 2012 and build_type != Debug
|
|
|
|
if((MSVC_VERSION GREATER 1700) AND NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Zc:strictStrings")
|
|
|
|
endif()
|
2015-03-04 00:18:15 +08:00
|
|
|
|
|
|
|
# Disable deprecation warnings about "non-secure" CRT functions
|
2015-03-26 19:05:13 +08:00
|
|
|
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS)
|
2015-05-28 00:57:00 +08:00
|
|
|
|
|
|
|
# Enable "Generate Intrinsic Functions"
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Oi")
|
2013-02-21 21:37:42 +08:00
|
|
|
endif()
|
|
|
|
|
2015-09-02 00:20:31 +08:00
|
|
|
#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
|
|
|
|
2015-08-12 05:57:57 +08:00
|
|
|
# Sub-directories
|
|
|
|
add_subdirectory(src)
|
|
|
|
add_subdirectory(tests)
|
|
|
|
add_subdirectory(doc)
|
2015-09-01 23:30:49 +08:00
|
|
|
if(GMIO_BUILD_BENCHMARKS)
|
2015-09-01 23:01:38 +08:00
|
|
|
add_subdirectory(benchmarks)
|
|
|
|
endif()
|
2016-03-08 00:48:33 +08:00
|
|
|
if(GMIO_BUILD_EXAMPLES)
|
|
|
|
add_subdirectory(examples)
|
|
|
|
endif()
|
2015-05-28 15:36:24 +08:00
|
|
|
|
2016-03-15 00:02:30 +08:00
|
|
|
message(STATUS "CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}")
|
2016-06-08 17:00:54 +08:00
|
|
|
message(STATUS "GMIO_STR2FLOAT_LIBCODE = ${GMIO_STR2FLOAT_LIBCODE}(${GMIO_STR2FLOAT_LIB})")
|
|
|
|
message(STATUS "GMIO_FLOAT2STR_LIBCODE = ${GMIO_FLOAT2STR_LIBCODE}(${GMIO_FLOAT2STR_LIB})")
|
2016-03-15 00:02:30 +08:00
|
|
|
|
2013-02-21 21:37:42 +08:00
|
|
|
# Examples:
|
2015-09-23 00:17:43 +08:00
|
|
|
# cmake -DCMAKE_INSTALL_PREFIX=gcc-linux64 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_DEBUG_POSTFIX=_d
|
2016-03-08 00:09:06 +08:00
|
|
|
# cmake -DCMAKE_INSTALL_PREFIX=gcc-linux64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_RELEASE_POSTFIX=
|
2013-02-21 21:37:42 +08:00
|
|
|
# make VERBOSE=1 or cmake -DCMAKE_VERBOSE_MAKEFILE=TRUE
|