Commit c8aa06b9 authored by Christoph Junghans's avatar Christoph Junghans
Browse files

cmake: build libs separate

parent b11fe2ed
Loading
Loading
Loading
Loading
+20 −6
Original line number Diff line number Diff line
@@ -348,12 +348,26 @@ endforeach()
foreach(SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD
  USER-MOLFILE USER-QMMM)
  if(ENABLE_${SIMPLE_LIB})
    string(REGEX REPLACE "^USER-" "" SIMPLE_LIB "${SIMPLE_LIB}")
    string(TOLOWER "${SIMPLE_LIB}" INC_DIR)
    file(GLOB_RECURSE ${SIMPLE_LIB}_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/${INC_DIR}/*.F
      ${LAMMPS_LIB_SOURCE_DIR}/${INC_DIR}/*.c ${LAMMPS_LIB_SOURCE_DIR}/${INC_DIR}/*.cpp)
    list(APPEND LIB_SOURCES ${${SIMPLE_LIB}_SOURCES})
    include_directories(${LAMMPS_LIB_SOURCE_DIR}/${INC_DIR})
    string(REGEX REPLACE "^USER-" "" PKG_LIB "${SIMPLE_LIB}")
    string(TOLOWER "${PKG_LIB}" PKG_LIB)
    file(GLOB_RECURSE ${PKG_LIB}_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.F
      ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.c ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.cpp)
    option(BUILD_SHARED_PKG_LIBS "Build package libs shared" OFF)
    if(BUILD_SHARED_PKG_LIBS)
      add_library(${PKG_LIB} SHARED ${${PKG_LIB}_SOURCES})
      set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION})
      if(INSTALL_LIB)
        install(TARGETS ${PKG_LIB} 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(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES})
    endif()
    list(APPEND LAMMPS_LINK_LIBS ${PKG_LIB})
    foreach(PKG_SRC ${${SIMPLE_LIB}_SOURCES})
      set_property(SOURCE ${PKG_SRC} APPEND PROPERTY COMPILE_FLAGS -I${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB})
    endforeach()
  endif()
endforeach()