diff --git a/README.md b/README.md index 409c75dd..9897fdb9 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file diff --git a/SConstruct b/SConstruct index 4e6fe709..c4df6dc3 100644 --- a/SConstruct +++ b/SConstruct @@ -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") @@ -22,6 +23,10 @@ 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) ) @@ -29,13 +34,13 @@ opts.Add( 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: @@ -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)