SConstruct 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!python
  2. import os, subprocess
  3. # Local dependency paths, adapt them to your setup
  4. godot_headers_path = "../../godot_headers/"
  5. godot_bin_path = "../../godot_fork/bin/"
  6. godot_lib_path = "../../godot_fork/bin/"
  7. env = Environment()
  8. if ARGUMENTS.get("use_llvm", "no") == "yes":
  9. env["CXX"] = "clang++"
  10. target = ARGUMENTS.get("target", "core")
  11. platform = ARGUMENTS.get("p", "linux")
  12. godot_name = "godot." + platform + ".tools.64"
  13. def add_sources(sources, directory):
  14. for file in os.listdir(directory):
  15. if file.endswith('.cpp'):
  16. sources.append(directory + '/' + file)
  17. if target == "core":
  18. if platform == "linux":
  19. env.Append(CCFLAGS = ['-g','-O3', '-std=c++14'])
  20. env.Append(CPPPATH=['.', godot_headers_path])
  21. if platform == "windows":
  22. env.Append(LIBS=[godot_name + '.lib'])
  23. env.Append(LIBPATH=[godot_lib_path])
  24. env.Append(CPPFLAGS=['-D_GD_CPP_CORE_API_IMPL'])
  25. sources = []
  26. add_sources(sources, "godot_cpp/core")
  27. library = env.SharedLibrary(target='godot_cpp_core', source=sources)
  28. Default(library)
  29. elif target == "bindings":
  30. if ARGUMENTS.get("generate_bindings", "no") == "yes":
  31. godot_executable = godot_bin_path + godot_name
  32. if platform == "windows":
  33. godot_executable += ".exe"
  34. # TODO Generating the API should be done only if the Godot build is more recent than the JSON file
  35. json_api_file = 'godot_api.json'
  36. subprocess.call([godot_executable, '--gdnative-generate-json-api', json_api_file])
  37. binding_generator_executable = '../binding_generator/target/debug/binding_generator'
  38. if platform == "windows":
  39. binding_generator_executable += ".exe"
  40. # TODO Should that be the job of the generator?
  41. if not os.path.isdir('godot_cpp/impl'):
  42. os.mkdir('godot_cpp/impl')
  43. # Note: the binding generator should have been built before
  44. subprocess.call([binding_generator_executable, json_api_file, 'godot_cpp/'])
  45. if platform == "linux":
  46. if env["CXX"] == "clang++":
  47. env.Append(CCFLAGS = ['-Wno-writable-strings'])
  48. else:
  49. env.Append(CCFLAGS = ['-Wno-write-strings', '-Wno-return-local-addr'])
  50. env.Append(CCFLAGS = ['-g','-O3', '-std=c++14'])
  51. env.Append(LINKFLAGS = ['-Wl,-R,\'$$ORIGIN\''])
  52. env.Append(CPPPATH=['.', godot_headers_path, './godot_cpp'])
  53. if platform == "windows":
  54. env.Append(LIBS=[godot_name])
  55. env.Append(LIBPATH=[godot_lib_path])
  56. env.Append(LIBS=['godot_cpp_core'])
  57. env.Append(LIBPATH=['.'])
  58. env.Append(CPPFLAGS=['-D_GD_CPP_BINDING_IMPL'])
  59. sources = []
  60. add_sources(sources, "godot_cpp/impl/")
  61. library = env.SharedLibrary(target='godot_cpp_bindings', source=sources)
  62. Default(library)