2
0

xmake.lua 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package("poco")
  2. set_homepage("https://pocoproject.org/")
  3. set_description("The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.")
  4. set_license("BSL-1.0")
  5. add_urls("https://github.com/pocoproject/poco/archive/refs/tags/poco-$(version)-release.tar.gz",
  6. "https://github.com/pocoproject/poco.git")
  7. add_versions("1.11.0", "8a7bfd0883ee95e223058edce8364c7d61026ac1882e29643822ce9b753f3602")
  8. add_versions("1.11.1", "2412a5819a239ff2ee58f81033bcc39c40460d7a8b330013a687c8c0bd2b4ac0")
  9. add_versions("1.12.1", "debc6d5d5eb946bb14e47cffc33db4fffb4f11765f34f8db04e71e866d1af8f9")
  10. if is_plat("windows") then
  11. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  12. end
  13. add_configs("mysql", {description = "Enable mysql support.", default = false, type = "boolean"})
  14. add_configs("postgresql", {description = "Enable postgresql support.", default = false, type = "boolean"})
  15. add_configs("odbc", {description = "Enable odbc support.", default = is_plat("windows"), type = "boolean"})
  16. add_deps("cmake")
  17. add_deps("openssl", "sqlite3", "expat", "zlib")
  18. add_defines("POCO_NO_AUTOMATIC_LIBS")
  19. on_load("windows", "linux", "macosx", function (package)
  20. if package:config("postgresql") then
  21. package:add("deps", "postgresql")
  22. end
  23. if package:config("mysql") then
  24. package:add("deps", "mysql")
  25. end
  26. if package:version():ge("1.12.0") then
  27. package:add("deps", "pcre2")
  28. else
  29. package:add("deps", "pcre")
  30. end
  31. end)
  32. on_install("windows", "linux", "macosx", function (package)
  33. io.replace("XML/CMakeLists.txt", "EXPAT REQUIRED", "EXPAT CONFIG REQUIRED")
  34. io.replace("XML/CMakeLists.txt", "EXPAT::EXPAT", "expat::expat")
  35. io.replace("XML/CMakeLists.txt", "PUBLIC POCO_UNBUNDLED", "PUBLIC POCO_UNBUNDLED XML_DTD XML_NS")
  36. io.replace("Foundation/CMakeLists.txt", "PUBLIC POCO_UNBUNDLED", "PUBLIC POCO_UNBUNDLED PCRE_STATIC")
  37. io.replace("Foundation/CMakeLists.txt", "POCO_SOURCES%(SRCS RegExp.-%)", "")
  38. if package:version():ge("1.12.0") and package:dep("pcre2"):exists() and not package:dep("pcre2"):config("shared") then
  39. io.replace("cmake/FindPCRE2.cmake", "NAMES pcre2-8", "NAMES pcre2-8-static pcre2-8", {plain = true})
  40. io.replace("cmake/FindPCRE2.cmake", "IMPORTED_LOCATION \"${PCRE2_LIBRARY}\"", "IMPORTED_LOCATION \"${PCRE2_LIBRARY}\"\nINTERFACE_COMPILE_DEFINITIONS PCRE2_STATIC", {plain = true})
  41. end
  42. local configs = {"-DPOCO_UNBUNDLED=ON", "-DENABLE_TESTS=OFF", "-DENABLE_PDF=ON"}
  43. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  44. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  45. if package:is_plat("windows") and not package:config("shared") then
  46. table.insert(configs, "-DPOCO_MT=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))
  47. end
  48. if package:is_plat("windows") then
  49. local vs_sdkver = import("core.tool.toolchain").load("msvc"):config("vs_sdkver")
  50. if vs_sdkver then
  51. local build_ver = string.match(vs_sdkver, "%d+%.%d+%.(%d+)%.?%d*")
  52. assert(tonumber(build_ver) >= 18362, "poco requires Windows SDK to be at least 10.0.18362.0")
  53. table.insert(configs, "-DCMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION=" .. vs_sdkver)
  54. table.insert(configs, "-DCMAKE_SYSTEM_VERSION=" .. vs_sdkver)
  55. end
  56. end
  57. for _, lib in ipairs({"mysql", "postgresql", "odbc"}) do
  58. table.insert(configs, "-DENABLE_DATA_" .. lib:upper() .. "=" .. (package:config(lib) and "ON" or "OFF"))
  59. end
  60. -- warning: only works on windows sdk 10.0.18362.0 and later
  61. import("package.tools.cmake").install(package, configs)
  62. end)
  63. on_test(function (package)
  64. assert(package:has_cxxtypes("Poco::BasicEvent<int>", {configs = {languages = "c++14"}, includes = "Poco/BasicEvent.h"}))
  65. end)