xmake.lua 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.11.6", "ef0ac1bd1fe4d84b38cde12fbaa7a441d41bfbd567434b9a57ef8b79a8367e74")
  10. add_versions("1.12.1", "debc6d5d5eb946bb14e47cffc33db4fffb4f11765f34f8db04e71e866d1af8f9")
  11. add_versions("1.12.2", "30442ccb097a0074133f699213a59d6f8c77db5b2c98a7c1ad9c5eeb3a2b06f3")
  12. add_versions("1.12.4", "71ef96c35fced367d6da74da294510ad2c912563f12cd716ab02b6ed10a733ef")
  13. if is_plat("windows") then
  14. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  15. end
  16. add_configs("mysql", {description = "Enable mysql support.", default = false, type = "boolean"})
  17. add_configs("postgresql", {description = "Enable postgresql support.", default = false, type = "boolean"})
  18. add_configs("odbc", {description = "Enable odbc support.", default = is_plat("windows"), type = "boolean"})
  19. add_deps("cmake")
  20. add_deps("openssl", "sqlite3", "expat", "zlib")
  21. add_defines("POCO_NO_AUTOMATIC_LIBS")
  22. on_load("windows", "linux", "macosx", function (package)
  23. if package:config("postgresql") then
  24. package:add("deps", "postgresql")
  25. end
  26. if package:config("mysql") then
  27. package:add("deps", "mysql")
  28. end
  29. if package:version():ge("1.12.0") then
  30. package:add("deps", "pcre2")
  31. else
  32. package:add("deps", "pcre")
  33. end
  34. end)
  35. on_install("windows", "linux", "macosx", function (package)
  36. io.replace("XML/CMakeLists.txt", "EXPAT REQUIRED", "EXPAT CONFIG REQUIRED")
  37. io.replace("XML/CMakeLists.txt", "EXPAT::EXPAT", "expat::expat")
  38. io.replace("XML/CMakeLists.txt", "PUBLIC POCO_UNBUNDLED", "PUBLIC POCO_UNBUNDLED XML_DTD XML_NS")
  39. io.replace("Foundation/CMakeLists.txt", "PUBLIC POCO_UNBUNDLED", "PUBLIC POCO_UNBUNDLED PCRE_STATIC")
  40. io.replace("Foundation/CMakeLists.txt", "POCO_SOURCES%(SRCS RegExp.-%)", "")
  41. if package:version():ge("1.12.0") and package:dep("pcre2"):exists() and not package:dep("pcre2"):config("shared") then
  42. io.replace("cmake/FindPCRE2.cmake", "NAMES pcre2-8", "NAMES pcre2-8-static pcre2-8", {plain = true})
  43. io.replace("cmake/FindPCRE2.cmake", "IMPORTED_LOCATION \"${PCRE2_LIBRARY}\"", "IMPORTED_LOCATION \"${PCRE2_LIBRARY}\"\nINTERFACE_COMPILE_DEFINITIONS PCRE2_STATIC", {plain = true})
  44. end
  45. local configs = {"-DPOCO_UNBUNDLED=ON", "-DENABLE_TESTS=OFF", "-DENABLE_PDF=ON"}
  46. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  47. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  48. if package:is_plat("windows") and not package:config("shared") then
  49. table.insert(configs, "-DPOCO_MT=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))
  50. end
  51. if package:is_plat("windows") then
  52. local vs_sdkver = import("core.tool.toolchain").load("msvc"):config("vs_sdkver")
  53. if vs_sdkver then
  54. local build_ver = string.match(vs_sdkver, "%d+%.%d+%.(%d+)%.?%d*")
  55. assert(tonumber(build_ver) >= 18362, "poco requires Windows SDK to be at least 10.0.18362.0")
  56. table.insert(configs, "-DCMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION=" .. vs_sdkver)
  57. table.insert(configs, "-DCMAKE_SYSTEM_VERSION=" .. vs_sdkver)
  58. end
  59. end
  60. for _, lib in ipairs({"mysql", "postgresql", "odbc"}) do
  61. table.insert(configs, "-DENABLE_DATA_" .. lib:upper() .. "=" .. (package:config(lib) and "ON" or "OFF"))
  62. end
  63. -- warning: only works on windows sdk 10.0.18362.0 and later
  64. import("package.tools.cmake").install(package, configs)
  65. end)
  66. on_test(function (package)
  67. assert(package:has_cxxtypes("Poco::BasicEvent<int>", {configs = {languages = "c++14"}, includes = "Poco/BasicEvent.h"}))
  68. end)