cmake: collect link libs

This commit is contained in:
Christoph Junghans 2017-07-14 14:21:21 -06:00
parent a566419ca6
commit 842dc1b58c
1 changed files with 14 additions and 12 deletions

View File

@ -25,15 +25,12 @@ include(CheckCCompilerFlag)
option(BUILD_SHARED_LIBS "Build shared libs" OFF)
include(GNUInstallDirs)
set(LAMMPS_LINK_LIBS)
option(ENABLE_MPI "Build MPI version" OFF)
if(ENABLE_MPI)
find_package(MPI)
find_package(MPI REQUIRED)
include_directories(${MPI_C_INCLUDE_PATH})
set(MPI_SOURCES)
else()
file(GLOB MPI_SOURCES ${LAMMPS_SOURCE_DIR}/STUBS/mpi.c)
include_directories(${LAMMPS_SOURCE_DIR}/STUBS)
set(MPI_CXX_LIBRARIES)
list(APPEND LAMMPS_LINK_LIBS ${MPI_CXX_LIBRARIES})
endif()
find_package(UnixCommands)
@ -49,16 +46,14 @@ find_package(JPEG)
if(JPEG_FOUND)
add_definitions(-DLAMMPS_JPEG)
include_directories(${JPEG_INCLUDE_DIR})
else()
set(JPEG_LIBRARIES)
list(APPEND LAMMPS_LINK_LIBS ${JPEG_LIBRARIES})
endif()
find_package(PNG)
if(PNG_FOUND)
include_directories(${PNG_INCLUDE_DIR})
list(APPEND LAMMPS_LINK_LIBS ${PNG_LIBRARIES})
add_definitions(-DLAMMPS_PNG)
else(PNG_FOUND)
set(PNG_LIBRARIES)
endif(PNG_FOUND)
########################################################################
@ -81,6 +76,7 @@ foreach(FUNC sin cos)
message(FATAL_ERROR "Could not find needed math function - ${FUNC}")
endif(NOT FOUND_${FUNC}_${MATH_LIBRARIES})
endforeach(FUNC)
list(APPEND LAMMPS_LINK_LIBS ${MATH_LIBRARIES})
######################################
# Include the following subdirectory #
@ -93,6 +89,12 @@ file(GLOB LIB_SOURCES ${LAMMPS_SOURCE_DIR}/*.cpp)
file(GLOB LMP_SOURCES ${LAMMPS_SOURCE_DIR}/main.cpp)
list(REMOVE_ITEM LIB_SOURCES ${LMP_SOURCES})
if(NOT ENABLE_MPI)
file(GLOB MPI_SOURCES ${LAMMPS_SOURCE_DIR}/STUBS/mpi.c)
list(APPEND LIB_SOURCES ${MPI_SOURCES})
include_directories(${LAMMPS_SOURCE_DIR}/STUBS)
endif()
foreach(PKG ${PACKAGES})
if(ENABLE_${PKG})
file(GLOB ${PKG}_SOURCES ${LAMMPS_SOURCE_DIR}/${PKG}/*.cpp)
@ -112,8 +114,8 @@ include_directories(${CMAKE_SOURCE_DIR}/Headers)
configure_file(${CMAKE_SOURCE_DIR}/Headers/package.h.cmakein ${CMAKE_BINARY_DIR}/cmake/package.h)
include_directories(${CMAKE_BINARY_DIR}/cmake)
add_library(lammps ${LIB_SOURCES} ${MPI_SOURCES})
target_link_libraries(lammps ${MPI_CXX_LIBRARIES} ${JPEG_LIBRARIES} ${PNG_LIBRARIES} ${MATH_LIBRARIES})
add_library(lammps ${LIB_SOURCES})
target_link_libraries(lammps ${LAMMPS_LINK_LIBS})
set_target_properties(lammps PROPERTIES SOVERSION ${SOVERSION})
install(TARGETS lammps LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})