From 76926b7fcf9828b774d2cf6fbfd4da3be4898b01 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Sun, 27 Aug 2017 03:54:40 -0400 Subject: [PATCH] Compile linalg as library and track link dependencies for correct link order --- cmake/CMakeLists.txt | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 53984cbf17..6abf445f3d 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -162,12 +162,23 @@ endif() if(ENABLE_MSCG OR ENABLE_USER-ATC OR ENABLE_USER-AWPMD OR ENABLE_USER-QUIP) find_package(LAPACK) - if(LAPACK_FOUND) - list(APPEND LAMMPS_LINK_LIBS ${LAPACK_LIBRARIES}) - else() + if(NOT LAPACK_FOUND) enable_language(Fortran) file(GLOB LAPACK_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/linalg/*.f) - list(APPEND LIB_SOURCES ${LAPACK_SOURCES}) + + if(BUILD_SHARED_PKG_LIBS) + add_library(linalg SHARED ${LAPACK_SOURCES}) + set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) + if(INSTALL_LIB) + install(TARGETS linalg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + else() + message(FATAL_ERROR "Shared library has to be installed, use -DINSTALL_LIB=ON to install lammps with a library") + endif() + else() + add_library(linalg STATIC ${LAPACK_SOURCES}) + endif() + target_compile_options(linalg PRIVATE -fno-second-underscore) + set(LAPACK_LIBRARIES linalg) endif() endif() @@ -368,6 +379,14 @@ foreach(SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD endif() endforeach() +if(ENABLE_USER-AWPMD) + target_link_libraries(awpmd ${LAPACK_LIBRARIES}) +endif() + +if(ENABLE_USER-ATC) + target_link_libraries(atc ${LAPACK_LIBRARIES}) +endif() + if(ENABLE_USER-H5MD) find_package(HDF5 REQUIRED) target_link_libraries(h5md ${HDF5_LIBRARIES})