Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ env.openvic_simulation = {}
# Tweak this if you want to use different folders, or more folders, to store your source code in.
source_path = "src/openvic-simulation"
include_path = "src"
# Mirror the simulation source tree into the per-config build dir
# Out-of-source build: variant tree holds object files and generated headers,
# not copies of the source. Compile diagnostics therefore reference original
# source paths.
sim_variant = build_dir + "/" + source_path # forward slashes so VariantDir matches
sim_variant_parent = build_dir + "/" + include_path # variant of "src/"
env.VariantDir(sim_variant, source_path, duplicate=True)
env.VariantDir(sim_variant, source_path, duplicate=False)

env.Append(CPPPATH=[[env.Dir(p) for p in [sim_variant, sim_variant_parent]]])
env.Append(CPPPATH=[[env.Dir(p) for p in [sim_variant, sim_variant_parent, source_path, include_path]]])

gen_commit_info = env.CommandNoCache(
sim_variant + "/gen/commit_info.gen.hpp",
Expand Down Expand Up @@ -98,8 +100,9 @@ Default(gen_commit_info, gen_license_info, gen_author_info)

# Exclude pch.cpp from the regular source list so it isn't compiled twice
# (env.PCH below builds it once with /Yc).
pch_cpp_source = source_path + "/pch.cpp"
pch_cpp_variant = sim_variant + "/pch.cpp"
sources = env.GlobRecursive("*.cpp", [sim_variant], pch_cpp_variant)
sources = env.GlobRecursiveVariant("*.cpp", source_path, sim_variant, pch_cpp_source)
env.simulation_sources = sources

library = None
Expand Down Expand Up @@ -130,16 +133,18 @@ if env["build_ovsim_library"]:
library = env.StaticLibrary(target=env.File(os.path.join(BINDIR, library_name)), source=sources)
default_args += [library]

# VariantDir(..., duplicate=True) copies sources into build_dir but does
# not register the copies as targets, so `scons -c` leaves them behind.
# Ensure `scons -c` wipes the per-config build dir, including any stragglers
# (gen headers, .pch caches) not directly attached to the library target.
env.Clean(library, env.Dir(build_dir))

env.Append(LIBPATH=[env.Dir(BINDIR)])
env.Prepend(LIBS=[library_name])

env.openvic_simulation["LIBPATH"] = env["LIBPATH"]
env.openvic_simulation["LIBS"] = env["LIBS"]
env.openvic_simulation["INCPATH"] = [env.Dir(sim_variant_parent)] + env.exposed_includes
# Variant parent for generated headers (gen/*.gen.hpp); source parent for
# authored headers (MSVC's preprocessor needs both physically in -I).
env.openvic_simulation["INCPATH"] = [env.Dir(sim_variant_parent), env.Dir(include_path)] + env.exposed_includes
env.openvic_simulation["GEN_FILES"] = gen_files

headless_program = None
Expand All @@ -150,10 +155,10 @@ if env["build_ovsim_headless"]:
headless_env = env.Clone()
headless_src = "src/headless"
headless_variant = build_dir + "/" + headless_src
headless_env.VariantDir(headless_variant, headless_src, duplicate=True)
headless_env.VariantDir(headless_variant, headless_src, duplicate=False)
headless_env.Append(CPPDEFINES=["OPENVIC_SIM_HEADLESS"])
headless_env.Append(CPPPATH=[headless_env.Dir(headless_variant)])
headless_env.headless_sources = env.GlobRecursive("*.cpp", [headless_variant])
headless_env.Append(CPPPATH=[headless_env.Dir(headless_variant), headless_env.Dir(headless_src)])
headless_env.headless_sources = env.GlobRecursiveVariant("*.cpp", headless_src, headless_variant)
if not env["build_ovsim_library"]:
headless_env.headless_sources += sources
headless_program = headless_env.Program(
Expand Down
2 changes: 1 addition & 1 deletion deps/lexy-vdf
Submodule lexy-vdf updated 2 files
+8 −9 SConstruct
+1 −1 scripts
2 changes: 1 addition & 1 deletion deps/openvic-dataloader
Submodule openvic-dataloader updated 2 files
+8 −7 SConstruct
+1 −1 scripts
2 changes: 1 addition & 1 deletion scripts
8 changes: 4 additions & 4 deletions tests/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ source_path = "src" # relative to this SCsub (i.e. tests/src under the sim root

tests_name = "openvic-simulation"
tests_env = env.Clone()
# Mirror tests/src into the per-config build dir
# Out-of-source build: variant tree holds object files only.
tests_variant = env["build_dir"] + "/tests/" + source_path
tests_env.VariantDir(tests_variant, source_path, duplicate=True)
tests_env.VariantDir(tests_variant, source_path, duplicate=False)
tests_env.Append(CPPDEFINES=["OPENVIC_SIMULATION_TESTS"])
tests_env.Append(CPPPATH=[tests_env.Dir(tests_variant)])
tests_env.tests_sources = env.GlobRecursive("*.cpp", [tests_variant])
tests_env.Append(CPPPATH=[tests_env.Dir(tests_variant), tests_env.Dir(source_path)])
tests_env.tests_sources = env.GlobRecursiveVariant("*.cpp", source_path, tests_variant)

SConscript("deps/SCsub", {"env": tests_env})

Expand Down
8 changes: 4 additions & 4 deletions tests/benchmarks/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ source_path = "src" # relative to this SCsub (i.e. tests/benchmarks/src under t

benchmarks_name = "openvic-simulation"
benchmarks_env = env.Clone()
# Mirror benchmarks/src into the per-config build dir
# Out-of-source build: variant tree holds object files only.
benchmarks_variant = env["build_dir"] + "/tests/benchmarks/" + source_path
benchmarks_env.VariantDir(benchmarks_variant, source_path, duplicate=True)
benchmarks_env.VariantDir(benchmarks_variant, source_path, duplicate=False)
benchmarks_env.Append(CPPDEFINES=["OPENVIC_SIMULATION_BENCHMARKS"])

benchmarks_env.Append(CPPPATH=[benchmarks_env.Dir(benchmarks_variant)])
benchmarks_env.benchmarks_sources = env.GlobRecursive("*.cpp", [benchmarks_variant])
benchmarks_env.Append(CPPPATH=[benchmarks_env.Dir(benchmarks_variant), benchmarks_env.Dir(source_path)])
benchmarks_env.benchmarks_sources = env.GlobRecursiveVariant("*.cpp", source_path, benchmarks_variant)

SConscript("deps/SCsub", {"env": benchmarks_env, "parent_env": env})

Expand Down
Loading