forked from lijiext/lammps
677 lines
26 KiB
CMake
677 lines
26 KiB
CMake
########################################
|
|
# CMake build system
|
|
# This file is part of LAMMPS
|
|
# Created by Christoph Junghans and Richard Berger
|
|
cmake_minimum_required(VERSION 2.8.12)
|
|
|
|
project(lammps CXX)
|
|
set(SOVERSION 0)
|
|
get_filename_component(LAMMPS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../src ABSOLUTE)
|
|
get_filename_component(LAMMPS_LIB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../lib ABSOLUTE)
|
|
get_filename_component(LAMMPS_LIB_BINARY_DIR ${CMAKE_BINARY_DIR}/lib ABSOLUTE)
|
|
get_filename_component(LAMMPS_DOC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../doc ABSOLUTE)
|
|
get_filename_component(LAMMPS_TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../tools ABSOLUTE)
|
|
get_filename_component(LAMMPS_PYTHON_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../python ABSOLUTE)
|
|
get_filename_component(LAMMPS_POTENTIALS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../potentials ABSOLUTE)
|
|
|
|
find_package(Git)
|
|
|
|
# by default, install into $HOME/.local (not /usr/local), so that no root access (and sudo!!) is needed
|
|
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
|
set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local" CACHE PATH "default install path" FORCE )
|
|
endif()
|
|
|
|
# To avoid conflicts with the conventional Makefile build system, we build everything here
|
|
file(GLOB LIB_SOURCES ${LAMMPS_SOURCE_DIR}/[^.]*.cpp)
|
|
file(GLOB LMP_SOURCES ${LAMMPS_SOURCE_DIR}/main.cpp)
|
|
list(REMOVE_ITEM LIB_SOURCES ${LMP_SOURCES})
|
|
|
|
# Cmake modules/macros are in a subdirectory to keep this file cleaner
|
|
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Modules)
|
|
|
|
include(LAMMPSUtils)
|
|
|
|
get_lammps_version(${LAMMPS_SOURCE_DIR}/version.h LAMMPS_VERSION)
|
|
|
|
include(PreventInSourceBuilds)
|
|
|
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_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_CXX_FLAGS)
|
|
string(TOUPPER "${CMAKE_BUILD_TYPE}" BTYPE)
|
|
|
|
# check for files auto-generated by make-based buildsystem
|
|
# this is fast, so check for it all the time
|
|
check_for_autogen_files(${LAMMPS_SOURCE_DIR})
|
|
|
|
######################################################################
|
|
# compiler tests
|
|
# these need ot be done early (before further tests).
|
|
#####################################################################
|
|
include(CheckCCompilerFlag)
|
|
include(CheckIncludeFileCXX)
|
|
|
|
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -restrict")
|
|
endif()
|
|
|
|
# GNU compiler features
|
|
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
|
option(ENABLE_COVERAGE "Enable code coverage" OFF)
|
|
mark_as_advanced(ENABLE_COVERAGE)
|
|
if(ENABLE_COVERAGE)
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
|
|
endif()
|
|
option(ENABLE_SANITIZE_ADDRESS "Enable address sanitizer" OFF)
|
|
mark_as_advanced(ENABLE_SANITIZE_ADDRESS)
|
|
if(ENABLE_SANITIZE_ADDRESS)
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
|
|
endif()
|
|
option(ENABLE_SANITIZE_UNDEFINED "Enable undefined behavior sanitizer" OFF)
|
|
mark_as_advanced(ENABLE_SANITIZE_UNDEFINED)
|
|
if(ENABLE_SANITIZE_UNDEFINED)
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
|
|
endif()
|
|
option(ENABLE_SANITIZE_THREAD "Enable thread sanitizer" OFF)
|
|
mark_as_advanced(ENABLE_SANITIZE_THREAD)
|
|
if(ENABLE_SANITIZE_THREAD)
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
|
|
endif()
|
|
endif()
|
|
|
|
########################################################################
|
|
# User input options #
|
|
########################################################################
|
|
option(BUILD_EXE "Build lmp binary" ON)
|
|
if(BUILD_EXE)
|
|
set(LAMMPS_MACHINE "" CACHE STRING "Suffix to append to lmp binary (WON'T enable any features automatically")
|
|
mark_as_advanced(LAMMPS_MACHINE)
|
|
if(LAMMPS_MACHINE)
|
|
set(LAMMPS_MACHINE "_${LAMMPS_MACHINE}")
|
|
endif()
|
|
set(LAMMPS_BINARY lmp${LAMMPS_MACHINE})
|
|
endif()
|
|
|
|
option(BUILD_LIB "Build LAMMPS library" OFF)
|
|
if(BUILD_LIB)
|
|
option(BUILD_SHARED_LIBS "Build shared library" OFF)
|
|
if(BUILD_SHARED_LIBS) # for all pkg libs, mpi_stubs and linalg
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
endif()
|
|
set(LAMMPS_LIB_SUFFIX "" CACHE STRING "Suffix to append to liblammps and pkg-config file")
|
|
mark_as_advanced(LAMMPS_LIB_SUFFIX)
|
|
if(LAMMPS_LIB_SUFFIX)
|
|
set(LAMMPS_LIB_SUFFIX "_${LAMMPS_LIB_SUFFIX}")
|
|
endif()
|
|
endif()
|
|
|
|
option(BUILD_TOOLS "Build and install LAMMPS tools (msi2lmp, binary2txt, chain)" OFF)
|
|
|
|
if(NOT BUILD_EXE AND NOT BUILD_LIB)
|
|
message(FATAL_ERROR "You need to at least enable one of two following options: BUILD_LIB or BUILD_EXE")
|
|
endif()
|
|
|
|
option(CMAKE_VERBOSE_MAKEFILE "Generate verbose Makefiles" OFF)
|
|
include(GNUInstallDirs)
|
|
|
|
set(LAMMPS_LINK_LIBS)
|
|
set(LAMMPS_DEPS)
|
|
set(LAMMPS_API_DEFINES)
|
|
|
|
set(DEFAULT_PACKAGES ASPHERE BODY CLASS2 COLLOID COMPRESS CORESHELL DIPOLE
|
|
GRANULAR KSPACE LATTE MANYBODY MC MESSAGE MISC MOLECULE PERI POEMS QEQ
|
|
REPLICA RIGID SHOCK SPIN SNAP SRD KIM PYTHON MSCG MPIIO VORONOI
|
|
USER-ATC USER-AWPMD USER-BOCS USER-CGDNA USER-MESO USER-CGSDK USER-COLVARS
|
|
USER-DIFFRACTION USER-DPD USER-DRUDE USER-EFF USER-FEP USER-H5MD USER-LB
|
|
USER-MANIFOLD USER-MEAMC USER-MGPT USER-MISC USER-MOFFF USER-MOLFILE
|
|
USER-NETCDF USER-PHONON USER-PLUMED USER-PTM USER-QTB USER-REAXC
|
|
USER-SCAFACOS USER-SDPD USER-SMD USER-SMTBQ USER-SPH USER-TALLY USER-UEF
|
|
USER-VTK USER-QUIP USER-QMMM USER-YAFF USER-ADIOS)
|
|
set(ACCEL_PACKAGES USER-OMP KOKKOS OPT USER-INTEL GPU)
|
|
foreach(PKG ${DEFAULT_PACKAGES} ${ACCEL_PACKAGES})
|
|
option(PKG_${PKG} "Build ${PKG} Package" OFF)
|
|
endforeach()
|
|
|
|
######################################################
|
|
# packages with special compiler needs or external libs
|
|
######################################################
|
|
include_directories(${LAMMPS_SOURCE_DIR})
|
|
|
|
if(PKG_USER-ADIOS)
|
|
# The search for ADIOS2 must come before MPI because
|
|
# it includes its own MPI search with the latest FindMPI.cmake
|
|
# script that defines the MPI::MPI_C target
|
|
enable_language(C)
|
|
find_package(ADIOS2 REQUIRED)
|
|
list(APPEND LAMMPS_LINK_LIBS adios2::adios2)
|
|
endif()
|
|
|
|
# do MPI detection after language activation, if MPI for these language is required
|
|
find_package(MPI QUIET)
|
|
option(BUILD_MPI "Build MPI version" ${MPI_FOUND})
|
|
if(BUILD_MPI)
|
|
find_package(MPI REQUIRED)
|
|
include_directories(${MPI_CXX_INCLUDE_PATH})
|
|
list(APPEND LAMMPS_LINK_LIBS ${MPI_CXX_LIBRARIES})
|
|
option(LAMMPS_LONGLONG_TO_LONG "Workaround if your system or MPI version does not recognize 'long long' data types" OFF)
|
|
if(LAMMPS_LONGLONG_TO_LONG)
|
|
add_definitions(-DLAMMPS_LONGLONG_TO_LONG)
|
|
endif()
|
|
else()
|
|
enable_language(C)
|
|
file(GLOB MPI_SOURCES ${LAMMPS_SOURCE_DIR}/STUBS/mpi.c)
|
|
add_library(mpi_stubs STATIC ${MPI_SOURCES})
|
|
include_directories(${LAMMPS_SOURCE_DIR}/STUBS)
|
|
list(APPEND LAMMPS_LINK_LIBS mpi_stubs)
|
|
endif()
|
|
|
|
set(LAMMPS_SIZES "smallbig" CACHE STRING "LAMMPS integer sizes (smallsmall: all 32-bit, smallbig: 64-bit #atoms #timesteps, bigbig: also 64-bit imageint, 64-bit atom ids)")
|
|
set(LAMMPS_SIZES_VALUES smallbig bigbig smallsmall)
|
|
set_property(CACHE LAMMPS_SIZES PROPERTY STRINGS ${LAMMPS_SIZES_VALUES})
|
|
validate_option(LAMMPS_SIZES LAMMPS_SIZES_VALUES)
|
|
string(TOUPPER ${LAMMPS_SIZES} LAMMPS_SIZES)
|
|
add_definitions(-DLAMMPS_${LAMMPS_SIZES})
|
|
set(LAMMPS_API_DEFINES "${LAMMPS_API_DEFINES} -DLAMMPS_${LAMMPS_SIZES}")
|
|
|
|
# posix_memalign is not available on Windows
|
|
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
|
set(LAMMPS_MEMALIGN "64" CACHE STRING "enables the use of the posix_memalign() call instead of malloc() when large chunks or memory are allocated by LAMMPS. Set to 0 to disable")
|
|
if(NOT ${LAMMPS_MEMALIGN} STREQUAL "0")
|
|
add_definitions(-DLAMMPS_MEMALIGN=${LAMMPS_MEMALIGN})
|
|
endif()
|
|
endif()
|
|
|
|
option(LAMMPS_EXCEPTIONS "enable the use of C++ exceptions for error messages (useful for library interface)" OFF)
|
|
if(LAMMPS_EXCEPTIONS)
|
|
add_definitions(-DLAMMPS_EXCEPTIONS)
|
|
set(LAMMPS_API_DEFINES "${LAMMPS_API_DEFINES} -DLAMMPS_EXCEPTIONS")
|
|
endif()
|
|
|
|
# "hard" dependencies between packages resulting
|
|
# in an error instead of skipping over files
|
|
pkg_depends(MPIIO MPI)
|
|
pkg_depends(USER-ATC MANYBODY)
|
|
pkg_depends(USER-LB MPI)
|
|
pkg_depends(USER-PHONON KSPACE)
|
|
pkg_depends(USER-SCAFACOS MPI)
|
|
|
|
find_package(OpenMP QUIET)
|
|
|
|
# TODO: this is a temporary workaround until a better solution is found. AK 2019-05-30
|
|
# GNU GCC 9.x uses settings incompatible with our use of 'default(none)' in OpenMP pragmas
|
|
# where we assume older GCC semantics. For the time being, we disable OpenMP by default
|
|
# for GCC 9.x and beyond. People may manually turn it on, but need to run the script
|
|
# src/USER-OMP/hack_openmp_for_pgi_gcc9.sh on all sources to make it compatible with gcc 9.
|
|
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.99.9))
|
|
option(BUILD_OMP "Build with OpenMP support" OFF)
|
|
else()
|
|
option(BUILD_OMP "Build with OpenMP support" ${OpenMP_FOUND})
|
|
endif()
|
|
|
|
if(BUILD_OMP)
|
|
find_package(OpenMP REQUIRED)
|
|
check_include_file_cxx(omp.h HAVE_OMP_H_INCLUDE)
|
|
if(NOT HAVE_OMP_H_INCLUDE)
|
|
message(FATAL_ERROR "Cannot find required 'omp.h' header file")
|
|
endif()
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
|
|
endif()
|
|
|
|
|
|
if(PKG_MSCG OR PKG_USER-ATC OR PKG_USER-AWPMD OR PKG_USER-PLUMED OR PKG_USER-QUIP OR PKG_LATTE)
|
|
find_package(LAPACK)
|
|
find_package(BLAS)
|
|
if(NOT LAPACK_FOUND OR NOT BLAS_FOUND)
|
|
if(CMAKE_GENERATOR STREQUAL "Ninja")
|
|
status(FATAL_ERROR "Cannot build internal linear algebra library with Ninja build tool due to lack for Fortran support")
|
|
endif()
|
|
enable_language(Fortran)
|
|
file(GLOB LAPACK_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/linalg/[^.]*.[fF])
|
|
add_library(linalg STATIC ${LAPACK_SOURCES})
|
|
set(LAPACK_LIBRARIES linalg)
|
|
else()
|
|
list(APPEND LAPACK_LIBRARIES ${BLAS_LIBRARIES})
|
|
endif()
|
|
endif()
|
|
|
|
|
|
find_package(JPEG QUIET)
|
|
option(WITH_JPEG "Enable JPEG support" ${JPEG_FOUND})
|
|
if(WITH_JPEG)
|
|
find_package(JPEG REQUIRED)
|
|
add_definitions(-DLAMMPS_JPEG)
|
|
include_directories(${JPEG_INCLUDE_DIR})
|
|
list(APPEND LAMMPS_LINK_LIBS ${JPEG_LIBRARIES})
|
|
endif()
|
|
|
|
find_package(PNG QUIET)
|
|
find_package(ZLIB QUIET)
|
|
if(PNG_FOUND AND ZLIB_FOUND)
|
|
option(WITH_PNG "Enable PNG support" ON)
|
|
else()
|
|
option(WITH_PNG "Enable PNG support" OFF)
|
|
endif()
|
|
if(WITH_PNG)
|
|
find_package(PNG REQUIRED)
|
|
find_package(ZLIB REQUIRED)
|
|
include_directories(${PNG_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS})
|
|
list(APPEND LAMMPS_LINK_LIBS ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
|
|
add_definitions(-DLAMMPS_PNG)
|
|
endif()
|
|
|
|
find_program(GZIP_EXECUTABLE gzip)
|
|
find_package_handle_standard_args(GZIP REQUIRED_VARS GZIP_EXECUTABLE)
|
|
option(WITH_GZIP "Enable GZIP support" ${GZIP_FOUND})
|
|
if(WITH_GZIP)
|
|
if(NOT GZIP_FOUND)
|
|
message(FATAL_ERROR "gzip executable not found")
|
|
endif()
|
|
add_definitions(-DLAMMPS_GZIP)
|
|
endif()
|
|
|
|
find_program(FFMPEG_EXECUTABLE ffmpeg)
|
|
find_package_handle_standard_args(FFMPEG REQUIRED_VARS FFMPEG_EXECUTABLE)
|
|
option(WITH_FFMPEG "Enable FFMPEG support" ${FFMPEG_FOUND})
|
|
if(WITH_FFMPEG)
|
|
if(NOT FFMPEG_FOUND)
|
|
message(FATAL_ERROR "ffmpeg executable not found")
|
|
endif()
|
|
add_definitions(-DLAMMPS_FFMPEG)
|
|
endif()
|
|
|
|
if(BUILD_SHARED_LIBS)
|
|
set(CONFIGURE_REQUEST_PIC "--with-pic")
|
|
set(CMAKE_REQUEST_PIC "-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}")
|
|
set(CUDA_REQUEST_PIC "-Xcompiler ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}")
|
|
else()
|
|
set(CONFIGURE_REQUEST_PIC)
|
|
set(CMAKE_REQUEST_PIC)
|
|
set(CUDA_REQUEST_PIC)
|
|
endif()
|
|
|
|
include(Packages/KSPACE)
|
|
include(Packages/PYTHON)
|
|
include(Packages/VORONOI)
|
|
include(Packages/USER-SCAFACOS)
|
|
include(Packages/USER-PLUMED)
|
|
include(Packages/USER-MOLFILE)
|
|
include(Packages/USER-NETCDF)
|
|
include(Packages/USER-SMD)
|
|
include(Packages/USER-QUIP)
|
|
include(Packages/USER-QMMM)
|
|
include(Packages/USER-VTK)
|
|
include(Packages/KIM)
|
|
include(Packages/MESSAGE)
|
|
include(Packages/MSCG)
|
|
include(Packages/COMPRESS)
|
|
|
|
# the windows version of LAMMPS requires a couple extra libraries
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
|
list(APPEND LAMMPS_LINK_LIBS -lwsock32 -lpsapi)
|
|
endif()
|
|
|
|
########################################################################
|
|
# Basic system tests (standard libraries, headers, functions, types) #
|
|
########################################################################
|
|
foreach(HEADER cmath)
|
|
check_include_file_cxx(${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)
|
|
if (CMAKE_VERSION VERSION_LESS "3.4")
|
|
enable_language(C) # check_library_exists isn't supported without a C compiler before v3.4
|
|
endif()
|
|
# RB: disabled this check because it breaks with KOKKOS CUDA enabled
|
|
#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})
|
|
|
|
######################################
|
|
# Generate Basic Style files
|
|
######################################
|
|
include(StyleHeaderUtils)
|
|
RegisterStyles(${LAMMPS_SOURCE_DIR})
|
|
|
|
##############################################
|
|
# add sources of enabled packages
|
|
############################################
|
|
foreach(PKG ${DEFAULT_PACKAGES})
|
|
set(${PKG}_SOURCES_DIR ${LAMMPS_SOURCE_DIR}/${PKG})
|
|
|
|
file(GLOB ${PKG}_SOURCES ${${PKG}_SOURCES_DIR}/[^.]*.cpp)
|
|
file(GLOB ${PKG}_HEADERS ${${PKG}_SOURCES_DIR}/[^.]*.h)
|
|
|
|
# check for package files in src directory due to old make system
|
|
DetectBuildSystemConflict(${LAMMPS_SOURCE_DIR} ${${PKG}_SOURCES} ${${PKG}_HEADERS})
|
|
|
|
if(PKG_${PKG})
|
|
# detects styles in package and adds them to global list
|
|
RegisterStyles(${${PKG}_SOURCES_DIR})
|
|
|
|
list(APPEND LIB_SOURCES ${${PKG}_SOURCES})
|
|
include_directories(${${PKG}_SOURCES_DIR})
|
|
endif()
|
|
|
|
RegisterPackages(${${PKG}_SOURCES_DIR})
|
|
endforeach()
|
|
|
|
# packages that need defines set
|
|
foreach(PKG MPIIO)
|
|
if(PKG_${PKG})
|
|
add_definitions(-DLMP_${PKG})
|
|
endif()
|
|
endforeach()
|
|
|
|
# dedicated check for entire contents of accelerator packages
|
|
foreach(PKG ${ACCEL_PACKAGES})
|
|
set(${PKG}_SOURCES_DIR ${LAMMPS_SOURCE_DIR}/${PKG})
|
|
|
|
file(GLOB ${PKG}_SOURCES ${${PKG}_SOURCES_DIR}/[^.]*.cpp)
|
|
file(GLOB ${PKG}_HEADERS ${${PKG}_SOURCES_DIR}/[^.]*.h)
|
|
|
|
# check for package files in src directory due to old make system
|
|
DetectBuildSystemConflict(${LAMMPS_SOURCE_DIR} ${${PKG}_SOURCES} ${${PKG}_HEADERS})
|
|
|
|
RegisterPackages(${${PKG}_SOURCES_DIR})
|
|
endforeach()
|
|
|
|
##############################################
|
|
# add lib sources of (simple) enabled packages
|
|
############################################
|
|
foreach(SIMPLE_LIB POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD
|
|
USER-QMMM)
|
|
if(PKG_${SIMPLE_LIB})
|
|
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)
|
|
add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES})
|
|
list(APPEND LAMMPS_LINK_LIBS ${PKG_LIB})
|
|
if(PKG_LIB STREQUAL awpmd)
|
|
target_include_directories(awpmd PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/awpmd/systems/interact ${LAMMPS_LIB_SOURCE_DIR}/awpmd/ivutils/include)
|
|
elseif(PKG_LIB STREQUAL h5md)
|
|
target_include_directories(h5md PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/h5md/include ${HDF5_INCLUDE_DIRS})
|
|
elseif(PKG_LIB STREQUAL colvars)
|
|
target_compile_options(colvars PRIVATE -DLEPTON)
|
|
target_include_directories(colvars PRIVATE ${LAMMPS_LIB_SOURCE_DIR}/colvars/lepton/include)
|
|
target_include_directories(colvars PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/colvars)
|
|
else()
|
|
target_include_directories(${PKG_LIB} PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB})
|
|
endif()
|
|
endif()
|
|
endforeach()
|
|
|
|
if(PKG_USER-AWPMD)
|
|
target_link_libraries(awpmd ${LAPACK_LIBRARIES})
|
|
endif()
|
|
|
|
if(PKG_USER-ATC)
|
|
if(LAMMPS_SIZES STREQUAL BIGBIG)
|
|
message(FATAL_ERROR "The USER-ATC Package is not compatible with -DLAMMPS_BIGBIG")
|
|
endif()
|
|
target_link_libraries(atc ${LAPACK_LIBRARIES})
|
|
endif()
|
|
|
|
include(Packages/USER-H5MD)
|
|
|
|
######################################################################
|
|
# packages which selectively include variants based on enabled styles
|
|
# e.g. accelerator packages
|
|
######################################################################
|
|
include(Packages/CORESHELL)
|
|
include(Packages/QEQ)
|
|
include(Packages/USER-OMP)
|
|
include(Packages/USER-SDPD)
|
|
include(Packages/KOKKOS)
|
|
include(Packages/OPT)
|
|
include(Packages/USER-INTEL)
|
|
include(Packages/GPU)
|
|
|
|
######################################################
|
|
# Generate style headers based on global list of
|
|
# styles registered during package selection
|
|
# Generate packages headers from all packages
|
|
######################################################
|
|
set(LAMMPS_STYLE_HEADERS_DIR ${CMAKE_CURRENT_BINARY_DIR}/styles)
|
|
|
|
GenerateStyleHeaders(${LAMMPS_STYLE_HEADERS_DIR})
|
|
GeneratePackagesHeaders(${LAMMPS_STYLE_HEADERS_DIR})
|
|
|
|
include_directories(${LAMMPS_STYLE_HEADERS_DIR})
|
|
|
|
######################################
|
|
# Generate lmpinstalledpkgs.h
|
|
######################################
|
|
set(temp "#ifndef LMP_INSTALLED_PKGS_H\n#define LMP_INSTALLED_PKGS_H\n")
|
|
set(temp "${temp}const char * LAMMPS_NS::LAMMPS::installed_packages[] = {\n")
|
|
set(temp_PKG_LIST ${DEFAULT_PACKAGES} ${ACCEL_PACKAGES})
|
|
list(SORT temp_PKG_LIST)
|
|
foreach(PKG ${temp_PKG_LIST})
|
|
if(PKG_${PKG})
|
|
set(temp "${temp} \"${PKG}\",\n")
|
|
endif()
|
|
endforeach()
|
|
set(temp "${temp} NULL\n};\n#endif\n\n")
|
|
message(STATUS "Generating lmpinstalledpkgs.h...")
|
|
file(WRITE "${LAMMPS_STYLE_HEADERS_DIR}/lmpinstalledpkgs.h.tmp" "${temp}" )
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${LAMMPS_STYLE_HEADERS_DIR}/lmpinstalledpkgs.h.tmp" "${LAMMPS_STYLE_HEADERS_DIR}/lmpinstalledpkgs.h")
|
|
|
|
######################################
|
|
# Generate lmpgitversion.h
|
|
######################################
|
|
add_custom_target(gitversion COMMAND ${CMAKE_COMMAND}
|
|
-DCMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
|
|
-DGIT_EXECUTABLE="${GIT_EXECUTABLE}"
|
|
-DGIT_FOUND="${GIT_FOUND}"
|
|
-DLAMMPS_STYLE_HEADERS_DIR="${LAMMPS_STYLE_HEADERS_DIR}"
|
|
-P ${CMAKE_CURRENT_SOURCE_DIR}/Modules/generate_lmpgitversion.cmake)
|
|
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${LAMMPS_STYLE_HEADERS_DIR}/gitversion.h)
|
|
list(APPEND LAMMPS_DEPS gitversion)
|
|
|
|
###########################################
|
|
# Actually add executable and lib to build
|
|
############################################
|
|
get_property(LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
|
|
list (FIND LANGUAGES "Fortran" _index)
|
|
if (${_index} GREATER -1)
|
|
list(APPEND LAMMPS_LINK_LIBS ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES})
|
|
endif()
|
|
list(REMOVE_DUPLICATES LAMMPS_LINK_LIBS)
|
|
if(BUILD_LIB)
|
|
add_library(lammps ${LIB_SOURCES})
|
|
target_link_libraries(lammps ${LAMMPS_LINK_LIBS})
|
|
if(LAMMPS_DEPS)
|
|
add_dependencies(lammps ${LAMMPS_DEPS})
|
|
endif()
|
|
set_target_properties(lammps PROPERTIES OUTPUT_NAME lammps${LAMMPS_LIB_SUFFIX})
|
|
set_target_properties(lammps PROPERTIES SOVERSION ${SOVERSION})
|
|
install(TARGETS lammps LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
|
install(FILES ${LAMMPS_SOURCE_DIR}/library.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lammps)
|
|
configure_file(pkgconfig/liblammps.pc.in ${CMAKE_CURRENT_BINARY_DIR}/liblammps${LAMMPS_LIB_SUFFIX}.pc @ONLY)
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/liblammps${LAMMPS_LIB_SUFFIX}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
|
configure_file(FindLAMMPS.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FindLAMMPS${LAMMPS_LIB_SUFFIX}.cmake @ONLY)
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FindLAMMPS${LAMMPS_LIB_SUFFIX}.cmake DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/Modules)
|
|
else()
|
|
list(APPEND LMP_SOURCES ${LIB_SOURCES})
|
|
endif()
|
|
|
|
if(BUILD_EXE)
|
|
add_executable(lmp ${LMP_SOURCES})
|
|
if(BUILD_LIB)
|
|
target_link_libraries(lmp lammps)
|
|
else()
|
|
target_link_libraries(lmp ${LAMMPS_LINK_LIBS})
|
|
if(LAMMPS_DEPS)
|
|
add_dependencies(lmp ${LAMMPS_DEPS})
|
|
endif()
|
|
endif()
|
|
|
|
set_target_properties(lmp PROPERTIES OUTPUT_NAME ${LAMMPS_BINARY})
|
|
install(TARGETS lmp DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
install(FILES ${LAMMPS_DOC_DIR}/lammps.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 RENAME ${LAMMPS_BINARY}.1)
|
|
endif()
|
|
|
|
if(BUILD_TOOLS)
|
|
add_executable(binary2txt ${LAMMPS_TOOLS_DIR}/binary2txt.cpp)
|
|
install(TARGETS binary2txt DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
|
|
# ninja-build currently does not support fortran. thus we skip building this tool
|
|
if(NOT CMAKE_GENERATOR STREQUAL "Ninja")
|
|
message(STATUS "Skipping building 'chain.x' with Ninja build tool due to lack of Fortran support")
|
|
enable_language(Fortran)
|
|
add_executable(chain.x ${LAMMPS_TOOLS_DIR}/chain.f)
|
|
target_link_libraries(chain.x ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES})
|
|
endif()
|
|
|
|
enable_language(C)
|
|
get_filename_component(MSI2LMP_SOURCE_DIR ${LAMMPS_TOOLS_DIR}/msi2lmp/src ABSOLUTE)
|
|
file(GLOB MSI2LMP_SOURCES ${MSI2LMP_SOURCE_DIR}/[^.]*.c)
|
|
add_executable(msi2lmp ${MSI2LMP_SOURCES})
|
|
target_link_libraries(msi2lmp m)
|
|
install(TARGETS msi2lmp DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
install(FILES ${LAMMPS_DOC_DIR}/msi2lmp.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
|
|
endif()
|
|
|
|
include(Documentation)
|
|
|
|
###############################################################################
|
|
# Install potential and force field files in data directory
|
|
###############################################################################
|
|
set(LAMMPS_INSTALL_POTENTIALS_DIR ${CMAKE_INSTALL_FULL_DATADIR}/lammps/potentials)
|
|
install(DIRECTORY ${LAMMPS_POTENTIALS_DIR} DESTINATION ${LAMMPS_INSTALL_POTENTIALS_DIR})
|
|
|
|
set(LAMMPS_INSTALL_FRC_FILES_DIR ${CMAKE_INSTALL_FULL_DATADIR}/lammps/frc_files)
|
|
install(DIRECTORY ${LAMMPS_TOOLS_DIR}/msi2lmp/frc_files/ DESTINATION ${LAMMPS_INSTALL_FRC_FILES_DIR})
|
|
|
|
configure_file(etc/profile.d/lammps.sh.in ${CMAKE_BINARY_DIR}/etc/profile.d/lammps.sh @ONLY)
|
|
configure_file(etc/profile.d/lammps.csh.in ${CMAKE_BINARY_DIR}/etc/profile.d/lammps.csh @ONLY)
|
|
install(
|
|
FILES ${CMAKE_BINARY_DIR}/etc/profile.d/lammps.sh
|
|
${CMAKE_BINARY_DIR}/etc/profile.d/lammps.csh
|
|
DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/profile.d
|
|
)
|
|
|
|
###############################################################################
|
|
# Install LAMMPS lib and python module into site-packages folder with
|
|
# "install-python" target. Behaves exactly like "make install-python" for
|
|
# conventional build. Only available, if a shared library is built.
|
|
# This is primarily for people that only want to use the Python wrapper.
|
|
###############################################################################
|
|
if(BUILD_LIB AND BUILD_SHARED_LIBS)
|
|
find_package(PythonInterp)
|
|
if (PYTHONINTERP_FOUND)
|
|
add_custom_target(
|
|
install-python
|
|
${PYTHON_EXECUTABLE} install.py -v ${LAMMPS_SOURCE_DIR}/version.h
|
|
-m ${LAMMPS_PYTHON_DIR}/lammps.py
|
|
-l ${CMAKE_BINARY_DIR}/liblammps${CMAKE_SHARED_LIBRARY_SUFFIX}
|
|
WORKING_DIRECTORY ${LAMMPS_PYTHON_DIR}
|
|
COMMENT "Installing LAMMPS Python module")
|
|
else()
|
|
add_custom_target(
|
|
install-python
|
|
${CMAKE_COMMAND} -E echo "Must have Python installed to install the LAMMPS Python module")
|
|
endif()
|
|
else()
|
|
add_custom_target(
|
|
install-python
|
|
${CMAKE_COMMAND} -E echo "Must build LAMMPS as a shared library to use the Python module")
|
|
endif()
|
|
|
|
###############################################################################
|
|
# Add LAMMPS python module to "install" target. This is taylored for building
|
|
# LAMMPS for package managers and with different prefix settings.
|
|
# This requires either a shared library or that the PYTHON package is included.
|
|
###############################################################################
|
|
if((BUILD_LIB AND BUILD_SHARED_LIBS) OR (PKG_PYTHON))
|
|
find_package(PythonInterp)
|
|
if (PYTHONINTERP_FOUND)
|
|
execute_process(COMMAND ${PYTHON_EXECUTABLE}
|
|
-c "import distutils.sysconfig as cg; print(cg.get_python_lib(1,0,prefix='${CMAKE_INSTALL_PREFIX}'))"
|
|
OUTPUT_VARIABLE PYTHON_DEFAULT_INSTDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
set(PYTHON_INSTDIR ${PYTHON_DEFAULT_INSTDIR} CACHE PATH "Installation folder for LAMMPS Python module")
|
|
install(FILES ${LAMMPS_PYTHON_DIR}/lammps.py DESTINATION ${PYTHON_INSTDIR})
|
|
endif()
|
|
endif()
|
|
|
|
include(Testing)
|
|
include(CodeCoverage)
|
|
|
|
###############################################################################
|
|
# Print package summary
|
|
###############################################################################
|
|
foreach(PKG ${DEFAULT_PACKAGES} ${ACCEL_PACKAGES})
|
|
if(PKG_${PKG})
|
|
message(STATUS "Building package: ${PKG}")
|
|
endif()
|
|
endforeach()
|
|
|
|
get_directory_property(CPPFLAGS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS)
|
|
include(FeatureSummary)
|
|
feature_summary(DESCRIPTION "The following packages have been found:" WHAT PACKAGES_FOUND)
|
|
message(STATUS "<<< Build configuration >>>
|
|
Build type ${CMAKE_BUILD_TYPE}
|
|
Install path ${CMAKE_INSTALL_PREFIX}
|
|
Compilers and Flags:
|
|
C++ Compiler ${CMAKE_CXX_COMPILER}
|
|
Type ${CMAKE_CXX_COMPILER_ID}
|
|
Version ${CMAKE_CXX_COMPILER_VERSION}
|
|
C++ Flags ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${BTYPE}}
|
|
Defines ${CPPFLAGS}")
|
|
get_property(LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
|
|
list (FIND LANGUAGES "Fortran" _index)
|
|
if (${_index} GREATER -1)
|
|
message(STATUS "Fortran Compiler ${CMAKE_Fortran_COMPILER}
|
|
Type ${CMAKE_Fortran_COMPILER_ID}
|
|
Version ${CMAKE_Fortran_COMPILER_VERSION}
|
|
Fortran Flags ${CMAKE_Fortran_FLAGS} ${CMAKE_Fortran_FLAGS_${BTYPE}}")
|
|
endif()
|
|
list (FIND LANGUAGES "C" _index)
|
|
if (${_index} GREATER -1)
|
|
message(STATUS "C Compiler ${CMAKE_C_COMPILER}
|
|
Type ${CMAKE_C_COMPILER_ID}
|
|
Version ${CMAKE_C_COMPILER_VERSION}
|
|
C Flags ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${BTYPE}}")
|
|
endif()
|
|
if(CMAKE_EXE_LINKER_FLAGS)
|
|
message(STATUS "Linker flags:
|
|
Executable ${CMAKE_EXE_LINKER_FLAGS}")
|
|
endif()
|
|
if(BUILD_SHARED_LIBS)
|
|
message(STATUS "Shared libraries ${CMAKE_SHARED_LINKER_FLAGS}")
|
|
else()
|
|
message(STATUS "Static libraries ${CMAKE_STATIC_LINKER_FLAGS}")
|
|
endif()
|
|
message(STATUS "Link libraries: ${LAMMPS_LINK_LIBS}")
|
|
if(BUILD_MPI)
|
|
message(STATUS "Using mpi with headers in ${MPI_CXX_INCLUDE_PATH} and ${MPI_CXX_LIBRARIES}")
|
|
endif()
|
|
if(PKG_GPU)
|
|
message(STATUS "GPU Api: ${GPU_API}")
|
|
if(GPU_API STREQUAL "CUDA")
|
|
message(STATUS "GPU Arch: ${GPU_ARCH}")
|
|
elseif(GPU_API STREQUAL "OPENCL")
|
|
message(STATUS "OCL Tune: ${OCL_TUNE}")
|
|
endif()
|
|
message(STATUS "GPU Precision: ${GPU_PREC}")
|
|
endif()
|
|
if(PKG_KOKKOS)
|
|
message(STATUS "Kokkos Arch: ${KOKKOS_ARCH}")
|
|
endif()
|
|
if(PKG_KSPACE)
|
|
message(STATUS "Using ${FFT} as FFT")
|
|
endif()
|