-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
226 lines (188 loc) · 7.71 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
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)
PROJECT(vca Fortran)
SET(VERSION 1.5.9)
MESSAGE(STATUS "OS: ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}")
SET(BUILD_TYPE "TESTING" CACHE STRING "Build type")
MESSAGE(STATUS "BUILD_TYPE=${BUILD_TYPE}")
SET(CMAKE_BUILD_TYPE ${BUILD_TYPE} CACHE INTERNAL "Build type" FORCE)
# Add our local CMAKE modules to the module path
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
INCLUDE(${CMAKE_MODULE_PATH}/ColorsMsg.cmake)
# Check that Fortran 90 is supported
IF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)
MESSAGE(FATAL_ERROR "Fortran compiler does not support F90")
ENDIF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)
IF( (${CMAKE_Fortran_COMPILER_ID} MATCHES Intel) OR (${CMAKE_Fortran_COMPILER_ID} MATCHES GNU))
MESSAGE(STATUS "Fortran Compiler id = ${CMAKE_Fortran_COMPILER_ID}")
ELSEIF()
MESSAGE(FATAL_ERROR "Unsupported Fortran compiler (use Intel or GNU). Try export FC=<your FC compiler> ")
ENDIF()
# Set some options the user may choose
OPTION(USE_MPI "Set MPI pre-compilation flag" ON)
OPTION(VERBOSE "Build a verbose Makefile" On)
OPTION(WITH_BLAS_LAPACK "Use internal Blas/Lapack" OFF)
IF(VERBOSE)
SET(CMAKE_VERBOSE_MAKEFILE OFF)
ELSE(VERBOSE)
SET(CMAKE_VERBOSE_MAKEFILE OFF)
ENDIF(VERBOSE)
############################################################
# Look for MPI if needed
############################################################
# reSet compiler to MPI is required
IF(USE_MPI)
FIND_PACKAGE(MPI REQUIRED)
IF(MPI_Fortran_FOUND)
SET(CMAKE_Fortran_COMPILER ${MPI_Fortran_COMPILER})
MESSAGE(STATUS "Set Fortran compiler to ${Yellow}${CMAKE_Fortran_COMPILER}${ColourReset}, ID=${CMAKE_Fortran_COMPILER_ID}")
SET(MPI_CPP "MPI") #pre-processing option
ELSE()
MESSAGE(FATAL_ERROR "MPI Found but No MPI-Fortran compiler can be determined.")
ENDIF()
ELSE(USE_MPI)
SET(MPI_CPP "")
ENDIF(USE_MPI)
############################################################
# Check for .git and extract the current SHA1 revision.
############################################################
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
FIND_PACKAGE(Git)
IF(GIT_FOUND)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_SHA1
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
MESSAGE( STATUS "Git version: ${GIT_SHA1}" )
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_BRANCH
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
SET(GIT_BRANCH_ "_${GIT_BRANCH}")
MESSAGE( STATUS "Git branch: ${GIT_BRANCH}" )
IF( "${GIT_BRANCH}" MATCHES "master")
UNSET(GIT_BRANCH)
UNSET(GIT_BRANCH_)
ENDIF()
ELSE(GIT_FOUND)
SET(GIT_SHA1 0)
ENDIF(GIT_FOUND)
ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
SET(REVISION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/revision.inc)
FILE(WRITE ${REVISION_FILE} "character(len=41),parameter,public :: revision = \"${GIT_SHA1}\"\n")
############################################################
# Look for required libraries: blas,lapack,scifor,dmft_tools
############################################################
# Find Scifor
FIND_PACKAGE(PkgConfig)
PKG_SEARCH_MODULE(SCIFOR REQUIRED scifor)
IF(${SCIFOR_FOUND})
MESSAGE(STATUS "SCIFOR found at: ${SCIFOR_PREFIX}")
ELSE()
MESSAGE(FATAL_ERROR "
Can not find SciFortran in this system. Check SciFor installation. Try adding the provided PKG-CONFIG file to the environment:
$ export PKG_CONFIG_PATH=<path_to_scifor_dir>/etc:$PKG_CONFIG_PATH")
ENDIF()
IF("${SCIFOR_LDFLAGS}" MATCHES "mkl")
FIND_PACKAGE(MKL QUIET)
ELSEIF("${SCIFOR_LDFLAGS}" MATCHES "blas" OR "lapack")
FIND_PACKAGE(BLAS REQUIRED)
FIND_PACKAGE(LAPACK REQUIRED)
ENDIF()
INCLUDE_DIRECTORIES(BEFORE ${SCIFOR_INCLUDE_DIRS})
# Find Dmft_tools
PKG_SEARCH_MODULE(DMFT_TOOLS REQUIRED dmft_tools)
IF(${DMFT_TOOLS_FOUND})
MESSAGE(STATUS "DMFT_TOOLS found at: ${DMFT_TOOLS_PREFIX}")
ELSE()
MESSAGE( FATAL_ERROR "
Can not find DMFT_TOOLS in this system. Check DMFT_TOOLS installation. Try adding the provided PKG-CONFIG file to the environment:
$ export PKG_CONFIG_PATH=<path_to_dmft_tools_dir>/etc:$PKG_CONFIG_PATH")
ENDIF()
INCLUDE_DIRECTORIES(BEFORE ${DMFT_TOOLS_INCLUDE_DIRS})
############################################################
# Set Fortran options based on BUILD_TYPE and FC ID
############################################################
if(CMAKE_Fortran_COMPILER_ID MATCHES GNU) # this is gfortran
SET(CMAKE_Fortran_MODDIR_FLAG "-J")
SET(CMAKE_Fortran_FLAGS "-cpp -ffree-line-length-none")
SET(CMAKE_Fortran_FLAGS_TESTING "-O2 -funroll-loops")
SET(CMAKE_Fortran_FLAGS_DEBUG "-O0 -p -g -Wsurprising -Waliasing -fwhole-file -fcheck=all -pedantic -fbacktrace -fbounds-check")
SET(CMAKE_Fortran_FLAGS_RELEASE "-O3 -ffast-math -march=native -funroll-loops") ##-fno-protect-parens -flto
elseif(CMAKE_Fortran_COMPILER_ID MATCHES Intel)
SET(CMAKE_Fortran_MODDIR_FLAG "-module ") #remember the ending white space here
SET(CMAKE_Fortran_FLAGS "-fpp")
SET(CMAKE_Fortran_FLAGS_TESTING "-O2 -ftz")
SET(CMAKE_Fortran_FLAGS_DEBUG "-p -O0 -g -fpe1 -warn -debug extended -traceback -check all,noarg_temp_created")
SET(CMAKE_Fortran_FLAGS_RELEASE "-O3 -ftz")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES G95)
SET(CMAKE_Fortran_MODDIR_FLAG "-fmod=")
SET(CMAKE_Fortran_FLAGS "-cpp")
SET(CMAKE_Fortran_FLAGS_TESTING "-O1 -fsloppy-char")
SET(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -ftrace=full")
SET(CMAKE_Fortran_FLAGS_RELEASE "-O3")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES PGI)
SET(CMAKE_Fortran_MODDIR_FLAG "-module ")
SET(CMAKE_Fortran_FLAGS "-")
SET(CMAKE_Fortran_FLAGS "")
SET(CMAKE_Fortran_FLAGS_DEBUG "-g -O0 -Mframe")
SET(CMAKE_Fortran_FLAGS_RELEASE "-O3 -mcmodel=medium -fast -Munroll")
endif()
#set MPI preprocessing defition:
IF(USE_MPI)
ADD_DEFINITIONS(-D_MPI)
ELSE(USE_MPI)
ADD_DEFINITIONS(-D_)
ENDIF(USE_MPI)
############################################################
# Define the actual files and folders that make up the build
############################################################
SET(USER_HOME $ENV{HOME})
# Define some directories
SET(DRIVERS ${CMAKE_SOURCE_DIR}/drivers)
#define PREFIX
SET(PREFIX "$ENV{HOME}/.bin" CACHE PATH "Prefix prepended to install directories")
SET(CMAKE_INSTALL_PREFIX "${PREFIX}" CACHE INTERNAL "Prefix prepended to install directories" FORCE)
# define the executable to compiler
SET(EXE vca_test CACHE STRING "Driver code to compile")
# SET(CMAKE_INSTALL_EXE "${EXE}" CACHE INTERNAL "Driver code to compile" FORCE)
FILE(GLOB VCA_LOCAL_SRC
VCA_SPARSE_MATRIX.f90
VCA_INPUT_VARS.f90
VCA_VARS_GLOBAL.f90
VCA_AUX_FUNX.f90
VCA_BATH_SETUP.f90
VCA_BATH_FUNCTIONS.f90
VCA_IO.f90
VCA_SETUP.f90
VCA_EIGENSPACE.f90
VCA_HAMILTONIAN_COMMON.f90
VCA_HAMILTONIAN_SPARSE_HxV.f90
VCA_HAMILTONIAN_DIRECT_HxV.f90
VCA_HAMILTONIAN.f90
VCA_DIAG.f90
VCA_GF_SHARED.f90
VCA_GF_NORMAL.f90
VCA_GREENS_FUNCTIONS.f90
VCA_OBSERVABLES.f90
VCA_OMEGA.f90
VCA_MAIN.f90
VCA.f90
)
SET(VCA_OBJS ${VCA_LOCAL_SRC})
ADD_EXECUTABLE(vca ${DRIVERS}/${EXE}.f90 ${VCA_OBJS})
TARGET_LINK_LIBRARIES(vca ${DMFT_TOOLS_LDFLAGS} ${SCIFOR_LDFLAGS})
SET_TARGET_PROPERTIES(vca PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_INSTALL_PREFIX}" OUTPUT_NAME "${EXE}${GIT_BRANCH_}")
MESSAGE(STATUS "Executable created at: ${Yellow}${CMAKE_INSTALL_PREFIX}/${EXE}${GIT_BRANCH_}${ColourReset}")
ADD_CUSTOM_TARGET(
completion
COMMAND scifor_completion.sh ${DRIVERS}/${EXE}.f90
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
# Add a distclean target to the Makefile
ADD_CUSTOM_TARGET(distclean
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/distclean.cmake
)