Setup for building both debug and release build for side by side deployment

pull/632/head
Bastiaan Olij 2021-09-29 10:47:08 +10:00
parent 6a720e5c7c
commit 0f47ba54ee
2 changed files with 38 additions and 26 deletions

View File

@ -2,10 +2,22 @@
import os import os
import sys import sys
# default values, adapt them to your setup
default_library_name = "libgdexample"
default_target_path = "demo/bin/"
# Local dependency paths, adapt them to your setup
cpp_bindings_path = "../"
# cpp_bindings_path = "godot-cpp/"
godot_headers_path = cpp_bindings_path + "godot-headers/"
cpp_library = "libgodot-cpp"
# Try to detect the host platform automatically. # Try to detect the host platform automatically.
# This is used if no `platform` argument is passed # This is used if no `platform` argument is passed
if sys.platform.startswith("linux"): if sys.platform.startswith("linux"):
host_platform = "linux" host_platform = "linux"
elif sys.platform.startswith("freebsd"):
host_platform = "freebsd"
elif sys.platform == "darwin": elif sys.platform == "darwin":
host_platform = "osx" host_platform = "osx"
elif sys.platform == "win32" or sys.platform == "msys": elif sys.platform == "win32" or sys.platform == "msys":
@ -18,20 +30,22 @@ env = Environment(ENV=os.environ)
opts = Variables([], ARGUMENTS) opts = Variables([], ARGUMENTS)
# Define our options # Define our options
opts.Add(EnumVariable("target", "Compilation target", "debug", ["d", "debug", "r", "release"])) opts.Add(EnumVariable("target", "Compilation target", "debug", allowed_values=("debug", "release"), ignorecase=2))
opts.Add(EnumVariable("platform", "Compilation platform", host_platform, ["", "windows", "x11", "linux", "osx"]))
opts.Add( opts.Add(
EnumVariable("p", "Compilation target, alias for 'platform'", host_platform, ["", "windows", "x11", "linux", "osx"]) EnumVariable(
"platform",
"Compilation platform",
host_platform,
# We'll need to support these in due times
# allowed_values=("linux", "freebsd", "osx", "windows", "android", "ios", "javascript"),
allowed_values=("linux", "windows"),
ignorecase=2,
)
) )
opts.Add(EnumVariable("bits", "Target platform bits", "64", ("32", "64"))) opts.Add(EnumVariable("bits", "Target platform bits", "64", ("32", "64")))
opts.Add(BoolVariable("use_llvm", "Use the LLVM / Clang compiler", "no")) opts.Add(BoolVariable("use_llvm", "Use the LLVM / Clang compiler", "no"))
opts.Add(PathVariable("target_path", "The path where the lib is installed.", "demo/bin/", PathVariable.PathAccept)) opts.Add(PathVariable("target_path", "The path where the lib is installed.", default_target_path, PathVariable.PathAccept))
opts.Add(PathVariable("target_name", "The library name.", "libgdexample", PathVariable.PathAccept)) opts.Add(PathVariable("target_name", "The library name.", default_library_name, PathVariable.PathAccept))
# Local dependency paths, adapt them to your setup
godot_headers_path = "../godot-headers/"
cpp_bindings_path = "../"
cpp_library = "libgodot-cpp"
# only support 64 at this time.. # only support 64 at this time..
bits = 64 bits = 64
@ -57,9 +71,6 @@ if env["use_llvm"]:
env["CC"] = "clang" env["CC"] = "clang"
env["CXX"] = "clang++" env["CXX"] = "clang++"
if env["p"] != "":
env["platform"] = env["p"]
if env["platform"] == "": if env["platform"] == "":
print("No valid target platform selected.") print("No valid target platform selected.")
quit() quit()
@ -82,23 +93,21 @@ if env["platform"] == "osx":
env.Append(CCFLAGS=["-arch", "x86_64"]) env.Append(CCFLAGS=["-arch", "x86_64"])
env.Append(CXXFLAGS=["-std=c++17"]) env.Append(CXXFLAGS=["-std=c++17"])
env.Append(LINKFLAGS=["-arch", "x86_64"]) env.Append(LINKFLAGS=["-arch", "x86_64"])
if env["target"] in ("debug", "d"): if env["target"] == "debug":
env.Append(CCFLAGS=["-g", "-O2"]) env.Append(CCFLAGS=["-g", "-O2"])
else: else:
env.Append(CCFLAGS=["-g", "-O3"]) env.Append(CCFLAGS=["-g", "-O3"])
elif env["platform"] in ("x11", "linux"): elif env["platform"] in ("x11", "linux"):
env["target_path"] += "x11/"
cpp_library += ".linux" cpp_library += ".linux"
env.Append(CCFLAGS=["-fPIC"]) env.Append(CCFLAGS=["-fPIC"])
env.Append(CXXFLAGS=["-std=c++17"]) env.Append(CXXFLAGS=["-std=c++17"])
if env["target"] in ("debug", "d"): if env["target"] == "debug":
env.Append(CCFLAGS=["-g3", "-Og"]) env.Append(CCFLAGS=["-g3", "-Og"])
else: else:
env.Append(CCFLAGS=["-g", "-O3"]) env.Append(CCFLAGS=["-g", "-O3"])
elif env["platform"] == "windows": elif env["platform"] == "windows":
env["target_path"] += "win64/"
cpp_library += ".windows" cpp_library += ".windows"
# This makes sure to keep the session environment variables on windows, # This makes sure to keep the session environment variables on windows,
# that way you can run scons in a vs 2017 prompt and it will find all the required tools # that way you can run scons in a vs 2017 prompt and it will find all the required tools
@ -107,7 +116,7 @@ elif env["platform"] == "windows":
env.Append(CPPDEFINES=["WIN32", "_WIN32", "_WINDOWS", "_CRT_SECURE_NO_WARNINGS"]) env.Append(CPPDEFINES=["WIN32", "_WIN32", "_WINDOWS", "_CRT_SECURE_NO_WARNINGS"])
env.Append(CCFLAGS=["-W3", "-GR"]) env.Append(CCFLAGS=["-W3", "-GR"])
env.Append(CXXFLAGS=["-std:c++17"]) env.Append(CXXFLAGS=["-std:c++17"])
if env["target"] in ("debug", "d"): if env["target"] == "debug":
env.Append(CPPDEFINES=["_DEBUG"]) env.Append(CPPDEFINES=["_DEBUG"])
env.Append(CCFLAGS=["-EHsc", "-MDd", "-ZI", "-FS"]) env.Append(CCFLAGS=["-EHsc", "-MDd", "-ZI", "-FS"])
env.Append(LINKFLAGS=["-DEBUG"]) env.Append(LINKFLAGS=["-DEBUG"])
@ -118,12 +127,11 @@ elif env["platform"] == "windows":
if not(env["use_llvm"]): if not(env["use_llvm"]):
env.Append(CPPDEFINES=["TYPED_METHOD_BIND"]) env.Append(CPPDEFINES=["TYPED_METHOD_BIND"])
if env["target"] in ("debug", "d"): # determine our architecture suffix
cpp_library += ".debug" arch_suffix = str(bits)
else:
cpp_library += ".release"
cpp_library += "." + str(bits) # suffix our godot-cpp library
cpp_library += "." + env["target"] + "." + arch_suffix
# make sure our binding library is properly includes # make sure our binding library is properly includes
env.Append(CPPPATH=[".", godot_headers_path, cpp_bindings_path + "include/", cpp_bindings_path + "gen/include/"]) env.Append(CPPPATH=[".", godot_headers_path, cpp_bindings_path + "include/", cpp_bindings_path + "gen/include/"])
@ -134,6 +142,8 @@ env.Append(LIBS=[cpp_library])
env.Append(CPPPATH=["src/"]) env.Append(CPPPATH=["src/"])
sources = Glob("src/*.cpp") sources = Glob("src/*.cpp")
library = env.SharedLibrary(target=env["target_path"] + env["target_name"], source=sources) target_name = "{}.{}.{}.{}".format(env["target_name"], env["platform"], env["target"], arch_suffix)
print(target_name)
library = env.SharedLibrary(target=env["target_path"] + target_name, source=sources)
Default(library) Default(library)

View File

@ -4,5 +4,7 @@ entry_symbol = "example_library_init"
[libraries] [libraries]
linux.64 = "bin/x11/libgdexample.so" linux.64.debug = "bin/libgdexample.linux.debug.64.so"
windows.64 = "bin/win64/libgdexample.dll" linux.64.release = "bin/libgdexample.linux.release.64.so"
windows.64.debug = "bin/libgdexample.windows.debug.64.dll"
windows.64.release = "bin/libgdexample.windows.release.64.dll"