]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
CMake: Implement a sanity check for user supplied CMAKE_C_FLAGS and CMAKE_CXX_FLAGS
authormaier <maier@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 5 Apr 2013 08:47:44 +0000 (08:47 +0000)
committermaier <maier@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 5 Apr 2013 08:47:44 +0000 (08:47 +0000)
git-svn-id: https://svn.dealii.org/trunk@29197 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/cmake/setup_cached_variables.cmake
deal.II/cmake/setup_compiler_flags.cmake
deal.II/cmake/setup_external_macros.cmake

index f5c760bd7d4afc96c81ee1bb143ec2a85f880584..a86be64cf1faefc064f26b0bbbaec1823bd72efe 100644 (file)
@@ -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
index 80572fa7df8585d4549700080aa63bd53a0f9256..b8bbda698436b637d5262b7da9691ec99fff3f8c 100644 (file)
 #
 
 
+###########################################################################
+#                                                                         #
+#                             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 :-]
index 6adfecc7ab8a1eea5d42bd99db29cb8788e97d59..f5c3a150a16ccfdf807fa73d8c6012f926ab1135 100644 (file)
@@ -18,6 +18,7 @@
 
 INCLUDE(CheckCXXCompilerFlag)
 INCLUDE(CheckCXXSourceCompiles)
+INCLUDE(CheckCSourceCompiles)
 INCLUDE(CheckCXXSourceRuns)
 INCLUDE(CheckCXXSymbolExists)
 INCLUDE(CheckIncludeFileCXX)

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.