From 67ddd4afc4fea722eb376a9fd3d27f2db39c5b0c Mon Sep 17 00:00:00 2001 From: maier Date: Sat, 1 Feb 2014 21:53:29 +0000 Subject: [PATCH] CMake: Break everything (tm) - Do not record full path of system libraries and use reduced link line instead. git-svn-id: https://svn.dealii.org/trunk@32369 0785d39b-7218-0410-832d-ea1e28bc413d --- .../checks/check_02_system_features.cmake | 8 +-- .../cmake/configure/configure_1_threads.cmake | 12 ++--- .../macro_filter_system_libraries.cmake | 43 ++++++++++++++++ .../macros/macro_find_system_library.cmake | 50 +++++++++++++++++++ deal.II/cmake/modules/FindDEALII_LAPACK.cmake | 13 +---- deal.II/cmake/modules/FindPETSC.cmake | 14 ++++-- deal.II/cmake/modules/FindUMFPACK.cmake | 4 +- deal.II/cmake/setup_finalize.cmake | 1 + deal.II/doc/news/changes.h | 5 ++ 9 files changed, 117 insertions(+), 33 deletions(-) create mode 100644 deal.II/cmake/macros/macro_filter_system_libraries.cmake create mode 100644 deal.II/cmake/macros/macro_find_system_library.cmake diff --git a/deal.II/cmake/checks/check_02_system_features.cmake b/deal.II/cmake/checks/check_02_system_features.cmake index df8616c2cc..259465b9f9 100644 --- a/deal.II/cmake/checks/check_02_system_features.cmake +++ b/deal.II/cmake/checks/check_02_system_features.cmake @@ -58,13 +58,7 @@ CHECK_CXX_SYMBOL_EXISTS("rand_r" "stdlib.h" HAVE_RAND_R) # # Do we have the Bessel function jn? # -# 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() +FIND_SYSTEM_LIBRARY(m_LIBRARY NAMES m) MARK_AS_ADVANCED(m_LIBRARY) IF(NOT m_LIBRARY MATCHES "-NOTFOUND") diff --git a/deal.II/cmake/configure/configure_1_threads.cmake b/deal.II/cmake/configure/configure_1_threads.cmake index bc698ad595..1d712c04b7 100644 --- a/deal.II/cmake/configure/configure_1_threads.cmake +++ b/deal.II/cmake/configure/configure_1_threads.cmake @@ -30,22 +30,16 @@ MACRO(SETUP_THREADING) # Unfortunately the FindThreads macro needs a working C compiler # 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 must be linked dynamically. - # - SWITCH_LIBRARY_PREFERENCE() - # # Clear the test flags because FindThreads.cmake will use a C compiler: # CLEAR_CMAKE_REQUIRED() + SWITCH_LIBRARY_PREFERENCE() FIND_PACKAGE(Threads) + SWITCH_LIBRARY_PREFERENCE() RESET_CMAKE_REQUIRED() - SWITCH_LIBRARY_PREFERENCE() ELSE() @@ -214,7 +208,7 @@ MACRO(FEATURE_THREADS_CONFIGURE_BUNDLED) # # TODO: Also necessary for external lib, use preference toggle # - FIND_LIBRARY(dl_LIBRARY NAMES dl) + FIND_SYSTEM_LIBRARY(dl_LIBRARY NAMES dl) MARK_AS_ADVANCED(dl_LIBRARY) IF(NOT dl_LIBRARY MATCHES "-NOTFOUND") LIST(APPEND THREADS_LIBRARIES ${dl_LIBRARY}) diff --git a/deal.II/cmake/macros/macro_filter_system_libraries.cmake b/deal.II/cmake/macros/macro_filter_system_libraries.cmake new file mode 100644 index 0000000000..49b4e75bf3 --- /dev/null +++ b/deal.II/cmake/macros/macro_filter_system_libraries.cmake @@ -0,0 +1,43 @@ +## --------------------------------------------------------------------- +## $Id$ +## +## Copyright (C) 2014 by the deal.II authors +## +## This file is part of the deal.II library. +## +## The deal.II library is free software; you can use it, redistribute +## it, and/or modify it under the terms of the GNU Lesser General +## Public License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## The full text of the license can be found in the file LICENSE at +## the top level of the deal.II distribution. +## +## --------------------------------------------------------------------- + +# +# This macro replaces absolute paths to system libraries with the +# corresponding short name within the FEATURE_LIBRARIES(|_DEBUG|_RELEASE) +# variables +# +# Usage: +# FILTER_SYSTEM_LIBRARIES(feature) +# + +MACRO(FILTER_SYSTEM_LIBRARIES _feature) + FOREACH(_variable + ${_feature}_LIBRARIES + ${_feature}_LIBRARIES_DEBUG + ${_feature}_LIBRARIES_RELEASE + ) + IF(DEFINED ${_variable}) + SET(_tmp_${_variable} ${${_variable}}) + SET(${_variable} "") + FOREACH(_lib ${_tmp_${_variable}}) + IF(_lib MATCHES "lib(c|quadmath|gfortran|m|rt|nsl|dl|pthread).so$") + string(REGEX REPLACE ".*lib([a-z]+).so$" "\\1" _lib ${_lib}) + ENDIF() + LIST(APPEND ${_variable} ${_lib}) + ENDFOREACH() + ENDIF() + ENDFOREACH() +ENDMACRO() diff --git a/deal.II/cmake/macros/macro_find_system_library.cmake b/deal.II/cmake/macros/macro_find_system_library.cmake new file mode 100644 index 0000000000..eda5e4a83c --- /dev/null +++ b/deal.II/cmake/macros/macro_find_system_library.cmake @@ -0,0 +1,50 @@ +## --------------------------------------------------------------------- +## $Id$ +## +## Copyright (C) 2013 - 2014 by the deal.II authors +## +## This file is part of the deal.II library. +## +## The deal.II library is free software; you can use it, redistribute +## it, and/or modify it under the terms of the GNU Lesser General +## Public License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## The full text of the license can be found in the file LICENSE at +## the top level of the deal.II distribution. +## +## --------------------------------------------------------------------- + +# +# Search for a system library. In contrast to normal libraries we do this +# purely via "-l" instead of selecting a full library path.. +# +# USAGE: +# FIND_SYSTEM_LIBRARY(variable NAMES [list of possible names]) +# + +MACRO(FIND_SYSTEM_LIBRARY) + SET(_argn ${ARGN}) + LIST(GET _argn 0 _variable) + LIST(REMOVE_AT _argn 0 1) + + if("${_variable}" MATCHES "^${_variable}$") + FOREACH(_arg ${_argn}) + LIST(APPEND CMAKE_REQUIRED_LIBRARIES "-l${_arg}") + CHECK_CXX_COMPILER_FLAG("" ${_variable}) + RESET_CMAKE_REQUIRED() + + IF(${_variable}) + UNSET(${_variable} CACHE) + SET(${_variable} ${_arg} CACHE STRING "A system library.") + SET(${_variable} ${_arg}) + BREAK() + ELSE() + UNSET(${_variable} CACHE) + ENDIF() + ENDFOREACH() + + IF(NOT _variable) + SET(${_variable} "${_variable}-NOTFOUND") + ENDIF() + ENDIF() +ENDMACRO() diff --git a/deal.II/cmake/modules/FindDEALII_LAPACK.cmake b/deal.II/cmake/modules/FindDEALII_LAPACK.cmake index 378851f71c..4257ab332d 100644 --- a/deal.II/cmake/modules/FindDEALII_LAPACK.cmake +++ b/deal.II/cmake/modules/FindDEALII_LAPACK.cmake @@ -94,28 +94,19 @@ IF(LAPACK_FOUND) # If CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES is not available, do it # unconditionally for the most common case (gfortran). # - # 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. - # SET(_fortran_libs ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}) SET_IF_EMPTY(_fortran_libs gfortran m quadmath c) - SWITCH_LIBRARY_PREFERENCE() FOREACH(_lib ${_fortran_libs}) - FIND_LIBRARY(${_lib}_LIBRARY - NAMES ${_lib} - HINTS - ${CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES} - ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}) + FIND_SYSTEM_LIBRARY(${_lib}_LIBRARY NAMES ${_lib}) MARK_AS_ADVANCED(${_lib}_LIBRARY) IF(NOT ${_lib}_LIBRARY MATCHES "-NOTFOUND") LIST(APPEND BLAS_LIBRARIES ${${_lib}_LIBRARY}) LIST(APPEND LAPACK_LIBRARIES ${${_lib}_LIBRARY}) ENDIF() + ENDFOREACH() - SWITCH_LIBRARY_PREFERENCE() # # Filter out spurious "FALSE" in the library lists: diff --git a/deal.II/cmake/modules/FindPETSC.cmake b/deal.II/cmake/modules/FindPETSC.cmake index 1a4f3122c4..7bd039a11c 100644 --- a/deal.II/cmake/modules/FindPETSC.cmake +++ b/deal.II/cmake/modules/FindPETSC.cmake @@ -137,7 +137,16 @@ IF(NOT PETSC_PETSCVARIABLES MATCHES "-NOTFOUND") ELSEIF(_token MATCHES "^-l") # Search for every library that was specified with -l: STRING(REGEX REPLACE "^-l" "" _token "${_token}") - IF(NOT _token MATCHES "(petsc|stdc\\+\\+|gcc_s)") + + IF(_token MATCHES "^(c|quadmath|gfortran|m|rt|nsl|dl|pthread)$") + FIND_SYSTEM_LIBRARY(PETSC_LIBRARY_${_token} NAMES ${_token}) + IF(NOT PETSC_LIBRARY_${_token} MATCHES "-NOTFOUND") + LIST(APPEND _petsc_libraries ${PETSC_LIBRARY_${_token}}) + ENDIF() + # Remove from cache, so that updating PETSC search paths will + # find a (possibly) new link interface + UNSET(PETSC_LIBRARY_${_token} CACHE) + ELSEIF(NOT _token MATCHES "(petsc|stdc\\+\\+|gcc_s)") FIND_LIBRARY(PETSC_LIBRARY_${_token} NAMES ${_token} HINTS ${_hints} @@ -145,12 +154,11 @@ IF(NOT PETSC_PETSCVARIABLES MATCHES "-NOTFOUND") IF(NOT PETSC_LIBRARY_${_token} MATCHES "-NOTFOUND") LIST(APPEND _petsc_libraries ${PETSC_LIBRARY_${_token}}) ENDIF() - # # Remove from cache, so that updating PETSC search paths will # find a (possibly) new link interface - # UNSET(PETSC_LIBRARY_${_token} CACHE) ENDIF() + ENDIF() ENDFOREACH() diff --git a/deal.II/cmake/modules/FindUMFPACK.cmake b/deal.II/cmake/modules/FindUMFPACK.cmake index 71f9361e1a..7594366b1e 100644 --- a/deal.II/cmake/modules/FindUMFPACK.cmake +++ b/deal.II/cmake/modules/FindUMFPACK.cmake @@ -179,9 +179,7 @@ IF(UMFPACK_FOUND) # lib does not record its dependence on librt.so as evidenced # by ldd :-( ): # - SWITCH_LIBRARY_PREFERENCE() - FIND_LIBRARY(rt_LIBRARY NAMES rt) - SWITCH_LIBRARY_PREFERENCE() + FIND_SYSTEM_LIBRARY(rt_LIBRARY NAMES rt) MARK_AS_ADVANCED(rt_LIBRARY) IF(NOT rt_LIBRARY MATCHES "-NOTFOUND") LIST(APPEND UMFPACK_LIBRARIES ${rt_LIBRARY}) diff --git a/deal.II/cmake/setup_finalize.cmake b/deal.II/cmake/setup_finalize.cmake index 92ed551db2..e304e24f52 100644 --- a/deal.II/cmake/setup_finalize.cmake +++ b/deal.II/cmake/setup_finalize.cmake @@ -82,6 +82,7 @@ ENDFOREACH() # Register features: # FOREACH(_feature ${DEAL_II_FEATURES}) + FILTER_SYSTEM_LIBRARIES(${_feature}) REGISTER_FEATURE(${_feature}) ENDFOREACH() diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index a083239b46..a767e1aa5d 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -124,6 +124,11 @@ inconvenience this causes.

Specific improvements

    +
  1. Fixed: The build system does no longer record full paths to system + libraries but uses the appropriate short names instead. +
    + (Matthias Maier, 2014/02/01) +
  2. Reworked: External feature setup. Disabling a feature now cleans up associated internal, cached variables. A per-feature linkage test now spots common linking inconsistencies early in the configuration stage (and not -- 2.39.5