CMakeLists.txt 48.1 KB
Newer Older
1
2
3
4
########################################
# CMake build system
# This file is part of LAMMPS
# Created by Christoph Junghans and Richard Berger
5
cmake_minimum_required(VERSION 2.8.12)
Christoph Junghans's avatar
Christoph Junghans committed
6

7
project(lammps CXX)
Christoph Junghans's avatar
Christoph Junghans committed
8
set(SOVERSION 0)
9
10
11
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)
12
get_filename_component(LAMMPS_DOC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../doc ABSOLUTE)
13

Christoph Junghans's avatar
Christoph Junghans committed
14

15
# To avoid conflicts with the conventional Makefile build system, we build everything here
Christoph Junghans's avatar
Christoph Junghans committed
16
17
18
19
file(GLOB LIB_SOURCES ${LAMMPS_SOURCE_DIR}/*.cpp)
file(GLOB LMP_SOURCES ${LAMMPS_SOURCE_DIR}/main.cpp)
list(REMOVE_ITEM LIB_SOURCES ${LMP_SOURCES})

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Utility functions
function(list_to_bulletpoints result)
    list(REMOVE_AT ARGV 0)
    set(temp "")
    foreach(item ${ARGV})
        set(temp "${temp}* ${item}\n")
    endforeach()
    set(${result} "${temp}" PARENT_SCOPE)
endfunction(list_to_bulletpoints)

function(validate_option name values)
    string(TOLOWER ${${name}} needle_lower)
    string(TOUPPER ${${name}} needle_upper)
    list(FIND ${values} ${needle_lower} IDX_LOWER)
    list(FIND ${values} ${needle_upper} IDX_UPPER)
    if(${IDX_LOWER} LESS 0 AND ${IDX_UPPER} LESS 0)
        list_to_bulletpoints(POSSIBLE_VALUE_LIST ${${values}})
        message(FATAL_ERROR "\n########################################################################\n"
Richard Berger's avatar
Richard Berger committed
38
                            "Invalid value '${${name}}' for option ${name}\n"
39
40
41
42
43
44
45
                            "\n"
                            "Possible values are:\n"
                            "${POSSIBLE_VALUE_LIST}"
                            "########################################################################")
    endif()
endfunction(validate_option)

Christoph Junghans's avatar
Christoph Junghans committed
46
# Cmake modules/macros are in a subdirectory to keep this file cleaner
47
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Modules)
48

49
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS)
Christoph Junghans's avatar
Christoph Junghans committed
50
51
  #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)
52
endif(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS)
Christoph Junghans's avatar
Christoph Junghans committed
53

54
55
56
57
58
59
60
61
# check for files auto-generated by make-based buildsystem
# this is fast, so check for it all the time
message(STATUS "Running check for auto-generated files from make-based build system")
file(GLOB SRC_AUTOGEN_FILES ${LAMMPS_SOURCE_DIR}/style_*.h)
list(APPEND SRC_AUTOGEN_FILES ${LAMMPS_SOURCE_DIR}/lmpinstalledpkgs.h)
foreach(_SRC ${SRC_AUTOGEN_FILES})
  get_filename_component(FILENAME "${_SRC}" NAME)
  if(EXISTS ${LAMMPS_SOURCE_DIR}/${FILENAME})
62
63
64
65
66
67
68
    message(FATAL_ERROR "\n########################################################################\n"
                          "Found header file(s) generated by the make-based build system\n"
                          "\n"
                          "Please run\n"
                          "make -C ${LAMMPS_SOURCE_DIR} purge\n"
                          "to remove\n"
                          "########################################################################")
69
70
  endif()
endforeach()
71

Christoph Junghans's avatar
Christoph Junghans committed
72
73
74
75
76
77
######################################################################
# compiler tests
# these need ot be done early (before further tests).
#####################################################################
include(CheckCCompilerFlag)

78
79
80
81
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
  set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -restrict")
endif()

82
83
84
# GNU compiler features
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
  option(ENABLE_COVERAGE "Enable code coverage" OFF)
85
  mark_as_advanced(ENABLE_COVERAGE)
86
87
88
89
  if(ENABLE_COVERAGE)
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
  endif()
  option(ENABLE_SANITIZE_ADDRESS "Enable address sanitizer" OFF)
90
  mark_as_advanced(ENABLE_SANITIZE_ADDRESS)
91
92
93
94
  if(ENABLE_SANITIZE_ADDRESS)
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
  endif()
  option(ENABLE_SANITIZE_UNDEFINED "Enable undefined behavior sanitizer" OFF)
95
  mark_as_advanced(ENABLE_SANITIZE_UNDEFINED)
96
97
98
99
  if(ENABLE_SANITIZE_UNDEFINED)
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
  endif()
  option(ENABLE_SANITIZE_THREAD "Enable thread sanitizer" OFF)
100
  mark_as_advanced(ENABLE_SANITIZE_THREAD)
101
102
103
  if(ENABLE_SANITIZE_THREAD)
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
  endif()
104
105
endif()

Christoph Junghans's avatar
Christoph Junghans committed
106
107
108
########################################################################
# User input options                                                   #
########################################################################
109
110
111
112
113
114
115
116
117
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()
endif()

118
119
120
121
122
123
124
125
126
127
128
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(LIB_SUFFIX "" CACHE STRING "Suffix to append to liblammps and pkg-config file")
  mark_as_advanced(LIB_SUFFIX)
  if(LIB_SUFFIX)
    set(LIB_SUFFIX "_${LIB_SUFFIX}")
  endif()
Christoph Junghans's avatar
Christoph Junghans committed
129
endif()
130
131
132

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")
Christoph Junghans's avatar
Christoph Junghans committed
133
endif()
134

135
option(CMAKE_VERBOSE_MAKEFILE "Generate verbose Makefiles" OFF)
Christoph Junghans's avatar
Christoph Junghans committed
136
137
include(GNUInstallDirs)

Christoph Junghans's avatar
Christoph Junghans committed
138
set(LAMMPS_LINK_LIBS)
139
set(LAMMPS_DEPS)
Christoph Junghans's avatar
Christoph Junghans committed
140
set(LAMMPS_API_DEFINES)
141
142
143
144

find_package(MPI QUIET)
option(BUILD_MPI "Build MPI version" ${MPI_FOUND})
if(BUILD_MPI)
Christoph Junghans's avatar
Christoph Junghans committed
145
  find_package(MPI REQUIRED)
146
  include_directories(${MPI_CXX_INCLUDE_PATH})
Christoph Junghans's avatar
Christoph Junghans committed
147
  list(APPEND LAMMPS_LINK_LIBS ${MPI_CXX_LIBRARIES})
148
  option(LAMMPS_LONGLONG_TO_LONG "Workaround if your system or MPI version does not recognize 'long long' data types" OFF)
149
150
151
  if(LAMMPS_LONGLONG_TO_LONG)
    add_definitions(-DLAMMPS_LONGLONG_TO_LONG)
  endif()
Christoph Junghans's avatar
Christoph Junghans committed
152
else()
153
  enable_language(C)
Christoph Junghans's avatar
Christoph Junghans committed
154
  file(GLOB MPI_SOURCES ${LAMMPS_SOURCE_DIR}/STUBS/mpi.c)
155
  add_library(mpi_stubs STATIC ${MPI_SOURCES})
Christoph Junghans's avatar
Christoph Junghans committed
156
  include_directories(${LAMMPS_SOURCE_DIR}/STUBS)
Christoph Junghans's avatar
Christoph Junghans committed
157
  list(APPEND LAMMPS_LINK_LIBS mpi_stubs)
Christoph Junghans's avatar
Christoph Junghans committed
158
159
endif()

160

161
set(LAMMPS_SIZES "smallbig" CACHE STRING "LAMMPS size limit")
162
163
164
165
166
167
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}")
Christoph Junghans's avatar
Christoph Junghans committed
168

169
170
# posix_memalign is not available on Windows
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
171
172
173
174
  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()
175
endif()
176

Richard Berger's avatar
Richard Berger committed
177
178
179
option(LAMMPS_EXCEPTIONS "enable the use of C++ exceptions for error messages (useful for library interface)" OFF)
if(LAMMPS_EXCEPTIONS)
  add_definitions(-DLAMMPS_EXCEPTIONS)
Richard Berger's avatar
Richard Berger committed
180
  set(LAMMPS_API_DEFINES "${LAMMPS_API_DEFINES} -DLAMMPS_EXCEPTIONS")
Richard Berger's avatar
Richard Berger committed
181
182
endif()

Christoph Junghans's avatar
Christoph Junghans committed
183
184
option(CMAKE_VERBOSE_MAKEFILE "Verbose makefile" OFF)

Christoph Junghans's avatar
Christoph Junghans committed
185
186
187
188
189
option(ENABLE_TESTING "Enable testing" OFF)
if(ENABLE_TESTING)
  enable_testing()
endif(ENABLE_TESTING)

190
set(DEFAULT_PACKAGES ASPHERE BODY CLASS2 COLLOID COMPRESS DIPOLE GRANULAR
191
  KSPACE MANYBODY MC MEAM MISC MOLECULE PERI REAX REPLICA RIGID SHOCK SPIN SNAP
192
193
194
  SRD KIM PYTHON MSCG MPIIO VORONOI POEMS LATTE 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
Christoph Junghans's avatar
Christoph Junghans committed
195
  USER-MOFFF USER-MOLFILE USER-NETCDF USER-PHONON USER-QTB USER-REAXC USER-SMD
Christoph Junghans's avatar
Christoph Junghans committed
196
  USER-SMTBQ USER-SPH USER-TALLY USER-UEF USER-VTK USER-QUIP USER-QMMM)
197
set(ACCEL_PACKAGES USER-OMP KOKKOS OPT USER-INTEL GPU)
198
set(OTHER_PACKAGES CORESHELL QEQ)
199
foreach(PKG ${DEFAULT_PACKAGES})
Richard Berger's avatar
Richard Berger committed
200
  option(PKG_${PKG} "Build ${PKG} Package" OFF)
201
endforeach()
202
foreach(PKG ${ACCEL_PACKAGES} ${OTHER_PACKAGES})
203
  option(PKG_${PKG} "Build ${PKG} Package" OFF)
204
205
endforeach()

Christoph Junghans's avatar
Christoph Junghans committed
206
macro(pkg_depends PKG1 PKG2)
207
  if(PKG_${PKG1} AND NOT (PKG_${PKG2} OR BUILD_${PKG2}))
Christoph Junghans's avatar
Christoph Junghans committed
208
    message(FATAL_ERROR "${PKG1} package needs LAMMPS to be build with ${PKG2}")
Christoph Junghans's avatar
Christoph Junghans committed
209
210
211
  endif()
endmacro()

212
213
# "hard" dependencies between packages resulting
# in an error instead of skipping over files
Christoph Junghans's avatar
Christoph Junghans committed
214
pkg_depends(MPIIO MPI)
Christoph Junghans's avatar
Christoph Junghans committed
215
pkg_depends(USER-ATC MANYBODY)
Christoph Junghans's avatar
Christoph Junghans committed
216
pkg_depends(USER-LB MPI)
Christoph Junghans's avatar
Christoph Junghans committed
217
pkg_depends(USER-PHONON KSPACE)
Christoph Junghans's avatar
Christoph Junghans committed
218

219
220
221
######################################################
# packages with special compiler needs or external libs
######################################################
222
if(PKG_REAX OR PKG_MEAM OR PKG_USER-QUIP OR PKG_USER-QMMM OR PKG_LATTE)
Christoph Junghans's avatar
Christoph Junghans committed
223
224
225
  enable_language(Fortran)
endif()

226
if(PKG_MEAM OR PKG_USER-H5MD OR PKG_USER-QMMM)
227
228
229
  enable_language(C)
endif()

230
231
find_package(OpenMP QUIET)
option(BUILD_OMP "Build with OpenMP support" ${OpenMP_FOUND})
232
if(BUILD_OMP OR PKG_USER-OMP OR PKG_KOKKOS OR PKG_USER-INTEL)
Christoph Junghans's avatar
Christoph Junghans committed
233
234
235
236
237
  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()

238
if(PKG_KSPACE)
239
240
241
242
243
244
245
246
  option(FFT_SINGLE "Use single precision FFT instead of double" OFF)
  set(FFTW "FFTW3")
  if(FFT_SINGLE)
    set(FFTW "FFTW3F")
    add_definitions(-DFFT_SINGLE)
  endif()
  find_package(${FFTW} QUIET)
  if(${FFTW}_FOUND)
247
    set(FFT "${FFTW}" CACHE STRING "FFT library for KSPACE package")
248
  else()
249
    set(FFT "KISS" CACHE STRING "FFT library for KSPACE package")
250
  endif()
251
252
253
  set(FFT_VALUES KISS ${FFTW} MKL)
  set_property(CACHE FFT PROPERTY STRINGS ${FFT_VALUES})
  validate_option(FFT FFT_VALUES)
254
  string(TOUPPER ${FFT} FFT)
255
  if(NOT FFT STREQUAL "KISS")
256
    find_package(${FFT} REQUIRED)
257
    if(NOT FFT STREQUAL "FFTW3F")
258
      add_definitions(-DFFT_FFTW)
259
260
261
    else()
      add_definitions(-DFFT_${FFT})
    endif()
262
263
    include_directories(${${FFT}_INCLUDE_DIRS})
    list(APPEND LAMMPS_LINK_LIBS ${${FFT}_LIBRARIES})
264
  else()
265
    add_definitions(-DFFT_KISS)
266
  endif()
267
  set(FFT_PACK "array" CACHE STRING "Optimization for FFT")
268
269
270
  set(FFT_PACK_VALUES array pointer memcpy)
  set_property(CACHE FFT_PACK PROPERTY STRINGS ${FFT_PACK_VALUES})
  validate_option(FFT_PACK FFT_PACK_VALUES)
271
  if(NOT FFT_PACK STREQUAL "array")
272
273
    string(TOUPPER ${FFT_PACK} FFT_PACK)
    add_definitions(-DFFT_PACK_${FFT_PACK})
Christoph Junghans's avatar
Christoph Junghans committed
274
  endif()
275
276
endif()

277
if(PKG_MSCG OR PKG_USER-ATC OR PKG_USER-AWPMD OR PKG_USER-QUIP OR PKG_LATTE)
Christoph Junghans's avatar
Christoph Junghans committed
278
  find_package(LAPACK)
279
  if(NOT LAPACK_FOUND)
Christoph Junghans's avatar
Christoph Junghans committed
280
    enable_language(Fortran)
281
    file(GLOB LAPACK_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/linalg/*.[fF])
282
    add_library(linalg STATIC ${LAPACK_SOURCES})
283
    set(LAPACK_LIBRARIES linalg)
Christoph Junghans's avatar
Christoph Junghans committed
284
  endif()
Christoph Junghans's avatar
Christoph Junghans committed
285
286
endif()

287
if(PKG_PYTHON)
Christoph Junghans's avatar
Christoph Junghans committed
288
  find_package(PythonInterp REQUIRED)
Christoph Junghans's avatar
Christoph Junghans committed
289
290
291
292
  find_package(PythonLibs REQUIRED)
  add_definitions(-DLMP_PYTHON)
  include_directories(${PYTHON_INCLUDE_DIR})
  list(APPEND LAMMPS_LINK_LIBS ${PYTHON_LIBRARY})
Christoph Junghans's avatar
Christoph Junghans committed
293
  if(BUILD_LIB AND BUILD_SHARED_LIBS)
294
295
296
297
298
299
    if(NOT PYTHON_INSTDIR)
      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_INSTDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
    endif()
    install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../python/lammps.py DESTINATION ${PYTHON_INSTDIR})
Christoph Junghans's avatar
Christoph Junghans committed
300
  endif()
301
302
endif()

303
find_package(JPEG QUIET)
304
305
option(WITH_JPEG "Enable JPEG support" ${JPEG_FOUND})
if(WITH_JPEG)
306
  find_package(JPEG REQUIRED)
307
308
  add_definitions(-DLAMMPS_JPEG)
  include_directories(${JPEG_INCLUDE_DIR})
Christoph Junghans's avatar
Christoph Junghans committed
309
  list(APPEND LAMMPS_LINK_LIBS ${JPEG_LIBRARIES})
310
311
endif()

312
313
find_package(PNG QUIET)
find_package(ZLIB QUIET)
Christoph Junghans's avatar
Christoph Junghans committed
314
if(PNG_FOUND AND ZLIB_FOUND)
315
  option(WITH_PNG "Enable PNG support" ON)
316
else()
317
  option(WITH_PNG "Enable PNG support" OFF)
318
endif()
319
if(WITH_PNG)
320
321
  find_package(PNG REQUIRED)
  find_package(ZLIB REQUIRED)
Christoph Junghans's avatar
Christoph Junghans committed
322
323
  include_directories(${PNG_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS})
  list(APPEND LAMMPS_LINK_LIBS ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
324
  add_definitions(-DLAMMPS_PNG)
Christoph Junghans's avatar
Christoph Junghans committed
325
endif()
326

327
328
find_program(GZIP_EXECUTABLE gzip)
find_package_handle_standard_args(GZIP REQUIRED_VARS GZIP_EXECUTABLE)
329
330
option(WITH_GZIP "Enable GZIP support" ${GZIP_FOUND})
if(WITH_GZIP)
331
332
333
  if(NOT GZIP_FOUND)
    message(FATAL_ERROR "gzip executable not found")
  endif()
334
335
336
  add_definitions(-DLAMMPS_GZIP)
endif()

337
338
find_program(FFMPEG_EXECUTABLE ffmpeg)
find_package_handle_standard_args(FFMPEG REQUIRED_VARS FFMPEG_EXECUTABLE)
339
340
option(WITH_FFMPEG "Enable FFMPEG support" ${FFMPEG_FOUND})
if(WITH_FFMPEG)
341
342
343
  if(NOT FFMPEG_FOUND)
    message(FATAL_ERROR "ffmpeg executable not found")
  endif()
344
345
346
  add_definitions(-DLAMMPS_FFMPEG)
endif()

347
if(PKG_VORONOI)
348
349
350
  option(DOWNLOAD_VORO "Download voro++ (instead of using the system's one)" OFF)
  if(DOWNLOAD_VORO)
    include(ExternalProject)
351
352
353
354

    if(BUILD_SHARED_LIBS)
        set(VORO_BUILD_OPTIONS "CFLAGS=-fPIC")
    else()
Richard Berger's avatar
Richard Berger committed
355
        set(VORO_BUILD_OPTIONS)
356
357
    endif()

358
359
360
    ExternalProject_Add(voro_build
      URL http://math.lbl.gov/voro++/download/dir/voro++-0.4.6.tar.gz
      URL_MD5 2338b824c3b7b25590e18e8df5d68af9
361
      CONFIGURE_COMMAND "" BUILD_COMMAND make ${VORO_BUILD_OPTIONS} BUILD_IN_SOURCE 1 INSTALL_COMMAND ""
362
363
364
365
366
367
368
369
370
371
372
      )
    ExternalProject_get_property(voro_build SOURCE_DIR)
    set(VORO_LIBRARIES ${SOURCE_DIR}/src/libvoro++.a)
    set(VORO_INCLUDE_DIRS ${SOURCE_DIR}/src)
    list(APPEND LAMMPS_DEPS voro_build)
  else()
    find_package(VORO)
    if(NOT VORO_FOUND)
      message(FATAL_ERROR "VORO not found, help CMake to find it by setting VORO_LIBRARY and VORO_INCLUDE_DIR, or set DOWNLOAD_VORO=ON to download it")
    endif()
  endif()
373
374
375
376
  include_directories(${VORO_INCLUDE_DIRS})
  list(APPEND LAMMPS_LINK_LIBS ${VORO_LIBRARIES})
endif()

377
if(PKG_LATTE)
378
379
  option(DOWNLOAD_LATTE "Download latte (instead of using the system's one)" OFF)
  if(DOWNLOAD_LATTE)
380
381
382
    message(STATUS "LATTE not found - we will build our own")
    include(ExternalProject)
    ExternalProject_Add(latte_build
383
      URL https://github.com/lanl/LATTE/archive/v1.2.1.tar.gz
384
      URL_MD5 85ac414fdada2d04619c8f936344df14
385
386
387
388
389
390
      SOURCE_SUBDIR cmake
      CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}
      )
    ExternalProject_get_property(latte_build INSTALL_DIR)
    set(LATTE_LIBRARIES ${INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}/liblatte.a)
    list(APPEND LAMMPS_DEPS latte_build)
391
392
393
394
395
  else()
    find_package(LATTE)
    if(NOT LATTE_FOUND)
      message(FATAL_ERROR "LATTE not found, help CMake to find it by setting LATTE_LIBRARY, or set DOWNLOAD_LATTE=ON to download it")
    endif()
396
  endif()
397
  list(APPEND LAMMPS_LINK_LIBS ${LATTE_LIBRARIES} ${LAPACK_LIBRARIES})
398
399
endif()

400
if(PKG_USER-MOLFILE)
Christoph Junghans's avatar
Christoph Junghans committed
401
402
403
404
  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)
Christoph Junghans's avatar
Christoph Junghans committed
405
406
endif()

407
if(PKG_USER-NETCDF)
Christoph Junghans's avatar
Christoph Junghans committed
408
409
410
411
412
413
  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()

414
if(PKG_USER-SMD)
415
416
  option(DOWNLOAD_EIGEN3 "Download Eigen3 (instead of using the system's one)" OFF)
  if(DOWNLOAD_EIGEN3)
417
418
419
420
    include(ExternalProject)
    ExternalProject_Add(Eigen3_build
      URL http://bitbucket.org/eigen/eigen/get/3.3.4.tar.gz 
      URL_MD5 1a47e78efe365a97de0c022d127607c3
421
422
423
424
      CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND ""
    )
    ExternalProject_get_property(Eigen3_build SOURCE_DIR)
    set(EIGEN3_INCLUDE_DIR ${SOURCE_DIR})
425
426
    list(APPEND LAMMPS_DEPS Eigen3_build)
  else()
427
    find_package(Eigen3)
428
    if(NOT Eigen3_FOUND)
429
      message(FATAL_ERROR "Eigen3 not found, help CMake to find it by setting EIGEN3_INCLUDE_DIR, or set DOWNLOAD_EIGEN3=ON to download it")
430
431
    endif()
  endif()
Christoph Junghans's avatar
Christoph Junghans committed
432
433
434
  include_directories(${EIGEN3_INCLUDE_DIR})
endif()

435
if(PKG_USER-QUIP)
Christoph Junghans's avatar
Christoph Junghans committed
436
  find_package(QUIP REQUIRED)
437
  list(APPEND LAMMPS_LINK_LIBS ${QUIP_LIBRARIES} ${LAPACK_LIBRARIES})
Christoph Junghans's avatar
Christoph Junghans committed
438
439
endif()

440
if(PKG_USER-QMMM)
441
  message(WARNING "Building QMMM with CMake is still experimental")
Christoph Junghans's avatar
Christoph Junghans committed
442
443
  find_package(QE REQUIRED)
  include_directories(${QE_INCLUDE_DIRS})
444
  list(APPEND LAMMPS_LINK_LIBS ${QE_LIBRARIES})
Christoph Junghans's avatar
Christoph Junghans committed
445
446
endif()

447
if(PKG_USER-VTK)
448
449
450
451
452
453
  find_package(VTK REQUIRED NO_MODULE)
  include(${VTK_USE_FILE})
  add_definitions(-DLAMMPS_VTK)
  list(APPEND LAMMPS_LINK_LIBS ${VTK_LIBRARIES})
endif()

454
if(PKG_KIM)
455
456
  option(DOWNLOAD_KIM "Download kim-api (instead of using the system's one)" OFF)
  if(DOWNLOAD_KIM)
457
458
    include(ExternalProject)
    ExternalProject_Add(kim_build
459
460
      URL https://github.com/openkim/kim-api/archive/v1.9.5.tar.gz
      URL_MD5 9f66efc128da33039e30659f36fc6d00
461
462
463
464
465
466
467
      BUILD_IN_SOURCE 1
      CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR>
      )
    ExternalProject_get_property(kim_build INSTALL_DIR)
    set(KIM_INCLUDE_DIRS ${INSTALL_DIR}/include/kim-api-v1)
    set(KIM_LIBRARIES ${INSTALL_DIR}/lib/libkim-api-v1.so)
    list(APPEND LAMMPS_DEPS kim_build)
468
469
470
471
472
  else()
    find_package(KIM)
    if(NOT KIM_FOUND)
      message(FATAL_ERROR "KIM not found, help CMake to find it by setting KIM_LIBRARY and KIM_INCLUDE_DIR, or set DOWNLOAD_KIM=ON to download it")
    endif()
473
  endif()
474
475
476
477
  list(APPEND LAMMPS_LINK_LIBS ${KIM_LIBRARIES})
  include_directories(${KIM_INCLUDE_DIRS})
endif()

478
if(PKG_MSCG)
479
  find_package(GSL REQUIRED)
480
481
482
483
484
485
486
  option(DOWNLOAD_MSCG "Download latte (instead of using the system's one)" OFF)
  if(DOWNLOAD_MSCG)
    include(ExternalProject)
    if(NOT LAPACK_FOUND)
      set(EXTRA_MSCG_OPTS "-DLAPACK_LIBRARIES=${CMAKE_CURRENT_BINARY_DIR}/liblinalg.a")
    endif()
    ExternalProject_Add(mscg_build
487
      URL https://github.com/uchicago-voth/MSCG-release/archive/1.7.3.1.tar.gz
488
489
490
      URL_MD5 8c45e269ee13f60b303edd7823866a91
      SOURCE_SUBDIR src/CMake
      CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE} ${EXTRA_MSCG_OPTS}
491
      BUILD_COMMAND make mscg INSTALL_COMMAND ""
492
      )
493
494
495
496
    ExternalProject_get_property(mscg_build BINARY_DIR)
    set(MSCG_LIBRARIES ${BINARY_DIR}/libmscg.a)
    ExternalProject_get_property(mscg_build SOURCE_DIR)
    set(MSCG_INCLUDE_DIRS ${SOURCE_DIR}/src)
497
498
    list(APPEND LAMMPS_DEPS mscg_build)
    if(NOT LAPACK_FOUND)
499
      file(MAKE_DIRECTORY ${MSCG_INCLUDE_DIRS})
500
501
502
503
504
505
      add_dependencies(mscg_build linalg)
    endif()
  else()
    find_package(MSCG)
    if(NOT MSCG_FOUND)
      message(FATAL_ERROR "MSCG not found, help CMake to find it by setting MSCG_LIBRARY and MSCG_INCLUDE_DIRS, or set DOWNLOAD_MSCG=ON to download it")
506
507
    endif()
  endif()
508
  list(APPEND LAMMPS_LINK_LIBS ${MSCG_LIBRARIES} ${GSL_LIBRARIES} ${LAPACK_LIBRARIES})
509
  include_directories(${MSCG_INCLUDE_DIRS})
510
511
endif()

512
if(PKG_COMPRESS)
513
514
515
516
517
  find_package(ZLIB REQUIRED)
  include_directories(${ZLIB_INCLUDE_DIRS})
  list(APPEND LAMMPS_LINK_LIBS ${ZLIB_LIBRARIES})
endif()

518
519
520
521
522
# the windows version of LAMMPS requires a couple extra libraries
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  list(APPEND LAMMPS_LINK_LIBS -lwsock32 -lpsapi)
endif()

Christoph Junghans's avatar
Christoph Junghans committed
523
524
525
########################################################################
# Basic system tests (standard libraries, headers, functions, types)   #
########################################################################
526
include(CheckIncludeFileCXX)
Christoph Junghans's avatar
Christoph Junghans committed
527
foreach(HEADER math.h)
528
  check_include_file_cxx(${HEADER} FOUND_${HEADER})
Christoph Junghans's avatar
Christoph Junghans committed
529
530
531
532
533
534
535
536
  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)
Christoph Junghans's avatar
Christoph Junghans committed
537
if (CMAKE_VERSION VERSION_LESS "3.4")
Christoph Junghans's avatar
Christoph Junghans committed
538
  enable_language(C) # check_library_exists isn't supported without a c compiler before v3.4
Christoph Junghans's avatar
Christoph Junghans committed
539
endif()
540
541
542
543
544
545
546
# 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)
Christoph Junghans's avatar
Christoph Junghans committed
547
list(APPEND LAMMPS_LINK_LIBS ${MATH_LIBRARIES})
Christoph Junghans's avatar
Christoph Junghans committed
548
549

######################################
550
# Generate Basic Style files
Christoph Junghans's avatar
Christoph Junghans committed
551
######################################
552
553
554
include(StyleHeaderUtils)
RegisterStyles(${LAMMPS_SOURCE_DIR})

555
556
557
##############################################
# add sources of enabled packages
############################################
558
foreach(PKG ${DEFAULT_PACKAGES})
559
560
561
562
  set(${PKG}_SOURCES_DIR ${LAMMPS_SOURCE_DIR}/${PKG})

  file(GLOB ${PKG}_SOURCES ${${PKG}_SOURCES_DIR}/*.cpp)
  file(GLOB ${PKG}_HEADERS ${${PKG}_SOURCES_DIR}/*.h)
563

564
565
  # check for package files in src directory due to old make system
  DetectBuildSystemConflict(${LAMMPS_SOURCE_DIR} ${${PKG}_SOURCES} ${${PKG}_HEADERS})
566

567
  if(PKG_${PKG})
568
569
570
    # detects styles in package and adds them to global list
    RegisterStyles(${${PKG}_SOURCES_DIR})

571
    list(APPEND LIB_SOURCES ${${PKG}_SOURCES})
572
    include_directories(${${PKG}_SOURCES_DIR})
573
574
  endif()
endforeach()
575

576
577
578
579
580
581
582
583
584
585
586
# 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})
endforeach()

587
588
589
##############################################
# add lib sources of (simple) enabled packages
############################################
Christoph Junghans's avatar
Christoph Junghans committed
590
foreach(SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD
Christoph Junghans's avatar
Christoph Junghans committed
591
  USER-QMMM)
592
  if(PKG_${SIMPLE_LIB})
593
594
595
596
    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)
597
    add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES})
Christoph Junghans's avatar
Christoph Junghans committed
598
599
600
601
602
    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)
603
604
    elseif(PKG_LIB STREQUAL colvars)
      target_compile_options(colvars PRIVATE -DLEPTON)
605
606
      target_include_directories(colvars PRIVATE ${LAMMPS_LIB_SOURCE_DIR}/colvars/lepton/include)
      target_include_directories(colvars PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/colvars)
Christoph Junghans's avatar
Christoph Junghans committed
607
608
    else()
      target_include_directories(${PKG_LIB} PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB})
609
    endif()
Christoph Junghans's avatar
Christoph Junghans committed
610
611
  endif()
endforeach()
Christoph Junghans's avatar
Christoph Junghans committed
612

613
if(PKG_USER-AWPMD)
614
615
616
  target_link_libraries(awpmd ${LAPACK_LIBRARIES})
endif()

617
if(PKG_USER-ATC)
618
619
620
  target_link_libraries(atc ${LAPACK_LIBRARIES})
endif()

621
if(PKG_USER-H5MD)
622
623
  find_package(HDF5 REQUIRED)
  target_link_libraries(h5md ${HDF5_LIBRARIES})
624
  target_include_directories(h5md PRIVATE ${HDF5_INCLUDE_DIRS})
625
endif()
626

627

Christoph Junghans's avatar
Christoph Junghans committed
628
######################################################################
629
630
# packages which selectively include variants based on enabled styles
# e.g. accelerator packages
Christoph Junghans's avatar
Christoph Junghans committed
631
######################################################################
632
633
634
635
636
637
638
639
640
641
642
643
644
645
if(PKG_CORESHELL)
    set(CORESHELL_SOURCES_DIR ${LAMMPS_SOURCE_DIR}/CORESHELL)
    set(CORESHELL_SOURCES)
    set_property(GLOBAL PROPERTY "CORESHELL_SOURCES" "${CORESHELL_SOURCES}")

    # detects styles which have a CORESHELL version
    RegisterStylesExt(${CORESHELL_SOURCES_DIR} cs CORESHELL_SOURCES)

    get_property(CORESHELL_SOURCES GLOBAL PROPERTY CORESHELL_SOURCES)

    list(APPEND LIB_SOURCES ${CORESHELL_SOURCES})
    include_directories(${CORESHELL_SOURCES_DIR})
endif()

646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
# Fix qeq/fire requires MANYBODY (i.e. COMB and COMB3) to be installed
if(PKG_QEQ)
  set(QEQ_SOURCES_DIR ${LAMMPS_SOURCE_DIR}/QEQ)
  file(GLOB QEQ_HEADERS ${QEQ_SOURCES_DIR}/fix*.h)
  file(GLOB QEQ_SOURCES ${QEQ_SOURCES_DIR}/fix*.cpp)

  if(NOT PKG_MANYBODY)
    list(REMOVE_ITEM QEQ_HEADERS ${QEQ_SOURCES_DIR}/fix_qeq_fire.h)
    list(REMOVE_ITEM QEQ_SOURCES ${QEQ_SOURCES_DIR}/fix_qeq_fire.cpp)
  endif()
  set_property(GLOBAL PROPERTY "QEQ_SOURCES" "${QEQ_SOURCES}")

  foreach(MY_HEADER ${QEQ_HEADERS})
    AddStyleHeader(${MY_HEADER} FIX)
  endforeach()

  get_property(QEQ_SOURCES GLOBAL PROPERTY QEQ_SOURCES)
  list(APPEND LIB_SOURCES ${QEQ_SOURCES})
  include_directories(${QEQ_SOURCES_DIR})
endif()

667
if(PKG_USER-OMP)
Christoph Junghans's avatar
Christoph Junghans committed
668
669
670
671
672
673
    set(USER-OMP_SOURCES_DIR ${LAMMPS_SOURCE_DIR}/USER-OMP)
    set(USER-OMP_SOURCES ${USER-OMP_SOURCES_DIR}/thr_data.cpp
                         ${USER-OMP_SOURCES_DIR}/thr_omp.cpp
                         ${USER-OMP_SOURCES_DIR}/fix_nh_omp.cpp
                         ${USER-OMP_SOURCES_DIR}/fix_nh_sphere_omp.cpp)
    set_property(GLOBAL PROPERTY "OMP_SOURCES" "${USER-OMP_SOURCES}")
674
675

    # detects styles which have USER-OMP version
Christoph Junghans's avatar
Christoph Junghans committed
676
    RegisterStylesExt(${USER-OMP_SOURCES_DIR} omp OMP_SOURCES)
677

678

Christoph Junghans's avatar
Christoph Junghans committed
679
    get_property(USER-OMP_SOURCES GLOBAL PROPERTY OMP_SOURCES)
680

681
682
    # manually add package dependent source files from USER-OMP that do not provide styles

683
684
685
686
    if(PKG_ASPHERE)
      list(APPEND USER-OMP_SOURCES ${USER-OMP_SOURCES_DIR}/fix_nh_asphere_omp.cpp)
    endif()

687
688
689
690
    if(PKG_RIGID)
      list(APPEND USER-OMP_SOURCES ${USER-OMP_SOURCES_DIR}/fix_rigid_nh_omp.cpp)
    endif()

691
692
693
694
695
696
697
698
699
700
701
702
    if(PKG_USER-REAXC)
      list(APPEND USER-OMP_SOURCES ${USER-OMP_SOURCES_DIR}/reaxc_bond_orders_omp.cpp
                                   ${USER-OMP_SOURCES_DIR}/reaxc_hydrogen_bonds_omp.cpp
                                   ${USER-OMP_SOURCES_DIR}/reaxc_nonbonded_omp.cpp
                                   ${USER-OMP_SOURCES_DIR}/reaxc_bonds_omp.cpp
                                   ${USER-OMP_SOURCES_DIR}/reaxc_init_md_omp.cpp
                                   ${USER-OMP_SOURCES_DIR}/reaxc_torsion_angles_omp.cpp
                                   ${USER-OMP_SOURCES_DIR}/reaxc_forces_omp.cpp
                                   ${USER-OMP_SOURCES_DIR}/reaxc_multi_body_omp.cpp
                                   ${USER-OMP_SOURCES_DIR}/reaxc_valence_angles_omp.cpp)
    endif()

Christoph Junghans's avatar
Christoph Junghans committed
703
704
    list(APPEND LIB_SOURCES ${USER-OMP_SOURCES})
    include_directories(${USER-OMP_SOURCES_DIR})
705
706
endif()

707
if(PKG_KOKKOS)
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
  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
                          ${LAMMPS_LIB_KOKKOS_SRC_DIR}/containers/src
                          ${LAMMPS_LIB_KOKKOS_SRC_DIR}/algorithms/src
                          ${LAMMPS_LIB_KOKKOS_BIN_DIR})
  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
                         ${KOKKOS_PKG_SOURCES_DIR}/atom_kokkos.cpp
                         ${KOKKOS_PKG_SOURCES_DIR}/atom_vec_kokkos.cpp
                         ${KOKKOS_PKG_SOURCES_DIR}/comm_kokkos.cpp
                         ${KOKKOS_PKG_SOURCES_DIR}/comm_tiled_kokkos.cpp
                         ${KOKKOS_PKG_SOURCES_DIR}/neighbor_kokkos.cpp
                         ${KOKKOS_PKG_SOURCES_DIR}/neigh_list_kokkos.cpp
                         ${KOKKOS_PKG_SOURCES_DIR}/neigh_bond_kokkos.cpp
                         ${KOKKOS_PKG_SOURCES_DIR}/fix_nh_kokkos.cpp
730
731
                         ${KOKKOS_PKG_SOURCES_DIR}/nbin_kokkos.cpp
                         ${KOKKOS_PKG_SOURCES_DIR}/npair_kokkos.cpp
732
733
                         ${KOKKOS_PKG_SOURCES_DIR}/domain_kokkos.cpp
                         ${KOKKOS_PKG_SOURCES_DIR}/modify_kokkos.cpp)
734
735
736
737
738

  if(PKG_KSPACE)
    list(APPEND KOKKOS_PKG_SOURCES ${KOKKOS_PKG_SOURCES_DIR}/gridcomm_kokkos.cpp)
  endif()

739
740
741
742
743
  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)

744
  # register kokkos-only styles
745
746
747
  RegisterNBinStyle(${KOKKOS_PKG_SOURCES_DIR}/nbin_kokkos.h)
  RegisterNPairStyle(${KOKKOS_PKG_SOURCES_DIR}/npair_kokkos.h)

748
  if(PKG_USER-DPD)
749
750
751
752
753
    get_property(KOKKOS_PKG_SOURCES GLOBAL PROPERTY KOKKOS_PKG_SOURCES)
    list(APPEND KOKKOS_PKG_SOURCES ${KOKKOS_PKG_SOURCES_DIR}/npair_ssa_kokkos.cpp)
    RegisterNPairStyle(${KOKKOS_PKG_SOURCES_DIR}/npair_ssa_kokkos.h)
    set_property(GLOBAL PROPERTY "KOKKOS_PKG_SOURCES" "${KOKKOS_PKG_SOURCES}")
  endif()
754

755
756
757
758
  get_property(KOKKOS_PKG_SOURCES GLOBAL PROPERTY KOKKOS_PKG_SOURCES)

  list(APPEND LIB_SOURCES ${KOKKOS_PKG_SOURCES})
  include_directories(${KOKKOS_PKG_SOURCES_DIR})
759
760
endif()

761
if(PKG_OPT)
Richard Berger's avatar
Richard Berger committed
762
763
764
765
766
767
768
769
770
771
772
773
774
    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()

775
if(PKG_USER-INTEL)
776
777
778
779
780
781
782
783
    find_package(TBB REQUIRED)
    find_package(MKL REQUIRED)

    if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
      message(FATAL_ERROR "USER-INTEL is only useful together with intel compiler")
    endif()

    if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16)
Christoph Junghans's avatar
Christoph Junghans committed
784
        message(FATAL_ERROR "USER-INTEL is needed at least 2016 intel compiler, found ${CMAKE_CXX_COMPILER_VERSION}")
785
    endif()
786
787
788

    if(NOT BUILD_OMP)
        message(FATAL_ERROR "USER-INTEL requires OpenMP")
789
    endif()
790
791
792

    if(NOT ${LAMMPS_MEMALIGN} STREQUAL "64")
        message(FATAL_ERROR "USER-INTEL is only useful with LAMMPS_MEMALIGN=64")
793
    endif()
794
795

    set(INTEL_ARCH "cpu" CACHE STRING "Architectures used by USER-INTEL (cpu or knl)")
796
797
798
    set(INTEL_ARCH_VALUES cpu knl)
    set_property(CACHE INTEL_ARCH PROPERTY STRINGS ${INTEL_ARCH_VALUES})
    validate_option(INTEL_ARCH INTEL_ARCH_VALUES)
799
    string(TOUPPER ${INTEL_ARCH} INTEL_ARCH)
800

Christoph Junghans's avatar
Christoph Junghans committed
801
    if(INTEL_ARCH STREQUAL "KNL")
802
803
804
805
806
      set(CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} -xHost -qopenmp -qoffload")
      set(MIC_OPTIONS "-qoffload-option,mic,compiler,\"-fp-model fast=2 -mGLOB_default_function_attrs=\\\"gather_scatter_loop_unroll=4\\\"\"")
      add_compile_options(-xMIC-AVX512 -qoffload -fno-alias -ansi-alias -restrict -qoverride-limits ${MIC_OPTIONS})
      add_definitions(-DLMP_INTEL_OFFLOAD)
    else()
Christoph Junghans's avatar
Christoph Junghans committed
807
      if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.4)
808
809
810
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xCOMMON-AVX512")
      else()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xHost")
811
      endif()
812
      include(CheckCXXCompilerFlag)
813
      foreach(_FLAG -O2 -fp-model fast=2 -no-prec-div -qoverride-limits -qopt-zmm-usage=high -qno-offload -fno-alias -ansi-alias -restrict)
814
815
        check_cxx_compiler_flag("${__FLAG}" COMPILER_SUPPORTS${_FLAG})
        if(COMPILER_SUPPORTS${_FLAG})
816
          add_compile_options(${_FLAG})
817
818
819
        endif()
      endforeach()
    endif()
820
821
822
823
824

    add_definitions(-DLMP_INTEL_USELRT -DLMP_USE_MKL_RNG)

    list(APPEND LAMMPS_LINK_LIBS ${TBB_MALLOC_LIBRARIES} ${MKL_LIBRARIES})

Christoph Junghans's avatar
Christoph Junghans committed
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
    set(USER-INTEL_SOURCES_DIR ${LAMMPS_SOURCE_DIR}/USER-INTEL)
    set(USER-INTEL_SOURCES ${USER-INTEL_SOURCES_DIR}/intel_preprocess.h
                           ${USER-INTEL_SOURCES_DIR}/intel_buffers.h
                           ${USER-INTEL_SOURCES_DIR}/intel_buffers.cpp
                           ${USER-INTEL_SOURCES_DIR}/math_extra_intel.h
                           ${USER-INTEL_SOURCES_DIR}/nbin_intel.h
                           ${USER-INTEL_SOURCES_DIR}/nbin_intel.cpp
                           ${USER-INTEL_SOURCES_DIR}/npair_intel.h
                           ${USER-INTEL_SOURCES_DIR}/npair_intel.cpp
                           ${USER-INTEL_SOURCES_DIR}/intel_simd.h
                           ${USER-INTEL_SOURCES_DIR}/intel_intrinsics.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()
847

848
if(PKG_GPU)
849
850
851
    if (CMAKE_VERSION VERSION_LESS "3.1") 
      message(FATAL_ERROR "For the GPU package you need at least cmake-3.1")
    endif()
852
853
854
855
    set(GPU_SOURCES_DIR ${LAMMPS_SOURCE_DIR}/GPU)
    set(GPU_SOURCES ${GPU_SOURCES_DIR}/gpu_extra.h
                    ${GPU_SOURCES_DIR}/fix_gpu.h
                    ${GPU_SOURCES_DIR}/fix_gpu.cpp)
Richard Berger's avatar
Richard Berger committed
856

857
    set(GPU_API "opencl" CACHE STRING "API used by GPU package")
858
859
860
861
    set(GPU_API_VALUES opencl cuda)
    set_property(CACHE GPU_API PROPERTY STRINGS ${GPU_API_VALUES})
    validate_option(GPU_API GPU_API_VALUES)
    string(TOUPPER ${GPU_API} GPU_API)
Richard Berger's avatar
Richard Berger committed
862

863
    set(GPU_PREC "mixed" CACHE STRING "LAMMPS GPU precision")
864
865
866
867
    set(GPU_PREC_VALUES double mixed single)
    set_property(CACHE GPU_PREC PROPERTY STRINGS ${GPU_PREC_VALUES})
    validate_option(GPU_PREC GPU_PREC_VALUES)
    string(TOUPPER ${GPU_PREC} GPU_PREC)
868

869
    if(GPU_PREC STREQUAL "DOUBLE")
870
      set(GPU_PREC_SETTING "DOUBLE_DOUBLE")
871
    elseif(GPU_PREC STREQUAL "MIXED")
872
      set(GPU_PREC_SETTING "SINGLE_DOUBLE")
873
    elseif(GPU_PREC STREQUAL "SINGLE")
874
875
      set(GPU_PREC_SETTING "SINGLE_SINGLE")
    endif()
Christoph Junghans's avatar
Christoph Junghans committed
876

877
    file(GLOB GPU_LIB_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/gpu/*.cpp)
Christoph Junghans's avatar
Christoph Junghans committed
878
    file(MAKE_DIRECTORY ${LAMMPS_LIB_BINARY_DIR}/gpu)
Richard Berger's avatar
Richard Berger committed
879

880
881
882
883
884
885
886
887
    if(GPU_API STREQUAL "CUDA")
      find_package(CUDA REQUIRED)
      find_program(BIN2C bin2c)
      if(NOT BIN2C)
        message(FATAL_ERROR "Couldn't find bin2c, use -DBIN2C helping cmake to find it.")
      endif()
      option(CUDPP_OPT "Enable CUDPP_OPT" ON)

Steven J. Plimpton's avatar
Steven J. Plimpton committed
888
      set(GPU_ARCH "sm_30" CACHE STRING "LAMMPS GPU CUDA SM architecture (e.g. sm_60)")
889

890
      file(GLOB GPU_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/*.cu ${CMAKE_CURRENT_SOURCE_DIR}/gpu/*.cu)
891
892
893
894
895
896
897
898
899
900
901
      list(REMOVE_ITEM GPU_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_pppm.cu)

      cuda_include_directories(${LAMMPS_LIB_SOURCE_DIR}/gpu ${LAMMPS_LIB_BINARY_DIR}/gpu)

      if(CUDPP_OPT)
        cuda_include_directories(${LAMMPS_LIB_SOURCE_DIR}/gpu/cudpp_mini)
        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()

      cuda_compile_cubin(GPU_GEN_OBJS ${GPU_LIB_CU} OPTIONS
Steven J. Plimpton's avatar
Steven J. Plimpton committed
902
                   -DUNIX -O3 -Xptxas -v --use_fast_math -DNV_KERNEL -DUCL_CUDADR -arch=${GPU_ARCH} -D_${GPU_PREC_SETTING})
903
904

      cuda_compile(GPU_OBJS ${GPU_LIB_CUDPP_CU} OPTIONS $<$<BOOL:${BUILD_SHARED_LIBS}>:-Xcompiler=-fPIC>
Steven J. Plimpton's avatar
Steven J. Plimpton committed
905
                   -DUNIX -O3 -Xptxas -v --use_fast_math -DUCL_CUDADR -arch=${GPU_ARCH} -D_${GPU_PREC_SETTING})
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921

      foreach(CU_OBJ ${GPU_GEN_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
          COMMAND ${BIN2C} -c -n ${CU_NAME} ${CU_OBJ} > ${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}_cubin.h
          DEPENDS ${CU_OBJ}
          COMMENT "Generating ${CU_NAME}_cubin.h")
        list(APPEND GPU_LIB_SOURCES ${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}_cubin.h)
      endforeach()
      set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${LAMMPS_LIB_BINARY_DIR}/gpu/*_cubin.h")


      add_library(gpu STATIC ${GPU_LIB_SOURCES} ${GPU_LIB_CUDPP_SOURCES} ${GPU_OBJS})
      target_link_libraries(gpu ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY})
      target_include_directories(gpu PRIVATE ${LAMMPS_LIB_BINARY_DIR}/gpu ${CUDA_INCLUDE_DIRS})
922
      target_compile_definitions(gpu PRIVATE -D_${GPU_PREC_SETTING} -DMPI_GERYON -DUCL_NO_EXIT)
923
924
925
926
927
928
929
930
931
932
933
934
935
      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)

      add_executable(nvc_get_devices ${LAMMPS_LIB_SOURCE_DIR}/gpu/geryon/ucl_get_devices.cpp)
      target_compile_definitions(nvc_get_devices PRIVATE -DUCL_CUDADR)
      target_link_libraries(nvc_get_devices PRIVATE ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY})
      target_include_directories(nvc_get_devices PRIVATE ${CUDA_INCLUDE_DIRS})


936
    elseif(GPU_API STREQUAL "OPENCL")
937
      find_package(OpenCL REQUIRED)
938
      set(OCL_TUNE "generic" CACHE STRING "OpenCL Device Tuning")
939
940
941
942
      set(OCL_TUNE_VALUES intel fermi kepler cypress generic)
      set_property(CACHE OCL_TUNE PROPERTY STRINGS ${OCL_TUNE_VALUES})
      validate_option(OCL_TUNE OCL_TUNE_VALUES)
      string(TOUPPER ${OCL_TUNE} OCL_TUNE)
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963

      include(OpenCLUtils)
      set(OCL_COMMON_HEADERS ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_preprocessor.h ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_aux_fun1.h)

      file(GLOB GPU_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/*.cu)
      list(REMOVE_ITEM GPU_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_gayberne.cu ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_gayberne_lj.cu)

      foreach(GPU_KERNEL ${GPU_LIB_CU})
          get_filename_component(basename ${GPU_KERNEL} NAME_WE)
          string(SUBSTRING ${basename} 4 -1 KERNEL_NAME)
          GenerateOpenCLHeader(${KERNEL_NAME} ${CMAKE_CURRENT_BINARY_DIR}/gpu/${KERNEL_NAME}_cl.h ${OCL_COMMON_HEADERS} ${GPU_KERNEL})
          list(APPEND GPU_LIB_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/gpu/${KERNEL_NAME}_cl.h)
      endforeach()

      GenerateOpenCLHeader(gayberne ${CMAKE_CURRENT_BINARY_DIR}/gpu/gayberne_cl.h ${OCL_COMMON_HEADERS} ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_ellipsoid_extra.h ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_gayberne.cu)
      GenerateOpenCLHeader(gayberne_lj ${CMAKE_CURRENT_BINARY_DIR}/gpu/gayberne_lj_cl.h ${OCL_COMMON_HEADERS} ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_ellipsoid_extra.h ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_gayberne_lj.cu)
      list(APPEND GPU_LIB_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/gpu/gayberne_cl.h ${CMAKE_CURRENT_BINARY_DIR}/gpu/gayberne_lj_cl.h)

      add_library(gpu STATIC ${GPU_LIB_SOURCES})
      target_link_libraries(gpu ${OpenCL_LIBRARIES})
      target_include_directories(gpu PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/gpu ${OpenCL_INCLUDE_DIRS})
964
      target_compile_definitions(gpu PRIVATE -D_${GPU_PREC_SETTING} -D${OCL_TUNE}_OCL -DMPI_GERYON -DUCL_NO_EXIT)
965
966
967
968
969
970
971
972
      target_compile_definitions(gpu PRIVATE -DUSE_OPENCL)

      list(APPEND LAMMPS_LINK_LIBS gpu)

      add_executable(ocl_get_devices ${LAMMPS_LIB_SOURCE_DIR}/gpu/geryon/ucl_get_devices.cpp)
      target_compile_definitions(ocl_get_devices PRIVATE -DUCL_OPENCL)
      target_link_libraries(ocl_get_devices PRIVATE ${OpenCL_LIBRARIES})
      target_include_directories(ocl_get_devices PRIVATE ${OpenCL_INCLUDE_DIRS})
973
    endif()
Richard Berger's avatar
Richard Berger committed
974
975

    # GPU package
Richard Berger's avatar
Richard Berger committed
976
    FindStyleHeaders(${GPU_SOURCES_DIR} FIX_CLASS fix_ FIX)
Christoph Junghans's avatar
Christoph Junghans committed
977
978
979
980

    set_property(GLOBAL PROPERTY "GPU_SOURCES" "${GPU_SOURCES}")

    # detects styles which have GPU version
Richard Berger's avatar
Richard Berger committed
981
    RegisterStylesExt(${GPU_SOURCES_DIR} gpu GPU_SOURCES)
Christoph Junghans's avatar
Christoph Junghans committed
982
983

    get_property(GPU_SOURCES GLOBAL PROPERTY GPU_SOURCES)
Richard Berger's avatar
Richard Berger committed
984
985

    list(APPEND LIB_SOURCES ${GPU_SOURCES})
Richard Berger's avatar
Richard Berger committed
986
    include_directories(${GPU_SOURCES_DIR})
Christoph Junghans's avatar
Christoph Junghans committed
987
988
endif()

989
990
######################################################
# Generate style headers based on global list of
991
# styles registered during package selection
992
993
994
995
996
######################################################
set(LAMMPS_STYLE_HEADERS_DIR ${CMAKE_CURRENT_BINARY_DIR}/styles)

GenerateStyleHeaders(${LAMMPS_STYLE_HEADERS_DIR})

997
include_directories(${LAMMPS_SOURCE_DIR})
998
999
include_directories(${LAMMPS_STYLE_HEADERS_DIR})

1000
######################################
For faster browsing, not all history is shown. View entire blame