xmake.lua 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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.11.8", "a59727335a9bf428dc1289cd8ce84f9c1749c1472a0cd3ae86bec85be23d7cbe")
  11. add_versions("1.12.1", "debc6d5d5eb946bb14e47cffc33db4fffb4f11765f34f8db04e71e866d1af8f9")
  12. add_versions("1.12.2", "30442ccb097a0074133f699213a59d6f8c77db5b2c98a7c1ad9c5eeb3a2b06f3")
  13. add_versions("1.12.4", "71ef96c35fced367d6da74da294510ad2c912563f12cd716ab02b6ed10a733ef")
  14. add_versions("1.12.5", "92b18eb0fcd2263069f03e7cc80f9feb43fb7ca23b8c822a48e42066b2cd17a6")
  15. add_versions("1.13.3", "9f074d230daf30f550c5bde5528037bdab6aa83b2a06c81a25e89dd3bcb7e419")
  16. add_configs("install_cpp_runtimes", {description = "Install c++ runtimes with Poco.", default = false, type = "boolean"})
  17. -- https://docs.pocoproject.org/current/00200-GettingStarted.html
  18. add_configs("foundation", {description = "Build Foundation support library.", default = true, type = "boolean", readonly = true})
  19. add_configs("xml", {description = "Build XML support library.", default = true, type = "boolean"})
  20. add_configs("json", {description = "Build JSON support library.", default = false, type = "boolean"})
  21. add_configs("net", {description = "Build Net support library.", default = false, type = "boolean"})
  22. add_configs("netssl", {description = "Build NetSSL support library (Need installed openssl libraries).", default = false, type = "boolean"})
  23. add_configs("crypto", {description = "Build Crypto support library (Need installed openssl libraries).", default = false, type = "boolean"})
  24. add_configs("jwt", {description = "Build JWT (JSON Web Token) library (Need installed openssl libraries).", default = false, type = "boolean"})
  25. add_configs("data", {description = "Build Data support library.", default = false, type = "boolean"})
  26. add_configs("sqlite", {description = "Build Data SQlite support library.", default = false, type = "boolean"})
  27. add_configs("mysql", {description = "Build Data MySQL or MariaDB support library (Need installed MySQL or MariaDB client libraries).", default = false, type = "boolean"})
  28. add_configs("mariadb", {description = "Build Data MySQL or MariaDB support library (Need installed MySQL or MariaDB client libraries).", default = false, type = "boolean"})
  29. add_configs("postgresql", {description = "Build SQL PosgreSQL support library (Need installed PostgreSQL client libraries).", default = false, type = "boolean"})
  30. add_configs("sql_parser", {description = "Build SQL Parser support library.", default = false, type = "boolean"})
  31. -- There is no odbc in xmake for now.
  32. -- Todo:
  33. add_configs("odbc", {description = "Build Data ODBC support library (Need installed ODBC libraries).", default = false, type = "boolean", readonly = true})
  34. add_configs("mongodb", {description = "Build MongoDB support library.", default = false, type = "boolean"})
  35. add_configs("redis", {description = "Build Redis support library.", default = false, type = "boolean"})
  36. add_configs("pdf", {description = "Build PDF support library.", default = false, type = "boolean"})
  37. add_configs("util", {description = "Build Util support library.", default = false, type = "boolean"})
  38. add_configs("zip", {description = "Build Zip support library.", default = true, type = "boolean"})
  39. add_configs("sevenzip", {description = "Build 7Zip support library.", default = false, type = "boolean"})
  40. -- There is no aprutil and apache2 in xmake for now.
  41. -- Todo:
  42. add_configs("apache_connector", {description = "Build ApacheConnector support library (Need installed apache and apr libraries).", default = false, type = "boolean", readonly = true})
  43. add_configs("cpp_parser", {description = "Build C++ parser library.", default = false, type = "boolean"})
  44. add_configs("encodings", {description = "Build Encodings library.", default = false, type = "boolean"})
  45. add_configs("encodings_compiler", {description = "Enable Encodings Compiler.", default = false, type = "boolean"})
  46. add_configs("page_compiler", {description = "Build PageCompiler.", default = false, type = "boolean"})
  47. add_configs("file2page", {description = "Build PageCompiler File2Page.", default = false, type = "boolean"})
  48. if is_plat("windows") then
  49. add_configs("netssl_win", {description = "Build NetSSL support library(Need installed openssl libraries For Windows only).", default = false, type = "boolean"})
  50. end
  51. add_configs("prometheus", {description = "Enable Prometheus.", default = false, type = "boolean"})
  52. add_configs("active_record", {description = "Enable ActiveRecord.", default = false, type = "boolean"})
  53. add_configs("active_record_compiler", {description = "Enable ActiveRecord Compiler.", default = false, type = "boolean"})
  54. add_configs("poco_doc", {description = "Build Poco Documentation Generator.", default = false, type = "boolean"})
  55. add_configs("poco_test", {description = "Build Unit tests.", default = false, type = "boolean"})
  56. add_deps("cmake")
  57. add_deps("sqlite3", "expat", "zlib") -- required: sqlite3(No option sqlite, sqlite3 is also required), expat, zlib, pcre/pcre2
  58. add_defines("POCO_NO_AUTOMATIC_LIBS")
  59. if is_plat("windows") then
  60. add_syslinks("iphlpapi")
  61. end
  62. on_load(function (package)
  63. if package:version():ge("1.12.0") then
  64. package:add("deps", "pcre2")
  65. else
  66. package:add("deps", "pcre")
  67. end
  68. if package:config("net") and package:is_plat("windows") then
  69. package:add("syslinks", "ws2_32")
  70. end
  71. if package:config("netssl") or package:config("crypto") or package:config("jwt") then
  72. package:add("deps", "openssl")
  73. end
  74. if package:config("mysql") then
  75. package:add("deps", "mysql")
  76. end
  77. if package:config("mariadb") then
  78. package:add("deps", "mariadb-connector-c")
  79. end
  80. if package:config("postgresql") then
  81. package:add("deps", "postgresql")
  82. end
  83. -- There is no odbc in xmake for now.
  84. if package:config("odbc") then
  85. package:add("deps", "odbc")
  86. end
  87. -- There is no aprutil and apache2 in xmake for now.
  88. if package:config("apache_connector") then
  89. package:add("deps", "apr")
  90. package:add("deps", "aprutil")
  91. package:add("deps", "apache2")
  92. end
  93. end)
  94. on_check(function (package)
  95. assert(not (package:is_plat("mingw") and package:is_subhost("macos")), "Poco not support mingw@macos")
  96. assert(not (package:is_plat("wasm")), "Poco not support wasm")
  97. assert(not (package:has_runtime("MT", "MTd") and package:config("shared")), "Poco cannot have both BUILD_SHARED_LIBS and POCO_MT")
  98. assert(not (package:config("mysql") and package:config("mariadb")), "Poco's options 'mysql' and 'mariadb' cannot exist together")
  99. -- warning: only works on windows sdk 10.0.18362.0 and later
  100. if package:is_plat("windows") then
  101. local vs_sdkver = package:toolchain("msvc"):config("vs_sdkver")
  102. if vs_sdkver then
  103. local build_ver = string.match(vs_sdkver, "%d+%.%d+%.(%d+)%.?%d*")
  104. assert(tonumber(build_ver) >= 18362, "poco requires Windows SDK to be at least 10.0.18362.0")
  105. end
  106. end
  107. -- check option's dependencies
  108. local dependencies = {xml = {"foundation"},
  109. json = {"foundation"},
  110. net = {"foundation"},
  111. netssl = {"foundation", "net", "util", "crypto"},
  112. crypto = {"foundation"},
  113. jwt = {"foundation", "json", "crypto"},
  114. data = {"foundation"},
  115. sqlite = {"foundation", "data"},
  116. mysql = {"foundation", "data"},
  117. mariadb = {"foundation", "data"},
  118. postgresql = {"foundation", "data"},
  119. sql_parser = {"foundation"},
  120. odbc = {"foundation", "data"},
  121. mongodb = {"foundation", "net"},
  122. redis = {"foundation", "net"},
  123. pdf = {"foundation", "xml", "json", "util"},
  124. util = {"foundation", "xml", "json"},
  125. zip = {"foundation", "xml"},
  126. sevenzip = {"foundation", "xml"},
  127. apache_connector = {"foundation", "xml", "json", "util", "net"},
  128. cpp_parser = {"foundation"},
  129. encodings = {"foundation"},
  130. encodings_compiler = {"foundation", "xml", "json", "util", "net"},
  131. page_compiler = {"foundation", "xml", "json", "util", "net"},
  132. file2page = {"foundation", "xml", "json", "util", "net"},
  133. netssl_win = {"foundation"},
  134. prometheus = {"foundation", "net"},
  135. active_record = {"foundation", "data", "sqlite"},
  136. active_record_compiler = {"foundation", "xml", "json", "util"}
  137. }
  138. for opt, deps in pairs(dependencies) do
  139. if package:config(opt) then
  140. local flag = true
  141. for _, dep in ipairs(deps) do
  142. flag = flag and package:config(dep)
  143. end
  144. assert(flag, "Option \'" .. opt .. "\' depends on {" .. table.concat(deps, ", ") .. "}. But some options not found")
  145. end
  146. end
  147. end)
  148. on_install(function (package)
  149. local configs = {"-DPOCO_UNBUNDLED=ON"} -- Using external dependencies
  150. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. ((package:debug() or package:has_runtime("MTd", "MDd")) and "Debug" or "Release"))
  151. table.insert(configs, "-DPOCO_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
  152. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  153. if package:is_plat("windows") then
  154. table.insert(configs, "-DPOCO_MT=" .. (package:has_runtime("MT", "MTd") and "ON" or "OFF"))
  155. end
  156. -- Todo: need to fix expat
  157. -- expat has a partial problem with the static library, resulting in missing macros in poco's xml module; the shared library has no problems
  158. if not package:dep("expat"):config("shared") then
  159. io.replace("XML/CMakeLists.txt", "EXPAT REQUIRED", "EXPAT CONFIG REQUIRED")
  160. io.replace("XML/CMakeLists.txt", "EXPAT::EXPAT", "expat::expat")
  161. io.replace("XML/CMakeLists.txt", "PUBLIC POCO_UNBUNDLED", "PUBLIC POCO_UNBUNDLED XML_DTD XML_NS")
  162. end
  163. -- Todo: need to fix pcre2
  164. -- pcre2 has a partial problem with the static library, resulting in missing macros in poco's foundation module; the shared library has no problems
  165. if package:version():ge("1.12.0") and not package:dep("pcre2"):config("shared") then
  166. io.replace("Foundation/CMakeLists.txt", "PUBLIC POCO_UNBUNDLED", "PUBLIC POCO_UNBUNDLED PCRE_STATIC")
  167. io.replace("Foundation/CMakeLists.txt", "POCO_SOURCES%(SRCS RegExp.-%)", "")
  168. io.replace("cmake/FindPCRE2.cmake", "NAMES pcre2-8", "NAMES pcre2-8-static pcre2-8", {plain = true})
  169. io.replace("cmake/FindPCRE2.cmake", "IMPORTED_LOCATION \"${PCRE2_LIBRARY}\"", "IMPORTED_LOCATION \"${PCRE2_LIBRARY}\"\nINTERFACE_COMPILE_DEFINITIONS PCRE2_STATIC", {plain = true})
  170. end
  171. if not package:config("install_cpp_runtimes") then
  172. io.replace("CMakeLists.txt", 'include(InstallRequiredSystemLibraries)', '', {plain = true})
  173. end
  174. table.insert(configs, "-DENABLE_XML=" .. (package:config("xml") and "ON" or "OFF"))
  175. table.insert(configs, "-DENABLE_JSON=" .. (package:config("json") and "ON" or "OFF"))
  176. table.insert(configs, "-DENABLE_NET=" .. (package:config("net") and "ON" or "OFF"))
  177. table.insert(configs, "-DENABLE_NETSSL=" .. (package:config("netssl") and "ON" or "OFF"))
  178. table.insert(configs, "-DENABLE_CRYPTO=" .. (package:config("crypto") and "ON" or "OFF"))
  179. table.insert(configs, "-DENABLE_JWT=" .. (package:config("jwt") and "ON" or "OFF"))
  180. table.insert(configs, "-DENABLE_DATA=" .. (package:config("data") and "ON" or "OFF"))
  181. table.insert(configs, "-DENABLE_DATA_SQLITE=" .. (package:config("sqlite") and "ON" or "OFF"))
  182. table.insert(configs, "-DENABLE_DATA_MYSQL=" .. (package:config("mysql") and "ON" or "OFF"))
  183. table.insert(configs, "-DENABLE_DATA_MYSQL=" .. (package:config("mariadb") and "ON" or "OFF"))
  184. table.insert(configs, "-DENABLE_DATA_POSTGRESQL=" .. (package:config("postgresql") and "ON" or "OFF"))
  185. table.insert(configs, "-DPOCO_DATA_NO_SQL_PARSER=" .. (package:config("sql_parser") and "OFF" or "ON"))
  186. table.insert(configs, "-DENABLE_DATA_ODBC=" .. (package:config("odbc") and "ON" or "OFF"))
  187. table.insert(configs, "-DENABLE_MONGODB=" .. (package:config("mongodb") and "ON" or "OFF"))
  188. table.insert(configs, "-DENABLE_REDIS=" .. (package:config("redis") and "ON" or "OFF"))
  189. table.insert(configs, "-DENABLE_PDF=" .. (package:config("pdf") and "ON" or "OFF"))
  190. table.insert(configs, "-DENABLE_UTIL=" .. (package:config("util") and "ON" or "OFF"))
  191. table.insert(configs, "-DENABLE_ZIP=" .. (package:config("zip") and "ON" or "OFF"))
  192. table.insert(configs, "-DENABLE_SEVENZIP=" .. (package:config("sevenzip") and "ON" or "OFF"))
  193. table.insert(configs, "-DENABLE_APACHECONNECTOR=" .. (package:config("apache_connector") and "ON" or "OFF"))
  194. table.insert(configs, "-DENABLE_CPPPARSER=" .. (package:config("cpp_parser") and "ON" or "OFF"))
  195. table.insert(configs, "-DENABLE_ENCODINGS=" .. (package:config("encodings") and "ON" or "OFF"))
  196. table.insert(configs, "-DENABLE_ENCODINGS_COMPILER=" .. (package:config("encodings_compiler") and "ON" or "OFF"))
  197. table.insert(configs, "-DENABLE_PAGECOMPILER=" .. (package:config("page_compiler") and "ON" or "OFF"))
  198. table.insert(configs, "-DENABLE_PAGECOMPILER_FILE2PAGE=" .. (package:config("file2page") and "ON" or "OFF"))
  199. if package:is_plat("windows") then
  200. table.insert(configs, "-DENABLE_NETSSL_WIN=" .. (package:config("netssl_win") and "ON" or "OFF"))
  201. end
  202. table.insert(configs, "-DENABLE_PROMETHEUS=" .. (package:config("prometheus") and "ON" or "OFF"))
  203. table.insert(configs, "-DENABLE_ACTIVERECORD=" .. (package:config("active_record") and "ON" or "OFF"))
  204. table.insert(configs, "-DENABLE_ACTIVERECORD_COMPILER=" .. (package:config("active_record_compiler") and "ON" or "OFF"))
  205. table.insert(configs, "-DENABLE_POCODOC=" .. (package:config("poco_doc") and "ON" or "OFF"))
  206. table.insert(configs, "-DENABLE_TESTS=" .. (package:config("poco_test") and "ON" or "OFF"))
  207. if package:config("mariadb") then
  208. for _, file in ipairs(os.files("Data/MySQL/include/**")) do
  209. io.replace(file, '#include <mysql/mysql.h>', '#include <mariadb/mysql.h>', {plain = true})
  210. end
  211. for _, file in ipairs(os.files("Data/MySQL/src/**")) do
  212. io.replace(file, '#include <mysql/mysql.h>', '#include <mariadb/mysql.h>', {plain = true})
  213. end
  214. end
  215. if package:config("mysql") or package:config("mariadb") then
  216. io.replace("Data/MySQL/include/Poco/Data/MySQL/MySQL.h", '#pragma comment(lib, "libmysql")', '', {plain = true})
  217. io.replace("cmake/FindMySQL.cmake", 'find_path(MYSQL_INCLUDE_DIR mysql/mysql.h', 'find_path(MYSQL_INCLUDE_DIR mysql/mysql.h mariadb/mysql.h', {plain = true})
  218. io.replace("cmake/FindMySQL.cmake", 'pkg_check_modules(PC_MARIADB QUIET mariadb)', 'pkg_check_modules(PC_MARIADB QUIET mariadb-connector-c)', {plain = true})
  219. io.replace("cmake/FindMySQL.cmake", 'find_library(MYSQL_LIBRARY NAMES mysqlclient\n', 'find_library(MYSQL_LIBRARY NAMES mysqlclient libmariadb\n', {plain = true})
  220. end
  221. import("package.tools.cmake").install(package, configs)
  222. end)
  223. on_test(function (package)
  224. assert(package:has_cxxtypes("Poco::BasicEvent<int>", {configs = {languages = "c++14"}, includes = "Poco/BasicEvent.h"}))
  225. -- option's test
  226. local optiontests = {{"xml", "Poco::XML::Document", "Poco/DOM/Document.h"},
  227. {"json", "Poco::JSON::Parser", "Poco/JSON/Parser.h"},
  228. {"net", "Poco::Net::HTTPServer", "Poco/Net/HTTPServer.h"},
  229. {"netssl", "Poco::Net::HTTPSStreamFactory", "Poco/Net/HTTPSStreamFactory.h"},
  230. {"crypto", "Poco::Crypto::CipherFactory", "Poco/Crypto/CipherFactory.h"},
  231. {"jwt", "Poco::JWT::Token", "Poco/JWT/Token.h"},
  232. {"data", "Poco::Data::Row", "Poco/Data/Row.h"},
  233. {"sqlite", "Poco::Data::SQLite::Connector", "Poco/Data/SQLite/Connector.h"},
  234. {"mysql", "Poco::Data::MySQL::Connector", "Poco/Data/MySQL/Connector.h"},
  235. {"mariadb", "Poco::Data::MySQL::Connector", "Poco/Data/MySQL/Connector.h"},
  236. {"postgresql", "Poco::Data::PostgreSQL::Connector", "Poco/Data/PostgreSQL/Connector.h"},
  237. -- {"sql_parser", "Poco::XML::Document", "Poco/DOM/Document.h"}, -- don't know how to check
  238. {"odbc", "Poco::Data::ODBC::Connector", "Poco/Data/ODBC/Connector.h"},
  239. {"mongodb", "Poco::MongoDB::Connection", "Poco/MongoDB/Connection.h"},
  240. {"redis", "Poco::Redis::Client", "Poco/Redis/Client.h"},
  241. {"pdf", "Poco::PDF::Document", "Poco/PDF/Document.h"},
  242. {"util", "Poco::Util::Application", "Poco/Util/Application.h"},
  243. {"zip", "Poco::Zip::Decompress", "Poco/Zip/Decompress.h"},
  244. {"sevenzip", "Poco::SevenZip::ArchiveEntry", "Poco/SevenZip/ArchiveEntry.h"},
  245. {"apache_connector", "Poco::ApacheConnector", "Poco/ApacheConnector.h"},
  246. {"cpp_parser", "Poco::CppParser::CppToken", "Poco/CppParser/CppToken.h"},
  247. {"encodings", "Poco::MacChineseSimpEncoding", "Poco/MacChineseSimpEncoding.h"},
  248. -- {"encodings_compiler", "Poco::XML::Document", "Poco/DOM/Document.h"}, -- don't know how to check
  249. -- {"page_compiler", "Poco::XML::Document", "Poco/DOM/Document.h"}, -- don't know how to check
  250. -- {"file2page", "Poco::XML::Document", "Poco/DOM/Document.h"}, -- don't know how to check
  251. {"netssl_win", "Poco::Net::HTTPSStreamFactory", "Poco/Net/HTTPSStreamFactory.h"},
  252. {"prometheus", "Poco::Prometheus::CounterSample", "Poco/Prometheus/CounterSample.h"},
  253. {"active_record", "Poco::ActiveRecord::DefaultStatementPlaceholderProvider", "Poco/ActiveRecord/ActiveRecord.h"}
  254. -- {"active_record_compiler", "Poco::XML::Document", "Poco/DOM/Document.h"} -- don't know how to check
  255. }
  256. for _, optiontest in ipairs(optiontests) do
  257. local name = optiontest[1]
  258. local test = optiontest[2]
  259. local file = optiontest[3]
  260. if package:config(name) then
  261. assert(package:has_cxxtypes(test, {configs = {languages = "c++17"}, includes = file}))
  262. end
  263. end
  264. end)