xmake.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package("openxr")
  2. set_homepage("https://khronos.org/openxr")
  3. set_description("Generated headers and sources for OpenXR loader.")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/KhronosGroup/OpenXR-SDK.git", {alias = "git"})
  6. add_urls("https://github.com/KhronosGroup/OpenXR-SDK/archive/refs/tags/release-$(version).tar.gz")
  7. add_versions("1.1.49", "74e9260a1876b0540171571a09bad853302ec68a911200321be8b0591ca94111")
  8. add_versions("git:1.1.49", "release-1.1.49")
  9. add_patches("1.1.49", "patches/1.1.49/fix-mingw.diff", "8cc18048e3be5f64e6f2038303bcfff7137290cf60785ff795d3d57ef1a717b3")
  10. add_patches("1.1.49", "patches/1.1.49/fix-freebsd.diff", "f4b63875a75609d2c4ce112f67e74713edb25eb238e9a544441f534a87b523b9")
  11. add_patches("1.1.49", "patches/1.1.49/ppc-support.diff", "1bb423ec10110f9003803c63d50154f60ba063917c34f066f12e957eef4424c0")
  12. add_configs("api_layers", {description = "Build the API layers.", default = false, type = "boolean"})
  13. if is_plat("mingw") and is_subhost("msys") then
  14. add_extsources("pacman::openxr-sdk")
  15. elseif is_plat("linux") then
  16. add_extsources("pacman::openxr", "apt::libopenxr-dev")
  17. end
  18. add_deps("cmake", "python 3.x", {kind = "binary"})
  19. add_deps("jsoncpp")
  20. if is_plat("linux", "cross", "bsd") then
  21. add_deps("libx11")
  22. elseif is_plat("android") then
  23. add_deps("egl-headers")
  24. end
  25. if is_plat("windows", "mingw") then
  26. add_syslinks("advapi32")
  27. elseif is_plat("linux", "bsd") then
  28. add_syslinks("pthread")
  29. elseif is_plat("android") then
  30. add_syslinks("log", "android")
  31. elseif is_plat("macosx") then
  32. add_frameworks("AppKit", "Foundation", "CoreGraphics")
  33. elseif is_plat("iphoneos") then
  34. add_frameworks("Foundation", "CoreGraphics", "OpenGLES")
  35. end
  36. on_install("!wasm", function (package)
  37. io.replace("src/CMakeLists.txt", "set(CMAKE_POSITION_INDEPENDENT_CODE ON)", "", {plain = true})
  38. if package:is_plat("mingw") then
  39. io.replace("src/loader/openxr-loader.def", "LIBRARY", "LIBRARY libopenxr_loader.dll", {plain = true})
  40. elseif package:is_plat("windows") then
  41. local runtime
  42. if package:has_runtime("MT") then
  43. runtime = "MultiThreaded"
  44. elseif package:has_runtime("MTd") then
  45. runtime = "MultiThreadedDebug"
  46. elseif package:has_runtime("MD") then
  47. runtime = "MultiThreadedDLL"
  48. elseif package:has_runtime("MDd") then
  49. runtime = "MultiThreadedDebugDLL"
  50. end
  51. io.replace("src/loader/CMakeLists.txt", "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL", runtime, {plain = true})
  52. io.replace("src/loader/CMakeLists.txt", "MultiThreaded$<$<CONFIG:Debug>:Debug>", runtime, {plain = true})
  53. end
  54. local configs = {
  55. "-DBUILD_CONFORMANCE_TESTS=OFF",
  56. "-DBUILD_TESTS=OFF",
  57. "-DOPENXR_DEBUG_POSTFIX=''",
  58. "-DBUILD_WITH_SYSTEM_JSONCPP=ON",
  59. }
  60. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  61. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  62. table.insert(configs, "-DDYNAMIC_LOADER=" .. (package:config("shared") and "ON" or "OFF"))
  63. table.insert(configs, "-DBUILD_API_LAYERS=" .. (package:config("api_layers") and "ON" or "OFF"))
  64. if package:is_plat("android") then
  65. table.insert(configs, "-DINSTALL_TO_ARCHITECTURE_PREFIXES=ON")
  66. os.vcp("include", package:installdir())
  67. end
  68. import("package.tools.cmake").install(package, configs, {packagedeps = "libx11"})
  69. end)
  70. on_test(function (package)
  71. assert(package:check_cxxsnippets({test = [[
  72. #include <openxr/openxr.h>
  73. #include <iostream>
  74. #include <cstring>
  75. void test() {
  76. XrInstanceCreateInfo createInfo = {};
  77. createInfo.type = XR_TYPE_INSTANCE_CREATE_INFO;
  78. strcpy(createInfo.applicationInfo.applicationName, "OpenXRTest");
  79. createInfo.applicationInfo.applicationVersion = 1;
  80. strcpy(createInfo.applicationInfo.engineName, "NoEngine");
  81. createInfo.applicationInfo.engineVersion = 1;
  82. createInfo.applicationInfo.apiVersion = XR_CURRENT_API_VERSION;
  83. XrInstance instance = XR_NULL_HANDLE;
  84. XrResult result = xrCreateInstance(&createInfo, &instance);
  85. if (result == XR_SUCCESS) {
  86. std::cout << "OpenXR instance created successfully." << std::endl;
  87. xrDestroyInstance(instance);
  88. } else {
  89. std::cerr << "Failed to create OpenXR instance. Error: " << result << std::endl;
  90. }
  91. }
  92. ]]}, {configs = {languages = "c++11"}}))
  93. end)