From 2fc5a6349e8b958d92e6997ab0cc2a5b176b0373 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Mon, 10 Dec 2012 12:25:40 +0100 Subject: [PATCH] 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. --- CMakeLists.txt | 3 +++ cmake/Modules/FindC99.cmake | 25 +++++++++++++++++++++++++ opm-core-config.cmake.in | 5 +++++ 3 files changed, 33 insertions(+) create mode 100644 cmake/Modules/FindC99.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index d5288679..5e75f029 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/cmake/Modules/FindC99.cmake b/cmake/Modules/FindC99.cmake new file mode 100644 index 00000000..1dcbe1e4 --- /dev/null +++ b/cmake/Modules/FindC99.cmake @@ -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 + ) diff --git a/opm-core-config.cmake.in b/opm-core-config.cmake.in index d08f469a..ed73362d 100644 --- a/opm-core-config.cmake.in +++ b/opm-core-config.cmake.in @@ -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: