From 20ca8bd07794d1030d81bc15592ce7bf714e10dd Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 30 May 2024 18:47:51 -0600 Subject: [PATCH 1/9] Add TGUI submodule --- .gitmodules | 4 ++++ deps/TGUI | 1 + 2 files changed, 5 insertions(+) create mode 160000 deps/TGUI diff --git a/.gitmodules b/.gitmodules index 00cc27e2d..117eba927 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,7 @@ [submodule "deps/Catch2"] path = deps/Catch2 url = https://github.com/catchorg/Catch2.git +[submodule "deps/TGUI"] + path = deps/TGUI + url = https://github.com/texus/TGUI.git + branch = 0.9 diff --git a/deps/TGUI b/deps/TGUI new file mode 160000 index 000000000..c638b49f1 --- /dev/null +++ b/deps/TGUI @@ -0,0 +1 @@ +Subproject commit c638b49f100cd9264aa63aaa69958c3e2918eeb4 From ee538ca30d9403e94bc320fde938eab26b9ce1df Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 30 May 2024 11:41:49 -0600 Subject: [PATCH 2/9] linux: clone and build TGUI submodule if necessary --- README.md | 3 ++- SConstruct | 31 ++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6d4f34e0f..fa2ebf039 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,8 @@ The following dependencies are required: - ZLib - This is included with the system on the Mac. For Linux builds, the following additional dependencies are required: -- [TGUI](https://tgui.eu/) - version 0.9 or later required +- [TGUI](https://tgui.eu/) - version 0.9, **built with C++14** as shown [here](./.github/workflows/scripts/linux/install-tgui.sh) + - or, if cmake is available when you call `scons`, TGUI will be built from source automatically - zenity command-line tools If you are using the Visual Studio toolset, we recommend installing diff --git a/SConstruct b/SConstruct index 5efb5c9d9..82df67d1d 100644 --- a/SConstruct +++ b/SConstruct @@ -221,12 +221,15 @@ if platform == 'darwin': # Sometimes it's easier just to copy the dependencies into the repo dir # We try to auto-detect this. if path.exists('deps/lib'): - env.Append(LIBPATH=['deps/lib']) + env.Append(LIBPATH=[os.getcwd() + '/deps/lib']) if platform == 'darwin': - env.Append(FRAMEWORKPATH=['deps/lib']) + env.Append(FRAMEWORKPATH=[os.getcwd() + '/deps/lib']) + +if path.exists('deps/lib64'): + env.Append(LIBPATH=[os.getcwd() + '/deps/lib64']) if path.exists('deps/include'): - env.Append(CPPPATH=['deps/include']) + env.Append(CPPPATH=[os.getcwd() + '/deps/include']) # Include directories @@ -299,6 +302,28 @@ if not env.GetOption('clean'): check_lib('sfml-audio', 'SFML-audio') check_lib('sfml-graphics', 'SFML-graphics') + # On Linux, build TGUI from the subtree if necessary + if platform == 'posix': + def check_tgui(conf, second_attempt=False): + if conf.CheckLib('libtgui', language='C++'): + return conf + else: + if second_attempt: + print('TGUI is missing, even after trying to build it!') + Exit(1) + else: + subprocess.call(["git", "submodule", "update", "--init", "deps/TGUI"]) + subprocess.call(["cmake", "-D", "TGUI_CXX_STANDARD=14", "-D", "CMAKE_INSTALL_PREFIX=../", "."], cwd="deps/TGUI") + subprocess.call(["make"], cwd="deps/TGUI") + subprocess.call(["make", "install"], cwd="deps/TGUI") + + env = conf.Finish() + env.Append(CPPPATH=[os.getcwd() + '/deps/include'], LIBPATH=[os.getcwd() + '/deps/lib', os.getcwd() + '/deps/lib64']) + conf = Configure(env) + return check_tgui(conf, True) + conf = check_tgui(conf) + + env = conf.Finish() env.Append(CPPDEFINES=["TIXML_USE_TICPP"]) From 9da275f8bb9cd5d935ca1d1ee412e3242bd80cf6 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 30 May 2024 10:54:48 -0600 Subject: [PATCH 3/9] ignore files generated by dependency builds --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 9a4536a76..2aa3a5c82 100644 --- a/.gitignore +++ b/.gitignore @@ -93,3 +93,6 @@ test/junk/*.map oldstructs.txt src/tools/gitrev.hpp rsrc/**/scenario + +# Dependency-generated files +deps/**/ From 826ca1bc95acecfa5b60153a10b9690a03a9cd70 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 30 May 2024 14:17:14 -0600 Subject: [PATCH 4/9] allow specifying partial build targets (fix #52) --- SConstruct | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/SConstruct b/SConstruct index 82df67d1d..f9151dd88 100644 --- a/SConstruct +++ b/SConstruct @@ -10,6 +10,14 @@ opts.Add('toolset', "Toolset to pass to the SCons builder", 'default') opts.Add(BoolVariable('debug', "Build with debug symbols and no optimization", False)) opts.Add(EnumVariable('bits', "Build for 32-bit or 64-bit architectures", '32', ('32', '64'))) +# Partial build flags -- by default, all targets will be built, +# but if at least one is specified, ONLY the specified targets will be built +partial_options = ('true', 'false', 'default') +opts.Add(EnumVariable('game', 'Build the game', 'default', partial_options)) +opts.Add(EnumVariable('pcedit', 'Build the character editor', 'default', partial_options)) +opts.Add(EnumVariable('scenedit', 'Build the scenario editor', 'default', partial_options)) +opts.Add(EnumVariable('test', 'Build the tests', 'default', partial_options)) + # Compiler configuration opts.Add("CXX", "C++ compiler") opts.Add("CC", "C compiler") @@ -27,6 +35,21 @@ platform = env['OS'] toolset = env['toolset'] arch = 'x86_64' if (env['bits'] == '64') else 'x86' +# Some kinda gnarly logic required to figure out which targets to build +possible_targets = ['game', 'pcedit', 'scenedit', 'test'] +# First, eliminate any which are specified NOT to build +targets = [target for target in possible_targets if env[target] != 'false'] + +# Then, we will assume the remaining targets should all build by default, UNLESS one +# or more targets are specified TO build. +any_specified_targets=False +for target in targets: + if env[target] == 'true': + any_specified_targets = True + +if any_specified_targets: + targets = [target for target in possible_targets if env[target] != 'default'] + # Update env based on options env.Replace(TARGET_ARCH=arch) env.Replace(tools=[toolset]) @@ -370,12 +393,7 @@ Export("install_dir party_classes common_sources") # Programs -SConscript([ - "build/obj/game/SConscript", - "build/obj/pcedit/SConscript", - "build/obj/scenedit/SConscript", - "build/obj/test/SConscript" -]) +SConscript([f"build/obj/{target}/SConscript" for target in targets]) # Data files From 9920a552be3d14c5f1168774dd1787c8bac89a5b Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 30 May 2024 20:02:04 -0600 Subject: [PATCH 5/9] Add Catch2 to README.md dependencies --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index fa2ebf039..035eaf30c 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ The following dependencies are required: libraries; if you're picky, you can run scons and see it enumerate exactly which libraries are needed - ZLib - This is included with the system on the Mac. +- Catch2 - If you want to build the unit tests, make sure to call `git submodule update --init deps/Catch2`. For Linux builds, the following additional dependencies are required: - [TGUI](https://tgui.eu/) - version 0.9, **built with C++14** as shown [here](./.github/workflows/scripts/linux/install-tgui.sh) From 1249f4b21d82f3362e075e94a2503968703878ed Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 30 May 2024 20:14:03 -0600 Subject: [PATCH 6/9] when building tests, make sure to clone Catch2 --- SConstruct | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SConstruct b/SConstruct index f9151dd88..07120d80d 100644 --- a/SConstruct +++ b/SConstruct @@ -325,6 +325,10 @@ if not env.GetOption('clean'): check_lib('sfml-audio', 'SFML-audio') check_lib('sfml-graphics', 'SFML-graphics') + # If building the tests, make sure Catch2 is cloned + if 'test' in targets and not path.exists('deps/Catch2/README.md'): + subprocess.call(["git", "submodule", "update", "--init", "deps/Catch2"]) + # On Linux, build TGUI from the subtree if necessary if platform == 'posix': def check_tgui(conf, second_attempt=False): From bceb8f478da737ef2acbc9e4780063c54f1bb992 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 30 May 2024 20:08:01 -0600 Subject: [PATCH 7/9] use correct debug build flags (fix #343) --- SConstruct | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SConstruct b/SConstruct index 07120d80d..7e0ef3a28 100644 --- a/SConstruct +++ b/SConstruct @@ -70,7 +70,10 @@ env.VariantDir('#build/obj/test', 'test') env.VariantDir('#build/obj/test/deps', 'deps') if env['debug']: - env.Append(CCFLAGS=['-g','-o0']) + if platform in ['posix', 'darwin']: + env.Append(CCFLAGS=['-g','-O0']) + elif platform == 'win32': + env.Append(CCFLAGS=['/Zi', '/Od']) # This command generates the header with git revision information def gen_gitrev(env, target, source): From 11451a731dfb7e0dcf9baec3b4993087520f37ef Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 30 May 2024 19:49:54 -0600 Subject: [PATCH 8/9] print a note about .sconsign.dblite on clean --- SConstruct | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SConstruct b/SConstruct index 7e0ef3a28..13574e38c 100644 --- a/SConstruct +++ b/SConstruct @@ -1,6 +1,7 @@ import os.path as path import os import subprocess +import atexit # Build options opts = Variables(None, ARGUMENTS) @@ -467,3 +468,5 @@ elif platform == "win32" and subprocess.call(['where', '/Q', 'makensis']) == 0: env.Clean('.', 'build') env.Clean('.', Glob('.sconsign.*')) +if env.GetOption('clean'): + atexit.register(lambda: print('If the build fails immediately after cleaning, delete .sconsign.dblite manually and try again.')) From cfea88d59cb29b2b6fc6143b40aad0967ac53fab Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 30 May 2024 20:37:22 -0600 Subject: [PATCH 9/9] use path.join instead of + --- SConstruct | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SConstruct b/SConstruct index 13574e38c..231b5fdcf 100644 --- a/SConstruct +++ b/SConstruct @@ -248,15 +248,15 @@ if platform == 'darwin': # Sometimes it's easier just to copy the dependencies into the repo dir # We try to auto-detect this. if path.exists('deps/lib'): - env.Append(LIBPATH=[os.getcwd() + '/deps/lib']) + env.Append(LIBPATH=[path.join(os.getcwd(), 'deps/lib')]) if platform == 'darwin': - env.Append(FRAMEWORKPATH=[os.getcwd() + '/deps/lib']) + env.Append(FRAMEWORKPATH=[path.join(os.getcwd(), 'deps/lib')]) if path.exists('deps/lib64'): - env.Append(LIBPATH=[os.getcwd() + '/deps/lib64']) + env.Append(LIBPATH=[path.join(os.getcwd(), 'deps/lib64')]) if path.exists('deps/include'): - env.Append(CPPPATH=[os.getcwd() + '/deps/include']) + env.Append(CPPPATH=[path.join(os.getcwd(), '/deps/include')]) # Include directories @@ -349,7 +349,7 @@ if not env.GetOption('clean'): subprocess.call(["make", "install"], cwd="deps/TGUI") env = conf.Finish() - env.Append(CPPPATH=[os.getcwd() + '/deps/include'], LIBPATH=[os.getcwd() + '/deps/lib', os.getcwd() + '/deps/lib64']) + env.Append(CPPPATH=[path.join(os.getcwd(), 'deps/include')], LIBPATH=[path.join(os.getcwd(), 'deps/lib'), path.join(os.getcwd(), 'deps/lib64')]) conf = Configure(env) return check_tgui(conf, True) conf = check_tgui(conf)