forked from lijiext/lammps
126 lines
4.2 KiB
CMake
126 lines
4.2 KiB
CMake
cmake_minimum_required(VERSION 3.1)
|
|
|
|
project(lammps)
|
|
set(SOVERSION 0)
|
|
set(LAMMPS_SOURCE_DIR ${CMAKE_SOURCE_DIR}/../src)
|
|
set(LAMMPS_LIB_SOURCE_DIR ${CMAKE_SOURCE_DIR}/../lib)
|
|
|
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_C_FLAGS)
|
|
#release comes with -O3 by default
|
|
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
|
|
endif(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_C_FLAGS)
|
|
|
|
enable_language(CXX)
|
|
|
|
######################################################################
|
|
# compiler tests
|
|
# these need ot be done early (before further tests).
|
|
#####################################################################
|
|
|
|
include(CheckCCompilerFlag)
|
|
|
|
########################################################################
|
|
# User input options #
|
|
########################################################################
|
|
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 REQUIRED)
|
|
include_directories(${MPI_C_INCLUDE_PATH})
|
|
list(APPEND LAMMPS_LINK_LIBS ${MPI_CXX_LIBRARIES})
|
|
endif()
|
|
|
|
find_package(UnixCommands)
|
|
|
|
option(CMAKE_VERBOSE_MAKEFILE "Verbose makefile" OFF)
|
|
|
|
set(PACKAGES ASPHERE REAX)
|
|
foreach(PKG ${PACKAGES})
|
|
option(ENABLE_${PKG} "Build ${PKG} Package" OFF)
|
|
endforeach()
|
|
|
|
find_package(JPEG)
|
|
if(JPEG_FOUND)
|
|
add_definitions(-DLAMMPS_JPEG)
|
|
include_directories(${JPEG_INCLUDE_DIR})
|
|
list(APPEND LAMMPS_LINK_LIBS ${JPEG_LIBRARIES})
|
|
endif()
|
|
|
|
find_package(PNG)
|
|
find_package(ZLIB)
|
|
if(PNG_FOUND AND ZLIB_FOUND)
|
|
include_directories(${PNG_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS})
|
|
list(APPEND LAMMPS_LINK_LIBS ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
|
|
add_definitions(-DLAMMPS_PNG)
|
|
endif()
|
|
|
|
########################################################################
|
|
# Basic system tests (standard libraries, headers, functions, types) #
|
|
########################################################################
|
|
include(CheckIncludeFile)
|
|
foreach(HEADER math.h)
|
|
check_include_file(${HEADER} FOUND_${HEADER})
|
|
if(NOT FOUND_${HEADER})
|
|
message(FATAL_ERROR "Could not find needed header - ${HEADER}")
|
|
endif(NOT FOUND_${HEADER})
|
|
endforeach(HEADER)
|
|
|
|
set(MATH_LIBRARIES "m" CACHE STRING "math library")
|
|
mark_as_advanced( MATH_LIBRARIES )
|
|
include(CheckLibraryExists)
|
|
foreach(FUNC sin cos)
|
|
check_library_exists(${MATH_LIBRARIES} ${FUNC} "" FOUND_${FUNC}_${MATH_LIBRARIES})
|
|
if(NOT FOUND_${FUNC}_${MATH_LIBRARIES})
|
|
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 #
|
|
######################################
|
|
|
|
#Do NOT go into src to not conflict with old Makefile build system
|
|
#add_subdirectory(src)
|
|
|
|
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)
|
|
list(APPEND LIB_SOURCES ${${PKG}_SOURCES})
|
|
include_directories(${LAMMPS_SOURCE_DIR}/${PKG})
|
|
endif()
|
|
endforeach()
|
|
|
|
if(ENABLE_REAX)
|
|
enable_language(Fortran)
|
|
file(GLOB REAX_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/reax/*.F)
|
|
list(APPEND LIB_SOURCES ${REAX_SOURCES})
|
|
include_directories(${LAMMPS_LIB_SOURCE_DIR}/reax)
|
|
endif()
|
|
include_directories(${LAMMPS_SOURCE_DIR})
|
|
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})
|
|
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})
|
|
|
|
add_executable(lmp ${LMP_SOURCES})
|
|
target_link_libraries(lmp lammps)
|
|
install(TARGETS lammps DESTINATION ${CMAKE_INSTALL_BINDIR})
|