From: Matthias Maier Date: Fri, 24 Jul 2020 14:42:17 +0000 (-0500) Subject: CMake: Fix static executable build for cmake 3.9 and newer X-Git-Tag: v9.3.0-rc1~1176^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83cbae7507068ada7452a8650114bd83054cf325;p=dealii.git CMake: Fix static executable build for cmake 3.9 and newer We have to filter the shared low-level runtime library "gcc_s" from the link interface to work around a change in the CMake configuration of Fortran. Closes #9184 --- diff --git a/cmake/modules/FindLAPACK.cmake b/cmake/modules/FindLAPACK.cmake index b512b26070..f56c5b8a4e 100644 --- a/cmake/modules/FindLAPACK.cmake +++ b/cmake/modules/FindLAPACK.cmake @@ -82,12 +82,23 @@ ENDIF() # If CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES is not available, do it # unconditionally for the most common case (gfortran). # -SET(_fortran_libs ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}) -SET_IF_EMPTY(_fortran_libs gfortran m quadmath c) -FOREACH(_lib ${_fortran_libs}) - FIND_SYSTEM_LIBRARY(${_lib}_LIBRARY NAMES ${_lib}) - LIST(APPEND _additional_libraries ${_lib}_LIBRARY) -ENDFOREACH() +IF(NOT BUILD_SHARED_LIBS) + SET(_fortran_libs ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}) + # + # Since CMake 3.9 the gcc runtime libraries libgcc.a and libgcc_s.so.1 + # have been added to the CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES variable. + # We thus have to remove the shared low-level runtime library + # libgcc_s.so.1 from the link interface; otherwise completely static + # linkage is broken. + # + LIST(REMOVE_ITEM _fortran_libs gcc_s) + SET_IF_EMPTY(_fortran_libs gfortran quadmath m) + + FOREACH(_lib ${_fortran_libs}) + FIND_SYSTEM_LIBRARY(${_lib}_LIBRARY NAMES ${_lib}) + LIST(APPEND _additional_libraries ${_lib}_LIBRARY) + ENDFOREACH() +ENDIF() SET(_lapack_include_dirs ${LAPACK_INCLUDE_DIRS})