xmake.lua 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package("opensubdiv")
  2. set_homepage("https://graphics.pixar.com/opensubdiv/docs/intro.html")
  3. set_description("OpenSubdiv is a set of open source libraries that implement high performance subdivision surface (subdiv) evaluation on massively parallel CPU and GPU architectures.")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/PixarAnimationStudios/OpenSubdiv.git", {alias = "git"})
  6. add_urls("https://github.com/PixarAnimationStudios/OpenSubdiv/archive/refs/tags/v$(version).tar.gz", {version = function (version) return version:gsub("%.", "_") end})
  7. add_versions("3.4.4", "20d49f80a2b778ad4d01f091ad88d8c2f91cf6c7363940c6213241ce6f1048fb")
  8. add_versions("3.5.0", "8f5044f453b94162755131f77c08069004f25306fd6dc2192b6d49889efb8095")
  9. add_versions("3.6.0", "bebfd61ab6657a4f4ff27845fb66a167d00395783bfbd253254d87447ed1d879")
  10. add_versions("git:3.6.0", "v3_6_0")
  11. if is_plat("windows", "wasm") then
  12. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  13. end
  14. if is_plat("windows", "linux", "macosx") then
  15. add_configs("glfw", {description = "Enable components depending on GLFW.", default = true, type = "boolean"})
  16. add_configs("ptex", {description = "Enable components depending on Ptex.", default = true, type = "boolean"})
  17. else
  18. add_configs("glfw", {description = "Enable components depending on GLFW.", default = false, type = "boolean"})
  19. add_configs("ptex", {description = "Enable components depending on Ptex.", default = false, type = "boolean"})
  20. end
  21. add_configs("tbb", {description = "Enable components depending on TBB.", default = false, type = "boolean"})
  22. add_configs("openmp", {description = "Enable OpenMP backend.", default = false, type = "boolean"})
  23. add_configs("opencl", {description = "Enable OpenCL backend.", default = false, type = "boolean"})
  24. add_configs("cuda", {description = "Enable CUDA backend.", default = false, type = "boolean"})
  25. add_deps("cmake")
  26. if is_plat("windows") then
  27. add_defines("NOMINMAX")
  28. end
  29. on_load(function (package)
  30. for _, dep in ipairs({"glfw", "ptex", "tbb"}) do
  31. if package:config(dep) then
  32. package:add("deps", dep)
  33. end
  34. end
  35. for _, dep in ipairs({"openmp", "opencl", "cuda"}) do
  36. if package:config(dep) then
  37. package:add("deps", dep, {system = true})
  38. end
  39. end
  40. end)
  41. on_install("windows", "linux", "macosx", "wasm", function (package)
  42. local configs = {"-DNO_EXAMPLES=ON", "-DNO_TUTORIALS=ON", "-DNO_REGRESSION=ON", "-DNO_DOC=ON", "-DNO_CLEW=ON", "-DNO_TESTS=ON", "-DNO_GLTESTS=ON"}
  43. if package:config("glfw") then
  44. io.replace("cmake/FindGLFW.cmake", "NOT X11_xf86vmode_FOUND", "FALSE", {plain = true})
  45. end
  46. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  47. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  48. for _, dep in ipairs({"glfw", "ptex", "tbb", "opencl", "cuda"}) do
  49. table.insert(configs, "-DNO_" .. dep:upper() .. "=" .. (package:config(dep) and "OFF" or "ON"))
  50. end
  51. table.insert(configs, "-DNO_OMP=" .. (package:config("openmp") and "OFF" or "ON"))
  52. if package:is_plat("windows") then
  53. local vs_sdkver = import("core.tool.toolchain").load("msvc"):config("vs_sdkver")
  54. if vs_sdkver then
  55. local build_ver = string.match(vs_sdkver, "%d+%.%d+%.(%d+)%.?%d*")
  56. assert(tonumber(build_ver) >= 18362, "OpenSubDiv requires Windows SDK to be at least 10.0.18362.0")
  57. table.insert(configs, "-DCMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION=" .. vs_sdkver)
  58. table.insert(configs, "-DCMAKE_SYSTEM_VERSION=" .. vs_sdkver)
  59. end
  60. table.insert(configs, "-DMSVC_STATIC_CRT=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))
  61. end
  62. import("package.tools.cmake").install(package, configs)
  63. if package:config("shared") then
  64. os.tryrm(path.join(package:installdir("lib"), "lib*.a"))
  65. end
  66. end)
  67. on_test(function (package)
  68. assert(package:check_cxxsnippets({test = [[
  69. #include <opensubdiv/osd/glMesh.h>
  70. void test() {
  71. OpenSubdiv::Osd::MeshBitset bits;
  72. bits.set(OpenSubdiv::Osd::MeshAdaptive, true);
  73. bits.set(OpenSubdiv::Osd::MeshUseSingleCreasePatch, true);
  74. }
  75. ]]}, {configs = {languages = "c++14"}}))
  76. end)