From 0fd21f2b6003a25e0cf6c077368c2246b6971606 Mon Sep 17 00:00:00 2001 From: peace-maker Date: Sat, 11 Jan 2025 12:16:34 +0100 Subject: [PATCH] Add option to create debug builds This allows to link sourcemod with `--enable-debug` on Windows. --- AMBuilder | 12 +++++++++++- configure.py | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/AMBuilder b/AMBuilder index b44b9aa..0f88e53 100644 --- a/AMBuilder +++ b/AMBuilder @@ -22,7 +22,8 @@ libsafetyhook.sources += AddSourceFilesFromDir(os.path.join(builder.currentSourc ]) for compiler in SafetyHook.all_targets: - binary = libsafetyhook.Configure(compiler, libsafetyhook.name, 'Release - {0}'.format(compiler.target.arch)) + tag = 'Debug' if builder.options.debug == '1' else 'Release' + binary = libsafetyhook.Configure(compiler, libsafetyhook.name, '{0} - {1}'.format(tag, compiler.target.arch)) # Configure the binary's compiler compiler = binary.compiler # Reset all flags, safetyhook requires specific compilation flags @@ -32,7 +33,16 @@ for compiler in SafetyHook.all_targets: compiler.includes = [] compiler.cxxincludes = [] + # Debugging + if builder.options.debug == '1': + compiler.defines += ['DEBUG', '_DEBUG'] + if compiler.target.platform == 'windows': + if builder.options.debug == '1': + compiler.cflags += ['/MTd', '/Od', '/RTC1'] + compiler.defines += ['_ITERATOR_DEBUG_LEVEL=0'] + else: + compiler.cflags += ['/MT'] compiler.cflags += [ "/W4", ] diff --git a/configure.py b/configure.py index 9972f24..f595272 100644 --- a/configure.py +++ b/configure.py @@ -4,4 +4,6 @@ parser = run.BuildParser(sourcePath = sys.path[0], api='2.2') parser.options.add_argument('--targets', type=str, dest='targets', default=None, help="Override the target architecture (use commas to separate multiple targets).") +parser.options.add_argument('--enable-debug', action='store_const', const='1', dest='debug', + help='Enable debugging symbols') parser.Configure() \ No newline at end of file