Probe for C99 standard available
Similar to the -std=c++0x flag for C++ code, we probe for, and add if available, -std=c99 for C code, since the compiler may generate different initialization code for this variant. The reporting from the bundled CMake modules is not as polished as for probing for C++ flags, but not bad enough to warrant rewriting the code from scratch just to fix the output.
This commit is contained in:
parent
0e88d99c50
commit
2fc5a6349e
@ -4,6 +4,7 @@ cmake_minimum_required (VERSION 2.8)
|
||||
project (opm-core)
|
||||
set (opm-core_VERSION_MAJOR 0)
|
||||
set (opm-core_VERSION_MINOR 3)
|
||||
enable_language (C)
|
||||
enable_language (CXX)
|
||||
|
||||
# build debug by default
|
||||
@ -28,6 +29,8 @@ include (OpmFind)
|
||||
|
||||
# dependencies
|
||||
list (APPEND opm-core_DEPS
|
||||
# compile with C99 support if available
|
||||
"C99"
|
||||
# compile with C++0x/11 support if available
|
||||
"CXX11Features"
|
||||
# matrix library
|
||||
|
25
cmake/Modules/FindC99.cmake
Normal file
25
cmake/Modules/FindC99.cmake
Normal file
@ -0,0 +1,25 @@
|
||||
# - Module that checks for supported C99 features.
|
||||
|
||||
# macro to only add option once
|
||||
include (AddOptions)
|
||||
|
||||
# try to use compiler flag -std=c99
|
||||
set (C_STD99_FLAGS "-std=c99")
|
||||
|
||||
# incidently, the C++ test is so simple that it can be used to compile C as well
|
||||
include (CheckCCompilerFlag)
|
||||
check_c_compiler_flag (${C_STD99_FLAGS} HAVE_C99)
|
||||
|
||||
# add option if we are capable
|
||||
if (HAVE_C99)
|
||||
add_options (C ALL_BUILDS "${C_STD99_FLAGS}")
|
||||
else (HAVE_C99)
|
||||
set (C_STD99_FLAGS)
|
||||
endif (HAVE_C99)
|
||||
|
||||
# handle quiet and required
|
||||
include (FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args (C99
|
||||
DEFAULT_MSG
|
||||
C_STD99_FLAGS
|
||||
)
|
@ -42,4 +42,9 @@ string (REPLACE "@CXX_STD0X_FLAGS@" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
string (STRIP "${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS)
|
||||
set (CMAKE_CXX_FLAGS "@CXX_STD0X_FLAGS@ ${CMAKE_CXX_FLAGS}")
|
||||
|
||||
# same as above, but for C99
|
||||
string (REPLACE "@C_STD99_FLAGS@" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
||||
string (STRIP "${CMAKE_C_FLAGS}" CMAKE_C_FLAGS)
|
||||
set (CMAKE_C_FLAG "@C_STD99_FLAGS@ ${CMAKE_C_FLAGS}")
|
||||
|
||||
# this is the contents of config.h as far as our probes can tell:
|
||||
|
Loading…
Reference in New Issue
Block a user