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