Protect against underlinking of UMFPACK library
If libumfpack.so does not declare an explicit dependency on libamd.so, the linker option -Wl,--as-needed will cause an undefined reference since we don't use libamd.so ourself. If the configuration determines that this may be the case, a linker option that forces linking the the AMD library is added for the SuiteSparse library, and the general configuration then gets out of the way if this is set.
This commit is contained in:
@@ -37,9 +37,6 @@ include (OpmDefaults)
|
||||
opm_defaults (opm-core)
|
||||
message (STATUS "Build type: ${CMAKE_BUILD_TYPE}")
|
||||
|
||||
# don't import more libraries than we need to
|
||||
include (UseOnlyNeeded)
|
||||
|
||||
# use tricks to do faster builds
|
||||
include (UseFastBuilds)
|
||||
|
||||
@@ -78,6 +75,9 @@ find_and_append_package_list_to (opm-core ${opm-core_DEPS})
|
||||
# it is not possible to query for Boost twice with different components.
|
||||
list (REMOVE_ITEM opm-core_LIBRARIES ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
|
||||
|
||||
# don't import more libraries than we need to
|
||||
include (UseOnlyNeeded)
|
||||
|
||||
# put debug information into every executable
|
||||
include (UseDebugSymbols)
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
# SuiteSparse_INCLUDE_DIRS Paths containing the SuiteSparse header files
|
||||
# SuiteSparse_LIBRARIES Name of the libraries which must be linked
|
||||
# SuiteSparse_DEFINITIONS Defines that must be passed to the compiler
|
||||
# SuiteSparse_LINKER_FLAGS Options that must be passed when linking
|
||||
#
|
||||
# See <http://www.cise.ufl.edu/research/sparse/SuiteSparse>.
|
||||
|
||||
@@ -171,18 +172,28 @@ if (CHOLMOD_LIBRARY)
|
||||
list (REVERSE CHOLMOD_LIBRARIES)
|
||||
endif (CHOLMOD_LIBRARY)
|
||||
if (UMFPACK_LIBRARY)
|
||||
set (UMFPACK_EXTRA_LIBS)
|
||||
# test if umfpack is usable with only amd and not cholmod
|
||||
try_compile_umfpack (HAVE_UMFPACK_WITHOUT_CHOLMOD ${AMD_LIBRARIES})
|
||||
if (HAVE_UMFPACK_WITHOUT_CHOLMOD)
|
||||
list (APPEND UMFPACK_LIBRARIES ${AMD_LIBRARIES})
|
||||
list (APPEND UMFPACK_EXTRA_LIBS ${AMD_LIBRARIES})
|
||||
else (HAVE_UMFPACK_WITHOUT_CHOLMOD)
|
||||
try_compile_umfpack (HAVE_UMFPACK_WITH_CHOLMOD ${CHOLMOD_LIBRARIES})
|
||||
if (HAVE_UMFPACK_WITH_CHOLMOD)
|
||||
list (APPEND UMFPACK_LIBRARIES ${CHOLMOD_LIBRARIES})
|
||||
list (APPEND UMFPACK_EXTRA_LIBS ${CHOLMOD_LIBRARIES})
|
||||
else (HAVE_UMFPACK_WITH_CHOLMOD)
|
||||
set (UMFPACK_LIBRARIES "-NOTFOUND")
|
||||
set (UMFPACK_EXTRA_LIBS "-NOTFOUND")
|
||||
endif (HAVE_UMFPACK_WITH_CHOLMOD)
|
||||
endif (HAVE_UMFPACK_WITHOUT_CHOLMOD)
|
||||
# test if umfpack is underlinked (CentOS 5.9), i.e. doesn't specify
|
||||
# that it depends on amd. in that case, force amd to be linked
|
||||
if ((CMAKE_CXX_PLATFORM_ID STREQUAL "Linux") AND CMAKE_COMPILER_IS_GNUCC)
|
||||
try_compile_umfpack (HAVE_UMFPACK_NOT_UNDERLINKED "-Wl,--as-needed" ${UMFPACK_EXTRA_LIBS})
|
||||
if (NOT HAVE_UMFPACK_NOT_UNDERLINKED)
|
||||
list (APPEND UMFPACK_LINKER_FLAGS "-Wl,--no-as-needed")
|
||||
endif (NOT HAVE_UMFPACK_NOT_UNDERLINKED)
|
||||
endif ((CMAKE_CXX_PLATFORM_ID STREQUAL "Linux") AND CMAKE_COMPILER_IS_GNUCC)
|
||||
list (APPEND UMFPACK_LIBRARIES ${UMFPACK_EXTRA_LIBS})
|
||||
list (REVERSE UMFPACK_LIBRARIES)
|
||||
list (REMOVE_DUPLICATES UMFPACK_LIBRARIES)
|
||||
list (REVERSE UMFPACK_LIBRARIES)
|
||||
@@ -211,6 +222,7 @@ foreach (module IN LISTS SuiteSparse_FIND_COMPONENTS)
|
||||
else (NOT SuiteSparse_${MODULE}_FOUND)
|
||||
set (HAVE_SUITESPARSE_${MODULE}_H 1 CACHE INT "Is ${module} header present?")
|
||||
list (APPEND SuiteSparse_LIBRARIES "${${MODULE}_LIBRARIES}")
|
||||
list (APPEND SuiteSparse_LINKER_FLAGS "${${MODULE}_LINKER_FLAGS}")
|
||||
list (APPEND SuiteSparse_INCLUDE_DIRS "${${MODULE}_INCLUDE_DIRS}")
|
||||
endif (NOT SuiteSparse_${MODULE}_FOUND)
|
||||
mark_as_advanced (HAVE_SUITESPARSE_${MODULE}_H)
|
||||
|
||||
@@ -11,8 +11,26 @@ function (prepend var_name value)
|
||||
endif (${var_name})
|
||||
endfunction (prepend var_name value)
|
||||
|
||||
if (CMAKE_CXX_PLATFORM_ID STREQUAL "Linux")
|
||||
prepend (CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
|
||||
prepend (CMAKE_MODULE_LINKER_FLAGS "-Wl,--as-needed")
|
||||
prepend (CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed")
|
||||
endif (CMAKE_CXX_PLATFORM_ID STREQUAL "Linux")
|
||||
# only ELF shared objects can be underlinked, and only GNU will accept
|
||||
# these parameters; otherwise just leave it to the defaults
|
||||
if ((CMAKE_CXX_PLATFORM_ID STREQUAL "Linux") AND CMAKE_COMPILER_IS_GNUCC)
|
||||
# these are the modules whose probes will turn up incompatible
|
||||
# flags on some systems
|
||||
set (_maybe_underlinked
|
||||
SuiteSparse
|
||||
)
|
||||
# check if any modules actually reported problems (by setting an
|
||||
# appropriate linker flag)
|
||||
set (_underlinked FALSE)
|
||||
foreach (_module IN LISTS _maybe_underlinked)
|
||||
if ("${${_module}_LINKER_FLAGS}" MATCHES "-Wl,--no-as-needed")
|
||||
set (_underlinked TRUE)
|
||||
endif ("${${_module}_LINKER_FLAGS}" MATCHES "-Wl,--no-as-needed")
|
||||
endforeach (_module)
|
||||
# if we didn't have any problems, then go ahead and add
|
||||
if (NOT _underlinked)
|
||||
prepend (CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
|
||||
prepend (CMAKE_MODULE_LINKER_FLAGS "-Wl,--as-needed")
|
||||
prepend (CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed")
|
||||
endif (NOT _underlinked)
|
||||
endif ((CMAKE_CXX_PLATFORM_ID STREQUAL "Linux") AND CMAKE_COMPILER_IS_GNUCC)
|
||||
|
||||
Reference in New Issue
Block a user