]> https://gitweb.dealii.org/ - dealii.git/commitdiff
CMake: Make a working C compiler optional. Do not require to have a strict
authorMatthias Maier <tamiko@kyomu.43-1.org>
Tue, 16 Jul 2013 09:30:56 +0000 (09:30 +0000)
committerMatthias Maier <tamiko@kyomu.43-1.org>
Tue, 16 Jul 2013 09:30:56 +0000 (09:30 +0000)
matching between C compiler and CXX compiler any more

git-svn-id: https://svn.dealii.org/trunk@30005 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/CMakeLists.txt
deal.II/cmake/checks/check_01_cpu_features.cmake
deal.II/cmake/configure/configure_1_lapack.cmake
deal.II/cmake/configure/configure_1_mpi.cmake
deal.II/cmake/configure/configure_1_threads.cmake
deal.II/cmake/setup_cached_variables.cmake
deal.II/cmake/setup_compiler_flags.cmake
deal.II/cmake/setup_external_macros.cmake

index e193114c9a1486fec2f10ede748e702cf248dfaa..7f7a4e95438c695d977f1ad42c3eb8559a7ae99c 100644 (file)
@@ -66,7 +66,8 @@ INCLUDE(setup_cached_variables)
 #
 # Now, set the project and set up the rest:
 #
-PROJECT(deal.II CXX C)
+PROJECT(deal.II CXX)
+ENABLE_LANGUAGE(C OPTIONAL)
 INCLUDE(setup_deal_ii)
 INCLUDE(setup_compiler_flags)
 
index 81ac8f6a2e881dbb225592464985ae47ce66f4f8..7eb1d358d9d29f18afbfa6c7a7d64e6a9f143c7f 100644 (file)
 #
 # Determine the Endianess of the platform:
 #
-INCLUDE(TestBigEndian)
-TEST_BIG_ENDIAN(DEAL_II_WORDS_BIGENDIAN)
+IF(CMAKE_C_COMPILER_WORKS)
+  INCLUDE(TestBigEndian)
+  TEST_BIG_ENDIAN(DEAL_II_WORDS_BIGENDIAN)
+ELSE()
+  MESSAGE(STATUS
+    "No suitable C compiler was found! Assuming little endian platform."
+    )
+ENDIF()
 
 
 IF(DEAL_II_ALLOW_PLATFORM_INTROSPECTION)
index ad3fb4fde6f0d1033f4639bc30497f8ed75f65fd..7e614ac738daa52029e0a5b1c0a1e72e123f732d 100644 (file)
@@ -101,10 +101,19 @@ MACRO(CHECK_FOR_LAPACK_FUNCTIONS)
   #
   ENABLE_IF_SUPPORTED(CMAKE_REQUIRED_FLAGS "-pthread")
 
-  FOREACH(_func ${DEAL_II_LAPACK_FUNCTIONS})
-    STRING(TOUPPER ${_func} _func_uppercase)
-    CHECK_FUNCTION_EXISTS(${_func} HAVE_${_func_uppercase})
-  ENDFOREACH()
+  IF(CMAKE_C_COMPILER_WORKS)
+    FOREACH(_func ${DEAL_II_LAPACK_FUNCTIONS})
+      STRING(TOUPPER ${_func} _func_uppercase)
+      CHECK_FUNCTION_EXISTS(${_func} HAVE_${_func_uppercase})
+    ENDFOREACH()
+  ELSE()
+    MESSAGE(STATUS
+      "No suitable C compiler was found! Skipping LAPACK symbol check."
+      )
+    FOREACH(_func ${DEAL_II_LAPACK_FUNCTIONS})
+      SET_IF_EMPTY(HAVE_${_func_uppercase} TRUE)
+    ENDFOREACH()
+  ENDIF()
 
   SET(CMAKE_REQUIRED_LIBRARIES)
   STRIP_FLAG(CMAKE_REQUIRED_FLAGS "${LAPACK_LINKER_FLAGS}")
