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
|
#!/usr/bin/env python
import os
import sys
from glob import glob
from pathlib import Path
# Neccessary to have our own build options without errors
SAVED_ARGUMENTS = ARGUMENTS.copy()
ARGUMENTS.pop('intermediate_delete', True)
env = SConscript("godot-cpp/SConstruct")
# Require C++20
if env.get("is_msvc", False):
env.Replace(CXXFLAGS=["/std:c++20"])
else:
env.Replace(CXXFLAGS=["-std=c++20"])
ARGUMENTS = SAVED_ARGUMENTS
# Custom options and profile flags.
customs = ["custom.py"]
profile = ARGUMENTS.get("profile", "")
if profile:
if os.path.isfile(profile):
customs.append(profile)
elif os.path.isfile(profile + ".py"):
customs.append(profile + ".py")
opts = Variables(customs, ARGUMENTS)
opts.Add(
BoolVariable("intermediate_delete", "Enables automatically deleting unassociated intermediate binary files.", True)
)
opts.Update(env)
Help(opts.GenerateHelpText(env))
def GlobRecursive(pattern, node='.'):
import SCons
results = []
for f in Glob(str(node) + '/*', source=True):
if type(f) is SCons.Node.FS.Dir:
results += GlobRecursive(pattern, f)
results += Glob(str(node) + '/' + pattern, source=True)
return results
# For the reference:
# - CCFLAGS are compilation flags shared between C and C++
# - CFLAGS are for C-specific compilation flags
# - CXXFLAGS are for C++-specific compilation flags
# - CPPFLAGS are for pre-processor flags
# - CPPDEFINES are for pre-processor defines
# - LINKFLAGS are for linking flags
# tweak this if you want to use different folders, or more folders, to store your source code in.
env.Append(CPPPATH=["extension/src/"])
sources = GlobRecursive("*.cpp", "extension/src")
# Remove unassociated intermediate binary files if allowed, usually the result of a renamed or deleted source file
if env["intermediate_delete"]:
def remove_extension(file : str):
if file.find(".") == -1: return file
return file[:file.rindex(".")]
found_one = False
for obj_file in [file[:-len(".os")] for file in glob("extension/src/*.os", recursive=True)]:
found = False
for source_file in sources:
if remove_extension(str(source_file)) == obj_file:
found = True
break
if not found:
if not found_one:
found_one = True
print("Unassociated intermediate files found...")
print("Removing "+obj_file+".os")
os.remove(obj_file+".os")
if env["platform"] == "macos":
library = env.SharedLibrary(
"game/bin/openvic2/libopenvic2.{}.{}.framework/libopenvic2.{}.{}".format(
env["platform"], env["target"], env["platform"], env["target"]
),
source=sources,
)
else:
suffix = ".{}.{}.{}".format(env["platform"], env["target"], env["arch"])
library = env.SharedLibrary(
"game/bin/openvic2/libopenvic2{}{}".format(suffix, env["SHLIBSUFFIX"]),
source=sources,
)
Default(library)
|