SConstruct 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!python
  2. import os, subprocess
  3. # Local dependency paths, adapt them to your setup
  4. godot_headers_path = ARGUMENTS.get("headers", os.getenv("GODOT_HEADERS", "../godot_headers/"))
  5. godot_bin_path = ARGUMENTS.get("godotbinpath", os.getenv("GODOT_BIN_PATH", "../godot_fork/bin/godot.x11.tools.64.llvm"))
  6. target = ARGUMENTS.get("target", "debug")
  7. platform = ARGUMENTS.get("p", ARGUMENTS.get("platform", "linux"))
  8. # This makes sure to keep the session environment variables on windows,
  9. # that way you can run scons in a vs 2017 prompt and it will find all the required tools
  10. env = Environment()
  11. if platform == "windows":
  12. env = Environment(ENV = os.environ)
  13. if ARGUMENTS.get("use_llvm", "no") == "yes":
  14. env["CXX"] = "clang++"
  15. def add_sources(sources, directory):
  16. for file in os.listdir(directory):
  17. if file.endswith('.cpp'):
  18. sources.append(directory + '/' + file)
  19. if platform == "osx":
  20. env.Append(CCFLAGS = ['-g','-O3', '-std=c++14', '-arch', 'x86_64'])
  21. env.Append(LINKFLAGS = ['-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup'])
  22. if platform == "linux":
  23. env.Append(CCFLAGS = ['-fPIC', '-g','-O3', '-std=c++14'])
  24. env.Append(CPPPATH=['.', godot_headers_path, 'include', 'include/core'])
  25. if platform == "windows":
  26. if target == "debug":
  27. env.Append(CCFLAGS = ['-EHsc', '-D_DEBUG', '/MDd'])
  28. else:
  29. env.Append(CCFLAGS = ['-O2', '-EHsc', '-DNDEBUG', '/MD'])
  30. sources = []
  31. add_sources(sources, "src/core")
  32. if ARGUMENTS.get("generate_bindings", "no") == "yes":
  33. # TODO Generating the API should be done only if the Godot build is more recent than the JSON file
  34. json_api_file = 'godot_api.json'
  35. subprocess.call([godot_bin_path, '--gdnative-generate-json-api', json_api_file])
  36. # actually create the bindings here
  37. import binding_generator
  38. binding_generator.generate_bindings(json_api_file)
  39. add_sources(sources, "src")
  40. library = env.StaticLibrary(target='bin/godot_cpp_bindings', source=sources)
  41. Default(library)