diff --git a/cpp/simple/SConstruct b/cpp/simple/SConstruct index 7bfa4bc..0b99836 100644 --- a/cpp/simple/SConstruct +++ b/cpp/simple/SConstruct @@ -1,40 +1,53 @@ #!python import os -# platform= makes it in line with Godots scons file, keeping p for backwards compatibility -platform = ARGUMENTS.get("p", "linux") -platform = ARGUMENTS.get("platform", platform) +opts = Variables([], ARGUMENTS) -# 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 -env = Environment() -if platform == "windows": - env = Environment(ENV=os.environ) +# Gets the standard flags CC, CCX, etc. +env = DefaultEnvironment() -godot_headers_path = ARGUMENTS.get("headers", os.getenv("GODOT_HEADERS", "godot-cpp/godot_headers")) -godot_bindings_path = ARGUMENTS.get("cpp_bindings", os.getenv("CPP_BINDINGS", "godot-cpp")) +godot_headers_path = "godot-cpp/godot_headers" +godot_bindings_path = "godot-cpp" -# default to debug build, must be same setting as used for cpp_bindings -target = ARGUMENTS.get("target", "debug") +# Define our options. Use future-proofed names for platforms. +platform_array = ["", "windows", "linuxbsd", "macos", "x11", "linux", "osx"] +opts.Add(EnumVariable("target", "Compilation target", "debug", ["d", "debug", "r", "release"])) +opts.Add(EnumVariable("platform", "Compilation platform", "", platform_array)) +opts.Add(EnumVariable("p", "Alias for 'platform'", "", platform_array)) +opts.Add(BoolVariable("use_llvm", "Use the LLVM / Clang compiler", "no")) +opts.Add(PathVariable("target_path", "The path where the lib is installed.", "project/gdnative/")) +opts.Add(PathVariable("target_name", "The library name.", "libsimple", PathVariable.PathAccept)) +opts.Update(env) if ARGUMENTS.get("use_llvm", "no") == "yes": env["CXX"] = "clang++" # put stuff that is the same for all first, saves duplication -if platform == "osx": - env.Append(CCFLAGS=["-g", "-O3", "-std=c++14", "-arch", "x86_64"]) - env.Append(LINKFLAGS=["-arch", "x86_64", "-framework", "Cocoa", "-Wl,-undefined,dynamic_lookup"]) -elif platform == "linux": - env.Append(CCFLAGS=["-g", "-O3", "-std=c++14", "-Wno-writable-strings"]) - env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"]) -elif platform == "windows": - # need to add detection of msvc vs mingw, this is for msvc... - env.Append(LINKFLAGS=["/WX"]) - if target == "debug": - env.Append(CCFLAGS=["-EHsc", "-D_DEBUG", "/MDd"]) +if env["platform"] == "osx": + if env["target"] in ("debug", "d"): + env.Append(CCFLAGS=["-g", "-O2", "-arch", "x86_64"]) + env.Append(LINKFLAGS=["-arch", "x86_64"]) else: - env.Append(CCFLAGS=["-O2", "-EHsc", "-DNDEBUG", "/MD"]) + env.Append(CCFLAGS=["-g", "-O3", "-arch", "x86_64"]) + env.Append(LINKFLAGS=["-arch", "x86_64"]) +elif env["platform"] == "linux": + if env["target"] in ("debug", "d"): + env.Append(CCFLAGS=["-fPIC", "-g3", "-Og"]) + else: + env.Append(CCFLAGS=["-fPIC", "-g", "-O3"]) +elif env["platform"] == "windows": + # This makes sure to keep the session environment variables + # on Windows, so that you can run scons in a VS 2017 prompt + # and it will find all the required tools. + env = Environment(ENV=os.environ) + opts.Update(env) + + env.Append(CCFLAGS=["-DWIN32", "-D_WIN32", "-D_WINDOWS", "-W3", "-GR", "-D_CRT_SECURE_NO_WARNINGS"]) + if env["target"] in ("debug", "d"): + env.Append(CCFLAGS=["-EHsc", "-D_DEBUG", "-MDd"]) + else: + env.Append(CCFLAGS=["-O2", "-EHsc", "-DNDEBUG", "-MD"]) def add_sources(sources, dir): @@ -52,15 +65,12 @@ env.Append( ] ) -if target == "debug": - env.Append(LIBS=["libgodot-cpp.linux.debug.64"]) -else: - env.Append(LIBS=["libgodot-cpp.linux.release.64"]) +env.Append(LIBS=[env.File(os.path.join("godot-cpp/bin", "libgodot-cpp.%s.%s.64%s" % (env["platform"], env["target"], env["LIBSUFFIX"])))]) env.Append(LIBPATH=[godot_bindings_path + "/bin/"]) sources = [] add_sources(sources, "src") -library = env.SharedLibrary(target="bin/libsimple", source=sources) +library = env.SharedLibrary(target=env["target_path"] + "/" + env["platform"] + "/" + env["target_name"], source=sources) Default(library) diff --git a/cpp/simple/project/bin/simple.gdnlib b/cpp/simple/project/gdnative/simple.gdnlib similarity index 100% rename from cpp/simple/project/bin/simple.gdnlib rename to cpp/simple/project/gdnative/simple.gdnlib diff --git a/cpp/simple/project/bin/simple.gdns b/cpp/simple/project/gdnative/simple.gdns similarity index 100% rename from cpp/simple/project/bin/simple.gdns rename to cpp/simple/project/gdnative/simple.gdns