| 1 |
# portion of https://github.com/lammps/lammps/raw/master/cmake/CMakeLists.txt |
| 2 |
# renamed to lowercase to test Windows behavior |
| 3 |
######################################## |
| 4 |
# CMake build system |
| 5 |
# This file is part of LAMMPS |
| 6 |
# Created by Christoph Junghans and Richard Berger |
| 7 |
cmake_minimum_required(VERSION 3.10) |
| 8 |
# set policy to silence warnings about ignoring <PackageName>_ROOT but use it |
| 9 |
if(POLICY CMP0074) |
| 10 |
cmake_policy(SET CMP0074 NEW) |
| 11 |
endif() |
| 12 |
# set policy to silence warnings about missing executable permissions in |
| 13 |
# pythonx.y-config when cross-compiling. review occasionally if it may be set to NEW |
| 14 |
if(POLICY CMP0109) |
| 15 |
cmake_policy(SET CMP0109 OLD) |
| 16 |
endif() |
| 17 |
######################################## |
| 18 |
|
| 19 |
project(lammps CXX) |
| 20 |
set(SOVERSION 0) |
| 21 |
|
| 22 |
get_filename_component(LAMMPS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/.. ABSOLUTE) |
| 23 |
get_filename_component(LAMMPS_LIB_BINARY_DIR ${CMAKE_BINARY_DIR}/lib ABSOLUTE) |
| 24 |
|
| 25 |
set(LAMMPS_SOURCE_DIR ${LAMMPS_DIR}/src) |
| 26 |
set(LAMMPS_LIB_SOURCE_DIR ${LAMMPS_DIR}/lib) |
| 27 |
set(LAMMPS_DOC_DIR ${LAMMPS_DIR}/doc) |
| 28 |
set(LAMMPS_TOOLS_DIR ${LAMMPS_DIR}/tools) |
| 29 |
set(LAMMPS_PYTHON_DIR ${LAMMPS_DIR}/python) |
| 30 |
set(LAMMPS_POTENTIALS_DIR ${LAMMPS_DIR}/potentials) |
| 31 |
|
| 32 |
set(LAMMPS_DOWNLOADS_URL "https://download.lammps.org" CACHE STRING "Base URL for LAMMPS downloads") |
| 33 |
set(LAMMPS_POTENTIALS_URL "${LAMMPS_DOWNLOADS_URL}/potentials") |
| 34 |
set(LAMMPS_THIRDPARTY_URL "${LAMMPS_DOWNLOADS_URL}/thirdparty") |
| 35 |
mark_as_advanced(LAMMPS_DOWNLOADS_URL) |
| 36 |
|
| 37 |
find_package(Git) |
| 38 |
|
| 39 |
# by default, install into $HOME/.local (not /usr/local), so that no root access (and sudo!!) is needed |
| 40 |
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) |
| 41 |
if((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND (NOT CMAKE_CROSSCOMPILING)) |
| 42 |
set(CMAKE_INSTALL_PREFIX "$ENV{USERPROFILE}/LAMMPS" CACHE PATH "Default install path" FORCE) |
| 43 |
else() |
| 44 |
set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local" CACHE PATH "Default install path" FORCE) |
| 45 |
endif() |
| 46 |
endif() |
| 47 |
|
| 48 |
# If enabled, no need to use LD_LIBRARY_PATH / DYLD_LIBRARY_PATH when installed |
| 49 |
option(LAMMPS_INSTALL_RPATH "Set runtime path for shared libraries linked to LAMMPS binaries" OFF) |
| 50 |
if(LAMMPS_INSTALL_RPATH) |
| 51 |
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}) |
| 52 |
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON) |
| 53 |
endif() |
| 54 |
|
| 55 |
# Cmake modules/macros are in a subdirectory to keep this file cleaner |
| 56 |
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Modules) |
| 57 |
|
| 58 |
# make sure LIBRARY_PATH is set if environment variable is set |
| 59 |
if(DEFINED ENV{LIBRARY_PATH}) |
| 60 |
list(APPEND CMAKE_LIBRARY_PATH "$ENV{LIBRARY_PATH}") |
| 61 |
message(STATUS "Appending $ENV{LIBRARY_PATH} to CMAKE_LIBRARY_PATH: ${CMAKE_LIBRARY_PATH}") |
| 62 |
endif() |
| 63 |
|
| 64 |
include(LAMMPSUtils) |
| 65 |
|
| 66 |
get_lammps_version(${LAMMPS_SOURCE_DIR}/version.h PROJECT_VERSION) |
| 67 |
|
| 68 |
include(PreventInSourceBuilds) |
| 69 |
|
| 70 |
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS) |
| 71 |
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE) |
| 72 |
endif(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS) |
| 73 |
string(TOUPPER "${CMAKE_BUILD_TYPE}" BTYPE) |
| 74 |
|
| 75 |
# check for files auto-generated by make-based buildsystem |
| 76 |
# this is fast, so check for it all the time |
| 77 |
check_for_autogen_files(${LAMMPS_SOURCE_DIR}) |
| 78 |
|
| 79 |
###################################################################### |
| 80 |
# compiler tests |
| 81 |
# these need ot be done early (before further tests). |
| 82 |
##################################################################### |
| 83 |
include(CheckIncludeFileCXX) |
| 84 |
|
| 85 |
# set required compiler flags and compiler/CPU arch specific optimizations |
| 86 |
if((CMAKE_CXX_COMPILER_ID STREQUAL "Intel") OR (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")) |
| 87 |
if(CMAKE_SYSTEM_NAME STREQUAL "Windows") |
| 88 |
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") |
| 89 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qrestrict") |
| 90 |
endif() |
| 91 |
if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.4) |
| 92 |
set(CMAKE_TUNE_DEFAULT "/QxCOMMON-AVX512") |
| 93 |
else() |
| 94 |
set(CMAKE_TUNE_DEFAULT "/QxHost") |
| 95 |
endif() |
| 96 |
else() |
| 97 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -restrict") |
| 98 |
if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.4) |
| 99 |
set(CMAKE_TUNE_DEFAULT "-xCOMMON-AVX512") |
| 100 |
else() |
| 101 |
set(CMAKE_TUNE_DEFAULT "-xHost") |
| 102 |
endif() |
| 103 |
endif() |
| 104 |
endif() |
| 105 |
|
| 106 |
# we require C++11 without extensions. Kokkos requires at least C++14 (currently) |
| 107 |
set(CMAKE_CXX_STANDARD 11) |
| 108 |
if(PKG_KOKKOS AND (CMAKE_CXX_STANDARD LESS 14)) |
| 109 |
set(CMAKE_CXX_STANDARD 14) |
| 110 |
endif() |
| 111 |
set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 112 |
set(CMAKE_CXX_EXTENSIONS OFF CACHE BOOL "Use compiler extensions") |
| 113 |
# ugly hacks for MSVC which by default always reports an old C++ standard in the __cplusplus macro |
| 114 |
# and prints lots of pointless warnings about "unsafe" functions |
| 115 |
if(MSVC) |
| 116 |
add_compile_options(/Zc:__cplusplus) |
| 117 |
add_compile_options(/wd4244) |
| 118 |
add_compile_options(/wd4267) |
| 119 |
add_compile_definitions(_CRT_SECURE_NO_WARNINGS) |
| 120 |
endif() |
| 121 |
|
| 122 |
# export all symbols when building a .dll file on windows |
| 123 |
if((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND BUILD_SHARED_LIBS) |
| 124 |
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) |
| 125 |
endif() |
| 126 |
|
| 127 |
######################################################################## |
| 128 |
# User input options # |
| 129 |
######################################################################## |
| 130 |
set(LAMMPS_MACHINE "" CACHE STRING "Suffix to append to lmp binary (WON'T enable any features automatically") |
| 131 |
mark_as_advanced(LAMMPS_MACHINE) |
| 132 |
if(LAMMPS_MACHINE) |
| 133 |
set(LAMMPS_MACHINE "_${LAMMPS_MACHINE}") |
| 134 |
endif() |
| 135 |
set(LAMMPS_BINARY lmp${LAMMPS_MACHINE}) |
| 136 |
|
| 137 |
option(BUILD_SHARED_LIBS "Build shared library" OFF) |
| 138 |
if(BUILD_SHARED_LIBS) # for all pkg libs, mpi_stubs and linalg |
| 139 |
set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 140 |
endif() |
| 141 |
|
| 142 |
option(BUILD_TOOLS "Build and install LAMMPS tools (msi2lmp, binary2txt, chain)" OFF) |
| 143 |
option(BUILD_LAMMPS_SHELL "Build and install the LAMMPS shell" OFF) |
| 144 |
|
| 145 |
# allow enabling clang-tidy for C++ files |
| 146 |
set(ENABLE_CLANG_TIDY OFF CACHE BOOL "Include clang-tidy processing when compiling") |
| 147 |
if(ENABLE_CLANG_TIDY) |
| 148 |
set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=*-header-filter=.*" CACHE STRING "") |
| 149 |
endif() |
| 150 |
|
| 151 |
include(GNUInstallDirs) |
| 152 |
file(GLOB ALL_SOURCES ${LAMMPS_SOURCE_DIR}/[^.]*.cpp) |
| 153 |
file(GLOB MAIN_SOURCES ${LAMMPS_SOURCE_DIR}/main.cpp) |
| 154 |
list(REMOVE_ITEM ALL_SOURCES ${MAIN_SOURCES}) |
| 155 |
add_library(lammps ${ALL_SOURCES}) |
| 156 |
|
| 157 |
# tell CMake to export all symbols to a .dll on Windows with MinGW cross-compilers |
| 158 |
if(BUILD_SHARED_LIBS AND (CMAKE_SYSTEM_NAME STREQUAL "Windows") AND CMAKE_CROSSCOMPILING) |
| 159 |
set_target_properties(lammps PROPERTIES LINK_FLAGS "-Wl,--export-all-symbols") |
| 160 |
endif() |
| 161 |
|
| 162 |
add_executable(lmp ${MAIN_SOURCES}) |
| 163 |
target_link_libraries(lmp PRIVATE lammps) |
| 164 |
set_target_properties(lmp PROPERTIES OUTPUT_NAME ${LAMMPS_BINARY}) |
| 165 |
install(TARGETS lmp EXPORT LAMMPS_Targets DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 166 |
|
| 167 |
option(CMAKE_VERBOSE_MAKEFILE "Generate verbose Makefiles" OFF) |
| 168 |
|
| 169 |
set(STANDARD_PACKAGES |
| 170 |
ADIOS |
| 171 |
ASPHERE |
| 172 |
ATC |
| 173 |
AWPMD |
| 174 |
BOCS |
| 175 |
BODY |
| 176 |
BROWNIAN |
| 177 |
CG-DNA |
| 178 |
CG-SDK |
| 179 |
CLASS2 |
| 180 |
COLLOID |
| 181 |
COLVARS |
| 182 |
COMPRESS |
| 183 |
DIELECTRIC |
| 184 |
DIFFRACTION |
| 185 |
DIPOLE |
| 186 |
DPD-BASIC |
| 187 |
DPD-MESO |
| 188 |
DPD-REACT |
| 189 |
DPD-SMOOTH |
| 190 |
DRUDE |
| 191 |
EFF |
| 192 |
EXTRA-COMPUTE |
| 193 |
EXTRA-DUMP |
| 194 |
EXTRA-FIX |
| 195 |
EXTRA-MOLECULE |
| 196 |
EXTRA-PAIR |
| 197 |
FEP |
| 198 |
GRANULAR |
| 199 |
H5MD |
| 200 |
INTERLAYER |
| 201 |
KIM |
| 202 |
KSPACE |
| 203 |
LATBOLTZ |
| 204 |
LATTE |
| 205 |
MACHDYN |
| 206 |
MANIFOLD |
| 207 |
MANYBODY |
| 208 |
MC |
| 209 |
MDI |
| 210 |
MEAM |
| 211 |
MESONT |
| 212 |
MESSAGE |
| 213 |
MGPT |
| 214 |
MISC |
| 215 |
ML-HDNNP |
| 216 |
ML-IAP |
| 217 |
ML-PACE |
| 218 |
ML-QUIP |
| 219 |
ML-RANN |
| 220 |
ML-SNAP |
| 221 |
MOFFF |
| 222 |
MOLECULE |
| 223 |
MOLFILE |
| 224 |
MPIIO |
| 225 |
MSCG |
| 226 |
NETCDF |
| 227 |
ORIENT |
| 228 |
PERI |
| 229 |
PHONON |
| 230 |
PLUGIN |
| 231 |
PLUMED |
| 232 |
POEMS |
| 233 |
PTM |
| 234 |
PYTHON |
| 235 |
QEQ |
| 236 |
QMMM |
| 237 |
QTB |
| 238 |
REACTION |
| 239 |
REAXFF |
| 240 |
REPLICA |
| 241 |
RIGID |
| 242 |
SCAFACOS |
| 243 |
SHOCK |
| 244 |
SMTBQ |
| 245 |
SPH |
| 246 |
SPIN |
| 247 |
SRD |
| 248 |
TALLY |
| 249 |
UEF |
| 250 |
VORONOI |
| 251 |
VTK |
| 252 |
YAFF) |
| 253 |
|
| 254 |
set(SUFFIX_PACKAGES CORESHELL GPU KOKKOS OPT INTEL OPENMP) |
| 255 |
|
| 256 |
foreach(PKG ${STANDARD_PACKAGES} ${SUFFIX_PACKAGES}) |
| 257 |
option(PKG_${PKG} "Build ${PKG} Package" OFF) |
| 258 |
endforeach() |
| 259 |
|
| 260 |
###################################################### |
| 261 |
# packages with special compiler needs or external libs |
| 262 |
###################################################### |
| 263 |
target_include_directories(lammps PUBLIC $<BUILD_INTERFACE:${LAMMPS_SOURCE_DIR}>) |
| 264 |
|
| 265 |
if(PKG_ADIOS) |
| 266 |
# The search for ADIOS2 must come before MPI because |
| 267 |
# it includes its own MPI search with the latest FindMPI.cmake |
| 268 |
# script that defines the MPI::MPI_C target |
| 269 |
enable_language(C) |
| 270 |
find_package(ADIOS2 REQUIRED) |
| 271 |
target_link_libraries(lammps PRIVATE adios2::adios2) |
| 272 |
endif() |
| 273 |
|
| 274 |
if(NOT CMAKE_CROSSCOMPILING) |
| 275 |
find_package(MPI QUIET) |
| 276 |
option(BUILD_MPI "Build MPI version" ${MPI_FOUND}) |
| 277 |
else() |
| 278 |
option(BUILD_MPI "Build MPI version" OFF) |
| 279 |
endif() |
| 280 |
|
| 281 |
if(BUILD_MPI) |
| 282 |
# do not include the (obsolete) MPI C++ bindings which makes |
| 283 |
# for leaner object files and avoids namespace conflicts |
| 284 |
set(MPI_CXX_SKIP_MPICXX TRUE) |
| 285 |
# We use a non-standard procedure to cross-compile with MPI on Windows |
| 286 |
if((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND CMAKE_CROSSCOMPILING) |
| 287 |
include(MPI4WIN) |
| 288 |
target_link_libraries(lammps PUBLIC MPI::MPI_CXX) |
| 289 |
else() |
| 290 |
find_package(MPI REQUIRED) |
| 291 |
target_link_libraries(lammps PUBLIC MPI::MPI_CXX) |
| 292 |
option(LAMMPS_LONGLONG_TO_LONG "Workaround if your system or MPI version does not recognize 'long long' data types" OFF) |
| 293 |
if(LAMMPS_LONGLONG_TO_LONG) |
| 294 |
target_compile_definitions(lammps PRIVATE -DLAMMPS_LONGLONG_TO_LONG) |
| 295 |
endif() |
| 296 |
endif() |
| 297 |
else() |
| 298 |
file(GLOB MPI_SOURCES ${LAMMPS_SOURCE_DIR}/STUBS/mpi.cpp) |
| 299 |
add_library(mpi_stubs STATIC ${MPI_SOURCES}) |
| 300 |
set_target_properties(mpi_stubs PROPERTIES OUTPUT_NAME lammps_mpi_stubs${LAMMPS_MACHINE}) |
| 301 |
target_include_directories(mpi_stubs PUBLIC $<BUILD_INTERFACE:${LAMMPS_SOURCE_DIR}/STUBS>) |
| 302 |
if(BUILD_SHARED_LIBS) |
| 303 |
target_link_libraries(lammps PRIVATE mpi_stubs) |
| 304 |
if(MSVC) |
| 305 |
target_link_libraries(lmp PRIVATE mpi_stubs) |
| 306 |
target_include_directories(lmp INTERFACE $<BUILD_INTERFACE:${LAMMPS_SOURCE_DIR}/STUBS>) |
| 307 |
target_compile_definitions(lmp INTERFACE $<INSTALL_INTERFACE:LAMMPS_LIB_NO_MPI>) |
| 308 |
endif(MSVC) |
| 309 |
target_include_directories(lammps INTERFACE $<BUILD_INTERFACE:${LAMMPS_SOURCE_DIR}/STUBS>) |
| 310 |
target_compile_definitions(lammps INTERFACE $<INSTALL_INTERFACE:LAMMPS_LIB_NO_MPI>) |
| 311 |
else() |
| 312 |
target_link_libraries(lammps PUBLIC mpi_stubs) |
| 313 |
endif() |
| 314 |
add_library(MPI::MPI_CXX ALIAS mpi_stubs) |
| 315 |
endif() |
| 316 |
|
| 317 |
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)") |
| 318 |
set(LAMMPS_SIZES_VALUES smallbig bigbig smallsmall) |
| 319 |
set_property(CACHE LAMMPS_SIZES PROPERTY STRINGS ${LAMMPS_SIZES_VALUES}) |
| 320 |
validate_option(LAMMPS_SIZES LAMMPS_SIZES_VALUES) |
| 321 |
string(TOUPPER ${LAMMPS_SIZES} LAMMPS_SIZES) |
| 322 |
target_compile_definitions(lammps PUBLIC -DLAMMPS_${LAMMPS_SIZES}) |
| 323 |
|
| 324 |
# posix_memalign is not available on Windows |
| 325 |
if(CMAKE_SYSTEM_NAME STREQUAL "Windows") |
| 326 |
set(LAMMPS_MEMALIGN "0" CACHE STRING "posix_memalign() is not available on Windows" FORCE) |
| 327 |
else() |
| 328 |
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") |
| 329 |
endif() |
| 330 |
if(NOT ${LAMMPS_MEMALIGN} STREQUAL "0") |
| 331 |
target_compile_definitions(lammps PRIVATE -DLAMMPS_MEMALIGN=${LAMMPS_MEMALIGN}) |
| 332 |
endif() |
| 333 |
|
| 334 |
option(LAMMPS_EXCEPTIONS "enable the use of C++ exceptions for error messages (useful for library interface)" ${ENABLE_TESTING}) |
| 335 |
if(LAMMPS_EXCEPTIONS) |
| 336 |
target_compile_definitions(lammps PUBLIC -DLAMMPS_EXCEPTIONS) |
| 337 |
endif() |