xmake.lua 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package("glm")
  2. set_homepage("https://glm.g-truc.net/")
  3. set_description("OpenGL Mathematics (GLM)")
  4. set_license("MIT")
  5. add_urls("https://github.com/g-truc/glm/archive/refs/tags/$(version).tar.gz",
  6. {version = function(version) return version:gsub("%+", ".") end})
  7. add_urls("https://github.com/g-truc/glm.git")
  8. add_versions("1.0.0", "e51f6c89ff33b7cfb19daafb215f293d106cd900f8d681b9b1295312ccadbd23")
  9. add_versions("0.9.9+8", "7d508ab72cb5d43227a3711420f06ff99b0a0cb63ee2f93631b162bfe1fe9592")
  10. add_configs("header_only", {description = "Use header only version.", default = true, type = "boolean"})
  11. add_configs("cxx_standard", {description = "Select c++ standard to build.", default = "14", type = "string", values = {"98", "11", "14", "17", "20"}})
  12. add_configs("modules", {description = "Build with C++20 modules support.", default = false, type = "boolean"})
  13. on_load(function (package)
  14. if package:config("modules") then
  15. package:config_set("header_only", false)
  16. package:config_set("cxx_standard", "20")
  17. end
  18. if not package:config("header_only") and not package:config("modules") then
  19. package:add("deps", "cmake")
  20. end
  21. end)
  22. on_install(function (package)
  23. if not package:config("modules") then
  24. if package:config("header_only") then
  25. os.cp("glm", package:installdir("include"))
  26. else
  27. io.replace("CMakeLists.txt", "NOT GLM_DISABLE_AUTO_DETECTION", "FALSE")
  28. local configs = {"-DGLM_BUILD_TESTS=OFF"}
  29. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  30. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  31. table.insert(configs, "-DCMAKE_CXX_STANDARD=" .. package:config("cxx_standard"))
  32. import("package.tools.cmake").install(package, configs)
  33. end
  34. else
  35. io.writefile("xmake.lua", [[
  36. target("glm")
  37. set_kind("$(kind)")
  38. set_languages("c++20")
  39. add_headerfiles("./(glm/**.hpp)")
  40. add_headerfiles("./(glm/**.h)")
  41. add_headerfiles("./(glm/**.inl)")
  42. add_includedirs(".")
  43. add_files("glm/**.cpp")
  44. add_files("glm/**.cppm", {public = true})
  45. ]])
  46. import("package.tools.xmake").install(package)
  47. end
  48. end)
  49. on_test(function (package)
  50. local cxx_standard = "c++" .. package:config("cxx_standard")
  51. assert(package:check_cxxsnippets({test = [[
  52. #include <glm/glm.hpp>
  53. #include <glm/ext/matrix_clip_space.hpp>
  54. void test() {
  55. glm::mat4 proj = glm::perspective(glm::radians(45.f), 1.33f, 0.1f, 10.f);
  56. }
  57. ]]}, {configs = {languages = cxx_standard}}))
  58. end)