forked from brettviren/wire-cell-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathwscript
154 lines (115 loc) · 5.12 KB
/
wscript
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
#!/usr/bin/env python
# Copyright 2015-2023 Brookhaven National Laboratory for the benefit
# of the Wire-Cell Team.
#
# This file is part of the wire-cell-toolkit project and distributed
# according to the LICENSE file provided as also part of this project.
import os
import sys
import subprocess
# fixme: move into waft/
from waflib.Logs import debug, info
TOP = '.'
APPNAME = 'WireCell'
def determine_version():
proc = subprocess.run(["git", "describe", "--tags"], capture_output=True)
if proc.returncode:
if os.path.exists("version.txt"):
return open("version.txt", "r").readlines()[0].strip()
raise FileNotFoundError("Wire-Cell Toolkit must either be built from a git clone or a version.txt must be provided in the source distribution")
version = proc.stdout.decode().strip()
proc = subprocess.run(["git", "rev-parse", "--abbrev-ref", "HEAD"], capture_output=True)
branch = proc.stdout.decode().strip()
if branch == "master" or branch[0].isdecimal():
return version
return f'{branch}-{version}'
VERSION = determine_version()
# Valid log level identifiers
log_levels = "trace debug info warn error critical off "
log_levels = (log_levels + log_levels.upper()).split()
# to avoid adding tooldir="waft" in all the load()'s
sys.path.insert(0, os.path.realpath("./waft"))
def options(opt):
opt.load("wcb")
# this used in cfg/wscript_build
opt.add_option('--install-config', type=str, default="",
help="Install configuration files for given experiment")
opt.add_option('--build-mode', type=str, default="",
help="Force the build mode (default, detect based on git branch)")
# fixme: add to spdlog entry in wcb.py
opt.add_option('--with-spdlog-static', type=str, default="yes",
help="Def is true, set to false if your spdlog is not compiled (not recomended)")
opt.add_option('--with-spdlog-active-level',
default = "debug",
choices = log_levels,
help="The compiled minimum log level for SPDLOG_<LEVEL>() macros (def=info)")
opt.add_option('--cxxstd', default='c++17',
help="Set the value for the compiler's --std= option, default 'c++17'")
def is_development():
'''
Return True if we are sitting on a "development" branch.
A "development" branch is any that is not master or a numerical release
branch.
'''
if VERSION == "master" or VERSION[0].isdecimal():
return False
return True
def configure(cfg):
# Save to BuildConfig.h and env
cfg.define("WIRECELL_VERSION", VERSION)
cfg.env.VERSION = VERSION
# see waft/wcb.py for how this is consumed.
cfg.env.IS_DEVELOPMENT = is_development()
if cfg.env.IS_DEVELOPMENT:
info(f"configuring for DEVELOPMENT ({VERSION})")
cfg.define("WIRECELL_DEVELOPMENT", VERSION)
else:
info(f"configuring for RELEASE ({VERSION})")
cfg.define("WIRECELL_RELEASE", VERSION)
# See https://github.com/WireCell/wire-cell-toolkit/issues/337
if not cfg.options.libdir and cfg.env.LIBDIR.endswith("lib64"):
cfg.env.LIBDIR = cfg.env.LIBDIR[:-2]
debug(f'configure: forcing: {cfg.env.LIBDIR=} instead of lib64/, use explicit --libdir if you really want it')
# Set to DEBUG to activate SPDLOG_DEBUG() macros or TRACE to activate both
# those and SPDLOG_TRACE() levels.
lu = cfg.options.with_spdlog_active_level.upper()
cfg.define("SPDLOG_ACTIVE_LEVEL", 'SPDLOG_LEVEL_' + lu, quote=False)
# See comments at top of Exceptions.h for context.
cfg.load('compiler_cxx')
cfg.check_cxx(lib='backtrace', use='backtrace',
uselib_store='BACKTRACE',
define_name = 'HAVE_BACKTRACE_LIB',
mandatory=False, fragment="""
#include <backtrace.h>
int main(int argc,const char *argv[])
{
struct backtrace_state *state = backtrace_create_state(nullptr,false,nullptr,nullptr);
}
""")
if cfg.is_defined('HAVE_BACKTRACE_LIB'):
cfg.env.LDFLAGS += ['-lbacktrace']
# fixme: this should go away when everyone is up to at least boost
# 1.78.
cfg.check_cxx(header_name="boost/core/span.hpp", use='boost',
define_name = 'HAVE_BOOST_CORE_SPAN_HPP',
mandatory=False)
# cfg.env.CXXFLAGS += ['-Wpedantic', '-Werror']
cfg.env.CXXFLAGS += ['-std='+cfg.options.cxxstd.lower()]
cfg.env.CXXFLAGS += ['-std=c++17']
if cfg.options.with_spdlog_static.lower() in ("yes","on","true"):
cfg.env.CXXFLAGS += ['-DSPDLOG_COMPILED_LIB=1']
# in principle, this should be the only line here. Any cruft
# above that has accrued should be seen as a fixme: move to
# wcb/waf-tools.
cfg.load("wcb")
cfg.env.CXXFLAGS += ['-I.']
info("Configured version %s" % VERSION)
def build(bld):
### we used to be set sloppiness globally. Now we use #pragma to
### selectively quell warnings. See util/docs/pragma.org for some info.
bld.env.CXXFLAGS += '-Wall -Wpedantic'.split()
bld.load('wcb')
def dumpenv(bld):
bld.load('wcb')
def packrepo(bld):
bld.load('wcb')