Skip to content

Commit 62cb6a0

Browse files
authored
Add sdk'less sample_ext and update -std to 14 (#1456)
1 parent ca1dcc9 commit 62cb6a0

File tree

8 files changed

+626
-1
lines changed

8 files changed

+626
-1
lines changed

public/sample_ext/AMBuildScript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class ExtensionConfig(object):
178178
'-fvisibility=hidden',
179179
]
180180
cxx.cxxflags += [
181-
'-std=c++11',
181+
'-std=c++14',
182182
'-fno-exceptions',
183183
'-fno-threadsafe-statics',
184184
'-Wno-non-virtual-dtor',

public/sample_ext_nosdk/AMBuildScript

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
2+
import os, sys
3+
4+
# Simple extensions do not need to modify this file.
5+
6+
def ResolveEnvPath(env, folder):
7+
if env in os.environ:
8+
path = os.environ[env]
9+
if os.path.isdir(path):
10+
return path
11+
return None
12+
13+
head = os.getcwd()
14+
oldhead = None
15+
while head != None and head != oldhead:
16+
path = os.path.join(head, folder)
17+
if os.path.isdir(path):
18+
return path
19+
oldhead = head
20+
head, tail = os.path.split(head)
21+
22+
return None
23+
24+
def Normalize(path):
25+
return os.path.abspath(os.path.normpath(path))
26+
27+
class ExtensionConfig(object):
28+
def __init__(self):
29+
self.binaries = []
30+
self.extensions = []
31+
self.generated_headers = None
32+
self.mms_root = None
33+
self.sm_root = None
34+
35+
@property
36+
def tag(self):
37+
if builder.options.debug == '1':
38+
return 'Debug'
39+
return 'Release'
40+
41+
def detectSDKs(self):
42+
if builder.options.sm_path:
43+
self.sm_root = builder.options.sm_path
44+
else:
45+
self.sm_root = ResolveEnvPath('SOURCEMOD18', 'sourcemod-1.8')
46+
if not self.sm_root:
47+
self.sm_root = ResolveEnvPath('SOURCEMOD', 'sourcemod')
48+
if not self.sm_root:
49+
self.sm_root = ResolveEnvPath('SOURCEMOD_DEV', 'sourcemod-central')
50+
51+
if not self.sm_root or not os.path.isdir(self.sm_root):
52+
raise Exception('Could not find a source copy of SourceMod')
53+
self.sm_root = Normalize(self.sm_root)
54+
55+
if builder.options.mms_path:
56+
self.mms_root = builder.options.mms_path
57+
else:
58+
self.mms_root = ResolveEnvPath('MMSOURCE110', 'mmsource-1.10')
59+
if not self.mms_root:
60+
self.mms_root = ResolveEnvPath('MMSOURCE', 'metamod-source')
61+
if not self.mms_root:
62+
self.mms_root = ResolveEnvPath('MMSOURCE_DEV', 'mmsource-central')
63+
64+
if not self.mms_root or not os.path.isdir(self.mms_root):
65+
raise Exception('Could not find a source copy of Metamod:Source')
66+
self.mms_root = Normalize(self.mms_root)
67+
68+
def configure(self):
69+
cxx = builder.DetectCompilers()
70+
71+
if cxx.like('gcc'):
72+
self.configure_gcc(cxx)
73+
elif cxx.vendor == 'msvc':
74+
self.configure_msvc(cxx)
75+
76+
# Optimization
77+
if builder.options.opt == '1':
78+
cxx.defines += ['NDEBUG']
79+
80+
# Debugging
81+
if builder.options.debug == '1':
82+
cxx.defines += ['DEBUG', '_DEBUG']
83+
84+
# Platform-specifics
85+
if builder.target_platform == 'linux':
86+
self.configure_linux(cxx)
87+
elif builder.target_platform == 'mac':
88+
self.configure_mac(cxx)
89+
elif builder.target_platform == 'windows':
90+
self.configure_windows(cxx)
91+
92+
# Finish up.
93+
cxx.includes += [
94+
os.path.join(self.sm_root, 'public'),
95+
]
96+
97+
def configure_gcc(self, cxx):
98+
cxx.defines += [
99+
'stricmp=strcasecmp',
100+
'_stricmp=strcasecmp',
101+
'_snprintf=snprintf',
102+
'_vsnprintf=vsnprintf',
103+
'HAVE_STDINT_H',
104+
'GNUC',
105+
]
106+
cxx.cflags += [
107+
'-pipe',
108+
'-fno-strict-aliasing',
109+
'-Wall',
110+
'-Werror',
111+
'-Wno-unused',
112+
'-Wno-switch',
113+
'-Wno-array-bounds',
114+
'-msse',
115+
'-m32',
116+
'-fvisibility=hidden',
117+
]
118+
cxx.cxxflags += [
119+
'-std=c++14',
120+
'-fno-exceptions',
121+
'-fno-threadsafe-statics',
122+
'-Wno-non-virtual-dtor',
123+
'-Wno-overloaded-virtual',
124+
'-fvisibility-inlines-hidden',
125+
]
126+
cxx.linkflags += ['-m32']
127+
128+
have_gcc = cxx.vendor == 'gcc'
129+
have_clang = cxx.vendor == 'clang'
130+
if cxx.version >= 'clang-3.6':
131+
cxx.cxxflags += ['-Wno-inconsistent-missing-override']
132+
if have_clang or (cxx.version >= 'gcc-4.6'):
133+
cxx.cflags += ['-Wno-narrowing']
134+
if have_clang or (cxx.version >= 'gcc-4.7'):
135+
cxx.cxxflags += ['-Wno-delete-non-virtual-dtor']
136+
if cxx.version >= 'gcc-4.8':
137+
cxx.cflags += ['-Wno-unused-result']
138+
139+
if have_clang:
140+
cxx.cxxflags += ['-Wno-implicit-exception-spec-mismatch']
141+
if cxx.version >= 'apple-clang-5.1' or cxx.version >= 'clang-3.4':
142+
cxx.cxxflags += ['-Wno-deprecated-register']
143+
else:
144+
cxx.cxxflags += ['-Wno-deprecated']
145+
cxx.cflags += ['-Wno-sometimes-uninitialized']
146+
147+
if have_gcc:
148+
cxx.cflags += ['-mfpmath=sse']
149+
150+
if builder.options.opt == '1':
151+
cxx.cflags += ['-O3']
152+
153+
def configure_msvc(self, cxx):
154+
if builder.options.debug == '1':
155+
cxx.cflags += ['/MTd']
156+
cxx.linkflags += ['/NODEFAULTLIB:libcmt']
157+
else:
158+
cxx.cflags += ['/MT']
159+
cxx.defines += [
160+
'_CRT_SECURE_NO_DEPRECATE',
161+
'_CRT_SECURE_NO_WARNINGS',
162+
'_CRT_NONSTDC_NO_DEPRECATE',
163+
'_ITERATOR_DEBUG_LEVEL=0',
164+
]
165+
cxx.cflags += [
166+
'/W3',
167+
]
168+
cxx.cxxflags += [
169+
'/EHsc',
170+
'/GR-',
171+
'/TP',
172+
]
173+
cxx.linkflags += [
174+
'/MACHINE:X86',
175+
'kernel32.lib',
176+
'user32.lib',
177+
'gdi32.lib',
178+
'winspool.lib',
179+
'comdlg32.lib',
180+
'advapi32.lib',
181+
'shell32.lib',
182+
'ole32.lib',
183+
'oleaut32.lib',
184+
'uuid.lib',
185+
'odbc32.lib',
186+
'odbccp32.lib',
187+
]
188+
189+
if builder.options.opt == '1':
190+
cxx.cflags += ['/Ox', '/Zo']
191+
cxx.linkflags += ['/OPT:ICF', '/OPT:REF']
192+
193+
if builder.options.debug == '1':
194+
cxx.cflags += ['/Od', '/RTC1']
195+
196+
# This needs to be after our optimization flags which could otherwise disable it.
197+
# Don't omit the frame pointer.
198+
cxx.cflags += ['/Oy-']
199+
200+
def configure_linux(self, cxx):
201+
cxx.defines += ['_LINUX', 'POSIX']
202+
cxx.linkflags += ['-Wl,--exclude-libs,ALL', '-lm']
203+
if cxx.vendor == 'gcc':
204+
cxx.linkflags += ['-static-libgcc']
205+
elif cxx.vendor == 'clang':
206+
cxx.linkflags += ['-lgcc_eh']
207+
208+
def configure_mac(self, cxx):
209+
cxx.defines += ['OSX', '_OSX', 'POSIX']
210+
cxx.cflags += ['-mmacosx-version-min=10.5']
211+
cxx.linkflags += [
212+
'-mmacosx-version-min=10.5',
213+
'-arch', 'i386',
214+
'-lstdc++',
215+
'-stdlib=libstdc++',
216+
]
217+
cxx.cxxflags += ['-stdlib=libstdc++']
218+
219+
def configure_windows(self, cxx):
220+
cxx.defines += ['WIN32', '_WINDOWS']
221+
222+
def ConfigureForExtension(self, context, compiler):
223+
compiler.cxxincludes += [
224+
os.path.join(context.currentSourcePath),
225+
os.path.join(context.currentSourcePath, 'sdk'),
226+
os.path.join(self.sm_root, 'public'),
227+
os.path.join(self.sm_root, 'public', 'extensions'),
228+
os.path.join(self.sm_root, 'sourcepawn', 'include'),
229+
os.path.join(self.sm_root, 'public', 'amtl', 'amtl'),
230+
os.path.join(self.sm_root, 'public', 'amtl'),
231+
]
232+
return compiler
233+
234+
def ConfigureForHL2(self, binary):
235+
compiler = binary.compiler
236+
237+
mms_path = os.path.join(self.mms_root, 'core')
238+
239+
compiler.cxxincludes += [
240+
os.path.join(mms_path),
241+
os.path.join(mms_path, 'sourcehook'),
242+
]
243+
244+
compiler.defines += ['META_NO_HL2SDK']
245+
246+
if compiler.like('msvc'):
247+
compiler.defines += ['COMPILER_MSVC', 'COMPILER_MSVC32']
248+
else:
249+
compiler.defines += ['COMPILER_GCC']
250+
251+
if builder.target_platform == 'linux':
252+
compiler.linkflags += ['-lstdc++']
253+
elif builder.target_platform == 'mac':
254+
compiler.linkflags.append('-liconv')
255+
256+
return binary
257+
258+
def HL2Library(self, context, name):
259+
binary = context.compiler.Library(name)
260+
self.ConfigureForExtension(context, binary.compiler)
261+
return self.ConfigureForHL2(binary)
262+
263+
def HL2Project(self, context, name):
264+
project = context.compiler.LibraryProject(name)
265+
self.ConfigureForExtension(context, project.compiler)
266+
return project
267+
268+
def HL2Config(self, project, name):
269+
binary = project.Configure(name, '{0}'.format(self.tag))
270+
return self.ConfigureForHL2(binary)
271+
272+
Extension = ExtensionConfig()
273+
Extension.detectSDKs()
274+
Extension.configure()
275+
276+
# Add additional buildscripts here
277+
BuildScripts = [
278+
'AMBuilder',
279+
]
280+
281+
if builder.backend == 'amb2':
282+
BuildScripts += [
283+
'PackageScript',
284+
]
285+
286+
builder.RunBuildScripts(BuildScripts, { 'Extension': Extension})

public/sample_ext_nosdk/AMBuilder

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
2+
import os, sys
3+
4+
projectName = 'sample'
5+
6+
# smsdk_ext.cpp will be automatically added later
7+
sourceFiles = [
8+
'extension.cpp',
9+
]
10+
11+
###############
12+
# Make sure to edit PackageScript, which copies your files to their appropriate locations
13+
# Simple extensions do not need to modify past this point.
14+
15+
project = Extension.HL2Project(builder, projectName + '.ext')
16+
17+
if os.path.isfile(os.path.join(builder.currentSourcePath, 'sdk', 'smsdk_ext.cpp')):
18+
# Use the copy included in the project
19+
project.sources += [os.path.join('sdk', 'smsdk_ext.cpp')]
20+
else:
21+
# Use the copy included with SM 1.6 and newer
22+
project.sources += [os.path.join(Extension.sm_root, 'public', 'smsdk_ext.cpp')]
23+
24+
project.sources += sourceFiles
25+
26+
binary = Extension.HL2Config(project, projectName + '.ext')
27+
28+
Extension.extensions = builder.Add(project)

public/sample_ext_nosdk/PackageScript

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# vim: set ts=8 sts=2 sw=2 tw=99 et ft=python:
2+
import os
3+
4+
# This is where the files will be output to
5+
# package is the default
6+
builder.SetBuildFolder('package')
7+
8+
# Add any folders you need to this list
9+
folder_list = [
10+
'addons/sourcemod/extensions',
11+
#'addons/sourcemod/scripting/include',
12+
#'addons/sourcemod/gamedata',
13+
#'addons/sourcemod/configs',
14+
]
15+
16+
# Create the distribution folder hierarchy.
17+
folder_map = {}
18+
for folder in folder_list:
19+
norm_folder = os.path.normpath(folder)
20+
folder_map[folder] = builder.AddFolder(norm_folder)
21+
22+
# Do all straight-up file copies from the source tree.
23+
def CopyFiles(src, dest, files):
24+
if not dest:
25+
dest = src
26+
dest_entry = folder_map[dest]
27+
for source_file in files:
28+
source_path = os.path.join(builder.sourcePath, src, source_file)
29+
builder.AddCopy(source_path, dest_entry)
30+
31+
# Include files
32+
#CopyFiles('include', 'addons/sourcemod/scripting/include',
33+
# [ 'sample.inc', ]
34+
#)
35+
36+
# GameData files
37+
#CopyFiles('gamedata', 'addons/sourcemod/gamedata',
38+
# [ 'myfile.txt',
39+
# 'file2.txt'
40+
# ]
41+
#)
42+
43+
# Config Files
44+
#CopyFiles('configs', 'addons/sourcemod/configs',
45+
# [ 'configfile.cfg',
46+
# 'otherconfig.cfg,
47+
# ]
48+
#)
49+
50+
# Copy binaries.
51+
for cxx_task in Extension.extensions:
52+
builder.AddCopy(cxx_task.binary, folder_map['addons/sourcemod/extensions'])

public/sample_ext_nosdk/configure.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# vim: set sts=2 ts=8 sw=2 tw=99 et:
2+
import sys
3+
from ambuild2 import run
4+
5+
# Simple extensions do not need to modify this file.
6+
7+
builder = run.PrepareBuild(sourcePath = sys.path[0])
8+
9+
builder.options.add_option('--mms-path', type=str, dest='mms_path', default=None,
10+
help='Path to Metamod:Source')
11+
builder.options.add_option('--sm-path', type=str, dest='sm_path', default=None,
12+
help='Path to SourceMod')
13+
builder.options.add_option('--enable-debug', action='store_const', const='1', dest='debug',
14+
help='Enable debugging symbols')
15+
builder.options.add_option('--enable-optimize', action='store_const', const='1', dest='opt',
16+
help='Enable optimization')
17+
18+
builder.Configure()

0 commit comments

Comments
 (0)