forked from electronic-structure/SIRIUS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
247 lines (212 loc) · 8.58 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
cmake_minimum_required(VERSION 3.12)
project(SIRIUS VERSION 6.5.7)
# set language and standard
enable_language(CXX Fortran)
set(CMAKE_CXX_STANDARD 14)
# user variables
set(CREATE_PYTHON_MODULE OFF CACHE BOOL "create sirius python module")
set(CREATE_FORTRAN_BINDINGS ON CACHE BOOL "build Fortran bindings")
set(BUILD_DOCS OFF CACHE BOOL "build doxygen doc")
set(USE_ELPA OFF CACHE BOOL "use scalapack")
set(USE_MAGMA OFF CACHE BOOL "use MAGMA")
set(USE_NLCGLIB OFF CACHE BOOL "enable nlcglib")
set(USE_CUDA OFF CACHE BOOL "use CUDA")
set(USE_ROCM OFF CACHE BOOL "use ROCM AMD GPU code")
set(USE_NVTX OFF CACHE BOOL "use Nvidia profiling tools library")
set(USE_VDWXC OFF CACHE BOOL "use libvdwxc for van der Walls corrections")
set(USE_MKL OFF CACHE BOOL "use Intel MKL")
set(USE_CRAY_LIBSCI OFF CACHE BOOL "use LAPACK/SCALAPACK from Cray LIBSCI")
set(USE_SCALAPACK OFF CACHE BOOL "use scalapack")
set(BUILD_TESTS OFF CACHE BOOL "build tests")
set(GPU_MODEL "none" CACHE STRING "The target GPU architecture; one of {none,P100,V100,G10x0}")
set(DEBUG_MEMORY_POOL OFF CACHE BOOL "explicit debugging of memory pool")
set(USE_OPENMP ON CACHE BOOL "use OpenMP")
set(PYTHON2 OFF CACHE STRING "Use Python 2.7")
set(USE_PROFILER ON CACHE BOOL "measure execution of functions with timer")
set(USE_MEMORY_POOL ON CACHE BOOL "use memory pool")
set(GPU_MEMORY_ALIGMENT "512" CACHE STRING "memory aligment of the GPU")
if(USE_CUDA AND USE_ROCM)
message(FATAL_ERROR "USE_CUDA and USE_ROCM must not be enabled at the same time!")
endif()
add_compile_definitions(__GPU_MEMORY_ALIGMENT=${GPU_MEMORY_ALIGMENT})
# if(USE_MKL AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel"))
# message(FATAL_ERROR "Unsupported compiler")
# endif()
set_property(CACHE GPU_MODEL PROPERTY STRINGS "none" "P100" "V100" "G10x0")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules")
list(APPEND CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
include(GitSubmodule) # include custom defined FindPackage modules
include(GNUInstallDirs) # required to get a proper LIBDIR variable
if (CREATE_PYTHON_MODULE)
if(PYTHON2)
# force cmake to use python2
set(PYBIND11_PYTHON_VERSION 2.7)
find_package(Python2 REQUIRED)
set(PYTHON_EXECUTABLE ${Python2_EXECUTABLE})
else()
find_package(Python3 REQUIRED)
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
endif()
endif()
# Set release as the default build type.
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE release CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "debug" "release" "relwithdebinfo")
endif()
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb -DDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -ggdb -O2")
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O2")
endif()
# Makes the build directory relocatable: requires CMake 3.14.7
#set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
# preserve rpaths when installing and make the install folder relocatable
# use `CMAKE_SKIP_INSTALL_RPATH` to skip this
# https://spack.readthedocs.io/en/latest/workflows.html#write-the-cmake-build
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
# skip RPATH if SIRIUS is installed to system directories
if(isSystemDir STREQUAL "-1")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
if(APPLE)
set(basePoint @loader_path)
else()
set(basePoint $ORIGIN)
endif()
file(RELATIVE_PATH relDir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_INSTALL_RPATH ${basePoint} ${basePoint}/${relDir})
endif()
# build shared libraries by default
option(BUILD_SHARED_LIBS "Build shared libraries." ON)
# generate compile_commands.json with compile commands for each target
set(CMAKE_EXPORT_COMPILE_COMMANDS "YES")
if(USE_NLCGLIB)
find_package(nlcglib REQUIRED)
find_package(Kokkos REQUIRED)
endif()
find_package(MPI REQUIRED)
find_package(GSL REQUIRED)
find_package(LibXC 3.0.0 REQUIRED)
find_package(LibSPG REQUIRED)
find_package(HDF5 REQUIRED C)
include(cmake/hdf5_target.cmake)
find_package(SpFFT 0.9.6 CONFIG REQUIRED)
if (USE_OPENMP)
find_package(OpenMP REQUIRED)
endif()
set(LINALG_LIB "")
if(USE_MKL)
set(USE_MKL_SHARED_LIBS On) # link against shared MKL libraries
find_package(MKL REQUIRED)
set(LINALG_LIB "sirius::mkl")
elseif(USE_CRAY_LIBSCI)
find_package(CRAY_LIBSCI REQUIRED)
set(LINALG_LIB "${CRAY_LIBSCI_LIBRARIES}")
else()
find_package(LAPACK REQUIRED)
set(LINALG_LIB "${LAPACK_LIBRARIES}")
if(USE_SCALAPACK)
find_package(SCALAPACK REQUIRED) # just sets scalapack_DIR
set(LINALG_LIB "${LINALG_LIB};${SCALAPACK_LIBRARIES}")
endif()
endif()
if(USE_ELPA)
find_package(Elpa REQUIRED)
endif(USE_ELPA)
if(USE_MAGMA)
find_package(MAGMA REQUIRED)
endif(USE_MAGMA)
if(USE_VDWXC)
find_package(LibVDWXC 0.3.0 REQUIRED)
endif(USE_VDWXC)
if(USE_CUDA)
enable_language(CUDA)
find_package(CUDA)
include(cmake/cudalibs_target.cmake)
if(GPU_MODEL MATCHES "P100")
message("set nvcc flags for P100")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -arch=sm_60")
elseif(GPU_MODEL MATCHES "V100")
message("set nvcc flags for V100")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -arch=sm_70")
elseif(GPU_MODEL MATCHES "G10x0")
message("set nvcc flags for geforce 1000")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -arch=sm_61")
endif()
endif(USE_CUDA)
if(USE_ROCM)
if(NOT HIP_HCC_FLAGS)
message(STATUS "Using default AMD gpu targets: gfx803, gfx900, gfx906. Set HIP_HCC_FLAGS to override.")
set(HIP_HCC_FLAGS ${HIP_HCC_FLAGS} --amdgpu-target=gfx803 --amdgpu-target=gfx900 --amdgpu-target=gfx906)
endif()
find_package(HIP REQUIRED)
# rocblas and hip have cmake config files, but add incompatible flags for mixed compiler usage, so we use custom find modules
find_package(ROCBLAS REQUIRED)
find_package(HIPLIBS REQUIRED)
endif()
# check if git command exists
find_program(GIT_EXE NAMES git)
# generate version header
string(TIMESTAMP SIRIUS_TIMESTAMP "%Y-%m-%d %H:%M:%S")
if(DEFINED GIT_EXE AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
execute_process(COMMAND git rev-parse HEAD
OUTPUT_VARIABLE SIRIUS_SHA
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND git describe --all
OUTPUT_VARIABLE SIRIUS_GIT_BRANCH
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "git hash ${SIRIUS_SHA}")
else()
set(SIRIUS_GIT_BRANCH "release v${SIRIUS_VERSION}")
set(SIRIUS_SHA "https://api.github.com/repos/electronic-structure/SIRIUS/git/ref/tags/v${SIRIUS_VERSION}")
endif()
configure_file("${PROJECT_SOURCE_DIR}/src/version.hpp.in"
"${PROJECT_BINARY_DIR}/src/version.hpp"
@ONLY)
# generate runtime options
file(STRINGS "${PROJECT_SOURCE_DIR}/src/options.json"
SIRIUS_RUNTIME_OPTIONS NEWLINE_CONSUME)
configure_file("${PROJECT_SOURCE_DIR}/src/runtime_options_json.hpp.in"
"${PROJECT_BINARY_DIR}/src/runtime_options_json.hpp"
@ONLY)
# install targets and modules
include(cmake/env_vars_map.cmake)
configure_file("${PROJECT_SOURCE_DIR}/cmake/siriusConfig.cmake.in"
"${PROJECT_BINARY_DIR}/siriusConfig.cmake"
@ONLY)
install(FILES "${PROJECT_BINARY_DIR}/siriusConfig.cmake"
"${PROJECT_SOURCE_DIR}/cmake/cudalibs_target.cmake"
"${PROJECT_SOURCE_DIR}/cmake/hdf5_target.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/sirius")
install(DIRECTORY "${PROJECT_SOURCE_DIR}/cmake/modules"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/sirius"
FILES_MATCHING PATTERN "*.cmake")
# sirius library
add_subdirectory(src)
# applications
if(BUILD_TESTS)
add_subdirectory(apps/tests)
add_subdirectory(apps/unit_tests)
endif(BUILD_TESTS)
add_subdirectory(apps/atoms)
add_subdirectory(apps/hydrogen)
add_subdirectory(apps/dft_loop)
if(USE_NLCGLIB)
add_subdirectory(apps/nlcg)
endif()
add_subdirectory(apps/upf)
add_subdirectory(apps/utils)
add_subdirectory(python_module)
add_subdirectory(doc)