From: Matthias Maier Date: Sat, 13 Jul 2013 10:17:06 +0000 (+0000) Subject: CMake: Ensure that dynamic/static final linkage of the executable and the correspondi... X-Git-Tag: v8.0.0~131 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=947a6a7138e05b7fd10cf8c1927eef49ccf7ab94;p=dealii.git CMake: Ensure that dynamic/static final linkage of the executable and the corresponding system libraries (shared/static) match git-svn-id: https://svn.dealii.org/trunk@29991 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/cmake/checks/check_02_system_features.cmake b/deal.II/cmake/checks/check_02_system_features.cmake index 128c1cc250..8c94745d8b 100644 --- a/deal.II/cmake/checks/check_02_system_features.cmake +++ b/deal.II/cmake/checks/check_02_system_features.cmake @@ -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() diff --git a/deal.II/cmake/configure/configure_1_lapack.cmake b/deal.II/cmake/configure/configure_1_lapack.cmake index 178fe501d2..ad3fb4fde6 100644 --- a/deal.II/cmake/configure/configure_1_lapack.cmake +++ b/deal.II/cmake/configure/configure_1_lapack.cmake @@ -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 diff --git a/deal.II/cmake/configure/configure_1_threads.cmake b/deal.II/cmake/configure/configure_1_threads.cmake index 1fa55f435e..ad4afe3b72 100644 --- a/deal.II/cmake/configure/configure_1_threads.cmake +++ b/deal.II/cmake/configure/configure_1_threads.cmake @@ -24,7 +24,14 @@ # 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 index 0000000000..d1b91c5645 --- /dev/null +++ b/deal.II/cmake/macros/macro_switch_library_preference.cmake @@ -0,0 +1,31 @@ +##### +## +## Copyright (C) 2013 by the deal.II authors +## +## This file is part of the deal.II library. +## +## +## This file is dual licensed under QPL 1.0 and LGPL 2.1 or any later +## version of the LGPL license. +## +## Author: Matthias Maier +## +##### + +# +# 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()