2
0

xmake.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package("libmobi")
  2. set_homepage("https://github.com/bfabiszewski/libmobi")
  3. set_description("C library for handling Kindle (MOBI) formats of ebook documents")
  4. set_license("MIT")
  5. set_urls("https://github.com/bfabiszewski/libmobi/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/bfabiszewski/libmobi.git")
  7. add_versions("v0.12", "78826d161c02ce93ff1cd62838b4d749df754f52185474b82e4093badf4689c1")
  8. add_configs("encryption", {description = "Enable encryption", default = false, type = "boolean"})
  9. add_configs("xmlwriter", {description = "Enable xmlwriter (for opf support)", default = false, type = "boolean"})
  10. add_configs("libxml2", {description = "Use libxml2 instead of internal xmlwriter", default = false, type = "boolean"})
  11. add_configs("zlib", {description = "Use zlib", default = false, type = "boolean"})
  12. add_configs("tools", {description = "Build tools", default = false, type = "boolean"})
  13. if is_plat("linux", "bsd") then
  14. add_syslinks("pthread")
  15. end
  16. on_load(function (package)
  17. if package:config("libxml2") then
  18. package:add("deps", "libxml2")
  19. end
  20. if package:config("zlib") then
  21. package:add("deps", "zlib")
  22. else
  23. package:add("deps", "miniz", {configs = {cmake = true}})
  24. end
  25. end)
  26. on_install(function (package)
  27. io.replace("CMakeLists.txt", "-Werror", "", {plain = true})
  28. io.replace("CMakeLists.txt", "cmake_minimum_required(VERSION 3.12)", "cmake_minimum_required(VERSION 3.13)", {plain = true})
  29. io.replace("src/CMakeLists.txt", "${CMAKE_CURRENT_SOURCE_DIR}/xmlwriter.c", "", {plain = true})
  30. if package:config("libxml2") then
  31. io.replace("CMakeLists.txt", "find_package(LibXml2 REQUIRED)", "find_package(LibXml2 CONFIG REQUIRED)", {plain = true})
  32. end
  33. if not package:config("tools") then
  34. io.replace("CMakeLists.txt", "add_subdirectory(tools)", "", {plain = true})
  35. end
  36. local cmake = io.readfile("CMakeLists.txt") .. [[
  37. include(GNUInstallDirs)
  38. install(TARGETS mobi
  39. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  40. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  41. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  42. )
  43. install(FILES src/mobi.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  44. ]]
  45. if not package:config("zlib") then
  46. cmake = cmake .. [[
  47. find_package(miniz REQUIRED)
  48. target_link_libraries(mobi PRIVATE miniz::miniz)
  49. ]]
  50. end
  51. io.writefile("CMakeLists.txt", cmake)
  52. if not package:config("shared") then
  53. io.replace("src/mobi.h", "__declspec(dllexport)", "", {plain = true})
  54. end
  55. local configs = {}
  56. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  57. table.insert(configs, "-DMOBI_DEBUG=" .. (package:is_debug() and "ON" or "OFF"))
  58. table.insert(configs, "-DMOBI_DEBUG_ALLOC=" .. (package:is_debug() and "ON" or "OFF"))
  59. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  60. table.insert(configs, "-DUSE_ENCRYPTION=" .. (package:config("encryption") and "ON" or "OFF"))
  61. table.insert(configs, "-DUSE_LIBXML2=" .. (package:config("libxml2") and "ON" or "OFF"))
  62. table.insert(configs, "-DUSE_ZLIB=" .. (package:config("zlib") and "ON" or "OFF"))
  63. table.insert(configs, "-DUSE_XMLWRITER=" .. (package:config("xmlwriter") and "ON" or "OFF"))
  64. local opt = {}
  65. if package:is_plat("windows") then
  66. opt.cxflags = "-D_CRT_SECURE_NO_WARNINGS"
  67. end
  68. import("package.tools.cmake").install(package, configs, opt)
  69. if package:config("shared") then
  70. io.replace(path.join(package:installdir("include"), "mobi.h"), "__declspec(dllexport)", "__declspec(dllimport)", {plain = true})
  71. end
  72. end)
  73. on_test(function (package)
  74. assert(package:has_cfuncs("mobi_init", {includes = "mobi.h"}))
  75. end)