xmake.lua 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package("godotcpp")
  2. set_homepage("https://godotengine.org/")
  3. set_description("C++ bindings for the Godot script API")
  4. set_urls("https://github.com/godotengine/godot-cpp.git")
  5. add_versions("3.2", "77d41fa179e40560f1e264ed483638bf51713779")
  6. add_deps("scons")
  7. add_includedirs("include", "include/core", "include/gen")
  8. on_install("linux", "windows", "macosx", "mingw", "cygwin", "iphoneos", "android", "msys", function (package)
  9. local configs = {"generate_bindings=yes"}
  10. table.insert(configs, "bits=" .. ((package:is_arch("x64") or package:is_arch("x86_64")) and "64" or "32"))
  11. if package:is_plat("windows") then
  12. io.replace("SConstruct", "/MD", "/" .. package:config("vs_runtime"), {plain = true})
  13. end
  14. -- this fixes an error on ios and osx (https://godotengine.org/qa/65616/problems-compiling-gdnative-c-example-on-osx)
  15. if package:is_plat("macosx", "iphoneos") then
  16. io.replace("SConstruct", "-std=c++14", "-std=c++17", {plain = true})
  17. end
  18. -- fix to use correct ranlib, @see https://github.com/godotengine/godot-cpp/issues/510
  19. if package:is_plat("android") then
  20. io.replace("SConstruct",
  21. [[env['AR'] = toolchain + "/bin/" + arch_info['tool_path'] + "-ar"]],
  22. [[env['AR'] = toolchain + "/bin/" + arch_info['tool_path'] + "-ar"
  23. env['RANLIB'] = toolchain + "/bin/" + arch_info['tool_path'] + "-ranlib"]], {plain = true})
  24. end
  25. import("package.tools.scons").build(package, configs)
  26. os.cp("bin/*." .. (package:is_plat("windows") and "lib" or "a"), package:installdir("lib"))
  27. os.cp("include/core/*.hpp", package:installdir("include/core"))
  28. os.cp("include/gen/*.hpp", package:installdir("include/gen"))
  29. os.cp("godot-headers/android", package:installdir("include"))
  30. os.cp("godot-headers/arvr", package:installdir("include"))
  31. os.cp("godot-headers/gdnative", package:installdir("include"))
  32. os.cp("godot-headers/nativescript", package:installdir("include"))
  33. os.cp("godot-headers/net", package:installdir("include"))
  34. os.cp("godot-headers/pluginscript", package:installdir("include"))
  35. os.cp("godot-headers/videodecoder", package:installdir("include"))
  36. os.cp("godot-headers/*.h", package:installdir("include"))
  37. end)
  38. on_test(function (package)
  39. assert(package:check_cxxsnippets({test = [[
  40. #include <Godot.hpp>
  41. #include <Reference.hpp>
  42. using namespace godot;
  43. class SimpleClass : public Reference {
  44. GODOT_CLASS(SimpleClass, Reference);
  45. public:
  46. SimpleClass() { }
  47. void _init() { }
  48. Variant method(Variant arg) {
  49. Variant ret; ret = arg; return ret;
  50. }
  51. static void _register_methods() {
  52. register_method("method", &SimpleClass::method);
  53. }
  54. };
  55. extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) { godot::Godot::gdnative_init(o); }
  56. extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *o) { godot::Godot::gdnative_terminate(o); }
  57. extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) {
  58. godot::Godot::nativescript_init(handle);
  59. godot::register_class<SimpleClass>();
  60. }
  61. ]]}, {configs = {languages = "cxx17"}}))
  62. end)