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