xmake.lua 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package("llgl")
  2. set_description("Low Level Graphics Library (LLGL) is a thin abstraction layer for the modern graphics APIs OpenGL, Direct3D, Vulkan, and Metal")
  3. set_homepage("https://github.com/LukasBanana/LLGL")
  4. set_license("BSD-3-Clause")
  5. add_urls("https://github.com/LukasBanana/LLGL/archive/refs/tags/Release-$(version)b.tar.gz",
  6. "https://github.com/LukasBanana/LLGL.git")
  7. add_versions("v0.04", "fdeda39bd31522bced0d889655b290e06688975d58ab20756c3eda9a5f21391f")
  8. if not is_plat("android", "iphoneos", "wasm", "bsd", "cross") then
  9. add_configs("opengl", {description = "Enable OpenGL Renderer", default = true, type = "boolean"})
  10. end
  11. if is_plat("android", "iphoneos") then
  12. add_configs("opengles", {description = "Enable OpenGLES Renderer", default = true, type = "boolean"})
  13. end
  14. add_configs("vulkan", {description = "Enable Vulkan Renderer", default = false, type = "boolean"})
  15. add_configs("null", {description = "Enable Null Renderer", default = true, type = "boolean"})
  16. if is_plat("windows", "mingw") then
  17. add_configs("d3d11", {description = "Enable D3D11 Renderer", default = true, type = "boolean"})
  18. add_configs("d3d12", {description = "Enable D3D12 Renderer", default = true, type = "boolean"})
  19. add_syslinks("dxgi", "d3d11", "d3d12", "d3dcompiler", "comdlg32", "user32", "gdi32", "opengl32", "shell32")
  20. elseif is_plat("linux") then
  21. add_configs("wayland", {description = "Enable Wayland", default = true, type = "boolean"})
  22. add_deps("wayland", "libxrandr", "libxrender")
  23. elseif is_plat("macosx") then
  24. add_configs("metal", {description = "Enable Metal Renderer", default = true, type = "boolean"})
  25. end
  26. add_deps("cmake")
  27. add_deps("gaussianlib")
  28. if on_check then
  29. on_check("android", function (package)
  30. local ndk = package:toolchain("ndk"):config("ndkver")
  31. assert(ndk and tonumber(ndk) < 27, "package(LLGL): requires NDK version earlier than r27.")
  32. end)
  33. end
  34. on_load(function (package)
  35. if package:is_plat("android") then
  36. -- Workaround NDK bug
  37. package:add("links", "android_native_app_glue")
  38. elseif package:is_plat("iphoneos") then
  39. package:add("frameworks", "Foundation", "UIKit")
  40. elseif package:is_plat("windows", "mingw") then
  41. package:add("defines", "NOMINMAX", "WIN32_LEAN_AND_MEAN", "UNICODE", "_UNICODE")
  42. if package:config("d3d11") or package:config("d3d12") then
  43. package:add("links", "LLGL_DXCommon" .. (package:is_debug() and "D" or ""))
  44. end
  45. if package:config("d3d11") then
  46. package:add("links", "LLGL_Direct3D11" .. (package:is_debug() and "D" or ""))
  47. end
  48. if package:config("d3d12") then
  49. package:add("links", "LLGL_Direct3D12" .. (package:is_debug() and "D" or ""))
  50. end
  51. end
  52. package:add("links", "LLGL" .. (package:is_debug() and "D" or ""))
  53. if package:config("opengl") then
  54. package:add("links", "LLGL_OpenGL" .. (package:is_debug() and "D" or ""))
  55. if package:is_plat("macosx") then
  56. package:add("frameworks", "OpenGL")
  57. elseif package:is_plat("android") then
  58. package:add("syslinks", "GLESv2")
  59. end
  60. end
  61. if package:config("opengles") then
  62. package:add("links", "LLGL_OpenGLES3" .. (package:is_debug() and "D" or ""))
  63. if package:is_plat("macosx", "iphoneos") then
  64. package:add("frameworks", "Foundation", "UIKit", "QuartzCore", "OpenGLES", "GLKit")
  65. end
  66. end
  67. if package:config("metal") then
  68. package:add("links", "LLGL_Metal" .. (package:is_debug() and "D" or ""))
  69. if package:is_plat("macosx") then
  70. package:add("frameworks", "Metal", "MetalKit")
  71. end
  72. end
  73. if package:config("vulkan") then
  74. package:add("links", "LLGL_Vulkan" .. (package:is_debug() and "D" or ""))
  75. package:add("deps", "vulkansdk")
  76. end
  77. if package:config("null") then
  78. package:add("links", "LLGL_Null" .. (package:is_debug() and "D" or ""))
  79. end
  80. end)
  81. on_install("!bsd and !cross", function (package)
  82. -- Help MinGW linkage issues
  83. io.replace("sources/Renderer/DXCommon/CMakeLists.txt",
  84. [[add_library(LLGL_DXCommon STATIC "${FilesDXCommon}")]],
  85. [[add_library(LLGL_DXCommon STATIC "${FilesDXCommon}")
  86. target_link_libraries(LLGL_DXCommon PRIVATE LLGL)]], {plain = true})
  87. -- Help CMakeLists.txt to acquire UNIX-like path
  88. io.replace("CMakeLists.txt", [[if(LLGL_ANDROID_PLATFORM)
  89. set(ANDROID_APP_GLUE_DIR "$ENV{ANDROID_NDK_ROOT}/sources/android/native_app_glue")
  90. set(
  91. FilesAndroidNativeAppGlue
  92. "${ANDROID_APP_GLUE_DIR}/android_native_app_glue.c"
  93. "${ANDROID_APP_GLUE_DIR}/android_native_app_glue.h"
  94. )
  95. endif()]], [[if(LLGL_ANDROID_PLATFORM)
  96. file(TO_CMAKE_PATH "$ENV{ANDROID_NDK_ROOT}" ANDROID_NDK_ROOT_CMAKE)
  97. set(ANDROID_APP_GLUE_DIR "${ANDROID_NDK_ROOT_CMAKE}/sources/android/native_app_glue")
  98. set(FilesAndroidNativeAppGlue
  99. "${ANDROID_APP_GLUE_DIR}/android_native_app_glue.c"
  100. "${ANDROID_APP_GLUE_DIR}/android_native_app_glue.h"
  101. )
  102. endif()
  103. ]], {plain = true})
  104. -- Help MinGW acquire std::uint32_t
  105. io.replace("sources/Renderer/Direct3D12/Buffer/D3D12BufferConstantsPool.h", [[#include <d3d12.h>]], [[#include <d3d12.h>
  106. #include <cstdint>]], {plain = true})
  107. local includedir = ""
  108. local fetchinfo = package:dep("gaussianlib"):fetch()
  109. if fetchinfo then
  110. includedir = table.concat(fetchinfo.includedirs or fetchinfo.sysincludedirs, ";")
  111. end
  112. local configs = {"-DLLGL_BUILD_TESTS=OFF", "-DLLGL_BUILD_EXAMPLES=OFF"}
  113. table.insert(configs, "-DLLGL_BUILD_STATIC_LIB=" .. (package:config("shared") and "OFF" or "ON"))
  114. table.insert(configs, "-DLLGL_BUILD_RENDERER_OPENGL=" .. (package:config("opengl") and "ON" or "OFF"))
  115. table.insert(configs, "-DLLGL_BUILD_RENDERER_OPENGLES3=" .. (package:config("opengles") and "ON" or "OFF"))
  116. table.insert(configs, "-DLLGL_BUILD_RENDERER_DIRECT3D11=" .. (package:config("d3d11") and "ON" or "OFF"))
  117. table.insert(configs, "-DLLGL_BUILD_RENDERER_DIRECT3D12=" .. (package:config("d3d12") and "ON" or "OFF"))
  118. table.insert(configs, "-DLLGL_BUILD_RENDERER_VULKAN=" .. (package:config("vulkan") and "ON" or "OFF"))
  119. table.insert(configs, "-DLLGL_BUILD_RENDERER_NULL=" .. (package:config("null") and "ON" or "OFF"))
  120. table.insert(configs, "-DLLGL_LINUX_ENABLE_WAYLAND=" .. (package:config("wayland") and "ON" or "OFF"))
  121. table.insert(configs, "-DLLGL_BUILD_RENDERER_METAL=" .. (package:config("metal") and "ON" or "OFF"))
  122. table.insert(configs, "-DGaussLib_INCLUDE_DIR=" .. includedir)
  123. local opt = {}
  124. if package:is_plat("linux") then
  125. opt.packagedeps = {"wayland", "libxrandr", "libxrender"}
  126. end
  127. import("package.tools.cmake").install(package, configs, opt)
  128. if package:is_plat("android") then
  129. -- Workaround NDK bug
  130. local ndk = package:toolchain("ndk")
  131. local ndk_path = ndk:config("ndk")
  132. os.cp(path.join(ndk_path, "sources", "android", "native_app_glue", "android_native_app_glue.h"), path.join(package:installdir("include"), "android_native_app_glue.h"))
  133. end
  134. end)
  135. on_test(function (package)
  136. assert(package:check_cxxsnippets({test = [[
  137. #include <LLGL/LLGL.h>
  138. void test() {
  139. auto t = LLGL::Timer::Tick();
  140. }
  141. ]]}, {configs = {languages = "c++11"}}))
  142. end)