]> https://gitweb.dealii.org/ - dealii.git/commitdiff
CMake: Rewrite parts of FindTrilinos.cmake to be way faster
authorMatthias Maier <tamiko@kyomu.43-1.org>
Sat, 17 Aug 2013 15:03:26 +0000 (15:03 +0000)
committerMatthias Maier <tamiko@kyomu.43-1.org>
Sat, 17 Aug 2013 15:03:26 +0000 (15:03 +0000)
git-svn-id: https://svn.dealii.org/trunk@30332 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/cmake/configure/configure_2_trilinos.cmake
deal.II/cmake/modules/FindTRILINOS.cmake
deal.II/cmake/setup_finalize.cmake

index 10cbe49551a26e256c60b161b4cc56bf9a5f7db4..3669492796fab047a6afeb9114f7110b639c31f3 100644 (file)
@@ -131,10 +131,10 @@ MACRO(FEATURE_TRILINOS_FIND_EXTERNAL var)
         "has to be configured to use the same number of bits as deal.II, but "
         "found:\n"
         "  DEAL_II_WITH_64BIT_INDICES = ${DEAL_II_WITH_64BIT_INDICES}\n"
-        "  TRILINOS_WITH_NO_32BIT_INDICES = ${TRILINOS_WITH_NO_32_BIT_INDICES}\n" 
+        "  TRILINOS_WITH_NO_32BIT_INDICES = ${TRILINOS_WITH_NO_32_BIT_INDICES}\n"
         )
       SET(${var} FALSE)
-    ENDIF()  
+    ENDIF()
 
     #
     # Trilinos has to be configured with 64bit indices if deal.II uses unsigned long
@@ -143,73 +143,41 @@ MACRO(FEATURE_TRILINOS_FIND_EXTERNAL var)
     IF(TRILINOS_WITH_NO_64BIT_INDICES AND DEAL_II_WITH_64BIT_INDICES)
       MESSAGE(STATUS "deal.II was configured to use 64bit global indices but "
         "Trilinos was not."
-        ) 
+        )
       SET(TRILINOS_ADDITIONAL_ERROR_STRING
         ${TRILINOS_ADDITIONAL_ERROR_STRING}
         "The Trilinos installation (found at \"${TRILINOS_DIR}\")\n"
         "has to be configured to use the same number of bits as deal.II, but "
         "found:\n"
         "  DEAL_II_WITH_64BIT_INDICES = ${DEAL_II_WITH_64BIT_INDICES}\n"
-        "  TRILINOS_WITH_NO_64BIT_INDICES = ${TRILINOS_WITH_NO_64_BIT_INDICES}\n" 
+        "  TRILINOS_WITH_NO_64BIT_INDICES = ${TRILINOS_WITH_NO_64_BIT_INDICES}\n"
         )
       SET(${var} FALSE)
-    ENDIF()  
-
+    ENDIF()
 
     #
     # Some versions of Sacado_cmath.hpp do things that aren't compatible
     # with the -std=c++0x flag of GCC, see deal.II FAQ.
     # Test whether that is indeed the case
     #
-    IF(${var})
-      LIST(APPEND CMAKE_REQUIRED_INCLUDES ${TRILINOS_INCLUDE_DIRS})
-      PUSH_TEST_FLAG("${DEAL_II_CXX11_FLAG}")
-
-      CHECK_CXX_SOURCE_COMPILES(
-        "
-        #include <Sacado_cmath.hpp>
-        int main(){ return 0; }
-        "
-        TRILINOS_SUPPORTS_CPP11)
-
-      IF(DEAL_II_CAN_USE_CXX11 AND NOT TRILINOS_SUPPORTS_CPP11)
-        #
-        # Try whether exporting HAS_C99_TR1_CMATH helps:
-        #
-        PUSH_TEST_FLAG("-DHAS_C99_TR1_CMATH")
-        CHECK_CXX_SOURCE_COMPILES(
-          "
-          #include <Sacado_cmath.hpp>
-          int main(){ return 0; }
-          "
-          TRILINOS_HAS_C99_TR1_WORKAROUND)
-        POP_TEST_FLAG()
-
-        IF(TRILINOS_HAS_C99_TR1_WORKAROUND)
-          LIST(APPEND DEAL_II_DEFINITIONS "HAS_C99_TR1_CMATH")
-          LIST(APPEND DEAL_II_USER_DEFINITIONS "HAS_C99_TR1_CMATH")
-        ELSE()
-          MESSAGE(STATUS "Could not find a sufficient Trilinos installation: "
-            "The installation is not compatible with the C++ standard selected for "
-            "this compiler."
-            )
-          SET(TRILINOS_ADDITIONAL_ERROR_STRING
-            ${TRILINOS_ADDITIONAL_ERROR_STRING}
-            "The Trilinos installation (found at \"${TRILINOS_DIR}\")\n"
-            "is not compatible with the C++ standard selected for\n"
-            "this compiler. See the deal.II FAQ page for a solution.\n\n"
-            )
-          SET(${var} FALSE)
-        ENDIF()
-      ENDIF()
+    IF(DEAL_II_CAN_USE_CXX11 AND NOT TRILINOS_SUPPORTS_CPP11)
 
