Skip to content

Commit

Permalink
Merge pull request #357 from NQNStudios/local-build-improvement-redo
Browse files Browse the repository at this point in the history
Local build improvement redo

Closes #330
  • Loading branch information
CelticMinstrel authored May 31, 2024
2 parents 2bfe697 + cfea88d commit b3cc666
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,6 @@ test/junk/*.map
oldstructs.txt
src/tools/gitrev.hpp
rsrc/**/scenario

# Dependency-generated files
deps/**/
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ 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 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
Expand Down
73 changes: 63 additions & 10 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os.path as path
import os
import subprocess
import atexit

# Build options
opts = Variables(None, ARGUMENTS)
Expand All @@ -10,6 +11,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")
Expand All @@ -27,6 +36,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])
Expand All @@ -47,7 +71,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):
Expand Down Expand Up @@ -221,12 +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=['deps/lib'])
env.Append(LIBPATH=[path.join(os.getcwd(), 'deps/lib')])
if platform == 'darwin':
env.Append(FRAMEWORKPATH=['deps/lib'])
env.Append(FRAMEWORKPATH=[path.join(os.getcwd(), 'deps/lib')])

if path.exists('deps/lib64'):
env.Append(LIBPATH=[path.join(os.getcwd(), 'deps/lib64')])

if path.exists('deps/include'):
env.Append(CPPPATH=['deps/include'])
env.Append(CPPPATH=[path.join(os.getcwd(), '/deps/include')])

# Include directories

Expand Down Expand Up @@ -299,6 +329,32 @@ 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):
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=[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)


env = conf.Finish()

env.Append(CPPDEFINES=["TIXML_USE_TICPP"])
Expand Down Expand Up @@ -345,12 +401,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

Expand Down Expand Up @@ -417,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.'))
1 change: 1 addition & 0 deletions deps/TGUI
Submodule TGUI added at c638b4

0 comments on commit b3cc666

Please sign in to comment.