Skip to content

Add Visual Studio project and solution generator to scons as a build option #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ Main Repo for the OpenVic2 Project
2. Build with `scons dev_build=yes`.
3. [Setup your IDE](https://godotengine.org/qa/108346/how-can-i-debug-runtime-errors-of-native-library-in-godot) so your Command/Host/Launching App is your Godot 4 binary and the Working Directory is the `game` directory.
4. Start the debugger.

## Generate Visual Studio Files
Run `scons vsproj=yes` and a project and solution file should be generated for you.
53 changes: 50 additions & 3 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ from pathlib import Path
# Neccessary to have our own build options without errors
SAVED_ARGUMENTS = ARGUMENTS.copy()
ARGUMENTS.pop('intermediate_delete', True)
ARGUMENTS.pop('vsproj', True)

env = SConscript("godot-cpp/SConstruct")

Expand All @@ -22,20 +23,24 @@ if profile:
customs.append(profile + ".py")
opts = Variables(customs, ARGUMENTS)

opts.Add(
BoolVariable("vsproj", "Generate a Visual Studio solution", False)
)

opts.Add(
BoolVariable("intermediate_delete", "Enables automatically deleting unassociated intermediate binary files.", True)
)

opts.Update(env)
Help(opts.GenerateHelpText(env))

def GlobRecursive(pattern, node='.'):
def GlobRecursive(pattern, node='.', strings=False):
import SCons
results = []
for f in Glob(str(node) + '/*', source=True):
for f in Glob(str(node) + '/*', source=True, strings=strings):
if type(f) is SCons.Node.FS.Dir:
results += GlobRecursive(pattern, f)
results += Glob(str(node) + '/' + pattern, source=True)
results += Glob(str(node) + '/' + pattern, source=True, strings=strings)
return results

# For the reference:
Expand Down Expand Up @@ -84,4 +89,46 @@ else:
source=sources,
)

if env["vsproj"]:
env.Tool('msvs')
env["CPPPATH"] = [Dir(path) for path in env["CPPPATH"]]
includes = GlobRecursive("*.hpp", "extension/src", strings=True)
includes.extend(GlobRecursive("*.h", "extension/src", strings=True))
includes.extend(Glob('godot-cpp/include/*.hpp', strings=True))
includes.extend(Glob('godot-cpp/gen/include/*.hpp', strings=True))
includes.extend(Glob('godot-cpp/gdextension/*.h', strings=True))

VS_PLATFORMS = ["Win32", "x64"]
VS_PLATFORM_IDS = ["x86_32", "x86_64"]
VS_CONFIGURATIONS = ["editor", "template_release", "template_debug"]

variant = []
variant += [
f'{config}|{platform}'
for config in VS_CONFIGURATIONS
for platform in VS_PLATFORMS
]

if not env.get("MSVS"):
env["MSVS"]["PROJECTSUFFIX"] = ".vcxproj"
env["MSVS"]["SOLUTIONSUFFIX"] = ".sln"

buildtarget = [s for s in library if str(s).endswith('dll')]

project = env.MSVSProject(target=['#openvic2' + env['MSVSPROJECTSUFFIX']],
srcs=[str(source_file) for source_file in sources],
incs=includes,
buildtarget=buildtarget,
variant=variant,
cpppaths=env["CPPPATH"],
cppdefines=env["CPPDEFINES"],
auto_build_solution=0
)

env.MSVSSolution(
target=['#openvic2' + env['MSVSSOLUTIONSUFFIX']],
projects=[project],
variant=variant
)

Default(library)