xmake.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package("omath")
  2. set_homepage("http://libomath.org")
  3. set_description("Cross-platform modern general purpose math library written in C++23")
  4. set_license("zlib")
  5. add_urls("https://github.com/orange-cpp/omath/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/orange-cpp/omath.git", {submodules = false})
  7. add_versions("v3.0.3", "f72ec671eb99d83bf6d63ec5eee7436110a9f340b416eefac51464665bbda06c")
  8. add_configs("avx2", {description = "Enable AVX2", default = true, type = "boolean"})
  9. add_configs("imgui", {description = "Define method to convert omath types to imgui types", default = true, type = "boolean"})
  10. add_deps("cmake")
  11. if is_plat("windows") then
  12. add_deps("pkgconf")
  13. else
  14. add_deps("pkg-config")
  15. end
  16. on_load(function (package)
  17. if package:config("imgui") then
  18. package:add("deps", "imgui")
  19. end
  20. end)
  21. on_install("!macosx and !iphoneos and !android and !bsd", function (package)
  22. if package:config("imgui") then
  23. local imgui = package:dep("imgui")
  24. if imgui and not imgui:is_system() then
  25. local imgui_fetch = imgui:fetch()
  26. if imgui_fetch then
  27. for _, inc in ipairs(imgui_fetch.includedirs or imgui_fetch.sysincludedirs) do
  28. os.mkdir(inc)
  29. end
  30. end
  31. end
  32. end
  33. io.replace("CMakeLists.txt", [[find_package(imgui CONFIG REQUIRED)]], [[include(FindPkgConfig)
  34. pkg_search_module("imgui" REQUIRED IMPORTED_TARGET "imgui")]], {plain = true})
  35. io.replace("CMakeLists.txt", [[imgui::imgui]], [[PkgConfig::imgui]], {plain = true})
  36. if package:is_plat("wasm") then
  37. io.replace("CMakeLists.txt", [[target_compile_options(${PROJECT_NAME} PRIVATE -mavx2 -mfma)]], [[target_compile_options(${PROJECT_NAME} PRIVATE -msimd128 -mavx2)]], {plain = true})
  38. end
  39. local configs = {"-DOMATH_THREAT_WARNING_AS_ERROR=OFF", "-DOMATH_BUILD_TESTS=OFF"}
  40. table.insert(configs, "-DOMATH_USE_AVX2=" .. (package:config("avx2") and "ON" or "OFF"))
  41. table.insert(configs, "-DOMATH_IMGUI_INTEGRATION=" .. (package:config("imgui") and "ON" or "OFF"))
  42. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  43. table.insert(configs, "-DOMATH_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
  44. import("package.tools.cmake").install(package, configs)
  45. end)
  46. on_test(function (package)
  47. assert(package:check_cxxsnippets({test = [[
  48. void test() {
  49. omath::Vector2 w = omath::Vector2(20.0, 30.0);
  50. }
  51. ]]}, {configs = {languages = "c++23"}, includes = "omath/vector2.hpp"}))
  52. end)