-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.cpp
53 lines (39 loc) · 1.41 KB
/
init.cpp
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
#include "scope/init/init.hpp"
#include "scope/init/flags.hpp"
#include "scope/utils/utils.hpp"
#include "scope/utils/version.hpp"
#include "config.hpp"
// Declare a new flag
DECLARE_FLAG_bool(example);
DEFINE_FLAG_bool(example, false, "an example flag");
// register an option statically
SCOPE_REGISTER_OPTS(
clara::Opt(FLAG(example))["-e1"]("static flag (from Example|Scope)")
);
void example_before_init() {
// Create a version string and tell scope about it
// These values are defined in example_scope/config.hpp.in
RegisterVersionString(
version(SCOPE_PROJECT_NAME,
SCOPE_VERSION,
SCOPE_GIT_REFSPEC,
SCOPE_GIT_HASH,
SCOPE_GIT_LOCAL_CHANGES)
);
RegisterOpt( clara::Opt(FLAG(example))["-e2"]("programmatic flag (from Example|Scope)") );
}
int example_init() {
// Do something with some command line flags
// parse(argc, argv);
if (FLAG(example)) {
LOG(critical, "Example flag was set, so exiting!");
// signal that initialization should fail
return 1;
}
// Do some other initialization
LOG(info, "Running the example benchmark init hook");
// Anything but 0 will cause Scope's init infrastructure to exit with this code
return 0;
}
SCOPE_REGISTER_BEFORE_INIT(example_before_init);
SCOPE_REGISTER_INIT(example_init);