-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlib_utils.py
79 lines (57 loc) · 2.29 KB
/
lib_utils.py
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
#!/usr/bin/env python3
import json
from patches import unity_tools
from pathlib import Path
lib_name = "godot_qoi"
output_dir = Path("addons") / lib_name / "libs"
src_folder = "src"
def setup_options(env, arguments, gen_help):
from SCons.Variables import Variables, BoolVariable, EnumVariable, PathVariable
opts = Variables([], arguments)
opts.Add(BoolVariable("lto", "Link-time optimization", False))
opts.Add(PathVariable("addon_output_dir", "Path to the output directory",
output_dir, PathVariable.PathIsDirCreate))
opts.Update(env)
gen_help(env, opts)
def setup_defines_and_flags(env):
env.Append(CPPDEFINES=["GDEXTENSION_LIBRARY"])
if env["lto"]:
if env.get("is_msvc", False):
env.AppendUnique(CCFLAGS=["/GL"])
env.AppendUnique(ARFLAGS=["/LTCG"])
env.AppendUnique(LINKFLAGS=["/LTCG"])
else:
env.AppendUnique(CCFLAGS=["-flto"])
env.AppendUnique(LINKFLAGS=["-flto"])
def get_sources(src):
res = [src_folder + "/" + file for file in src]
res = unity_tools.generate_unity_build(res, "qoi_")
return res
def get_library_object(env, arguments=None, gen_help=None):
if arguments != None and gen_help:
setup_options(env, arguments, gen_help)
setup_defines_and_flags(env)
env.Append(CPPPATH=[src_folder])
src = []
with open(src_folder + "/default_sources.json") as f:
src = json.load(f)
# store all obj's in a dedicated folder
env["SHOBJPREFIX"] = "#obj/"
# some additional tags
additional_tags = ""
library_full_name = "lib" + lib_name + ".{}.{}.{}{}{}".format(
env["platform"], env["target"], env["arch"], additional_tags,env["SHLIBSUFFIX"])
env.Default(env.SharedLibrary(
target=env.File(Path(env["addon_output_dir"]) / library_full_name),
source=get_sources(src),
SHLIBSUFFIX=env["SHLIBSUFFIX"]
))
# Needed for easy reuse of this library in other build scripts
# TODO: not tested at the moment. Probably need some changes in the C++ code
env = env.Clone()
env.Append(LIBPATH=[env.Dir(env["addon_output_dir"])])
if env.get("is_msvc", False):
env.Append(LIBS=[library_full_name.replace(".dll", ".lib")])
else:
env.Append(LIBS=[library_full_name])
return env