-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfigure.py
118 lines (101 loc) · 5.31 KB
/
configure.py
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
import sys
import os
import textwrap
import traceback
cmake_dict = {'SLATE_DIR':['', 'Path to SLATE installation',
'--SLATE_DIR=/path/to/SLATE/installation'],
'BOOST_DIR':['','Path to the boost installation',
'--DEALII_PATH=/path/to/boost/installation'],
'DEALII_PATH':['','Path to the deal.ii installation',
'--DEALII_PATH=/path/to/deal.ii/installation'],
'CMAKE_BUILD_TYPE':['', 'Build type Debug/Release',
'--CMAKE_BUILD_TYPE=Debug'],
'CMAKE_C_COMPILER':['', 'C compiler to use',
'--CMAKE_C_COMPILER=gcc'],
'CMAKE_C_FLAGS':['','C compiler flags',
'--CMAKE_C_FLAGS="-g -O2"'],
'CMAKE_CXX_COMPILER':['', 'C++ compiler to use',
'--CMAKE_CXX_COMPILER=gcc'],
'CMAKE_CXX_FLAGS':['','C++ compiler flags',
'--CMAKE_CXX_FLAGS="-g -O2"'],
'ENABLE_MPI':['ON','''ON or OFF based on whether to use MPI '''\
'''or not. Default=ON''',
'--ENABLE_MPI=ON'],
'ENABLE_MPI_DEVICE_AWARE':['ON','''ON or OFF based on whether '''\
'''the MPI library is device or cuda aware. Must have '''\
'''--ENABLE_MPI=ON for it to make sense. Default=OFF''',
'--ENABLE_MPI_DEVICE_AWARE=OFF'],
'MPI_C_COMPILER':['', '''MPI C compiler to use. Must have
--ENABLE_MPI=ON for it to make sense.''',
'--MPI_C_COMPILER=mpicc'],
'MPI_CXX_COMPILER':['', '''MPI C++ compiler to use. Must have
--ENABLE_MPI=ON for it to make sense.''',
'--MPI_CXX_COMPILER=mpicc++'],
'ENABLE_CUDA':['OFF','ON or OFF based on whether to use CUDA/GPU or not',
'--ENABLE_CUDA=OFF'],
'CMAKE_CUDA_FLAGS':['','Additional flags for CUDA',
'''--CMAKE_CUDA_FLAGS="-arch=sm_70"'''],
'LIBXML_LIBRARIES': ['', 'Path to libxml2 libraries',
'''--LIBXML_LIBRARIES=
"-L/path/to/libxml2/libraries -lxml2"
'''],
'LIBXML_PATH': ['', 'Path to libxml2 include director',
'''--LIBXML_PATH=
"/path/to/libxml2/include"
'''],
'LIBXC_DIR':['', 'Path to LIBXC installation',
'--LIBXC_DIR=/path/to/LIBXC/installation'],
'LIBXC_LIBRARY': ['', 'Path to libxc libraries',
'''--LIBXC_LIBRARY=
"-L/path/to/libxc/library"
''']}
def sanityCheck(string):
if '=' not in string:
raise Exception('''Invalid command line option ''' + string +
''' passed. Maybe you forgot to use "=" to assign'''\
'''the option?''')
def splitString(string):
if string[:2] != "--":
raise Exception('''Invalid command line option ''' + string +
''' passed. Maybe you forgot to prefix with "--"?''')
pos = string.find('=')
return string[2:pos], string[pos+1:]
def wrapInDoubleQuotes(string):
return '"'+ string +'"'
if __name__ == "__main__":
numArgs = len(sys.argv)
if numArgs < 2:
raise ValueError('''No options passed to configure. Use python ''' \
'''configure.py --help to see the options''')
if sys.argv[1] == '--help' or sys.argv[1] == '-h':
print('Options')
print('--------')
max_key_length = 0
for key in cmake_dict:
if(len(key) > max_key_length):
max_key_length = len(key)
for key in cmake_dict:
value = cmake_dict[key]
print("--{0:<{1}}\t{2}".format(key,max_key_length,value[1]))
print("\t"+' '*(max_key_length-2)+'e.g.,'+value[2]+"\n")
else:
if not 'DFTEFE_PATH' in os.environ:
raise KeyError('''DFTEFE_PATH is not set. Please use export'''\
'''DFTEFE_PATH=/path/to/dft-efe/parent/folder''')
else:
DFTEFE_PATH = os.environ['DFTEFE_PATH']
f = open('CMakeConfigOptions.txt','w')
print('DFTEFE_PATH='+ '"' + DFTEFE_PATH + '"', file=f)
for i in range(1,numArgs):
arg = sys.argv[i]
sanityCheck(arg)
key,value = splitString(arg)
cmake_dict[key][0] = value
for key in cmake_dict:
value = cmake_dict[key][0]
if key not in ['ENABLE_MPI', 'ENABLE_MPI_DEVICE_AWARE', 'ENABLE_CUDA', 'CMAKE_BUILD_TYPE', 'CMAKE_C_COMPILER',
'CMAKE_CXX_COMPILER', 'MPI_C_COMPILER',
'MPI_CXX_COMPILER']:
value = wrapInDoubleQuotes(value)
print(key + '=' + value, file=f)
f.close()