2017-07-20 08:34:07 +08:00
########################################
# CMake build system
# This file is part of LAMMPS
# Created by Christoph Junghans and Richard Berger
2017-07-13 05:54:44 +08:00
cmake_minimum_required ( VERSION 3.1 )
project ( lammps )
set ( SOVERSION 0 )
2017-07-14 17:00:38 +08:00
set ( LAMMPS_SOURCE_DIR ${ CMAKE_SOURCE_DIR } /../src )
2017-07-14 17:36:52 +08:00
set ( LAMMPS_LIB_SOURCE_DIR ${ CMAKE_SOURCE_DIR } /../lib )
2017-07-16 04:33:36 +08:00
set ( LAMMPS_LIB_BINARY_DIR ${ CMAKE_BINARY_DIR } /lib )
2017-07-13 05:54:44 +08:00
2017-07-20 08:34:07 +08:00
#To not conflict with old Makefile build system, we build everything here
2017-07-17 11:43:29 +08:00
file ( GLOB LIB_SOURCES ${ LAMMPS_SOURCE_DIR } /*.cpp )
file ( GLOB LMP_SOURCES ${ LAMMPS_SOURCE_DIR } /main.cpp )
list ( REMOVE_ITEM LIB_SOURCES ${ LMP_SOURCES } )
2017-07-15 05:55:36 +08:00
# Cmake modules/macros are in a subdirectory to keep this file cleaner
2017-07-15 06:49:05 +08:00
set ( CMAKE_MODULE_PATH ${ CMAKE_SOURCE_DIR } /Modules )
2017-07-26 09:09:20 +08:00
if ( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS )
2017-07-13 05:54:44 +08:00
#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 )
2017-07-26 09:09:20 +08:00
endif ( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS )
2017-07-13 05:54:44 +08:00
2017-07-18 01:52:06 +08:00
foreach ( STYLE_FILE style_angle.h style_atom.h style_body.h style_bond.h style_command.h style_compute.h style_dihedral.h style_dump.h
s t y l e _ f i x . h s t y l e _ i m p r o p e r . h s t y l e _ i n t e g r a t e . h s t y l e _ k s p a c e . h s t y l e _ m i n i m i z e . h s t y l e _ n b i n . h s t y l e _ n p a i r . h s t y l e _ n s t e n c i l . h
s t y l e _ n t o p o . h s t y l e _ p a i r . h s t y l e _ r e a d e r . h s t y l e _ r e g i o n . h )
if ( EXISTS ${ LAMMPS_SOURCE_DIR } / ${ STYLE_FILE } )
message ( FATAL_ERROR "There is a ${STYLE_FILE} in ${LAMMPS_SOURCE_DIR}, please clean up the source directory first" )
endif ( )
endforeach ( )
2017-07-13 05:54:44 +08:00
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 )
2017-08-27 21:06:08 +08:00
option ( BUILD_SHARED_PKG_LIBS "Build package libs shared" OFF )
2017-07-15 08:33:27 +08:00
option ( INSTALL_LIB "Install lammps library and header" ON )
2017-08-27 21:06:08 +08:00
if ( NOT INSTALL_LIB AND ( BUILD_SHARED_LIBS OR BUILD_SHARED_PKG_LIBS ) )
message ( FATAL_ERROR "Shared libs need to be installed, enable install with -DINSTALL_LIB=ON" )
endif ( )
2017-08-28 08:40:55 +08:00
if ( BUILD_SHARED_LIBS OR BUILD_SHARED_PKG_LIBS )
set ( CMAKE_POSITION_INDEPENDENT_CODE ON )
endif ( )
2017-07-13 05:54:44 +08:00
include ( GNUInstallDirs )
2017-07-15 04:21:21 +08:00
set ( LAMMPS_LINK_LIBS )
2017-07-13 05:54:44 +08:00
option ( ENABLE_MPI "Build MPI version" OFF )
if ( ENABLE_MPI )
2017-07-15 04:21:21 +08:00
find_package ( MPI REQUIRED )
2017-07-13 05:54:44 +08:00
include_directories ( ${ MPI_C_INCLUDE_PATH } )
2017-07-15 04:21:21 +08:00
list ( APPEND LAMMPS_LINK_LIBS ${ MPI_CXX_LIBRARIES } )
2017-07-18 03:28:34 +08:00
option ( LAMMPS_LONGLONG_TO_LONG "Workaround if your system or MPI version does not recognize 'long long' data types" OFF )
2017-07-18 03:26:46 +08:00
if ( LAMMPS_LONGLONG_TO_LONG )
add_definitions ( -DLAMMPS_LONGLONG_TO_LONG )
endif ( )
2017-07-17 12:53:53 +08:00
else ( )
file ( GLOB MPI_SOURCES ${ LAMMPS_SOURCE_DIR } /STUBS/mpi.c )
2017-08-27 22:58:47 +08:00
if ( BUILD_SHARED_PKG_LIBS )
add_library ( mpi_stubs SHARED ${ MPI_SOURCES } )
2017-08-28 03:45:48 +08:00
set_target_properties ( mpi_stubs PROPERTIES SOVERSION ${ SOVERSION } )
2017-08-27 22:58:47 +08:00
if ( INSTALL_LIB )
install ( TARGETS mpi_stubs LIBRARY DESTINATION ${ CMAKE_INSTALL_LIBDIR } ARCHIVE DESTINATION ${ CMAKE_INSTALL_LIBDIR } )
endif ( )
else ( )
add_library ( mpi_stubs STATIC ${ MPI_SOURCES } )
endif ( )
2017-07-17 12:53:53 +08:00
include_directories ( ${ LAMMPS_SOURCE_DIR } /STUBS )
2017-08-27 22:58:47 +08:00
list ( APPEND LAMMPS_LINK_LIBS mpi_stubs )
2017-07-13 05:54:44 +08:00
endif ( )
2017-07-18 02:22:28 +08:00
set ( LAMMPS_SIZE_LIMIT "LAMMPS_SMALLBIG" CACHE STRING "Lammps size limit" )
set_property ( CACHE LAMMPS_SIZE_LIMIT PROPERTY STRINGS LAMMPS_SMALLBIG LAMMPS_BIGBIG LAMMPS_SMALLSMALL )
add_definitions ( -D ${ LAMMPS_SIZE_LIMIT } )
2017-07-18 03:26:46 +08:00
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" )
add_definitions ( -DLAMMPS_MEMALIGN= ${ LAMMPS_MEMALIGN } )
2017-08-01 01:48:22 +08:00
option ( LAMMPS_EXCEPTIONS "enable the use of C++ exceptions for error messages (useful for library interface)" OFF )
if ( LAMMPS_EXCEPTIONS )
add_definitions ( -DLAMMPS_EXCEPTIONS )
endif ( )
2017-07-13 05:54:44 +08:00
option ( CMAKE_VERBOSE_MAKEFILE "Verbose makefile" OFF )
2017-07-21 06:14:02 +08:00
option ( ENABLE_TESTING "Enable testing" OFF )
if ( ENABLE_TESTING )
enable_testing ( )
endif ( ENABLE_TESTING )
2017-07-21 05:15:29 +08:00
option ( ENABLE_ALL "Build all default packages" OFF )
set ( DEFAULT_PACKAGES ASPHERE BODY CLASS2 COLLOID COMPRESS CORESHELL DIPOLE GRANULAR
K S P A C E M A N Y B O D Y M C M E A M M I S C M O L E C U L E P E R I Q E Q
R E A X R E P L I C A R I G I D S H O C K S N A P S R D )
set ( OTHER_PACKAGES KIM PYTHON MSCG MPIIO VORONOI POEMS
U S E R - A T C U S E R - A W P M D U S E R - C G D N A
2017-07-17 07:01:28 +08:00
U S E R - C G S D K U S E R - C O L V A R S U S E R - D I F F R A C T I O N U S E R - D P D U S E R - D R U D E U S E R - E F F
2017-07-17 07:52:43 +08:00
U S E R - F E P U S E R - H 5 M D U S E R - L B U S E R - M A N I F O L D U S E R - M E A M C U S E R - M G P T U S E R - M I S C
U S E R - M O L F I L E U S E R - N E T C D F U S E R - P H O N O N U S E R - Q T B U S E R - R E A X C U S E R - S M D
2017-07-17 12:07:21 +08:00
U S E R - S M T B Q U S E R - S P H U S E R - T A L L Y U S E R - V T K U S E R - Q U I P U S E R - Q M M M )
2017-07-18 01:01:08 +08:00
set ( ACCEL_PACKAGES USER-OMP KOKKOS OPT USER-INTEL GPU )
2017-07-21 05:15:29 +08:00
foreach ( PKG ${ DEFAULT_PACKAGES } )
2017-07-15 07:41:13 +08:00
option ( ENABLE_ ${ PKG } "Build ${PKG} Package" ${ ENABLE_ALL } )
2017-07-14 12:54:48 +08:00
endforeach ( )
2017-07-21 05:15:29 +08:00
foreach ( PKG ${ ACCEL_PACKAGES } ${ OTHER_PACKAGES } )
2017-07-15 06:49:05 +08:00
option ( ENABLE_ ${ PKG } "Build ${PKG} Package" OFF )
endforeach ( )
2017-07-17 01:14:08 +08:00
macro ( pkg_depends PKG1 PKG2 )
if ( ENABLE_ ${ PKG1 } AND NOT ENABLE_ ${ PKG2 } )
2017-07-17 06:18:58 +08:00
message ( FATAL_ERROR "${PKG1} package needs LAMMPS to be build with ${PKG2}" )
2017-07-17 01:14:08 +08:00
endif ( )
endmacro ( )
pkg_depends ( MPIIO MPI )
pkg_depends ( QEQ MANYBODY )
2017-07-17 06:18:58 +08:00
pkg_depends ( USER-ATC MANYBODY )
2017-07-17 07:01:28 +08:00
pkg_depends ( USER-H5MD MPI )
pkg_depends ( USER-LB MPI )
2017-07-17 07:52:43 +08:00
pkg_depends ( USER-MISC MANYBODY )
pkg_depends ( USER-PHONON KSPACE )
2017-07-16 22:32:14 +08:00
2017-07-21 05:02:41 +08:00
if ( ENABLE_BODY AND ENABLE_POEMS )
message ( FATAL_ERROR "BODY and POEMS cannot be enabled at the same time" )
endif ( )
2017-07-20 08:34:07 +08:00
######################################################
# packages with special compiler needs or external libs
######################################################
2017-07-17 12:37:51 +08:00
if ( ENABLE_REAX OR ENABLE_MEAM OR ENABLE_USER-QUIP OR ENABLE_USER-QMMM )
2017-07-17 11:31:57 +08:00
enable_language ( Fortran )
2017-08-28 02:10:46 +08:00
include ( CheckFortranCompilerFlag )
check_Fortran_compiler_flag ( "-fno-second-underscore" FC_HAS_NO_SECOND_UNDERSCORE )
2017-07-17 11:31:57 +08:00
endif ( )
if ( ENABLE_KOKKOS OR ENABLE_MSCG )
# starting with CMake 3.1 this is all you have to do to enforce C++11
set ( CMAKE_CXX_STANDARD 11 ) # C++11...
set ( CMAKE_CXX_STANDARD_REQUIRED ON ) #...is required...
set ( CMAKE_CXX_EXTENSIONS OFF ) #...without compiler extensions like gnu++11
endif ( )
2017-07-17 12:52:59 +08:00
if ( ENABLE_USER-OMP OR ENABLE_KOKKOS OR ENABLE_USER-INTEL )
2017-07-17 11:31:57 +08:00
find_package ( OpenMP REQUIRED )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" )
endif ( )
2017-07-15 05:55:36 +08:00
if ( ENABLE_KSPACE )
2017-07-20 08:54:15 +08:00
set ( FFT "KISSFFT" CACHE STRING "FFT library for KSPACE package" )
set_property ( CACHE FFT PROPERTY STRINGS KISSFFT FFTW3 MKL FFTW2 )
if ( NOT FFT STREQUAL "KISSFFT" )
find_package ( ${ FFT } REQUIRED )
add_definitions ( -DFFT_ ${ FFT } )
include_directories ( ${ ${FFT } _INCLUDE_DIRS} )
list ( APPEND LAMMPS_LINK_LIBS ${ ${FFT } _LIBRARIES} )
endif ( )
2017-07-18 03:21:42 +08:00
set ( PACK_OPTIMIZATION "PACK_ARRAY" CACHE STRING "Optimization for FFT" )
2017-07-22 01:38:02 +08:00
set_property ( CACHE PACK_OPTIMIZATION PROPERTY STRINGS PACK_ARRAY PACK_POINTER PACK_MEMCPY )
2017-07-20 00:35:48 +08:00
if ( NOT PACK_OPTIMIZATION STREQUAL "PACK_ARRAY" )
add_definitions ( -D ${ PACK_OPTIMIZATION } )
endif ( )
2017-07-18 03:21:42 +08:00
endif ( )
if ( ENABLE_MISC )
option ( LAMMPS_XDR "include XDR compatibility files for doing particle dumps in XTC format" OFF )
if ( LAMMPS_XDR )
2017-08-27 22:58:47 +08:00
add_definitions ( -DLAMMPS_XDR ) # for liblammps
2017-07-18 03:21:42 +08:00
endif ( )
2017-07-15 05:55:36 +08:00
endif ( )
2017-07-17 11:31:57 +08:00
if ( ENABLE_MSCG OR ENABLE_USER-ATC OR ENABLE_USER-AWPMD OR ENABLE_USER-QUIP )
2017-07-17 11:43:29 +08:00
find_package ( LAPACK )
2017-08-27 15:54:40 +08:00
if ( NOT LAPACK_FOUND )
2017-07-17 11:43:29 +08:00
enable_language ( Fortran )
file ( GLOB LAPACK_SOURCES ${ LAMMPS_LIB_SOURCE_DIR } /linalg/*.f )
2017-08-27 15:54:40 +08:00
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 } )
endif ( )
else ( )
add_library ( linalg STATIC ${ LAPACK_SOURCES } )
endif ( )
2017-08-28 02:10:46 +08:00
include ( CheckFortranCompilerFlag )
check_Fortran_compiler_flag ( "-fno-second-underscore" FC_HAS_NO_SECOND_UNDERSCORE )
if ( FC_HAS_NO_SECOND_UNDERSCORE )
target_compile_options ( linalg PRIVATE -fno-second-underscore )
endif ( )
2017-08-27 15:54:40 +08:00
set ( LAPACK_LIBRARIES linalg )
2017-07-17 11:43:29 +08:00
endif ( )
2017-07-17 06:18:58 +08:00
endif ( )
2017-07-16 07:29:33 +08:00
if ( ENABLE_PYTHON )
2017-07-20 05:15:24 +08:00
find_package ( PythonInterp REQUIRED )
2017-07-16 22:22:19 +08:00
find_package ( PythonLibs REQUIRED )
add_definitions ( -DLMP_PYTHON )
include_directories ( ${ PYTHON_INCLUDE_DIR } )
list ( APPEND LAMMPS_LINK_LIBS ${ PYTHON_LIBRARY } )
2017-07-25 10:17:17 +08:00
if ( NOT PYTHON_INSTDIR )
execute_process ( COMMAND ${ PYTHON_EXECUTABLE }
2017-07-20 05:15:24 +08:00
- c " i m p o r t d i s t u t i l s . s y s c o n f i g a s c g ; print ( cg.get_python_lib(1,0,prefix=' ${ CMAKE_INSTALL_PREFIX } ' ) ) "
2017-07-25 10:17:17 +08:00
O U T P U T _ V A R I A B L E P Y T H O N _ I N S T D I R O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
endif ( )
2017-07-20 05:15:24 +08:00
install ( FILES ${ CMAKE_SOURCE_DIR } /../python/lammps.py DESTINATION ${ PYTHON_INSTDIR } )
if ( NOT BUILD_SHARED_LIBS )
2017-08-01 01:35:41 +08:00
message ( FATAL_ERROR "Python package need lammps to be build shared, use -DBUILD_SHARED_LIBS=ON" )
2017-07-20 05:15:24 +08:00
endif ( )
2017-07-16 07:29:33 +08:00
endif ( )
2017-07-14 12:54:48 +08:00
find_package ( JPEG )
if ( JPEG_FOUND )
add_definitions ( -DLAMMPS_JPEG )
include_directories ( ${ JPEG_INCLUDE_DIR } )
2017-07-15 04:21:21 +08:00
list ( APPEND LAMMPS_LINK_LIBS ${ JPEG_LIBRARIES } )
2017-07-14 12:54:48 +08:00
endif ( )
2017-07-14 16:53:07 +08:00
find_package ( PNG )
2017-07-15 04:44:44 +08:00
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 } )
2017-07-14 16:53:07 +08:00
add_definitions ( -DLAMMPS_PNG )
2017-07-15 04:44:44 +08:00
endif ( )
2017-07-14 16:53:07 +08:00
2017-07-23 03:57:15 +08:00
find_program ( GZIP_EXECUTABLE gzip )
find_package_handle_standard_args ( GZIP REQUIRED_VARS GZIP_EXECUTABLE )
if ( GZIP_FOUND )
2017-07-15 04:49:53 +08:00
add_definitions ( -DLAMMPS_GZIP )
endif ( )
2017-07-23 03:57:15 +08:00
find_program ( FFMPEG_EXECUTABLE ffmpeg )
find_package_handle_standard_args ( FFMPEG REQUIRED_VARS FFMPEG_EXECUTABLE )
if ( FFMPEG_FOUND )
2017-07-18 04:01:05 +08:00
add_definitions ( -DLAMMPS_FFMPEG )
endif ( )
2017-07-17 01:29:31 +08:00
if ( ENABLE_VORONOI )
find_package ( VORO REQUIRED ) #some distros
include_directories ( ${ VORO_INCLUDE_DIRS } )
list ( APPEND LAMMPS_LINK_LIBS ${ VORO_LIBRARIES } )
endif ( )
2017-07-17 07:52:43 +08:00
if ( ENABLE_USER-MOLFILE )
2017-08-28 02:23:30 +08:00
add_library ( molfile INTERFACE )
target_include_directories ( molfile INTERFACE ${ LAMMPS_LIB_SOURCE_DIR } /molfile )
target_link_libraries ( molfile INTERFACE ${ CMAKE_DL_LIBS } )
list ( APPEND LAMMPS_LINK_LIBS molfile )
2017-07-17 07:52:43 +08:00
endif ( )
if ( ENABLE_USER-NETCDF )
find_package ( NetCDF REQUIRED )
include_directories ( NETCDF_INCLUDE_DIR )
list ( APPEND LAMMPS_LINK_LIBS ${ NETCDF_LIBRARY } )
add_definitions ( -DLMP_HAS_NETCDF -DNC_64BIT_DATA=0x0020 )
endif ( )
if ( ENABLE_USER-SMD )
find_package ( Eigen3 REQUIRED )
include_directories ( ${ EIGEN3_INCLUDE_DIR } )
endif ( )
2017-07-17 11:31:57 +08:00
if ( ENABLE_USER-QUIP )
find_package ( QUIP REQUIRED )
2017-08-27 21:13:55 +08:00
list ( APPEND LAMMPS_LINK_LIBS ${ QUIP_LIBRARIES } ${ LAPACK_LIBRARIES } ${ CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES } )
2017-07-17 11:31:57 +08:00
endif ( )
2017-07-17 12:07:21 +08:00
if ( ENABLE_USER-QMMM )
find_package ( QE REQUIRED )
include_directories ( ${ QE_INCLUDE_DIRS } )
2017-07-17 12:37:51 +08:00
list ( APPEND LAMMPS_LINK_LIBS ${ QE_LIBRARIES } ${ CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES } )
2017-07-17 12:07:21 +08:00
endif ( )
2017-07-20 08:34:07 +08:00
if ( ENABLE_USER-VTK )
find_package ( VTK REQUIRED NO_MODULE )
include ( ${ VTK_USE_FILE } )
add_definitions ( -DLAMMPS_VTK )
list ( APPEND LAMMPS_LINK_LIBS ${ VTK_LIBRARIES } )
endif ( )
if ( ENABLE_KIM )
find_package ( KIM REQUIRED )
list ( APPEND LAMMPS_LINK_LIBS ${ KIM_LIBRARIES } )
include_directories ( ${ KIM_INCLUDE_DIRS } )
endif ( )
if ( ENABLE_MSCG )
find_package ( GSL REQUIRED )
set ( LAMMPS_LIB_MSCG_BIN_DIR ${ LAMMPS_LIB_BINARY_DIR } /mscg )
set ( MSCG_TARBALL ${ LAMMPS_LIB_MSCG_BIN_DIR } /MS-CG-master.zip )
set ( LAMMPS_LIB_MSCG_BIN_DIR ${ LAMMPS_LIB_MSCG_BIN_DIR } /MSCG-release-master/src )
if ( NOT EXISTS ${ LAMMPS_LIB_MSCG_BIN_DIR } )
if ( NOT EXISTS ${ MSCG_TARBALL } )
message ( STATUS "Downloading ${MSCG_TARBALL}" )
file ( DOWNLOAD
h t t p s : / / g i t h u b . c o m / u c h i c a g o - v o t h / M S C G - r e l e a s e / a r c h i v e / m a s t e r . z i p
$ { M S C G _ T A R B A L L } S H O W _ P R O G R E S S ) #EXPECTED_MD5 cannot be due due to master
endif ( )
message ( STATUS "Unpacking ${MSCG_TARBALL}" )
execute_process ( COMMAND ${ CMAKE_COMMAND } -E tar xvf ${ MSCG_TARBALL }
W O R K I N G _ D I R E C T O R Y $ { L A M M P S _ L I B _ B I N A R Y _ D I R } / m s c g )
endif ( )
file ( GLOB MSCG_SOURCES ${ LAMMPS_LIB_MSCG_BIN_DIR } /*.cpp )
2017-08-28 03:45:48 +08:00
if ( BUILD_SHARED_PKG_LIBS )
add_library ( mscg SHARED ${ MSCG_SOURCES } )
set_target_properties ( mscg PROPERTIES SOVERSION ${ SOVERSION } )
if ( INSTALL_LIB )
install ( TARGETS mscg LIBRARY DESTINATION ${ CMAKE_INSTALL_LIBDIR } ARCHIVE DESTINATION ${ CMAKE_INSTALL_LIBDIR } )
endif ( )
else ( )
add_library ( mscg STATIC ${ MSCG_SOURCES } )
endif ( )
2017-08-27 21:15:00 +08:00
list ( APPEND LAMMPS_LINK_LIBS mscg )
target_compile_options ( mscg PRIVATE -DDIMENSION=3 -D_exclude_gromacs=1 )
target_include_directories ( mscg PUBLIC ${ LAMMPS_LIB_MSCG_BIN_DIR } )
target_link_libraries ( mscg ${ GSL_LIBRARIES } ${ LAPACK_LIBRARIES } )
2017-07-20 08:34:07 +08:00
endif ( )
2017-07-13 05:54:44 +08:00
########################################################################
# 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 )
2017-07-15 04:21:21 +08:00
list ( APPEND LAMMPS_LINK_LIBS ${ MATH_LIBRARIES } )
2017-07-13 05:54:44 +08:00
######################################
2017-07-20 08:34:07 +08:00
# Generate Basic Style files
2017-07-13 05:54:44 +08:00
######################################
2017-07-15 06:49:05 +08:00
include ( StyleHeaderUtils )
RegisterStyles ( ${ LAMMPS_SOURCE_DIR } )
2017-07-20 08:34:07 +08:00
##############################################
# add sources of enabled packages
############################################
2017-07-25 02:54:26 +08:00
foreach ( PKG ${ DEFAULT_PACKAGES } ${ OTHER_PACKAGES } )
2017-07-14 12:54:48 +08:00
if ( ENABLE_ ${ PKG } )
2017-07-15 06:49:05 +08:00
set ( ${ PKG } _SOURCES_DIR ${ LAMMPS_SOURCE_DIR } / ${ PKG } )
# detects styles in package and adds them to global list
RegisterStyles ( ${ ${PKG } _SOURCES_DIR} )
file ( GLOB ${ PKG } _SOURCES ${ ${PKG } _SOURCES_DIR}/*.cpp )
2017-07-14 12:54:48 +08:00
list ( APPEND LIB_SOURCES ${ ${PKG } _SOURCES} )
2017-07-15 06:49:05 +08:00
include_directories ( ${ ${PKG } _SOURCES_DIR} )
2017-07-14 12:54:48 +08:00
endif ( )
endforeach ( )
2017-07-14 13:27:55 +08:00
2017-07-20 08:34:07 +08:00
##############################################
# add lib sources of (simple) enabled packages
############################################
2017-07-17 07:52:43 +08:00
foreach ( SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD
2017-08-28 02:23:30 +08:00
U S E R - Q M M M )
2017-07-17 01:07:36 +08:00
if ( ENABLE_ ${ SIMPLE_LIB } )
2017-08-22 01:12:36 +08:00
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
$ { L A M M P S _ L I B _ S O U R C E _ D I R } / $ { P K G _ L I B } / * . c $ { L A M M P S _ L I B _ S O U R C E _ D I R } / $ { P K G _ L I B } / * . c p p )
2017-08-28 02:23:30 +08:00
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 } )
2017-08-22 03:09:52 +08:00
endif ( )
2017-08-27 15:04:32 +08:00
else ( )
2017-08-28 02:23:30 +08:00
add_library ( ${ PKG_LIB } STATIC ${ ${PKG_LIB } _SOURCES} )
endif ( )
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 )
else ( )
target_include_directories ( ${ PKG_LIB } PUBLIC ${ LAMMPS_LIB_SOURCE_DIR } / ${ PKG_LIB } )
2017-08-27 15:04:32 +08:00
endif ( )
2017-07-17 01:07:36 +08:00
endif ( )
endforeach ( )
2017-07-16 22:22:19 +08:00
2017-08-27 15:54:40 +08:00
if ( ENABLE_USER-AWPMD )
target_link_libraries ( awpmd ${ LAPACK_LIBRARIES } )
endif ( )
if ( ENABLE_USER-ATC )
target_link_libraries ( atc ${ LAPACK_LIBRARIES } )
endif ( )
2017-08-22 05:04:03 +08:00
if ( ENABLE_USER-H5MD )
find_package ( HDF5 REQUIRED )
target_link_libraries ( h5md ${ HDF5_LIBRARIES } )
2017-08-27 15:04:32 +08:00
target_include_directories ( h5md PRIVATE ${ HDF5_INCLUDE_DIRS } )
2017-08-22 05:04:03 +08:00
endif ( )
2017-08-28 02:10:46 +08:00
if ( ENABLE_MEAM AND FC_HAS_NO_SECOND_UNDERSCORE )
foreach ( FSRC ${ meam_SOURCES } )
if ( FSRC MATCHES "\.F$" )
set_property ( SOURCE ${ MSCG_SOURCE } APPEND PROPERTY COMPILE_FLAGS "-fno-second-underscore" )
endif ( )
endforeach ( )
endif ( )
if ( ENABLE_REAX AND FC_HAS_NO_SECOND_UNDERSCORE )
target_compile_options ( reax PRIVATE -fno-second-underscore )
endif ( )
2017-08-22 05:04:03 +08:00
2017-07-16 22:22:19 +08:00
######################################################################
2017-07-15 06:49:05 +08:00
# packages which selectively include variants based on enabled styles
# e.g. accelerator packages
2017-07-16 22:22:19 +08:00
######################################################################
2017-07-17 10:19:20 +08:00
if ( ENABLE_USER-OMP )
set ( USER-OMP_SOURCES_DIR ${ LAMMPS_SOURCE_DIR } /USER-OMP )
set ( USER-OMP_SOURCES ${ USER-OMP_SOURCES_DIR } /thr_data.cpp
$ { U S E R - O M P _ S O U R C E S _ D I R } / t h r _ o m p . c p p
$ { U S E R - O M P _ S O U R C E S _ D I R } / f i x _ n h _ o m p . c p p
$ { U S E R - O M P _ S O U R C E S _ D I R } / f i x _ n h _ s p h e r e _ o m p . c p p )
set_property ( GLOBAL PROPERTY "OMP_SOURCES" "${USER-OMP_SOURCES}" )
2017-07-15 11:07:53 +08:00
# detects styles which have USER-OMP version
2017-07-17 10:19:20 +08:00
RegisterStylesExt ( ${ USER-OMP_SOURCES_DIR } omp OMP_SOURCES )
2017-07-15 11:07:53 +08:00
2017-07-17 10:19:20 +08:00
get_property ( USER-OMP_SOURCES GLOBAL PROPERTY OMP_SOURCES )
2017-07-15 11:07:53 +08:00
2017-07-17 10:19:20 +08:00
list ( APPEND LIB_SOURCES ${ USER-OMP_SOURCES } )
include_directories ( ${ USER-OMP_SOURCES_DIR } )
2017-07-15 11:07:53 +08:00
endif ( )
2017-07-16 04:33:36 +08:00
if ( ENABLE_KOKKOS )
2017-07-20 08:34:07 +08:00
set ( LAMMPS_LIB_KOKKOS_SRC_DIR ${ LAMMPS_LIB_SOURCE_DIR } /kokkos )
set ( LAMMPS_LIB_KOKKOS_BIN_DIR ${ LAMMPS_LIB_BINARY_DIR } /kokkos )
add_definitions ( -DLMP_KOKKOS )
add_subdirectory ( ${ LAMMPS_LIB_KOKKOS_SRC_DIR } ${ LAMMPS_LIB_KOKKOS_BIN_DIR } )
set ( Kokkos_INCLUDE_DIRS ${ LAMMPS_LIB_KOKKOS_SRC_DIR } /core/src
$ { L A M M P S _ L I B _ K O K K O S _ S R C _ D I R } / c o n t a i n e r s / s r c
$ { L A M M P S _ L I B _ K O K K O S _ S R C _ D I R } / a l g o r i t h m s / s r c
$ { L A M M P S _ L I B _ K O K K O S _ B I N _ D I R } )
include_directories ( ${ Kokkos_INCLUDE_DIRS } )
list ( APPEND LAMMPS_LINK_LIBS kokkos )
set ( KOKKOS_PKG_SOURCES_DIR ${ LAMMPS_SOURCE_DIR } /KOKKOS )
set ( KOKKOS_PKG_SOURCES ${ KOKKOS_PKG_SOURCES_DIR } /kokkos.cpp
$ { K O K K O S _ P K G _ S O U R C E S _ D I R } / a t o m _ k o k k o s . c p p
$ { K O K K O S _ P K G _ S O U R C E S _ D I R } / a t o m _ v e c _ k o k k o s . c p p
$ { K O K K O S _ P K G _ S O U R C E S _ D I R } / c o m m _ k o k k o s . c p p
$ { K O K K O S _ P K G _ S O U R C E S _ D I R } / c o m m _ t i l e d _ k o k k o s . c p p
$ { K O K K O S _ P K G _ S O U R C E S _ D I R } / n e i g h b o r _ k o k k o s . c p p
$ { K O K K O S _ P K G _ S O U R C E S _ D I R } / n e i g h _ l i s t _ k o k k o s . c p p
$ { K O K K O S _ P K G _ S O U R C E S _ D I R } / n e i g h _ b o n d _ k o k k o s . c p p
$ { K O K K O S _ P K G _ S O U R C E S _ D I R } / f i x _ n h _ k o k k o s . c p p
$ { K O K K O S _ P K G _ S O U R C E S _ D I R } / d o m a i n _ k o k k o s . c p p
$ { K O K K O S _ P K G _ S O U R C E S _ D I R } / m o d i f y _ k o k k o s . c p p )
set_property ( GLOBAL PROPERTY "KOKKOS_PKG_SOURCES" "${KOKKOS_PKG_SOURCES}" )
# detects styles which have KOKKOS version
RegisterStylesExt ( ${ KOKKOS_PKG_SOURCES_DIR } kokkos KOKKOS_PKG_SOURCES )
get_property ( KOKKOS_PKG_SOURCES GLOBAL PROPERTY KOKKOS_PKG_SOURCES )
list ( APPEND LIB_SOURCES ${ KOKKOS_PKG_SOURCES } )
include_directories ( ${ KOKKOS_PKG_SOURCES_DIR } )
2017-07-16 04:33:36 +08:00
endif ( )
2017-07-17 08:52:38 +08:00
if ( ENABLE_OPT )
set ( OPT_SOURCES_DIR ${ LAMMPS_SOURCE_DIR } /OPT )
set ( OPT_SOURCES )
set_property ( GLOBAL PROPERTY "OPT_SOURCES" "${OPT_SOURCES}" )
# detects styles which have OPT version
RegisterStylesExt ( ${ OPT_SOURCES_DIR } opt OPT_SOURCES )
get_property ( OPT_SOURCES GLOBAL PROPERTY OPT_SOURCES )
list ( APPEND LIB_SOURCES ${ OPT_SOURCES } )
include_directories ( ${ OPT_SOURCES_DIR } )
endif ( )
2017-07-17 12:52:59 +08:00
if ( ENABLE_USER-INTEL )
set ( USER-INTEL_SOURCES_DIR ${ LAMMPS_SOURCE_DIR } /USER-INTEL )
set ( USER-INTEL_SOURCES ${ USER-INTEL_SOURCES_DIR } /intel_preprocess.h
$ { U S E R - I N T E L _ S O U R C E S _ D I R } / i n t e l _ b u f f e r s . h
$ { U S E R - I N T E L _ S O U R C E S _ D I R } / i n t e l _ b u f f e r s . c p p
$ { U S E R - I N T E L _ S O U R C E S _ D I R } / m a t h _ e x t r a _ i n t e l . h
$ { U S E R - I N T E L _ S O U R C E S _ D I R } / n b i n _ i n t e l . h
$ { U S E R - I N T E L _ S O U R C E S _ D I R } / n b i n _ i n t e l . c p p
$ { U S E R - I N T E L _ S O U R C E S _ D I R } / n p a i r _ i n t e l . h
$ { U S E R - I N T E L _ S O U R C E S _ D I R } / n p a i r _ i n t e l . c p p
$ { U S E R - I N T E L _ S O U R C E S _ D I R } / i n t e l _ s i m d . h
$ { U S E R - I N T E L _ S O U R C E S _ D I R } / i n t e l _ i n t r i n s i c s . h )
set_property ( GLOBAL PROPERTY "USER-INTEL_SOURCES" "${USER-INTEL_SOURCES}" )
# detects styles which have USER-INTEL version
RegisterStylesExt ( ${ USER-INTEL_SOURCES_DIR } opt USER-INTEL_SOURCES )
get_property ( USER-INTEL_SOURCES GLOBAL PROPERTY USER-INTEL_SOURCES )
list ( APPEND LIB_SOURCES ${ USER-INTEL_SOURCES } )
include_directories ( ${ USER-INTEL_SOURCES_DIR } )
endif ( )
2017-07-15 06:49:05 +08:00
2017-07-17 13:03:11 +08:00
if ( ENABLE_GPU )
find_package ( CUDA REQUIRED )
2017-07-19 03:47:03 +08:00
find_program ( BIN2C bin2c )
if ( NOT BIN2C )
2017-08-01 01:35:41 +08:00
message ( FATAL_ERROR "Couldn't find bin2c, use -DBIN2C helping cmake to find it." )
2017-07-19 03:47:03 +08:00
endif ( )
set ( GPU_PREC "SINGLE_DOUBLE" CACHE STRING "Lammps gpu precision size" )
set_property ( CACHE GPU_PREC PROPERTY STRINGS SINGLE_DOUBLE SINGLE_SINGLE DOUBLE_DOUBLE )
2017-07-21 04:30:52 +08:00
option ( CUDPP_OPT "Enable CUDPP_OPT" ON )
2017-07-17 13:03:11 +08:00
2017-07-21 04:12:17 +08:00
file ( GLOB GPU_LIB_SOURCES ${ LAMMPS_LIB_SOURCE_DIR } /gpu/*.cpp )
file ( GLOB GPU_LIB_CU ${ LAMMPS_LIB_SOURCE_DIR } /gpu/*.cu ${ CMAKE_SOURCE_DIR } /gpu/*.cu )
2017-07-19 06:01:35 +08:00
file ( GLOB_RECURSE GPU_NOT_LIB_CU ${ LAMMPS_LIB_SOURCE_DIR } /gpu/lal_pppm.cu )
list ( REMOVE_ITEM GPU_LIB_CU ${ GPU_NOT_LIB_CU } )
2017-08-28 04:58:19 +08:00
# still missing a way to limit defines to GPU build only
# something like cuda_compile_definitions()
# one way is this, the other adding it to OPTIONS
add_definitions ( -D_ ${ GPU_PREC } )
add_definitions ( -DNV_KERNEL -DUCL_CUDADR )
cuda_include_directories ( ${ LAMMPS_LIB_SOURCE_DIR } /gpu ${ LAMMPS_LIB_BINARY_DIR } /gpu )
2017-07-21 04:30:52 +08:00
if ( CUDPP_OPT )
2017-08-28 04:58:19 +08:00
cuda_include_directories ( ${ LAMMPS_LIB_SOURCE_DIR } /gpu/cudpp_mini )
2017-07-21 04:30:52 +08:00
file ( GLOB GPU_LIB_CUDPP_SOURCES ${ LAMMPS_LIB_SOURCE_DIR } /gpu/cudpp_mini/*.cpp )
file ( GLOB GPU_LIB_CUDPP_CU ${ LAMMPS_LIB_SOURCE_DIR } /gpu/cudpp_mini/*.cu )
endif ( )
2017-08-28 04:58:19 +08:00
2017-07-21 04:30:52 +08:00
cuda_compile ( GPU_OBJS ${ GPU_LIB_CU } ${ GPU_LIB_CUDPP_CU } OPTIONS $< $<BOOL:${BUILD_SHARED_LIBS} > :-Xcompiler=-fPIC> )
2017-08-28 04:58:19 +08:00
2017-07-19 06:01:35 +08:00
file ( MAKE_DIRECTORY ${ LAMMPS_LIB_BINARY_DIR } /gpu )
2017-07-19 08:38:36 +08:00
foreach ( CU_OBJ ${ GPU_OBJS } )
get_filename_component ( CU_NAME ${ CU_OBJ } NAME_WE )
string ( REGEX REPLACE "^.*_lal_" "" CU_NAME "${CU_NAME}" )
add_custom_command ( OUTPUT ${ LAMMPS_LIB_BINARY_DIR } /gpu/ ${ CU_NAME } _cubin.h
2017-07-19 09:29:40 +08:00
C O M M A N D $ { B I N 2 C } - c - n $ { C U _ N A M E } $ { C U _ O B J } > $ { L A M M P S _ L I B _ B I N A R Y _ D I R } / g p u / $ { C U _ N A M E } _ c u b i n . h
2017-07-19 06:01:35 +08:00
D E P E N D S $ { C U _ O B J }
2017-07-19 08:38:36 +08:00
C O M M E N T " G e n e r a t i n g $ { C U _ N A M E } _ c u b i n . h " )
2017-08-28 04:58:19 +08:00
list ( APPEND GPU_LIB_SOURCES ${ LAMMPS_LIB_BINARY_DIR } /gpu/ ${ CU_NAME } _cubin.h )
2017-07-21 04:12:17 +08:00
if ( ${ CU_NAME } STREQUAL "pppm_d" ) #pppm_d doesn't get linked into the lib
set ( CU_FORBIDDEN_OBJ "${CU_OBJ}" )
endif ( )
2017-07-19 06:01:35 +08:00
endforeach ( )
2017-07-21 04:12:17 +08:00
list ( REMOVE_ITEM GPU_OBJS "${CU_FORBIDDEN_OBJ}" )
2017-07-26 09:09:20 +08:00
set_directory_properties ( PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${LAMMPS_LIB_BINARY_DIR}/gpu/*_cubin.h" )
2017-08-28 04:58:19 +08:00
cuda_add_library ( gpu ${ GPU_LIB_SOURCES } ${ GPU_LIB_CUDPP_SOURCES } ${ GPU_OBJS } STATIC )
target_include_directories ( gpu PRIVATE ${ LAMMPS_LIB_BINARY_DIR } /gpu )
if ( CUDPP_OPT )
target_include_directories ( gpu PRIVATE ${ LAMMPS_LIB_SOURCE_DIR } /gpu/cudpp_mini )
target_compile_definitions ( gpu PRIVATE -DUSE_CUDPP )
endif ( )
list ( APPEND LAMMPS_LINK_LIBS gpu )
# GPU package
set ( GPU_SOURCES_DIR ${ LAMMPS_SOURCE_DIR } /GPU )
set ( GPU_SOURCES ${ GPU_SOURCES_DIR } /gpu_extra.h )
include_directories ( ${ GPU_SOURCES_DIR } )
set_property ( GLOBAL PROPERTY "GPU_SOURCES" "${GPU_SOURCES}" )
# detects styles which have GPU version
RegisterStylesExt ( ${ GPU_SOURCES_DIR } opt GPU_SOURCES )
get_property ( GPU_SOURCES GLOBAL PROPERTY GPU_SOURCES )
list ( APPEND LIB_SOURCES ${ GPU_SOURCES } )
2017-07-17 13:03:11 +08:00
endif ( )
2017-07-15 06:49:05 +08:00
######################################################
# Generate style headers based on global list of
# styles registered during package selection
######################################################
set ( LAMMPS_STYLE_HEADERS_DIR ${ CMAKE_CURRENT_BINARY_DIR } /styles )
GenerateStyleHeaders ( ${ LAMMPS_STYLE_HEADERS_DIR } )
2017-07-14 17:00:38 +08:00
include_directories ( ${ LAMMPS_SOURCE_DIR } )
2017-07-15 06:49:05 +08:00
include_directories ( ${ LAMMPS_STYLE_HEADERS_DIR } )
2017-07-20 08:34:07 +08:00
###########################################
# Actually add executable and lib to build
############################################
2017-07-15 04:21:21 +08:00
add_library ( lammps ${ LIB_SOURCES } )
target_link_libraries ( lammps ${ LAMMPS_LINK_LIBS } )
2017-07-13 05:54:44 +08:00
set_target_properties ( lammps PROPERTIES SOVERSION ${ SOVERSION } )
2017-07-15 08:33:27 +08:00
if ( INSTALL_LIB )
install ( TARGETS lammps LIBRARY DESTINATION ${ CMAKE_INSTALL_LIBDIR } ARCHIVE DESTINATION ${ CMAKE_INSTALL_LIBDIR } )
install ( FILES ${ LAMMPS_SOURCE_DIR } /lammps.h DESTINATION ${ CMAKE_INSTALL_INCLUDEDIR } )
endif ( )
2017-07-13 05:54:44 +08:00
add_executable ( lmp ${ LMP_SOURCES } )
target_link_libraries ( lmp lammps )
2017-07-15 08:33:27 +08:00
install ( TARGETS lmp DESTINATION ${ CMAKE_INSTALL_BINDIR } )
2017-07-21 06:14:02 +08:00
if ( ENABLE_TESTING )
2017-07-26 09:09:20 +08:00
add_test ( ShowHelp ${ CMAKE_CURRENT_BINARY_DIR } /lmp -help )
2017-07-21 06:14:02 +08:00
endif ( )
2017-07-15 07:41:13 +08:00
2017-07-20 08:34:07 +08:00
##################################
# Print package summary
##################################
2017-07-21 05:15:29 +08:00
foreach ( PKG ${ DEFAULT_PACKAGES } ${ OTHER_PACKAGES } ${ ACCEL_PACKAGES } )
2017-07-15 07:41:13 +08:00
if ( ENABLE_ ${ PKG } )
message ( STATUS "Building package: ${PKG}" )
endif ( )
endforeach ( )