xmake.lua 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. -- Usage
  2. --[[
  3. add_requires("luisa-compute")
  4. set_languages("c++20")
  5. target("test")
  6. set_kind("binary")
  7. add_files("src/main.cpp")
  8. add_packages("luisa-compute")
  9. on_config(function (target)
  10. -- Context require a path to find backend shared libraries
  11. -- Context context{argv[1]};
  12. target:add("runargs", path.join(target:pkg("luisa-compute"):installdir(), "bin"))
  13. -- -- Use target:targetdir() path
  14. -- -- Context context{argv[0]};
  15. -- os.vcp(path.join(target:pkg("luisa-compute"):installdir(), "bin/*.dll"), target:targetdir())
  16. end)
  17. --]]
  18. package("luisa-compute")
  19. set_homepage("https://luisa-render.com/")
  20. set_description("High-Performance Rendering Framework on Stream Architectures")
  21. set_license("Apache-2.0")
  22. add_urls("https://github.com/LuisaGroup/LuisaCompute.git", {submodules = false})
  23. add_versions("2025.11.05", "f363db428873120924880e28d3a284202edb237a")
  24. add_configs("cuda", {description = "Enable CUDA backend", default = false, type = "boolean"})
  25. add_configs("vulkan", {description = "Enable Vulkan backend", default = false, type = "boolean"})
  26. add_configs("cpu", {description = "Enable CPU backend", default = false, type = "boolean"})
  27. add_configs("gui", {description = "Enable GUI support", default = false, type = "boolean"})
  28. add_configs("shared", {description = "Build shared library.", default = true, type = "boolean", readonly = true})
  29. if is_host("windows") then
  30. set_policy("platform.longpaths", true)
  31. end
  32. add_includedirs("include", "include/luisa/ext")
  33. add_defines(
  34. "LUISA_USE_SYSTEM_SPDLOG=1",
  35. "LUISA_USE_SYSTEM_XXHASH=1",
  36. "LUISA_USE_SYSTEM_MAGIC_ENUM=1",
  37. "LUISA_USE_SYSTEM_STL=1",
  38. "LUISA_USE_SYSTEM_REPROC=1",
  39. "LUISA_USE_SYSTEM_YYJSON=1",
  40. "MARL_USE_SYSTEM_STL=1",
  41. "LUISA_USE_SYSTEM_MARL=1",
  42. "LUISA_USE_SYSTEM_LMDB=1",
  43. "LUISA_ENABLE_DSL=1",
  44. "LUISA_ENABLE_XIR=1"
  45. )
  46. if is_plat("windows") then
  47. add_defines("LUISA_PLATFORM_WINDOWS=1", "_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR")
  48. elseif is_plat("macosx") then
  49. add_defines("LUISA_PLATFORM_APPLE=1")
  50. else
  51. add_defines("LUISA_PLATFORM_UNIX=1")
  52. end
  53. if is_plat("linux") then
  54. add_links("luisa-xir", "luisa-dsl", "luisa-runtime", "luisa-ast", "luisa-osl", "luisa-core", "luisa-ext-volk")
  55. end
  56. add_deps("cmake", "pkgconf")
  57. add_deps("spdlog", {configs = {header_only = false, fmt_external = true}})
  58. add_deps("lmdb", "reproc", "xxhash", "yyjson", "magic_enum", "marl", "stb") -- TODO: half
  59. if is_plat("linux") then
  60. add_deps("libuuid")
  61. end
  62. on_check(function (package)
  63. assert(package:is_arch64(), "package(luisa-compute) only support 64 bit")
  64. end)
  65. on_load(function (package)
  66. if package:config("gui") then
  67. package:add("deps", "glfw")
  68. package:add("defines", "LUISA_USE_SYSTEM_GLFW=1")
  69. end
  70. if package:config("cuda") then
  71. package:add("deps", "cuda")
  72. end
  73. if package:config("vulkan") then
  74. package:add("deps", "vulkansdk")
  75. package:add("defines", "LUISA_USE_SYSTEM_VULKAN=1")
  76. end
  77. end)
  78. on_install("windows|x64", "linux", "macosx", function (package)
  79. if package:has_tool("cxx", "cl") then
  80. package:add("cxflags", "/Zc:preprocessor", "/Zc:__cplusplus")
  81. end
  82. local configs = {
  83. "-DLUISA_COMPUTE_ENABLE_SCCACHE=OFF",
  84. "-DLUISA_COMPUTE_BUILD_TESTS=OFF",
  85. "-DLUISA_COMPUTE_USE_SYSTEM_LIBS=ON",
  86. "-DLUISA_COMPUTE_ENABLE_RUST=OFF",
  87. "-DLUISA_COMPUTE_ENABLE_REMOTE=OFF",
  88. }
  89. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  90. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  91. table.insert(configs, "-DLUISA_COMPUTE_ENABLE_UNITY_BUILD=" .. (not package:is_plat("linux") and "ON" or "OFF"))
  92. table.insert(configs, "-DLUISA_COMPUTE_ENABLE_LTO=" .. (package:config("lto") and "ON" or "OFF"))
  93. table.insert(configs, "-DLUISA_COMPUTE_ENABLE_SANITIZERS=" .. (package:config("asan") and "ON" or "OFF"))
  94. if package:is_plat("windows") and package:is_debug() then
  95. -- xmake default flags will break unity build
  96. table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=")
  97. end
  98. table.insert(configs, "-DLUISA_COMPUTE_ENABLE_CUDA=" .. (package:config("cuda") and "ON" or "OFF"))
  99. table.insert(configs, "-DLUISA_COMPUTE_ENABLE_VULKAN=" .. (package:config("vulkan") and "ON" or "OFF"))
  100. table.insert(configs, "-DLUISA_COMPUTE_ENABLE_CPU=" .. (package:config("cpu") and "ON" or "OFF"))
  101. table.insert(configs, "-DLUISA_COMPUTE_ENABLE_GUI=" .. (package:config("gui") and "ON" or "OFF"))
  102. os.vcp(package:dep("stb"):installdir("include/stb"), "src/ext/stb/")
  103. import("package.tools.cmake").install(package, configs)
  104. if package:is_plat("windows") and package:is_debug() then
  105. local dir = package.builddir and package:builddir() or package:buildir()
  106. os.vcp(path.join(dir, "lib/*.pdb"), package:installdir("bin"))
  107. end
  108. end)
  109. on_test(function (package)
  110. assert(package:check_cxxsnippets({test = [[
  111. #include <luisa/luisa-compute.h>
  112. #include <luisa/dsl/sugar.h>
  113. void test(int argc, char *argv[]) {
  114. luisa::compute::Context context{argv[0]};
  115. luisa::compute::Device device = context.create_device("cuda");
  116. luisa::compute::Stream stream = device.create_stream();
  117. }
  118. ]]}, {configs = {languages = "c++20"}}))
  119. end)