2
0

xmake.lua 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. package("diligentcore")
  2. set_homepage("http://diligentgraphics.com/diligent-engine/")
  3. set_description("A modern cross-platform low-level graphics API")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/DiligentGraphics/DiligentCore/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/DiligentGraphics/DiligentCore.git", {submodules = false})
  7. add_versions("v2.5.6", "abc190c05ee7e5ef2bba52fcbc5fdfe2256cce3435efba9cfe263a386653f671")
  8. add_patches("v2.5.6", "patches/v2.5.6/debundle-thirdparty.diff", "3d276a78e9ae47516668229dcb644f328a3602d389a3d73784eeb52d8a53108d")
  9. add_patches("v2.5.6", "patches/v2.5.6/enforce-static-lib-type-for-platform-libraries.diff", "ee88a2a04348dcc9de7960a87ff5dc1fb1b534caf1f6224bb2d0c88d37a4bc53")
  10. add_patches("v2.5.6", "patches/v2.5.6/fix-build-deps-pkgconf.diff", "9998204546cf551a48301e972b582eeeaf002607a4f474086d7d80f4762451ee")
  11. add_patches("v2.5.6", "patches/v2.5.6/fix-install-path.diff", "0fa50da9946dff8e57713edc4a224b8b54c548242e1c556d3dc11354eb69b2c1")
  12. add_patches("v2.5.6", "patches/v2.5.6/fix-spirv-cross-namespace.diff", "d5a866d4b5bce061a3597dcc026cb88c4b9f92af352ef4071750d355b8b924f0")
  13. add_includedirs("include", "include/DiligentCore")
  14. add_deps("pkgconf")
  15. if is_plat("windows", "linux", "mingw", "macosx") then
  16. add_configs("opengl", {description = "Enable OpenGL/GLES backend", default = true, type = "boolean"})
  17. end
  18. if is_plat("windows") then
  19. add_configs("d3d11", {description = "Enable Direct3D11 backend", default = true, type = "boolean"})
  20. add_configs("d3d12", {description = "Enable Direct3D12 backend", default = true, type = "boolean"})
  21. end
  22. add_configs("vulkan", {description = "Enable Vulkan backend", default = true, type = "boolean"})
  23. add_configs("hlsl", {description = "Enable HLSL", default = true, type = "boolean"})
  24. add_configs("glslang", {description = "Enable GLSLang", default = true, type = "boolean"})
  25. add_configs("archiver", {description = "Enable archiver", default = true, type = "boolean"})
  26. add_configs("format_validation", {description = "Enable format validation", default = false, type = "boolean"})
  27. if is_plat("linux") then
  28. add_syslinks("pthread", "dl")
  29. end
  30. if is_plat("macosx") then
  31. add_frameworks("AppKit")
  32. elseif is_plat("iphoneos") then
  33. add_frameworks("CoreFoundation", "Foundation", "OpenGLES")
  34. end
  35. add_deps("cmake")
  36. add_deps("xxhash")
  37. if is_plat("linux") then
  38. add_deps("libx11", "libxrandr", "libxrender", "libxinerama", "libxfixes", "libxcursor", "libxi", "libxext", "wayland")
  39. end
  40. on_load(function (package)
  41. if package:is_plat("windows") then
  42. package:add("defines", "NOMINMAX", "WIN32_LEAN_AND_MEAN", "UNICODE")
  43. end
  44. if package:config("shared") then
  45. package:add("defines", "ENGINE_DLL=1")
  46. end
  47. if package:config("opengl") then
  48. package:add("deps", "opengl", "glew")
  49. if package:is_plat("macosx") then
  50. package:add("frameworks", "OpenGL")
  51. end
  52. end
  53. if package:config("vulkan") then
  54. package:add("deps", "vulkan-headers")
  55. package:add("deps", "volk", {configs = {header_only = true}})
  56. end
  57. if package:config("vulkan") or (package:config("archiver") and package:config("opengl")) then
  58. package:add("deps", "spirv-headers")
  59. end
  60. if package:config("hlsl") or package:config("archiver") or package:config("glslang") then
  61. if package:is_plat("linux") then
  62. package:add("deps", "glslang", {configs = {shared = true}})
  63. else
  64. package:add("deps", "glslang")
  65. end
  66. package:add("deps", "spirv-tools")
  67. end
  68. package:add("deps", "spirv-cross")
  69. end)
  70. on_install("windows", "linux", "macosx", function (package)
  71. -- Do not enforce /GL
  72. io.replace("CMakeLists.txt", [[set(DEFAULT_DILIGENT_MSVC_RELEASE_COMPILE_OPTIONS /GL)]], [[]], {plain = true})
  73. -- Dump CMakeLists.txt variables related for platform & rendering backend for package defines
  74. local CMakeLists_content = io.readfile("CMakeLists.txt")
  75. io.writefile("CMakeLists.txt", CMakeLists_content .. [[
  76. get_cmake_property(vars VARIABLES)
  77. list(SORT vars)
  78. set(TARGET_VARS
  79. PLATFORM_ANDROID PLATFORM_EMSCRIPTEN PLATFORM_IOS PLATFORM_LINUX PLATFORM_MACOS PLATFORM_TVOS PLATFORM_UNIVERSAL_WINDOWS PLATFORM_WIN32
  80. ARCHIVER_SUPPORTED D3D11_SUPPORTED D3D12_SUPPORTED GLES_SUPPORTED GL_SUPPORTED METAL_SUPPORTED VULKAN_SUPPORTED WEBGPU_SUPPORTED
  81. )
  82. file(WRITE "${CMAKE_BINARY_DIR}/variables.txt" "")
  83. foreach(var IN LISTS vars)
  84. if(var IN_LIST TARGET_VARS)
  85. file(APPEND "${CMAKE_BINARY_DIR}/variables.txt" "${var}=${${var}}\n")
  86. endif()
  87. endforeach()
  88. ]])
  89. local configs = {"-DDILIGENT_INSTALL_CORE=ON"}
  90. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  91. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  92. table.insert(configs, "-DDILIGENT_INSTALL_PDB=" .. (package:is_debug() and "ON" or "OFF"))
  93. table.insert(configs, "-DDILIGENT_DEVELOPMENT=" .. (package:is_debug() and "ON" or "OFF"))
  94. table.insert(configs, "-DDILIGENT_NO_OPENGL=" .. (package:config("opengl") and "OFF" or "ON"))
  95. table.insert(configs, "-DDILIGENT_NO_DIRECT3D11=" .. (package:config("d3d11") and "OFF" or "ON"))
  96. table.insert(configs, "-DDILIGENT_NO_DIRECT3D12=" .. (package:config("d3d12") and "OFF" or "ON"))
  97. table.insert(configs, "-DDILIGENT_NO_VULKAN=" .. (package:config("vulkan") and "OFF" or "ON"))
  98. table.insert(configs, "-DDILIGENT_NO_ARCHIVER=" .. (package:config("archiver") and "OFF" or "ON"))
  99. table.insert(configs, "-DDILIGENT_NO_HLSL=" .. (package:config("hlsl") and "OFF" or "ON"))
  100. table.insert(configs, "-DDILIGENT_NO_GLSLANG=" .. (package:config("glslang") and "OFF" or "ON"))
  101. table.insert(configs, "-DDILIGENT_NO_FORMAT_VALIDATION=" .. (package:config("format_validation") and "OFF" or "ON"))
  102. import("package.tools.cmake").install(package, configs)
  103. -- Gather missing defines into *data* so we could gather *data* for on_test
  104. local vars_file = path.join(package:buildir(), "variables.txt")
  105. if os.isfile(vars_file) then
  106. local content = io.readfile(vars_file)
  107. for _, line in ipairs(content:split("\n")) do
  108. line = line:trim()
  109. if #line > 0 then
  110. local var, value = line:match("^([^=]+)=(.+)$")
  111. if var and value == "TRUE" then
  112. package:add("defines", var)
  113. end
  114. end
  115. end
  116. end
  117. -- Move every folder of $(builddir)/include into prepended folder include/DiligentCore
  118. local target_dir = path.join(package:installdir("include"), "DiligentCore")
  119. os.mkdir(target_dir)
  120. for _, dir in ipairs(os.dirs(package:installdir("include/*"))) do
  121. if dir ~= target_dir then
  122. os.mv(dir, target_dir)
  123. end
  124. end
  125. end)
  126. on_test(function (package)
  127. if package:config("opengl") then
  128. assert(package:check_cxxsnippets({test = [[
  129. #include <DiligentCore/Graphics/GraphicsEngineOpenGL/interface/EngineFactoryOpenGL.h>
  130. void test() {
  131. Diligent::EngineGLCreateInfo create_info;
  132. Diligent::IEngineFactoryOpenGL* factory = nullptr;
  133. Diligent::SwapChainDesc scd;
  134. factory->CreateDeviceAndSwapChainGL(create_info, nullptr, nullptr, scd, nullptr);
  135. }
  136. ]]}, {configs = {languages = "c++17"}}))
  137. end
  138. if package:config("d3d11") then
  139. assert(package:check_cxxsnippets({test = [[
  140. #include <DiligentCore/Graphics/GraphicsEngineD3D11/interface/EngineFactoryD3D11.h>
  141. void test() {
  142. Diligent::EngineD3D11CreateInfo create_info;
  143. Diligent::IEngineFactoryD3D11* factory = nullptr;
  144. factory->CreateDeviceAndContextsD3D11(create_info, nullptr, nullptr);
  145. }
  146. ]]}, {configs = {languages = "c++17"}}))
  147. end
  148. if package:config("d3d12") then
  149. assert(package:check_cxxsnippets({test = [[
  150. #include <DiligentCore/Graphics/GraphicsEngineD3D12/interface/EngineFactoryD3D12.h>
  151. void test() {
  152. Diligent::EngineD3D12CreateInfo create_info;
  153. Diligent::IEngineFactoryD3D12* factory = nullptr;
  154. factory->CreateDeviceAndContextsD3D12(create_info, nullptr, nullptr);
  155. }
  156. ]]}, {configs = {languages = "c++17"}}))
  157. end
  158. if package:config("vulkan") then
  159. assert(package:check_cxxsnippets({test = [[
  160. #include <DiligentCore/Graphics/GraphicsEngineVulkan/interface/EngineFactoryVk.h>
  161. void test() {
  162. Diligent::EngineVkCreateInfo create_info;
  163. Diligent::IEngineFactoryVk* factory = nullptr;
  164. factory->CreateDeviceAndContextsVk(create_info, nullptr, nullptr);
  165. }
  166. ]]}, {configs = {languages = "c++17"}}))
  167. end
  168. end)