|
| 1 | +#!/usr/bin/env python |
| 2 | +import os |
| 3 | +import subprocess |
| 4 | +import platform |
| 5 | +import sys |
| 6 | + |
| 7 | +import SCons |
| 8 | +from SCons.Script.SConscript import SConsEnvironment |
| 9 | + |
| 10 | + |
| 11 | +def BenchmarkPostAction(target=None, source=None, env=None): |
| 12 | + print() |
| 13 | + return subprocess.run([target[0].path]).returncode |
| 14 | + |
| 15 | + |
| 16 | +def BuildBenchmarks(env, **kwargs): |
| 17 | + benchmark = env.Program(**kwargs) |
| 18 | + env.NoCache(benchmark) |
| 19 | + return benchmark |
| 20 | + |
| 21 | + |
| 22 | +def RunBenchmarks(env): |
| 23 | + benchmark_action = env.Action(BenchmarkPostAction, None) |
| 24 | + benchmark_post_action = env.AddPostAction(env.benchmark, benchmark_action) |
| 25 | + env.AlwaysBuild(benchmark_post_action) |
| 26 | + |
| 27 | + |
| 28 | +SConsEnvironment.BuildBenchmarks = BuildBenchmarks |
| 29 | +SConsEnvironment.RunBenchmarks = RunBenchmarks |
| 30 | + |
| 31 | +Import("env") |
| 32 | + |
| 33 | +BINDIR = "bin" |
| 34 | + |
| 35 | +env.openvic_simulation_benchmarks = {} |
| 36 | + |
| 37 | +# For the reference: |
| 38 | +# - CCFLAGS are compilation flags shared between C and C++ |
| 39 | +# - CFLAGS are for C-specific compilation flags |
| 40 | +# - CXXFLAGS are for C++-specific compilation flags |
| 41 | +# - CPPFLAGS are for pre-processor flags |
| 42 | +# - CPPDEFINES are for pre-processor defines |
| 43 | +# - LINKFLAGS are for linking flags |
| 44 | + |
| 45 | +# tweak this if you want to use different folders, or more folders, to store your source code in. |
| 46 | +source_path = "src" |
| 47 | + |
| 48 | +benchmarks_name = "openvic-simulation" |
| 49 | +benchmarks_env = env.Clone() |
| 50 | +benchmarks_env.Append(CPPDEFINES=["OPENVIC_SIMULATION_BENCHMARKS"]) |
| 51 | +benchmarks_env.Append(CPPPATH=[benchmarks_env.Dir(source_path)]) |
| 52 | +benchmarks_env.benchmarks_sources = env.GlobRecursive("*.cpp", [source_path]) |
| 53 | + |
| 54 | +SConscript("deps/SCsub", {"env": benchmarks_env, "parent_env": env }) |
| 55 | + |
| 56 | +benchmarks_env.benchmark = benchmarks_env.BuildBenchmarks( |
| 57 | + source=benchmarks_env.benchmarks_sources, |
| 58 | + target=os.path.join(BINDIR, benchmarks_name), |
| 59 | + PROGSUFFIX=".benchmarks" + env["PROGSUFFIX"], |
| 60 | +) |
| 61 | +Default(benchmarks_env.benchmark) |
| 62 | + |
| 63 | +Return("benchmarks_env") |
0 commit comments