CMakeLists.txt 6.52 KB
Newer Older
Victor Yu's avatar
Victor Yu committed
1
### CMake version ###
Victor Yu's avatar
Victor Yu committed
2
CMAKE_MINIMUM_REQUIRED(VERSION 3.0 FATAL_ERROR)
Victor Yu's avatar
Victor Yu committed
3
4

### Project ###
Victor Yu's avatar
Victor Yu committed
5
PROJECT(elsi VERSION 2.5.0 LANGUAGES NONE)
6
7
8
9
SET(elsi_URL "http://elsi-interchange.org")
SET(elsi_EMAIL "elsi-team@duke.edu")
SET(elsi_LICENSE "BSD 3")
SET(elsi_DESCRIPTION "Electronic Structure Infrastructure")
Victor Yu's avatar
Victor Yu committed
10
SET(elsi_DATESTAMP "20200524")
Victor Yu's avatar
Victor Yu committed
11

Victor Yu's avatar
Victor Yu committed
12
13
### CMake modules ###
LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
Victor Yu's avatar
Victor Yu committed
14
INCLUDE(Utils)
Victor Yu's avatar
Victor Yu committed
15

Victor Yu's avatar
Victor Yu committed
16
### Installation paths ###
Victor Yu's avatar
Victor Yu committed
17
IF(PROJECT_BINARY_DIR STREQUAL PROJECT_SOURCE_DIR)
18
19
  MESSAGE(FATAL_ERROR "${MAGENTA}Build in the source directory is not allowed${COLORRESET}")
