-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
94 lines (67 loc) · 2.29 KB
/
SConstruct
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
94
#!/usr/bin/env python
import subprocess
import os
from pathlib import Path
ADDON_DIR = "project/addons/libm8gd"
BUILD_DIR = "build"
TARGET_LIB = "libm8gd"
env = SConscript("thirdparty/godot-cpp/SConstruct")
def call(*args) -> str:
return subprocess.run(args, capture_output=True).stdout.decode().strip()
def call_split(*args) -> list[str]:
return call(*args).split(" ")
# create build directory if doesn't exist
Path(BUILD_DIR).mkdir(exist_ok=True)
USING_OSXCROSS: bool = "OSXCROSS_ROOT" in os.environ
if USING_OSXCROSS:
if env["arch"] == "universal":
print("OSXCross does not support universal builds.")
Exit(255)
else:
print("using OSXCross SDK: %s" % env["osxcross_sdk"])
PKG_CONFIG: str
if env["platform"] == "macos" and USING_OSXCROSS:
PKG_CONFIG = "x86_64-apple-%s-pkg-config" % env["osxcross_sdk"]
else:
PKG_CONFIG = "pkg-config"
CFLAGS = call_split(PKG_CONFIG, "--cflags", "libserialport")
print("using pkg-config: %s" % PKG_CONFIG)
print("using cxx: %s" % env["CXX"])
# add sources
env.Append(CPPPATH=["src/"])
sources = Glob("src/*.cpp")
# set flags
if env["target"] == "template_release":
env.Append(CFLAGS=["-O2"])
env.Append(CFLAGS=["-Wall", "-pipe"])
env.Append(CFLAGS=CFLAGS)
print("architecture: %s" % env["arch"])
if env["platform"] == "macos" and USING_OSXCROSS:
# explicitly link the static library
LIB_FILE = (
call(PKG_CONFIG, "--variable=libdir", "libserialport") + "/libserialport.a"
)
print("library path: %s" % LIB_FILE)
env.Append(LIBS=File(LIB_FILE))
else:
LIBPATH = call_split(PKG_CONFIG, "--libs-only-L", "--static", "libserialport")
LIBS = call_split(PKG_CONFIG, "--libs-only-l", "--static", "libserialport")
print("library paths: %s" % LIBPATH)
print("library flags: %s" % LIBS)
env.Append(LIBPATH=LIBPATH)
env.Append(LIBS=LIBS)
# create library target
if env["platform"] == "macos":
env.Append(CCFLAGS=CFLAGS)
library = env.SharedLibrary(
target="%s/%s.%s.%s.framework"
% (ADDON_DIR, TARGET_LIB, env["platform"], env["target"]),
source=sources,
)
else:
library = env.SharedLibrary(
target="%s/%s.%s.%s%s"
% (ADDON_DIR, TARGET_LIB, env["platform"], env["target"], env["SHLIBSUFFIX"]),
source=sources,
)
Default(library)