index 479b363af58b0f29347badb119e50c233cb4d391..fc88e1e1fbf3a29230d9016820900bd5f615e553 100644 (file)
@@ -18,7 +18,7 @@
 
 MACRO(FEATURE_MPI_FIND_EXTERNAL var)
   #
-  # Enable Fortran support so that MPI_Fortran_LIBRARIES is set up.
+  # Enable C and Fortran support so that MPI_Fortran_LIBRARIES is set up.
   #
   IF(NOT CMAKE_Fortran_COMPILER_WORKS)
     ENABLE_LANGUAGE(Fortran OPTIONAL)
@@ -38,8 +38,22 @@ MACRO(FEATURE_MPI_FIND_EXTERNAL var)
   # directly.
   #
   SET_IF_EMPTY(MPI_CXX_COMPILER ${CMAKE_CXX_COMPILER})
-  SET_IF_EMPTY(MPI_C_COMPILER ${CMAKE_C_COMPILER}) # for good measure
-  SET_IF_EMPTY(MPI_Fortran_COMPILER ${CMAKE_Fortran_COMPILER}) # for good measure
+  IF(CMAKE_C_COMPILER_WORKS)
+    SET_IF_EMPTY(MPI_C_COMPILER ${CMAKE_C_COMPILER}) # for good measure
+  ELSE()
+    MESSAGE(STATUS
+      "No suitable C compiler was found! MPI C interface can not be "
+      "autodetected"
+      )
+  ENDIF()
+  IF(CMAKE_Fortran_COMPILER_WORKS)
+    SET_IF_EMPTY(MPI_Fortran_COMPILER ${CMAKE_Fortran_COMPILER}) # for good measure
+  ELSE()
+    MESSAGE(STATUS
+      "No suitable Fortran compiler was found! MPI Fortran interface can "
+      "not be autodetected"
+      )
+  ENDIF()
   FIND_PACKAGE(MPI)
 
   IF(NOT MPI_CXX_FOUND)
index ad4afe3b72552fac08f644cb2e3e6caf9ca841ef..5161e6ee5995345024f32b753e918a3d5cae2d29 100644 (file)
 #
 MACRO(SETUP_THREADING)
   #
-  # Switch the library preference back to prefer dynamic libraries if
-  # DEAL_II_PREFER_STATIC_LIBS=TRUE but DEAL_II_STATIC_EXECUTABLE=FALSE. In
-  # this case system libraries should be linked dynamically.
+  # Unfortunately the FindThreads macro needs a working C compiler
   #
-  SWITCH_LIBRARY_PREFERENCE()
-  FIND_PACKAGE(Threads)
-  SWITCH_LIBRARY_PREFERENCE()
+  IF(CMAKE_C_COMPILER_WORKS)
+    #
+    # Switch the library preference back to prefer dynamic libraries if
+    # DEAL_II_PREFER_STATIC_LIBS=TRUE but DEAL_II_STATIC_EXECUTABLE=FALSE. In
+    # this case system libraries should be linked dynamically.
+    #
+    SWITCH_LIBRARY_PREFERENCE()
+    FIND_PACKAGE(Threads)
+    SWITCH_LIBRARY_PREFERENCE()
+
+  ELSE()
+
+    #
+    # We have no way to query for thread support. Just assume that it is
+    # provided by Pthreads...
+    #
+    MESSAGE(STATUS
+      "No suitable C compiler was found! Assuming threading is provided by Pthreads."
+      )
+    SET_IF_EMPTY(Threads_FOUND TRUE)
+    SET_IF_EMPTY(CMAKE_THREAD_LIBS_INIT "-lpthread")
+    SET_IF_EMPTY(CMAKE_USE_PTHREADS_INIT TRUE)
+  ENDIF()
 
   IF(NOT Threads_FOUND)
-    # TODO:
+    #
+    # TODO: This is a dead end. Threading might be setup with internal TBB
+    # so we have no way of returning unsuccessfully...
+    #
     MESSAGE(FATAL_ERROR
       "\nInternal configuration error: No Threading support found\n\n"
       )
