diff --git a/c/glfw/SConstruct b/c/glfw/SConstruct new file mode 100644 index 0000000..7d4511c --- /dev/null +++ b/c/glfw/SConstruct @@ -0,0 +1,92 @@ +#!python +import os, subprocess + +opts = Variables([], ARGUMENTS) + +# Define the relative path to the Godot headers. +godot_headers_path = "godot_headers/" + +# Gets the standard flags CC, CCX, etc. +env = DefaultEnvironment() +env["STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME"] = 1 + +# 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.", "libglfw", PathVariable.PathAccept)) + +# Only support 64-bit systems. +bits = 64 + +# Updates the environment with the option variables. +opts.Update(env) + +# Process platform arguments. +if env["p"] != "": + env["platform"] = env["p"] + +if env["platform"] == "osx": + env["platform"] = "macos" +elif env["platform"] in ("x11", "linux"): + env["platform"] = "linuxbsd" + +if env["platform"] == "": + print("No valid target platform selected.") + quit() + +env["target_path"] += env["platform"] + "/" + +# Process other arguments. +if env["use_llvm"]: + env["CC"] = "clang" + env["CXX"] = "clang++" + +# Check our platform specifics +if env["platform"] == "macos": + if env["target"] in ("debug", "d"): + env.Append(CCFLAGS=["-g", "-O2", "-arch", "x86_64"]) + env.Append(LINKFLAGS=["-arch", "x86_64"]) + else: + env.Append(CCFLAGS=["-g", "-O3", "-arch", "x86_64"]) + env.Append(LINKFLAGS=["-arch", "x86_64"]) + +elif env["platform"] == "linuxbsd": + 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.Append(ENV=os.environ) + + 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"]) + +# Make sure our library includes the Godot headers. +env.Append(CPPPATH=[".", godot_headers_path]) + +# Make sure our library looks in the target path for any other +# libraries it may need. The path needs to be project-relative. +env.Append(LINKFLAGS=["-Wl,-rpath,gdnative/" + env["platform"]]) + +# Tweak this if you want to use different folders, +# or more folders, to store your source code in. +env.Append(CPPPATH=["src/"]) +sources = Glob("src/*.c") + +library = env.SharedLibrary(target=env["target_path"] + env["target_name"], source=sources) + +Default(library) + +# Generates help for the -h scons option. +Help(opts.GenerateHelpText(env)) diff --git a/c/glfw/GLFW.gdnlib b/c/glfw/project/gdnative/glfw.gdnlib similarity index 100% rename from c/glfw/GLFW.gdnlib rename to c/glfw/project/gdnative/glfw.gdnlib diff --git a/c/glfw/GLFW.gdns b/c/glfw/project/gdnative/glfw.gdns similarity index 100% rename from c/glfw/GLFW.gdns rename to c/glfw/project/gdnative/glfw.gdns diff --git a/c/glfw/project/gdnative/linuxbsd/.gitignore b/c/glfw/project/gdnative/linuxbsd/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/c/glfw/project/gdnative/linuxbsd/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/c/glfw/project/gdnative/macos/.gitignore b/c/glfw/project/gdnative/macos/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/c/glfw/project/gdnative/macos/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/c/glfw/project/gdnative/windows/.gitignore b/c/glfw/project/gdnative/windows/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/c/glfw/project/gdnative/windows/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/c/glfw/icon.png b/c/glfw/project/icon.png similarity index 100% rename from c/glfw/icon.png rename to c/glfw/project/icon.png diff --git a/c/glfw/icon.png.import b/c/glfw/project/icon.png.import similarity index 100% rename from c/glfw/icon.png.import rename to c/glfw/project/icon.png.import diff --git a/c/glfw/Main.tscn b/c/glfw/project/main.tscn similarity index 100% rename from c/glfw/Main.tscn rename to c/glfw/project/main.tscn diff --git a/c/glfw/project.godot b/c/glfw/project/project.godot similarity index 100% rename from c/glfw/project.godot rename to c/glfw/project/project.godot diff --git a/c/instance_binding/SConstruct b/c/instance_binding/SConstruct index 7f2d068..d65a2b5 100644 --- a/c/instance_binding/SConstruct +++ b/c/instance_binding/SConstruct @@ -1,49 +1,92 @@ #!python import os, subprocess -# Local dependency paths, adapt them to your setup -godot_headers_path = ARGUMENTS.get("headers", os.getenv("GODOT_HEADERS", "../../../godot_headers/")) +opts = Variables([], ARGUMENTS) -target = ARGUMENTS.get("target", "debug") +# Define the relative path to the Godot headers. +godot_headers_path = "godot_headers/" -# platform= makes it in line with Godots scons file, keeping p for backwards compatibility -platform = ARGUMENTS.get("p", "linux") -platform = ARGUMENTS.get("platform", platform) +# Gets the standard flags CC, CCX, etc. +env = DefaultEnvironment() +env["STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME"] = 1 -# 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) +# 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.", "libinstance_binding", PathVariable.PathAccept)) -if ARGUMENTS.get("use_llvm", "no") == "yes": +# Only support 64-bit systems. +bits = 64 + +# Updates the environment with the option variables. +opts.Update(env) + +# Process platform arguments. +if env["p"] != "": + env["platform"] = env["p"] + +if env["platform"] == "osx": + env["platform"] = "macos" +elif env["platform"] in ("x11", "linux"): + env["platform"] = "linuxbsd" + +if env["platform"] == "": + print("No valid target platform selected.") + quit() + +env["target_path"] += env["platform"] + "/" + +# Process other arguments. +if env["use_llvm"]: env["CC"] = "clang" + env["CXX"] = "clang++" - -def add_sources(sources, directory): - for file in os.listdir(directory): - if file.endswith(".c"): - sources.append(directory + "/" + file) - - -if platform == "osx": - env.Append(CCFLAGS=["-g", "-O3", "-arch", "x86_64"]) - env.Append(LINKFLAGS=["-arch", "x86_64"]) - -if platform == "linux": - env.Append(CCFLAGS=["-fPIC", "-g", "-O3", "-std=c11"]) - -if platform == "windows": - if target == "debug": - env.Append(CCFLAGS=["-EHsc", "-D_DEBUG", "/MDd"]) +# Check our platform specifics +if env["platform"] == "macos": + 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"]) -# , 'include', 'include/core' +elif env["platform"] == "linuxbsd": + 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.Append(ENV=os.environ) + + 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"]) + +# Make sure our library includes the Godot headers. env.Append(CPPPATH=[".", godot_headers_path]) -sources = [] -add_sources(sources, "src") +# Make sure our library looks in the target path for any other +# libraries it may need. The path needs to be project-relative. +env.Append(LINKFLAGS=["-Wl,-rpath,gdnative/" + env["platform"]]) + +# Tweak this if you want to use different folders, +# or more folders, to store your source code in. +env.Append(CPPPATH=["src/"]) +sources = Glob("src/*.c") + +library = env.SharedLibrary(target=env["target_path"] + env["target_name"], source=sources) -library = env.SharedLibrary(target="bin/instance_binding_demo", source=sources) Default(library) + +# Generates help for the -h scons option. +Help(opts.GenerateHelpText(env)) diff --git a/c/instance_binding/default_env.tres b/c/instance_binding/project/default_env.tres similarity index 100% rename from c/instance_binding/default_env.tres rename to c/instance_binding/project/default_env.tres diff --git a/c/instance_binding/bin/instance_binding_demo.gdnlib b/c/instance_binding/project/gdnative/instance_binding.gdnlib similarity index 100% rename from c/instance_binding/bin/instance_binding_demo.gdnlib rename to c/instance_binding/project/gdnative/instance_binding.gdnlib diff --git a/c/instance_binding/bin/instance_binding_demo.gdns b/c/instance_binding/project/gdnative/instance_binding.gdns similarity index 100% rename from c/instance_binding/bin/instance_binding_demo.gdns rename to c/instance_binding/project/gdnative/instance_binding.gdns diff --git a/c/instance_binding/project/gdnative/linuxbsd/.gitignore b/c/instance_binding/project/gdnative/linuxbsd/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/c/instance_binding/project/gdnative/linuxbsd/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/c/instance_binding/project/gdnative/macos/.gitignore b/c/instance_binding/project/gdnative/macos/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/c/instance_binding/project/gdnative/macos/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/c/instance_binding/project/gdnative/windows/.gitignore b/c/instance_binding/project/gdnative/windows/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/c/instance_binding/project/gdnative/windows/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/c/instance_binding/icon.png b/c/instance_binding/project/icon.png similarity index 100% rename from c/instance_binding/icon.png rename to c/instance_binding/project/icon.png diff --git a/c/instance_binding/main.gd b/c/instance_binding/project/main.gd similarity index 100% rename from c/instance_binding/main.gd rename to c/instance_binding/project/main.gd diff --git a/c/instance_binding/main.tscn b/c/instance_binding/project/main.tscn similarity index 100% rename from c/instance_binding/main.tscn rename to c/instance_binding/project/main.tscn diff --git a/c/instance_binding/project.godot b/c/instance_binding/project/project.godot similarity index 100% rename from c/instance_binding/project.godot rename to c/instance_binding/project/project.godot diff --git a/c/instance_binding/src/instance_binding_demo.c b/c/instance_binding/src/instance_binding.c similarity index 100% rename from c/instance_binding/src/instance_binding_demo.c rename to c/instance_binding/src/instance_binding.c