-      RESET_CMAKE_REQUIRED()
-
-      #
-      # Remove the following variables from the cache to force a recheck:
-      #
-      UNSET(TRILINOS_SUPPORTS_CPP11 CACHE)
-      UNSET(TRILINOS_HAS_C99_TR1_WORKAROUND CACHE)
+      IF(TRILINOS_HAS_C99_TR1_WORKAROUND)
+        LIST(APPEND DEAL_II_DEFINITIONS "HAS_C99_TR1_CMATH")
+        LIST(APPEND DEAL_II_USER_DEFINITIONS "HAS_C99_TR1_CMATH")
+      ELSE()
+        MESSAGE(STATUS "Could not find a sufficient Trilinos installation: "
+          "The installation is not compatible with the C++ standard selected for "
+          "this compiler."
+          )
+        SET(TRILINOS_ADDITIONAL_ERROR_STRING
+          ${TRILINOS_ADDITIONAL_ERROR_STRING}
+          "The Trilinos installation (found at \"${TRILINOS_DIR}\")\n"
+          "is not compatible with the C++ standard selected for\n"
+          "this compiler. See the deal.II FAQ page for a solution.\n\n"
+          )
+        SET(${var} FALSE)
+      ENDIF()
     ENDIF()
 
   ENDIF(TRILINOS_FOUND)
@@ -217,13 +185,6 @@ ENDMACRO()
 
 
 MACRO(FEATURE_TRILINOS_CONFIGURE_EXTERNAL)
-  #
-  # *Boy* Sanitize the include paths given by TrilinosConfig.cmake...
-  #
-  STRING(REGEX REPLACE
-    "(lib64|lib)\\/cmake\\/Trilinos\\/\\.\\.\\/\\.\\.\\/\\.\\.\\/" ""
-    TRILINOS_INCLUDE_DIRS "${TRILINOS_INCLUDE_DIRS}"
-    )
 
   INCLUDE_DIRECTORIES(${TRILINOS_INCLUDE_DIRS})
 
index 184056045874e939441c3bf118dd0d8d7d71da6b..b347b32ccf7cb9304d2b366a52ede902ffa69f0d 100644 (file)
@@ -19,7 +19,7 @@
 #
 # This module exports:
 #
-#   TRILINOS_DIR (cached)
+#   TRILINOS_DIR
 #   TRILINOS_INCLUDE_DIRS
 #   TRILINOS_LIBRARIES
 #   TRILINOS_VERSION
@@ -27,6 +27,8 @@
 #   TRILINOS_VERSION_MINOR
 #   TRILINOS_VERSION_SUBMINOR
 #   TRILINOS_WITH_MPI
+#   TRILINOS_SUPPORTS_CPP11
+#   TRILINOS_HAS_C99_TR1_WORKAROUND
 #
 
 INCLUDE(FindPackageHandleStandardArgs)
@@ -34,13 +36,13 @@ INCLUDE(FindPackageHandleStandardArgs)
 SET_IF_EMPTY(TRILINOS_DIR "$ENV{TRILINOS_DIR}")
 
 #
-# Include the trilinos package configuration:
+# Do not include TrilinosConfig.cmake directly, it is just too big o_O
 #
