Belle II Software light-2406-ragdoll
config.py
1#!/usr/bin/env python
2
3
10
11from SCons.Script import Configure, Environment
12import os
13import sys
14
15
16def CheckEnvVar(conf, var, text=None):
17 """check for the existance of an environment variable"""
18
19 if text:
20 conf.Message(f'Checking for {text}...')
21 else:
22 conf.Message(f'Checking for environment variable {var}...')
23 result = var in conf.env['ENV']
24 conf.Result(result)
25 return result
26
27
28def CheckConfigTool(conf, tool):
29 """check for the existance of a tool"""
30
31 conf.Message(f'Checking for {tool}...')
32 (result, version) = conf.TryAction(f'{tool} --version')
33 conf.Result(result)
34 return result
35
36
37def CheckPackage(conf, package, text=None):
38 """check for the existance of a package via the pkg-config tool"""
39
40 if not text:
41 text = package
42 conf.Message(f'Checking for {text}...')
43 (result, output) = conf.TryAction(f'pkg-config --exists {package}')
44 conf.Result(result)
45 return result
46
47
48def CheckFile(conf, dir, text=None):
49 """check for the existance a file"""
50
51 if text:
52 conf.Message(f'Checking for {text}...')
53 else:
54 conf.Message(f'Checking for directory {dir}...')
55 if conf.env.FindFile(dir, '.') is None:
56 result = 0
57 else:
58 result = 1
59 conf.Result(result)
60 return result
61
62
63def configure_belle2(conf):
64 """check the Belle II environment"""
65
66 # Belle II environment setup
67 if not conf.CheckEnvVar('BELLE2_TOOLS', 'Belle II environment setup'):
68 print('Belle II software environment is not set up.')
69 print('-> Source "setup_belle2" from the tools/ directory.')
70 return False
71
72 # local Belle II release setup
73 if not conf.CheckEnvVar('BELLE2_ANALYSIS_DIR', 'analysis setup') \
74 and not conf.CheckEnvVar('BELLE2_LOCAL_DIR', 'local release setup'):
75 print('analysis or local release is not set up.')
76 print('-> Execute "b2setup" in your local analysis or release directory.')
77 return False
78
79 return True
80
81
82def configure_system(conf):
83 """configure the system packages"""
84
85 # xml (in externals)
86 conf.env.ParseConfig('xml2-config --cflags')
87 xml_env = Environment(ENV=os.environ)
88 xml_env.ParseConfig('xml2-config --libs')
89 conf.env['XML_LIBS'] = xml_env['LIBS']
90
91 # TEve
92 conf.env['HAS_TEVE'] = False
93 conf.env['TEVE_LIBS'] = []
94 if conf.CheckLibWithHeader("Eve", "TEveViewer.h", language="c++", autoadd=0, call="TEveViewer();"):
95 conf.env['HAS_TEVE'] = True
96 conf.env['TEVE_LIBS'] = ['Gui', 'Eve', 'Ged', 'RGL', 'TreePlayer']
97
98 # sqlite3
99 conf.env['HAS_SQLITE'] = False
100 conf.env['SQLITE_LIBS'] = []
101 if conf.CheckLibWithHeader('sqlite3', 'sqlite3.h', 'C',
102 'sqlite3_open_v2(":memory:",0,SQLITE_OPEN_READONLY,0);'
103 ):
104 conf.env['HAS_SQLITE'] = True
105 conf.env.Append(CPPDEFINES='-DHAS_SQLITE')
106 sqlite_env = Environment(ENV=os.environ)
107 sqlite_env.ParseConfig('pkg-config sqlite3 --libs')
108 conf.env['SQLITE_LIBS'] = sqlite_env['LIBS']
109
110 # valgrind
111 conf.env['HAS_CALLGRIND'] = False
112 if conf.CheckHeader('valgrind/callgrind.h'):
113 conf.env['HAS_CALLGRIND'] = True
114 conf.env.Append(CPPDEFINES='-DHAS_CALLGRIND')
115
116 # check for OpenMP
117 conf.env['HAS_OPENMP'] = False
118 if conf.CheckHeader('omp.h', language="C++"):
119 conf.env['HAS_OPENMP'] = True
120 conf.env.Append(CPPDEFINES='-DHAS_OPENMP')
121
122 # graphviz
123 conf.env['HAS_DOT'] = False
124 if conf.CheckProg('dot'):
125 conf.env['HAS_DOT'] = True
126
127 return True
128
129
130def configure_externals(conf):
131 """configure the external packages"""
132
133 try:
134 extdir = conf.env['EXTDIR']
135 sys.path[:0] = [os.environ['BELLE2_TOOLS'], extdir]
136 from externals import config_externals
137 return config_externals(conf)
138 except Exception as e:
139 print('Configuration of externals failed:', e)
140 return False
141
142 return True
143
144
145def configure(env):
146 """configure the environment"""
147
148 conf = Configure(env, custom_tests={
149 'CheckEnvVar': CheckEnvVar,
150 'CheckConfigTool': CheckConfigTool,
151 'CheckPackage': CheckPackage,
152 'CheckFile': CheckFile,
153 })
154
155 if not configure_belle2(conf) or not configure_externals(conf) \
156 or not configure_system(conf):
157 return False
158
159 env = conf.Finish()
160
161 return True