forked from aoterodelaroza/critic2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
324 lines (281 loc) · 11.1 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
## project and version
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
# policies
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
## some project variables
set(critic2_MAJOR_VERSION 1)
set(critic2_MINOR_VERSION 1)
set(critic2_URL "https://aoterodelaroza.github.io/critic2/")
set(critic2_EMAIL "[email protected]")
set(critic2_LICENSE "GNU/GPL version 3")
set(critic2_DESCRIPTION "Analysis of quantum mechanical calculations in molecules and solids")
string(TIMESTAMP DATE "%a %d %b %Y %H:%M:%S")
## build recipes
if (BUILD_RECIPE STREQUAL "MSYS2")
## system and compiler details
set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
## set the cache
set(CMAKE_INSTALL_PREFIX "D:/msys2/home/media service/critic2-install" CACHE PATH "Install directory" FORCE)
set(BUILD_TESTING ON CACHE BOOL "" FORCE)
set(ENABLE_GUI ON CACHE BOOL "" FORCE)
set(BUILD_TYPE "Debug" CACHE STRING "" FORCE)
set(GLFW3_ROOT "/home/alberto/dll/glfw-3.3.8.bin.WIN64" CACHE STRING "" FORCE)
set(USE_GUI_THREADS ON CACHE BOOL "" FORCE)
elseif (BUILD_RECIPE STREQUAL "WINE")
## system and compiler details
set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
set(CMAKE_CROSSCOMPILING_EMULATOR wine)
set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
## set the cache
set(CMAKE_INSTALL_PREFIX "/home/alberto/critic2-install" CACHE PATH "Install directory" FORCE)
set(CRITIC2_ROOT "Z:\\home\\alberto\\critic2-install\\share" CACHE STRING "Critic2 ROOT directory" FORCE)
set(BUILD_TESTING ON CACHE BOOL "" FORCE)
set(ENABLE_GUI ON CACHE BOOL "" FORCE)
set(BUILD_TYPE "Debug" CACHE STRING "" FORCE)
set(GLFW3_ROOT "/home/alberto/critic2-install/glfw-3.3.8.bin.WIN64" CACHE STRING "" FORCE)
set(USE_GUI_THREADS ON CACHE BOOL "" FORCE)
endif()
## project definition
project(critic2 VERSION "${critic2_MAJOR_VERSION}.${critic2_MINOR_VERSION}" LANGUAGES C Fortran)
## global flags for cmake
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_VERBOSE_MAKEFILE ON)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
include(GNUInstallDirs)
include(utils)
## whether we are following a build recipe
if(NOT BUILD_RECIPE)
set(BUILD_RECIPE OFF CACHE STRING "Choose the build recipe." FORCE)
endif()
set_property(CACHE BUILD_RECIPE PROPERTY STRINGS OFF MSYS2 WINE)
## default build type, and type options
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release)
## interface options
option(ENABLE_GUI "Enables the critic2 GUI" OFF)
option(USE_EXTERNAL_LAPACK "Use external LAPACK/BLAS library (linear algebra operations)." ON)
#option(USE_EXTERNAL_QHULL "Use external QHULL library (calculation of convex hulls)." ON)
#option(USE_EXTERNAL_SPGLIB "Use external spglib library (crystal symmetry determination)." ON)
option(USE_LIBXC "Use the libxc library for access (exchange-correlation energies and potentials)." ON)
option(USE_LIBCINT "Use the libcint library (calculation of molecular integrals with Gaussian functions)." ON)
option(USE_READLINE "Use the readline library (improved command-line interface)." ON)
option(ENABLE_OPENMP "Enable OpenMP parallelization." ON)
option(BUILD_STATIC "Build critic2 statically (tested only on linux, and no GUI)." OFF)
## testing
option(BUILD_TESTING "Enable the regression tests for the critic2 build." OFF)
include(CTest)
## GUI requirements
if (ENABLE_GUI)
## GUI options
option(USE_FREETYPE "Use the freetype library (improved font rendering in GUI)." ON)
option(USE_GUI_THREADS "Use threads in the GUI." ON)
## needs -fPIC
enable_language(CXX)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
## find GUI libraries
if (USE_FREETYPE)
find_package(Freetype)
endif()
## glfw3
find_package(GLFW3 REQUIRED)
## opengl
set(OpenGL_GL_PREFERENCE "GLVND")
find_package(OpenGL REQUIRED)
## the GUI requires threads
set(ENABLE_OPENMP ON)
## find pthreads
if (USE_GUI_THREADS)
find_package(Threads REQUIRED)
if(THREADS_HAVE_PTHREAD_ARG)
set_property(TARGET critic2 PROPERTY COMPILE_OPTIONS "-pthread")
set_property(TARGET critic2 PROPERTY INTERFACE_COMPILE_OPTIONS "-pthread")
endif()
endif()
endif()
## perform a static build
if (BUILD_STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set(BLA_STATIC ON)
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_EXE_LINKER_FLAGS "-static")
find_library(LIBDL_LIBRARY NAMES dl)
if(NOT LIBDL_LIBRARY)
error("Dynamic linking static library not found")
endif()
mark_as_advanced(LIBDL_LIBRARY)
set(CMAKE_Fortran_LINK_EXECUTABLE "${CMAKE_Fortran_LINK_EXECUTABLE} ${LIBDL_LIBRARY}")
endif()
## compiler flags, fortran, and check versions
if ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "Intel")
set(FFLAGS_DEBUG "-g -O0 -C -traceback -debug all -fpp -check all")
set(FFLAGS_RELEASE "-O3")
if ("${CMAKE_Fortran_COMPILER_VERSION}" VERSION_EQUAL 20.2.1.20201112)
set(FFLAGS_DEBUG "-g -O0 -traceback -debug all -fpp")
elseif ("${CMAKE_Fortran_COMPILER_VERSION}" VERSION_LESS 19.0)
set(_message "\nA version of intel fortran >=19.5 is required to compile the development version of critic2. "
"Please, visit: https://aoterodelaroza.github.io/critic2/installation/#whichcompilerswork"
"for more information.\n")
message(FATAL_ERROR ${_message})
endif()
elseif("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
set(FFLAGS_DEBUG "-g -Og -fcheck=all -fbounds-check -Wall -Wunused-parameter -Wno-maybe-uninitialized -ffpe-trap=invalid,zero,overflow -fbacktrace -fdump-core -cpp")
set(FFLAGS_RELEASE "-O3")
if ("${CMAKE_Fortran_COMPILER_VERSION}" VERSION_LESS 6.0.0)
set(_message "\nA version of gfortran >=6.0 is required to compile the development version of critic2. "
"Please, visit: https://aoterodelaroza.github.io/critic2/installation/#whichcompilerswork"
"for more information.\n")
message(FATAL_ERROR ${_message})
endif()
endif()
## compiler flags, C
if("${CMAKE_C_COMPILER_ID}" MATCHES "GNU")
set(CFLAGS_DEBUG "-D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -fasynchronous-unwind-tables -fexceptions -ggdb -Wall")
set(CFLAGS_RELEASE "-O3")
endif()
## compiler flags, CXX
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
set(CXXFLAGS_DEBUG "-D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -fasynchronous-unwind-tables -fexceptions -ggdb -Wall")
set(CXXFLAGS_RELEASE "-O3")
endif()
## set the compiler flags
string(TOUPPER ${CMAKE_BUILD_TYPE} BT)
set(CMAKE_Fortran_FLAGS_${BT} "${FFLAGS_${BT}}")
set(CMAKE_C_FLAGS_${BT} "${CFLAGS_${BT}}")
set(CMAKE_CXX_FLAGS_${BT} "${CXXFLAGS_${BT}}")
## build recipes flags
if (BUILD_RECIPE STREQUAL "MSYS2" OR BUILD_RECIPE STREQUAL "WINE")
set(CMAKE_Fortran_FLAGS_${BT} "${CMAKE_Fortran_FLAGS_${BT}} -mwindows")
set(CMAKE_C_FLAGS_${BT} "${CMAKE_C_FLAGS_${BT}} -mwindows")
set(CMAKE_CXX_FLAGS_${BT} "${CMAKE_CXX_FLAGS_${BT}} -mwindows")
endif()
## openmp
if (ENABLE_OPENMP)
find_package(OpenMP MODULE COMPONENTS Fortran)
if (OPENMP_FOUND)
set(CMAKE_Fortran_FLAGS_${BT} "${CMAKE_Fortran_FLAGS_${BT}} ${OpenMP_Fortran_FLAGS}")
endif()
endif()
## lapack
if (USE_EXTERNAL_LAPACK)
set(LAPACK_FIND_QUIETLY "ON")
find_package(LAPACK)
endif()
# ## qhull -- deactivated
# if (USE_EXTERNAL_QHULL)
# find_package(QHULL)
# endif()
# ## spglib -- deactivated because the interface keeps changing!
# if (USE_EXTERNAL_SPGLIB)
# find_package(SPGLIB)
# endif()
## numdiff
find_package(NUMDIFF)
## libxc
if (USE_LIBXC)
find_package(LIBXC)
if (LIBXC_FOUND)
set(MINLIBXC_VERSION 5.0)
if (${LIBXC_VERSION} VERSION_LESS ${MINLIBXC_VERSION})
set(LIBXC_FOUND FALSE)
message("!! Libxc version found (${LIBXC_VERSION},${LIBXC_xc_LIBRARY}) too old (requires ${MINLIBXC_VERSION})")
endif()
unset(MINLIBXC_VERSION)
endif()
endif()
## readline
if (USE_READLINE)
find_package(READLINE)
endif()
## libcint
if (USE_LIBCINT)
find_package(LIBCINT)
endif()
## the syntax.txt target
add_custom_target(syntax
COMMAND wget -qO - 'raw.githubusercontent.com/aoterodelaroza/aoterodelaroza.github.io/master/_critic2/13_syntax.md' | awk '/~~~/{a=!a\;next}a{print}' > syntax.txt
)
## process subdirectories
add_subdirectory(src)
add_subdirectory(dat)
if (BUILD_TESTING AND NUMDIFF_FOUND)
add_subdirectory(tests)
endif()
## summary
set(_message
"\n\n### ${CMAKE_PROJECT_NAME}, ${CMAKE_PROJECT_VERSION}###\n"
"Date: ${DATE}\n"
"Build type: ${CMAKE_BUILD_TYPE}\n"
"Fortran compiler: ${CMAKE_Fortran_COMPILER} (${CMAKE_Fortran_COMPILER_ID}, ${CMAKE_Fortran_COMPILER_VERSION})\n"
"Fortran flags: ${CMAKE_Fortran_FLAGS_${BT}}\n"
"C compiler: ${CMAKE_C_COMPILER} (${CMAKE_C_COMPILER_ID}, ${CMAKE_C_COMPILER_VERSION})\n"
"C flags: ${CMAKE_C_FLAGS_${BT}}\n"
"CXX compiler: ${CMAKE_CXX_COMPILER} (${CMAKE_CXX_COMPILER_ID}, ${CMAKE_CXX_COMPILER_VERSION})\n"
"CXX flags: ${CMAKE_CXX_FLAGS_${BT}}\n"
"Install directory: ${CMAKE_INSTALL_PREFIX}\n"
"OpenMP parallelization: ${OPENMP_FOUND}\n"
)
if (LAPACK_FOUND)
set(_message "${_message}Lapack: lib=${LAPACK_LIBRARIES}\n")
else()
set(_message "${_message}Lapack: <internal>\n")
endif()
# if (QHULL_FOUND)
# set(_message "${_message}Qhull: lib=${QHULL_LIBRARIES} | inc=${QHULL_INCLUDE_DIRS}\n")
# else()
# set(_message "${_message}Qhull: <internal>\n")
# endif()
# if (SPGLIB_FOUND)
# set(_message "${_message}Spglib: lib=${SPGLIB_LIBRARY}\n")
# else()
# set(_message "${_message}Spglib: <internal>\n")
# endif()
if (LIBXC_FOUND)
set(_message "${_message}Libxc: ${LIBXC_VERSION} | lib=${LIBXC_xcf90_LIBRARY} ${LIBXC_xc_LIBRARY} | inc=${LIBXC_INCLUDE_DIRS}\n")
else()
set(_message "${_message}Libxc: not used\n")
endif()
if (LIBCINT_FOUND)
set(_message "${_message}Libcint: ${LIBCINT_VERSION} | lib=${LIBCINT_LIBRARY}\n")
else()
set(_message "${_message}Libcint: not used\n")
endif()
if (READLINE_FOUND)
set(_message "${_message}Readline: lib=${READLINE_LIBRARY} | inc=${READLINE_INCLUDE_DIRS}\n")
else()
set(_message "${_message}Readline: not used\n")
endif()
if (NUMDIFF_FOUND)
set(_message "${_message}Numdiff: ${NUMDIFF_EXE}\n")
else()
set(_message "${_message}Numdiff: not found\n")
endif()
set(_message "${_message}GUI build: ${ENABLE_GUI}\n")
if (ENABLE_GUI)
set(_message
"${_message}gl: lib=${OPENGL_LIBRARIES} | inc=${OPENGL_INCLUDE_DIRS}\n"
"glm: lib=${GLM_LIBRARIES} | inc=${GLM_INCLUDE_DIRS}\n"
"glfw: lib=${GLFW3_LIBRARY} | inc=${GLFW3_INCLUDE_DIR}\n"
"freetype: lib=${FREETYPE_LIBRARIES} | inc=${FREETYPE_INCLUDE_DIRS}\n"
"dl: lib=${CMAKE_DL_LIBS}\n")
endif()
set(_message "${_message}################################\n")
message(STATUS ${_message})