index 8b6a6d4465eb61bdbb794bd79b77506e20c4928b..87250ab3260c3a418fdebe51119d30afa95daf71 100644 (file)
@@ -230,6 +230,10 @@ FOREACH(_flag
   CMAKE_C_FLAGS_DEBUG
   CMAKE_C_FLAGS_MINSIZEREL
   CMAKE_C_FLAGS_RELWITHDEBINFO
+  CMAKE_Fortran_FLAGS_RELEASE
+  CMAKE_Fortran_FLAGS_DEBUG
+  CMAKE_Fortran_FLAGS_MINSIZEREL
+  CMAKE_Fortran_FLAGS_RELWITHDEBINFO
   CMAKE_SHARED_LINKER_FLAGS
   CMAKE_SHARED_LINKER_FLAGS_DEBUG
   CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL
@@ -244,7 +248,6 @@ ENDFOREACH()
 # 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
@@ -278,13 +281,11 @@ ENDFOREACH()
 
 
 #
-# Finally, read in CFLAGS, CXXFLAGS and LDFLAGS from environment and
-# prepend them to the saved variables:
+# Finally, read in CXXFLAGS and LDFLAGS from environment and prepend them
+# to the saved variables:
 #
-SET(CMAKE_C_FLAGS_SAVED "$ENV{CFLAGS} ${CMAKE_C_FLAGS_SAVED}")
 SET(CMAKE_CXX_FLAGS_SAVED "$ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS_SAVED}")
 SET(DEAL_II_LINKER_FLAGS_SAVED "$ENV{LDFLAGS} ${DEAL_II_LINKER_FLAGS_SAVED}")
-UNSET(ENV{CFLAGS})
 UNSET(ENV{CXXFLAGS})
 UNSET(ENV{LDFLAGS})
 
index f3df43df99148925309bcef782ce67b90f4a9d5b..f2f26ee3120683bca7264e697f49c4a09cd9c135 100644 (file)
 ###########################################################################
 
 #
-# Check the user provided C and CXX flags:
+# Check the user provided CXX flags:
+#
+#
+# Omit to test for a sane C and Fortran toolchain for now..
 #
-
-IF(NOT "${CMAKE_C_FLAGS_SAVED}" STREQUAL "${DEAL_II_C_FLAGS_SAVED}")
-  UNSET(DEAL_II_HAVE_USABLE_C_FLAGS CACHE)
-ENDIF()
-SET(DEAL_II_C_FLAGS_SAVED "${CMAKE_C_FLAGS_SAVED}" CACHE INTERNAL "" FORCE)
-
-SET(CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS_SAVED}")
-CHECK_C_SOURCE_COMPILES(
-  "int main(){ return 0; }"
-  DEAL_II_HAVE_USABLE_C_FLAGS)
-SET(CMAKE_REQUIRED_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()
-
-
 IF(NOT "${CMAKE_CXX_FLAGS_SAVED}" STREQUAL "${DEAL_II_CXX_FLAGS_SAVED}")
   UNSET(DEAL_II_HAVE_USABLE_CXX_FLAGS CACHE)
 ENDIF()
@@ -104,20 +86,6 @@ IF(NOT DEAL_II_HAVE_USABLE_CXX_FLAGS)
 ENDIF()
 
 
-#
-# CMAKE_C_COMPILER and CMAKE_CXX_COMPILER have to be of the same brand.
-#
-IF(NOT ( "${CMAKE_C_COMPILER_ID}" STREQUAL "${CMAKE_CXX_COMPILER_ID}" AND
-         "${CMAKE_C_COMPILER_VERSION}" STREQUAL "${CMAKE_CXX_COMPILER_VERSION}" ) )
-    MESSAGE(FATAL_ERROR "\n"
-      "Configuration error: The specified C and CXX compiler have to be of the "
-      "same family, but cmake found:\n"
-      "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}\n"
-      "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}\n"
-      )
-ENDIF()
-
-
 ###########################################################################
 #                                                                         #
 #                            Compiler setup:                              #
index f5c3a150a16ccfdf807fa73d8c6012f926ab1135..6adfecc7ab8a1eea5d42bd99db29cb8788e97d59 100644 (file)
@@ -18,7 +18,6 @@
 
 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.