This repository was archived by the owner on Oct 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSConstruct
133 lines (105 loc) · 3.73 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
import os, sys, subprocess
from SCons.Tool import msvc, mingw
from SCons.Variables import *
default_platform = "windows"
platforms = ("windows", "linux", "macos")
architecture_array = ["x86_64", "x86_32"]
opts = Variables([], ARGUMENTS)
env = Environment(tools=["default"], PLATFORM="")
opts.Add(EnumVariable('target', "Compilation target", 'debug', ['debug', 'release']))
opts.Add(
EnumVariable(
"platform",
"Target platform",
default_platform,
allowed_values=platforms,
ignorecase=2,
)
)
opts.Add(EnumVariable("arch", "CPU architecture", architecture_array[0], architecture_array))
opts.Update(env)
# hxgodot haxelib folder
hxgodotPath = subprocess.check_output('haxelib libpath hxgodot', shell=True).decode('utf-8').strip()
libTargetString = '-debug' if env['target'] == 'debug' else ''
# hxgodot libnames
static_lib_name = f'libHxGodot{libTargetString}'
shared_lib_name = f"hxgodot.{env['target']}.{env['arch']}"
# platform specifics
link_flags = []
cc_flags = []
if env['platform'] == "windows":
static_lib_name += '.lib'
shared_lib_name = 'lib' + shared_lib_name + '.dll'
env.Append(ENV = os.environ)
if env["arch"] == "x86_64":
env["TARGET_ARCH"] = "amd64"
link_flags.append("-machine:x64")
elif env["arch"] == "x86_32":
env["TARGET_ARCH"] = 'x86'
link_flags.append("-machine:x86")
env["is_msvc"] = True
msvc.generate(env)
env.Tool("mslib")
env.Tool("mslink")
env.Append(LIBS=['user32.lib', 'Ws2_32.lib', 'Crypt32.lib', 'Advapi32.lib'])
env.Append(CPPDEFINES=["WIN32", "_WIN32", "_WINDOWS", "_CRT_SECURE_NO_WARNINGS"])
cc_flags = cc_flags + ['-EHs', '-FS', '-GR', '-GS-', '-MT', '-nologo', '-Oy-', '-wd4996', '/fp:precise', '/WX-']
if env['target'] == 'debug':
cc_flags.append('-Od')
link_flags.append('-debug:full')
else:
cc_flags.append('-O2')
elif env['platform'] == "linux":
static_lib_name += '.a'
shared_lib_name += '.dso'
env.Append(ENV = os.environ)
if env["arch"] == "x86_64":
cc_flags.append('-m64')
else:
cc_flags.append('-m32')
env.Append(CPPDEFINES=["_CRT_SECURE_NO_DEPRECATE"])
cc_flags = cc_flags + ['-fpic', '-fPIC', '-frtti', '-fvisibility=hidden', '-std=c++11', '-Wno-invalid-offsetof', '-Wno-overflow', '-x', 'c++']
if env['target'] == 'debug':
cc_flags.append('-g')
else:
cc_flags.append('-O2')
elif env['platform'] == "macos":
static_lib_name += '.a'
shared_lib_name += '.dylib'
env.Append(ENV = os.environ)
if env["arch"] == "x86_64":
cc_flags.append('-m64')
else:
cc_flags.append('-m32')
env.Append(CPPDEFINES=["_CRT_SECURE_NO_DEPRECATE"])
cc_flags = cc_flags + ['-frtti', '-fvisibility=hidden', '-std=c++11', '-Wno-invalid-offsetof', '-Wno-overflow', '-x', 'c++']
if env['target'] == 'debug':
cc_flags.append('-g')
else:
cc_flags.append('-O2')
env.Append(LINKFLAGS = link_flags)
env.Append(CCFLAGS = cc_flags)
# build shared objs here
env.VariantDir('bin/obj', f'{hxgodotPath}src/', duplicate=0)
# run haxe compile
hxCmd = f'haxe build.hxml {libTargetString}'
if env["arch"] == "x86_64":
hxCmd = hxCmd + ' -D HXCPP_M64'
hxlib = env.Command('bin/'+static_lib_name, [], hxCmd)
env.AlwaysBuild(hxlib)
# build our lib
env.Append(CPPPATH=[
'bin/include'
])
env.Append(LIBPATH=['bin/'])
env.Append(LIBS=[static_lib_name])
env.Append(CPPPATH=[f'bin/obj/'])
sources = Glob(f'bin/obj/*.cpp')
library = env.SharedLibrary(target='bin/' + shared_lib_name , source=sources)
# make the shared lib depend on hxcpp builds
env.Depends(library, hxlib)
#
Default(library)
# Generates help for the -h scons option.
Help(opts.GenerateHelpText(env))