xmake.lua 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package("ktx")
  2. set_homepage("https://github.com/KhronosGroup/KTX-Software")
  3. set_description("KTX (Khronos Texture) Library and Tools")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/KhronosGroup/KTX-Software/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/KhronosGroup/KTX-Software.git", {submodules = false})
  7. add_versions("v4.4.0", "3585d76edcdcbe3a671479686f8c81c1c10339f419e4b02a9a6f19cc6e4e0612")
  8. add_patches("4.4.0", "patches/4.4.0/dep-unbundle.patch", "2b883bcbfc19f80d72b812d68b606b6e2a4234d913ad92c45d8030bd94207a59")
  9. add_configs("tools", {description = "Create KTX tools", default = false, type = "boolean"})
  10. add_configs("decoder", {description = "ETC decoding support", default = false, type = "boolean"})
  11. add_configs("opencl", {description = "Compile with OpenCL support so applications can choose to use it.", default = false, type = "boolean"})
  12. add_configs("embed", {description = "Embed bitcode in binaries.", default = false, type = "boolean"})
  13. add_configs("ktx1", {description = "Enable KTX 1 support.", default = true, type = "boolean"})
  14. add_configs("ktx2", {description = "Enable KTX 2 support.", default = true, type = "boolean"})
  15. add_configs("vulkan", {description = "Enable Vulkan texture upload.", default = false, type = "boolean"})
  16. add_configs("opengl", {description = "Enable OpenGL texture upload.", default = is_plat("wasm"), type = "boolean"})
  17. -- This project .def file export 64-bit symbols only
  18. if is_plat("wasm", "iphoneos") or (is_plat("windows", "mingw") and is_arch("x86", "i386")) then
  19. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  20. end
  21. add_deps("cmake")
  22. if is_subhost("windows") then
  23. add_deps("pkgconf")
  24. else
  25. add_deps("pkg-config")
  26. end
  27. add_deps("astc-encoder", "zstd")
  28. -- TODO
  29. if is_plat("iphoneos") then
  30. add_includedirs("lib/ktx.framework/Headers")
  31. add_linkdirs("lib/ktx.framework")
  32. add_frameworkdirs("lib/ktx.framework")
  33. add_frameworks("ktx")
  34. end
  35. on_check(function (package)
  36. if is_subhost("windows") and os.arch() == "arm64" then
  37. raise("package(ktx) require python (from pkgconf) for building, but windows arm64 python binaries are unsupported")
  38. end
  39. if package:is_plat("linux") and package:is_arch("arm64") then
  40. raise("package(ktx) dep(astc-encoder) unsupported linux arm64")
  41. end
  42. end)
  43. on_load(function (package)
  44. if package:config("tools") then
  45. package:add("deps", "fmt", "cxxopts", {private = true})
  46. end
  47. if not package:config("shared") then
  48. package:add("defines", "KHRONOS_STATIC")
  49. end
  50. if package:config("ktx1") then
  51. package:add("defines", "KTX_FEATURE_KTX1")
  52. end
  53. if package:config("ktx2") then
  54. package:add("defines", "KTX_FEATURE_KTX2")
  55. end
  56. end)
  57. on_install("!iphoneos and !wasm", function (package)
  58. if package:has_runtime("MD", "MT") then
  59. io.replace("CMakeLists.txt", "_DEBUG", "", {plain = true})
  60. end
  61. -- TODO: unbundle basisu & dfdutils
  62. -- io.replace("CMakeLists.txt", "external/dfdutils%g*.c\n", "")
  63. -- io.replace("CMakeLists.txt", "external%g*.cpp\n", "")
  64. io.writefile("external/basisu/zstd/zstd.c", "")
  65. io.replace("CMakeLists.txt", "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/external/basisu/zstd>", "", {plain = true})
  66. io.replace("CMakeLists.txt", "$ $<INSTALL_INTERFACE:external/basisu/zstd>", "", {plain = true})
  67. local file = io.open("CMakeLists.txt", "a")
  68. file:write([[
  69. include(FindPkgConfig)
  70. pkg_search_module("libzstd" REQUIRED IMPORTED_TARGET "libzstd")
  71. target_link_libraries(ktx PUBLIC PkgConfig::libzstd)
  72. target_link_libraries(ktx_read PUBLIC PkgConfig::libzstd)
  73. ]])
  74. file:close()
  75. if package:config("tools") then
  76. io.replace("CMakeLists.txt", "add_subdirectory(external/fmt)", "find_package(fmt CONFIG REQUIRED)", {plain = true})
  77. io.replace("CMakeLists.txt", "add_subdirectory(external/cxxopts)", "find_package(cxxopts CONFIG REQUIRED)", {plain = true})
  78. end
  79. local configs = {"-DKTX_FEATURE_TESTS=OFF"}
  80. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  81. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  82. if not package:gitref() and package:version():startswith("v") then
  83. table.insert(configs, "-DKTX_GIT_VERSION_FULL=" .. package:version())
  84. end
  85. table.insert(configs, "-DKTX_FEATURE_TOOLS=" .. (package:config("tools") and "ON" or "OFF"))
  86. table.insert(configs, "-DKTX_FEATURE_ETC_UNPACK=" .. (package:config("decoder") and "ON" or "OFF"))
  87. table.insert(configs, "-DBASISU_SUPPORT_OPENCL=" .. (package:config("opencl") and "ON" or "OFF"))
  88. table.insert(configs, "-DKTX_EMBED_BITCODE=" .. (package:config("embed") and "ON" or "OFF"))
  89. table.insert(configs, "-DKTX_FEATURE_KTX1=" .. (package:config("ktx1") and "ON" or "OFF"))
  90. table.insert(configs, "-DKTX_FEATURE_KTX2=" .. (package:config("ktx2") and "ON" or "OFF"))
  91. table.insert(configs, "-DKTX_FEATURE_VK_UPLOAD=" .. (package:config("vulkan") and "ON" or "OFF"))
  92. table.insert(configs, "-DKTX_FEATURE_GL_UPLOAD=" .. (package:config("opengl") and "ON" or "OFF"))
  93. import("package.tools.cmake").install(package, configs)
  94. end)
  95. on_test(function (package)
  96. assert(package:has_cfuncs("ktxErrorString", {includes = "ktx.h"}))
  97. end)