xmake.lua 3.1 KB

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