ENDIF()
Victor Yu's avatar
Victor Yu committed
20
SET(CMAKE_Fortran_MODULE_DIRECTORY "${PROJECT_BINARY_DIR}/include")
Victor Yu's avatar
Victor Yu committed
21
22
23
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
24
FILE(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/generated")
25
26
27
28
29
30
IF(NOT DEFINED CMAKE_INSTALL_INCLUDEDIR)
  SET(CMAKE_INSTALL_INCLUDEDIR "include" CACHE PATH "Location to install module and header files")
ENDIF()
IF(NOT DEFINED CMAKE_INSTALL_LIBDIR)
  SET(CMAKE_INSTALL_LIBDIR "lib" CACHE PATH "Location to install library files")
ENDIF()
31
32
33
34
IF(IS_ABSOLUTE CMAKE_INSTALL_LIBDIR)
  GET_FILENAME_COMPONENT(LIBDIR_ABS ${CMAKE_INSTALL_LIBDIR} ABSOLUTE)
ELSE()
  GET_FILENAME_COMPONENT(LIBDIR_ABS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" ABSOLUTE)
35
ENDIF()
36
37
38
39
40
41
IF(IS_ABSOLUTE CMAKE_INSTALL_INCLUDEDIR)
  GET_FILENAME_COMPONENT(INCDIR_ABS ${CMAKE_INSTALL_INCLUDEDIR} ABSOLUTE)
ELSE()
  GET_FILENAME_COMPONENT(INCDIR_ABS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}" ABSOLUTE)
ENDIF()
IF(LIBDIR_ABS STREQUAL "${PROJECT_BINARY_DIR}/lib" OR INCDIR_ABS STREQUAL "${PROJECT_BINARY_DIR}/include")
Victor Yu's avatar
Victor Yu committed
42
43
  MESSAGE(FATAL_ERROR "${MAGENTA}Installation directory cannot be the same as build directory${COLORRESET}")
ENDIF()
Victor Yu's avatar
Victor Yu committed
44

Victor Yu's avatar
Victor Yu committed
45
### Options ###
46
47
OPTION(ENABLE_TESTS "Build ELSI Fortran test programs" OFF)
OPTION(ENABLE_C_TESTS "Build ELSI C test programs" OFF)
48
OPTION(ENABLE_PEXSI "Enable PEXSI" OFF)
Victor Yu's avatar
Victor Yu committed
49
OPTION(ENABLE_EIGENEXA "Enable EigenExa" OFF)
Victor Yu's avatar
Victor Yu committed
50
OPTION(ENABLE_SIPS "Enable SLEPc-SIPs" OFF)
Victor Yu's avatar
Victor Yu committed
51
OPTION(ENABLE_MAGMA "Enable MAGMA" OFF)
52
OPTION(ENABLE_BSEPACK "Enable BSEPACK" OFF)
Victor Yu's avatar
Victor Yu committed
53
OPTION(USE_MPI_MODULE "Use MPI module instead of mpif.h in Fortran code" OFF)
54
55
OPTION(USE_EXTERNAL_ELPA "Use external ELPA" OFF)
OPTION(USE_EXTERNAL_OMM "Use external libOMM" OFF)
Victor Yu's avatar
Victor Yu committed
56
OPTION(USE_EXTERNAL_PEXSI "Use external PEXSI" OFF)
57
OPTION(USE_EXTERNAL_NTPOLY "Use external NTPoly" OFF)
Victor Yu's avatar
Victor Yu committed
58
OPTION(USE_EXTERNAL_BSEPACK "Use external BSEPACK" OFF)
59
OPTION(USE_GPU_CUDA "Use GPU acceleration based on CUDA" OFF)
Victor Yu's avatar
Victor Yu committed
60
OPTION(ADD_UNDERSCORE "Suffix C functions with an underscore" ON)
Victor Yu's avatar
Victor Yu committed
61
OPTION(BUILD_SHARED_LIBS "Whether to build shared or static libraries" OFF)
62
SET(ELPA2_KERNEL "" CACHE STRING "Use AVX/AVX2/AVX512 ELPA2 kernel")
63
64
SET(MPIEXEC_NP "mpirun -n 4" CACHE STRING "Command to run parallel tests with multiple MPI tasks")
SET(MPIEXEC_1P "mpirun -n 1" CACHE STRING "Command to run serial tests with 1 MPI task")
Victor Yu's avatar
Victor Yu committed
65
SET(SCOTCH_LAST_RESORT "NOT_USED" CACHE STRING "Command to run PT-SCOTCH header generation")
Victor Yu's avatar
Victor Yu committed
66
67
SET(LIB_PATHS "" CACHE STRING "List of directories containing libraries to be linked against")
SET(INC_PATHS "" CACHE STRING "List of include directories")
68
SET(LIBS "" CACHE STRING "List of external libraries to be linked against")
Victor Yu's avatar
Victor Yu committed
69

70
71
72
### Compilers ###
IF(NOT DEFINED CMAKE_Fortran_COMPILER)
  MESSAGE(FATAL_ERROR "${MAGENTA}Fortran compiler must be set${COLORRESET}")
73
ENDIF()
74
75
76
77
ENABLE_LANGUAGE(Fortran)

IF(NOT DEFINED CMAKE_C_COMPILER)
  MESSAGE(FATAL_ERROR "${MAGENTA}C compiler must be set${COLORRESET}")
78
ENDIF()
79
80
ENABLE_LANGUAGE(C)

81
82
83
IF(ENABLE_PEXSI)
  IF(NOT DEFINED CMAKE_CXX_COMPILER)
    MESSAGE(FATAL_ERROR "${MAGENTA}C++ compiler must be set${COLORRESET}")
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
  ENDIF()
  ENABLE_LANGUAGE(CXX)
ENDIF()

IF(USE_GPU_CUDA)
  IF(${CMAKE_VERSION} VERSION_LESS 3.8)
    MESSAGE(FATAL_ERROR "${MAGENTA}CUDA support requires CMake 3.8 or higher${COLORRESET}")
  ENDIF()
  ENABLE_LANGUAGE(CUDA)

  # See gitlab.kitware.com/cmake/cmake/issues/17797
  IF(NOT CMAKE_GENERATOR STREQUAL Ninja AND ${CMAKE_VERSION} VERSION_LESS 3.11)
    SET(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_INCLUDES 0)
    SET(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
    SET(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_OBJECTS 0)
99
  ENDIF()
100
ENDIF()
101
102

### External libraries ###
Victor Yu's avatar
Victor Yu committed
103
STRING(REPLACE "-l" "" LIBS "${LIBS}")
104
FOREACH(str LIBS LIB_PATHS INC_PATHS)
105
106
  convert_to_list(${str})
ENDFOREACH()
Victor Yu's avatar
Victor Yu committed
107
generate_library_targets(LIB_PATHS LIBS)
Victor Yu's avatar
Victor Yu committed
108

Victor Yu's avatar
Victor Yu committed
109
### Compilations ###
110
111
112
113
114
115
116
117
118
119
120
121
122
IF(USE_EXTERNAL_ELPA)
  MESSAGE(STATUS "Using external ELPA")
ELSE()
  MESSAGE(STATUS "Enabling internal ELPA")
  ADD_SUBDIRECTORY(external/ELPA)
ENDIF()

IF(USE_EXTERNAL_OMM)
  MESSAGE(STATUS "Using external libOMM")
ELSE()
  MESSAGE(STATUS "Enabling internal libOMM")
  ADD_SUBDIRECTORY(external/libOMM)
ENDIF()
123

124
IF(ENABLE_PEXSI)
Victor Yu's avatar
Victor Yu committed
125
126
  IF(USE_EXTERNAL_PEXSI)
    MESSAGE(STATUS "Using external PEXSI")
127
  ELSE()
Victor Yu's avatar
Victor Yu committed
128
    MESSAGE(STATUS "Enabling internal PEXSI")
129
    MESSAGE(STATUS "Enabling internal SuperLU_DIST")
Victor Yu's avatar
Victor Yu committed
130
    MESSAGE(STATUS "Enabling internal PT-SCOTCH")
Victor Yu's avatar
Victor Yu committed
131
    ADD_SUBDIRECTORY(external/PEXSI)
132
    ADD_SUBDIRECTORY(external/SuperLU_DIST)
Victor Yu's avatar
Victor Yu committed
133
    ADD_SUBDIRECTORY(external/SCOTCH)
134
  ENDIF()
135
ENDIF()
Victor Yu's avatar
Victor Yu committed
136

Victor Yu's avatar
Victor Yu committed
137
138
139
140
IF(ENABLE_EIGENEXA)
  MESSAGE(STATUS "Enabling EigenExa")
ENDIF()

141
IF(ENABLE_SIPS)
Victor Yu's avatar
Victor Yu committed
142
  MESSAGE(STATUS "Enabling SLEPc-SIPs")
143
  ADD_SUBDIRECTORY(external/SIPS)
144
ENDIF()
145

146
147
148
149
150
151
152
IF(USE_EXTERNAL_NTPOLY)
  MESSAGE(STATUS "Using external NTPoly")
ELSE()
  MESSAGE(STATUS "Enabling internal NTPoly")
  ADD_SUBDIRECTORY(external/NTPoly)
ENDIF()

Victor Yu's avatar
Victor Yu committed
153
154
155
156
IF(ENABLE_MAGMA)
  MESSAGE(STATUS "Enabling MAGMA")
ENDIF()

157
158
159
160
161
162
163
IF(ENABLE_BSEPACK)
  IF(USE_EXTERNAL_BSEPACK)
    MESSAGE(STATUS "Using external BSEPACK")
  ELSE()
    MESSAGE(STATUS "Enabling internal BSEPACK")
    ADD_SUBDIRECTORY(external/BSEPACK)
  ENDIF()
Victor Yu's avatar
Victor Yu committed
164
165
ENDIF()

166
ADD_SUBDIRECTORY(external/FortJSON)
167
ADD_SUBDIRECTORY(src)
168

169
170
171
IF(ENABLE_TESTS OR ENABLE_C_TESTS)
  MESSAGE(STATUS "Enabling test programs")
  ENABLE_TESTING()
172
173
  ADD_SUBDIRECTORY(test)
ENDIF()
174
175
176

ADD_CUSTOM_TARGET(pack rm -rf ${PROJECT_BINARY_DIR}/elsi_packed
  COMMAND mkdir ${PROJECT_BINARY_DIR}/elsi_packed
Victor Yu's avatar
Victor Yu committed
177
  COMMAND cp ${PROJECT_SOURCE_DIR}/.elsi.pc.in ${PROJECT_BINARY_DIR}/elsi_packed
178
179
  COMMAND cp ${PROJECT_SOURCE_DIR}/CMakeLists.txt ${PROJECT_BINARY_DIR}/elsi_packed
  COMMAND cp ${PROJECT_SOURCE_DIR}/LICENSE ${PROJECT_BINARY_DIR}/elsi_packed
Victor Yu's avatar
Victor Yu committed
180
  COMMAND cp ${PROJECT_SOURCE_DIR}/README.md ${PROJECT_BINARY_DIR}/elsi_packed
181
182
183
184
  COMMAND cp -r ${PROJECT_SOURCE_DIR}/cmake ${PROJECT_BINARY_DIR}/elsi_packed
  COMMAND cp -r ${PROJECT_SOURCE_DIR}/external ${PROJECT_BINARY_DIR}/elsi_packed
  COMMAND cp -r ${PROJECT_SOURCE_DIR}/src ${PROJECT_BINARY_DIR}/elsi_packed
  VERBATIM)