From d635d6fd5027247ccd99573264e0fcd317e2455b Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Fri, 5 Apr 2013 08:47:44 +0000 Subject: [PATCH] CMake: Implement a sanity check for user supplied CMAKE_C_FLAGS and CMAKE_CXX_FLAGS git-svn-id: https://svn.dealii.org/trunk@29197 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/cmake/setup_cached_variables.cmake | 4 ++ deal.II/cmake/setup_compiler_flags.cmake | 46 ++++++++++++++++++++++ deal.II/cmake/setup_external_macros.cmake | 1 + 3 files changed, 51 insertions(+) diff --git a/deal.II/cmake/setup_cached_variables.cmake b/deal.II/cmake/setup_cached_variables.cmake index f5c760bd7d..a86be64cf1 100644 --- a/deal.II/cmake/setup_cached_variables.cmake +++ b/deal.II/cmake/setup_cached_variables.cmake @@ -200,11 +200,15 @@ ENDFOREACH() SET_IF_EMPTY(CMAKE_C_FLAGS "$ENV{CFLAGS}") SET_IF_EMPTY(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS}") SET_IF_EMPTY(CMAKE_SHARED_LINKER_FLAGS "$ENV{LDFLAGS}") +UNSET(ENV{CFLAGS}) +UNSET(ENV{CXXFLAGS}) +UNSET(ENV{LDFLAGS}) # # Set cached compiler flags to an empty string: # SET(DEAL_II_USED_FLAGS + CMAKE_C_FLAGS CMAKE_CXX_FLAGS DEAL_II_CXX_FLAGS_DEBUG DEAL_II_CXX_FLAGS_RELEASE diff --git a/deal.II/cmake/setup_compiler_flags.cmake b/deal.II/cmake/setup_compiler_flags.cmake index 80572fa7df..b8bbda6984 100644 --- a/deal.II/cmake/setup_compiler_flags.cmake +++ b/deal.II/cmake/setup_compiler_flags.cmake @@ -54,6 +54,46 @@ # +########################################################################### +# # +# Sanity checks: # +# # +########################################################################### + +# +# Check the user provided C and CXX flags: +# Only do this for CMAKE_C_FLAGS and CMAKE_CXX_FLAGS as this check is very +# costly +# +SET(CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS_SAVED}") +CHECK_C_SOURCE_COMPILES( + "int main(){ return 0; }" + DEAL_II_HAVE_USABLE_C_FLAGS) + +IF(NOT DEAL_II_HAVE_USABLE_C_FLAGS) + UNSET(DEAL_II_HAVE_USABLE_C_FLAGS CACHE) + MESSAGE(FATAL_ERROR "\n" + "Configuration error: Cannot compile with the specified C flags: " + "${CMAKE_C_FLAGS_SAVED}\n" + ) +ENDIF() +UNSET(DEAL_II_HAVE_USABLE_C_FLAGS CACHE) + +SET(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX_FLAGS_SAVED}") +CHECK_CXX_SOURCE_COMPILES( + "int main(){ return 0; }" + DEAL_II_HAVE_USABLE_CXX_FLAGS) +SET(CMAKE_REQUIRED_FLAGS "") + +IF(NOT DEAL_II_HAVE_USABLE_CXX_FLAGS) + UNSET(DEAL_II_HAVE_USABLE_CXX_FLAGS CACHE) + MESSAGE(FATAL_ERROR "\n" + "Configuration error: Cannot compile with the specified CXX flags: " + "${CMAKE_CXX_FLAGS_SAVED}\n" + ) +ENDIF() +UNSET(DEAL_II_HAVE_USABLE_CXX_FLAGS CACHE) + # # CMAKE_C_COMPILER and CMAKE_CXX_COMPILER have to be of the same brand. # @@ -68,6 +108,12 @@ IF(NOT ( "${CMAKE_C_COMPILER_ID}" STREQUAL "${CMAKE_CXX_COMPILER_ID}" AND ENDIF() +########################################################################### +# # +# Compiler setup: # +# # +########################################################################### + IF(DEAL_II_SETUP_DEFAULT_COMPILER_FLAGS) # # *Hooray* We are allowed to set compiler flags :-] diff --git a/deal.II/cmake/setup_external_macros.cmake b/deal.II/cmake/setup_external_macros.cmake index 6adfecc7ab..f5c3a150a1 100644 --- a/deal.II/cmake/setup_external_macros.cmake +++ b/deal.II/cmake/setup_external_macros.cmake @@ -18,6 +18,7 @@ INCLUDE(CheckCXXCompilerFlag) INCLUDE(CheckCXXSourceCompiles) +INCLUDE(CheckCSourceCompiles) INCLUDE(CheckCXXSourceRuns) INCLUDE(CheckCXXSymbolExists) INCLUDE(CheckIncludeFileCXX) -- 2.39.5