]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
CMake: Ensure that dynamic/static final linkage of the executable and the correspondi...
authormaier <maier@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 13 Jul 2013 10:17:06 +0000 (10:17 +0000)
committermaier <maier@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 13 Jul 2013 10:17:06 +0000 (10:17 +0000)
git-svn-id: https://svn.dealii.org/trunk@29991 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/cmake/checks/check_02_system_features.cmake
deal.II/cmake/configure/configure_1_lapack.cmake
deal.II/cmake/configure/configure_1_threads.cmake
deal.II/cmake/macros/macro_switch_library_preference.cmake [new file with mode: 0644]

index 128c1cc250e48f9edde791c2eceb2b9349e21be8..8c94745d8b3a09d632c95ed1fda6bc7b277ec335 100644 (file)
@@ -56,15 +56,21 @@ CHECK_CXX_SYMBOL_EXISTS("rand_r" "stdlib.h" HAVE_RAND_R)
 #
 # Do we have the Bessel function jn?
 #
-FIND_LIBRARY(m_lib NAMES m)
-MARK_AS_ADVANCED(m_lib)
+# 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_LIBRARY(m_LIBRARY NAMES m)
+SWITCH_LIBRARY_PREFERENCE()
+MARK_AS_ADVANCED(m_LIBRARY)
 
-IF(NOT m_lib MATCHES "-NOTFOUND")
-  SET(CMAKE_REQUIRED_LIBRARIES ${m_lib})
+IF(NOT m_LIBRARY MATCHES "-NOTFOUND")
+  SET(CMAKE_REQUIRED_LIBRARIES ${m_LIBRARY})
   CHECK_CXX_SYMBOL_EXISTS("jn" "math.h" HAVE_JN)
   SET(CMAKE_REQUIRED_LIBRARIES)
   IF(HAVE_JN)
-    LIST(APPEND DEAL_II_EXTERNAL_LIBRARIES ${m_lib})
+    LIST(APPEND DEAL_II_EXTERNAL_LIBRARIES ${m_LIBRARY})
   ENDIF()
 ENDIF()
 
index 178fe501d28e7c5baa6ca12d6b5d27ed79c1bb8c..ad3fb4fde6f0d1033f4639bc30497f8ed75f65fd 100644 (file)
@@ -45,16 +45,23 @@ MACRO(FEATURE_LAPACK_FIND_EXTERNAL var)
     # Do this unconditionally for the most common case:
     # TODO: Non-GNU setups...
     #
+    #
+    # 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()
     FOREACH(_lib gfortran m quadmath)
-      FIND_LIBRARY(${_lib}_lib
+      FIND_LIBRARY(${_lib}_LIBRARY
         NAMES ${_lib}
         HINTS ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES})
-      MARK_AS_ADVANCED(${_lib}_lib)
+      MARK_AS_ADVANCED(${_lib}_LIBRARY)
 
-      IF(NOT ${_lib}_lib MATCHES "-NOTFOUND")
-        LIST(APPEND LAPACK_LIBRARIES ${${_lib}_lib})
+      IF(NOT ${_lib}_LIBRARY MATCHES "-NOTFOUND")
+        LIST(APPEND LAPACK_LIBRARIES ${${_lib}_LIBRARY})
       ENDIF()
     ENDFOREACH()
+    SWITCH_LIBRARY_PREFERENCE()
 
     MARK_AS_ADVANCED(
       atlas_LIBRARY
index 1fa55f435e6d8217f4205f38a7618284eb46dc3c..ad4afe3b72552fac08f644cb2e3e6caf9ca841ef 100644 (file)
 # The macro will be included in CONFIGURE_FEATURE_THREADS_EXTERNAL/BUNDLED.
 #
 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.
+  #
+  SWITCH_LIBRARY_PREFERENCE()
   FIND_PACKAGE(Threads)
+  SWITCH_LIBRARY_PREFERENCE()
 
   IF(NOT Threads_FOUND)
     # TODO:
diff --git a/deal.II/cmake/macros/macro_switch_library_preference.cmake b/deal.II/cmake/macros/macro_switch_library_preference.cmake
new file mode 100644 (file)
index 0000000..d1b91c5
--- /dev/null
@@ -0,0 +1,31 @@
+#####
+##
+## Copyright (C) 2013 by the deal.II authors
+##
+## This file is part of the deal.II library.
+##
+## <TODO: Full License information>
+## This file is dual licensed under QPL 1.0 and LGPL 2.1 or any later
+## version of the LGPL license.
+##
+## Author: Matthias Maier <matthias.maier@iwr.uni-heidelberg.de>
+##
+#####
+
+#
+# This macro toggles the preference for static/shared libraries if
+# DEAL_II_PREFER_STATIC_LIBS=TRUE but the final executable will still be
+# dynamically linked, i.e. DEAL_II_STATIC_EXECUTABLE=OFF
+#
+# Usage:
+#     SWITCH_LIBRARY_PREFERENCE()
+#
+
+MACRO(SWITCH_LIBRARY_PREFERENCE)
+  IF(DEAL_II_PREFER_STATIC_LIBS AND NOT DEAL_II_STATIC_EXECUTABLE)
+    #
+    # Invert the search order for libraries when DEAL_II_PREFER_STATIC_LIBS
+    # is set. This will prefer static archives instead of shared libraries:
+    LIST(REVERSE CMAKE_FIND_LIBRARY_SUFFIXES)
+  ENDIF()
+ENDMACRO()

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.