-FIND_PACKAGE(TRILINOS_CONFIG
-  CONFIG QUIET
-  NAMES Trilinos TRILINOS
+# Just search for the file:
+#
+FIND_FILE(TRILINOS_CONFIG
+  NAMES TrilinosConfig.cmake trilinos-config.cmake
   HINTS
-    ${TRILINOS_DIR}/lib/cmake/Trilinos
     ${TRILINOS_DIR}
   PATH_SUFFIXES
     lib64/cmake/Trilinos
@@ -51,7 +53,72 @@ FIND_PACKAGE(TRILINOS_CONFIG
   NO_SYSTEM_ENVIRONMENT_PATH
   )
 
-SET(TRILINOS_INCLUDE_DIRS ${Trilinos_INCLUDE_DIRS})
+IF(NOT "${TRILINOS_CONFIG}" STREQUAL "${TRILINOS_CONFIG_SAVED}")
+  SET(_new_trilinos_config TRUE)
+ENDIF()
+SET(TRILINOS_CONFIG_SAVED "${TRILINOS_CONFIG}" CACHE INTERNAL "" FORCE)
+
+
+IF(NOT TRILINOS_CONFIG MATCHES "-NOTFOUND")
+
+  SET(_filtered_trilinos_config
+    "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TrilinosConfig.cmake"
+    )
+
+  IF(_new_trilinos_config)
+    GET_FILENAME_COMPONENT(_trilinos_path "${TRILINOS_CONFIG}" PATH)
+    FILE(WRITE ${_filtered_trilinos_config} "SET(_cmake_current_list_dir ${_trilinos_path})\n")
+
+    #
+    # Only pick up every line that starts with "^SET("...
+    #
+    FILE(STRINGS "${TRILINOS_CONFIG}" _trilinos_config_filtered REGEX "^SET")
+
+    FOREACH(_line ${_trilinos_config_filtered})
+      STRING(REPLACE "CMAKE_CURRENT_LIST_DIR" "_cmake_current_list_dir"
+        _line "${_line}"
+        )
+      FILE(APPEND ${_filtered_trilinos_config} "${_line}\n")
+    ENDFOREACH()
+  ENDIF()
+
+  #
+  # ... and include only that:
+  #
+  INCLUDE(${_filtered_trilinos_config})
+
+  SET(TRILINOS_CONFIG_FOUND TRUE)
+ENDIF()
+
+
+#
+# Look for the one include file that we'll query for further information:
+#
+IF(_new_trilinos_config)
+  UNSET(EPETRA_CONFIG_H CACHE)
+ENDIF()
+FIND_FILE(EPETRA_CONFIG_H Epetra_config.h
+  HINTS ${Trilinos_INCLUDE_DIRS}
+  NO_DEFAULT_PATH
+  NO_CMAKE_ENVIRONMENT_PATH
+  NO_CMAKE_PATH
+  NO_SYSTEM_ENVIRONMENT_PATH
+  NO_CMAKE_SYSTEM_PATH
+  NO_CMAKE_FIND_ROOT_PATH
+  )
+IF(EPETRA_CONFIG_H MATCHES "-NOTFOUND")
+  SET(TRILINOS_CONFIG_FOUND FALSE)
+ELSE()
+  SET(TRILINOS_INCLUDE_DIRS ${Trilinos_INCLUDE_DIRS})
+  #
+  # *Boy* Sanitize the include paths given by TrilinosConfig.cmake...
+  #
+  STRING(REGEX REPLACE
+    "(lib64|lib)\\/cmake\\/Trilinos\\/\\.\\.\\/\\.\\.\\/\\.\\.\\/" ""
+    TRILINOS_INCLUDE_DIRS "${TRILINOS_INCLUDE_DIRS}"
+    )
+ENDIF()
+
 
 #
 # We'd like to have the full library names but the Trilinos package only
@@ -59,6 +126,10 @@ SET(TRILINOS_INCLUDE_DIRS ${Trilinos_INCLUDE_DIRS})
 # So we check again for every lib and store the full path:
 #
 FOREACH(_library ${Trilinos_LIBRARIES})
+  IF(_new_trilinos_config)
+    UNSET(TRILINOS_LIBRARY_${_library} CACHE)
+  ENDIF()
+
   FIND_LIBRARY(TRILINOS_LIBRARY_${_library}
     NAMES ${_library}
     HINTS ${Trilinos_LIBRARY_DIRS}
@@ -70,13 +141,11 @@ FOREACH(_library ${Trilinos_LIBRARIES})
     NO_CMAKE_FIND_ROOT_PATH
     )
 
-  LIST(APPEND TRILINOS_LIBRARIES ${TRILINOS_LIBRARY_${_library}})
-
-  #
-  # Remove the variables from the cache, so that updating TRILINOS_DIR will
-  # find the new libraries..
-  #
-  UNSET(TRILINOS_LIBRARY_${_library} CACHE)
+  IF(TRILINOS_LIBRARY_${_library} MATCHES "-NOTFOUND")
+    SET(TRILINOS_CONFIG_FOUND FALSE)
+  ELSE()
+    LIST(APPEND TRILINOS_LIBRARIES ${TRILINOS_LIBRARY_${_library}})
+  ENDIF()
 ENDFOREACH()
 
 #
@@ -116,15 +185,6 @@ IF(TRILINOS_FOUND)
   #
   # Determine whether Trilinos was configured with MPI and 64bit indices:
   #
-  FIND_FILE(EPETRA_CONFIG_H Epetra_config.h
-    HINTS ${TRILINOS_INCLUDE_DIRS}
-    NO_DEFAULT_PATH
-    NO_CMAKE_ENVIRONMENT_PATH
-    NO_CMAKE_PATH
-    NO_SYSTEM_ENVIRONMENT_PATH
-    NO_CMAKE_SYSTEM_PATH
-    NO_CMAKE_FIND_ROOT_PATH
-    )
   FILE(STRINGS "${EPETRA_CONFIG_H}" EPETRA_MPI_STRING
     REGEX "#define HAVE_MPI")
   IF("${EPETRA_MPI_STRING}" STREQUAL "")
@@ -147,10 +207,46 @@ IF(TRILINOS_FOUND)
     SET(TRILINOS_WITH_NO_64BITS_INDICES FALSE)
   ENDIF()
 
-  UNSET(EPETRA_CONFIG_H CACHE)
+  #
+  # Some versions of Sacado_cmath.hpp do things that aren't compatible
+  # with the -std=c++0x flag of GCC, see deal.II FAQ.
+  # Test whether that is indeed the case:
+  #
+  IF(_new_trilinos_config)
+    UNSET(TRILINOS_SUPPORTS_CPP11 CACHE)
+    UNSET(TRILINOS_HAS_C99_TR1_WORKAROUND CACHE)
+  ENDIF()
+
+  LIST(APPEND CMAKE_REQUIRED_INCLUDES ${TRILINOS_INCLUDE_DIRS})
+  PUSH_TEST_FLAG("${DEAL_II_CXX11_FLAG}")
+
+  CHECK_CXX_SOURCE_COMPILES(
+    "
+    #include <Sacado_cmath.hpp>
+    int main(){ return 0; }
+    "
+    TRILINOS_SUPPORTS_CPP11
+    )
+
+  #
+  # Try whether exporting HAS_C99_TR1_CMATH helps:
+  #
+  PUSH_TEST_FLAG("-DHAS_C99_TR1_CMATH")
+  CHECK_CXX_SOURCE_COMPILES(
+    "
+    #include <Sacado_cmath.hpp>
+    int main(){ return 0; }
+    "
+    TRILINOS_HAS_C99_TR1_WORKAROUND
+    )
+
+  RESET_CMAKE_REQUIRED()
+
 
   MARK_AS_ADVANCED(TRILINOS_DIR)
+
 ELSE()
+
   SET(TRILINOS_DIR "" CACHE PATH
     "An optional hint to a Trilinos installation"
     )
index c90b9263cac4448a66b49d550d2c859e2399c9f4..a651931f347fa18cf161cb2e85d7ef00fa2fa6a2 100644 (file)
@@ -172,9 +172,7 @@ FOREACH(_var ${_variables})
     LIST(APPEND _components "${_var}")
   ELSEIF(_var MATCHES "(MPI_CXX_COMPILER|MPI_CXX_COMPILE_FLAGS|MPI_CXX_LINK_FLAGS)")
     LIST(APPEND _features_config ${_var})
-  ELSEIF(_var MATCHES "(LIBRARIES|INCLUDE_PATH|INCLUDE_DIRS|LINKER_FLAGS)"
-         # Avoid a lot of Trilinos variables:
-         AND (NOT _var MATCHES "_TPL_|_MPI_") )
+  ELSEIF(_var MATCHES "(LIBRARIES|INCLUDE_PATH|INCLUDE_DIRS|LINKER_FLAGS)")
     LIST(APPEND _features_config ${_var})
   ENDIF()
 ENDFOREACH()

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.