xmake.lua 5.9 KB

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