fix_poco_shared_build (#4994)

* fix_poco_shared_build

* remove_useless_content

* move_checks

* fix_move_checks

* test_other_plats

* fix_no_expat_on_some_plat

* fix_poco_not_support_mingw@macos

* fix_poco_not_support mingw@macos

* fix_pcre2 path for wasm

* fix_poco not suppport wasm

* add_Poco's modules dependencies check, add_Poco's modules test
pull/5098/head
Snowinter 3 months ago committed by GitHub
parent a73fb26307
commit cc2d57ebd6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      packages/e/expat/xmake.lua
  2. 265
      packages/p/poco/xmake.lua

@ -24,7 +24,7 @@ package("expat")
end
end)
on_install("windows", "linux", "macosx", "android", "mingw", "cross", "bsd", function (package)
on_install(function (package)
local configs = {"-DEXPAT_BUILD_EXAMPLES=OFF", "-DEXPAT_BUILD_TESTS=OFF", "-DEXPAT_BUILD_DOCS=OFF"}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
table.insert(configs, "-DEXPAT_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))

@ -16,82 +16,267 @@ package("poco")
add_versions("1.12.5", "92b18eb0fcd2263069f03e7cc80f9feb43fb7ca23b8c822a48e42066b2cd17a6")
add_versions("1.13.3", "9f074d230daf30f550c5bde5528037bdab6aa83b2a06c81a25e89dd3bcb7e419")
add_configs("install_cpp_runtimes", {description = "Install c++ runtimes with Poco.", default = false, type = "boolean"})
-- https://docs.pocoproject.org/current/00200-GettingStarted.html
add_configs("foundation", {description = "Build Foundation support library.", default = true, type = "boolean", readonly = true})
add_configs("xml", {description = "Build XML support library.", default = true, type = "boolean"})
add_configs("json", {description = "Build JSON support library.", default = false, type = "boolean"})
add_configs("net", {description = "Build Net support library.", default = false, type = "boolean"})
add_configs("netssl", {description = "Build NetSSL support library (Need installed openssl libraries).", default = false, type = "boolean"})
add_configs("crypto", {description = "Build Crypto support library (Need installed openssl libraries).", default = false, type = "boolean"})
add_configs("jwt", {description = "Build JWT (JSON Web Token) library (Need installed openssl libraries).", default = false, type = "boolean"})
add_configs("data", {description = "Build Data support library.", default = false, type = "boolean"})
add_configs("sqlite", {description = "Build Data SQlite support library.", default = false, type = "boolean"})
add_configs("mysql", {description = "Build Data MySQL or MariaDB support library (Need installed MySQL or MariaDB client libraries).", default = false, type = "boolean"})
add_configs("mariadb", {description = "Build Data MySQL or MariaDB support library (Need installed MySQL or MariaDB client libraries).", default = false, type = "boolean"})
add_configs("postgresql", {description = "Build SQL PosgreSQL support library (Need installed PostgreSQL client libraries).", default = false, type = "boolean"})
add_configs("sql_parser", {description = "Build SQL Parser support library.", default = false, type = "boolean"})
-- There is no odbc in xmake for now.
-- Todo:
add_configs("odbc", {description = "Build Data ODBC support library (Need installed ODBC libraries).", default = false, type = "boolean", readonly = true})
add_configs("mongodb", {description = "Build MongoDB support library.", default = false, type = "boolean"})
add_configs("redis", {description = "Build Redis support library.", default = false, type = "boolean"})
add_configs("pdf", {description = "Build PDF support library.", default = false, type = "boolean"})
add_configs("util", {description = "Build Util support library.", default = false, type = "boolean"})
add_configs("zip", {description = "Build Zip support library.", default = true, type = "boolean"})
add_configs("sevenzip", {description = "Build 7Zip support library.", default = false, type = "boolean"})
-- There is no aprutil and apache2 in xmake for now.
-- Todo:
add_configs("apache_connector", {description = "Build ApacheConnector support library (Need installed apache and apr libraries).", default = false, type = "boolean", readonly = true})
add_configs("cpp_parser", {description = "Build C++ parser library.", default = false, type = "boolean"})
add_configs("encodings", {description = "Build Encodings library.", default = false, type = "boolean"})
add_configs("encodings_compiler", {description = "Enable Encodings Compiler.", default = false, type = "boolean"})
add_configs("page_compiler", {description = "Build PageCompiler.", default = false, type = "boolean"})
add_configs("file2page", {description = "Build PageCompiler File2Page.", default = false, type = "boolean"})
if is_plat("windows") then
add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
add_configs("netssl_win", {description = "Build NetSSL support library(Need installed openssl libraries For Windows only).", default = false, type = "boolean"})
end
add_configs("mysql", {description = "Enable mysql support.", default = false, type = "boolean"})
add_configs("postgresql", {description = "Enable postgresql support.", default = false, type = "boolean"})
add_configs("mongodb", {description = "Enable mongodb support.", default = false, type = "boolean"})
add_configs("odbc", {description = "Enable odbc support.", default = is_plat("windows"), type = "boolean"})
add_configs("sql_parser", {description = "Enable poco data sql parser.", default = false, type = "boolean"})
add_configs("prometheus", {description = "Enable Prometheus.", default = false, type = "boolean"})
add_configs("active_record", {description = "Enable ActiveRecord.", default = false, type = "boolean"})
add_configs("active_record_compiler", {description = "Enable ActiveRecord Compiler.", default = false, type = "boolean"})
add_configs("poco_doc", {description = "Build Poco Documentation Generator.", default = false, type = "boolean"})
add_configs("poco_test", {description = "Build Unit tests.", default = false, type = "boolean"})
add_deps("cmake")
add_deps("openssl", "sqlite3", "expat", "zlib")
add_deps("sqlite3", "expat", "zlib") -- required: sqlite3(No option sqlite, sqlite3 is also required), expat, zlib, pcre/pcre2
add_defines("POCO_NO_AUTOMATIC_LIBS")
if is_plat("windows") then
add_syslinks("iphlpapi")
end
on_load(function (package)
if package:config("postgresql") then
package:add("deps", "postgresql")
end
if package:config("mysql") then
package:add("deps", "mysql")
end
if package:version():ge("1.12.0") then
package:add("deps", "pcre2")
else
package:add("deps", "pcre")
end
end)
on_install("windows", "linux", "macosx", "mingw|x86_64@msys", function (package)
io.replace("XML/CMakeLists.txt", "EXPAT REQUIRED", "EXPAT CONFIG REQUIRED")
io.replace("XML/CMakeLists.txt", "EXPAT::EXPAT", "expat::expat")
io.replace("XML/CMakeLists.txt", "PUBLIC POCO_UNBUNDLED", "PUBLIC POCO_UNBUNDLED XML_DTD XML_NS")
io.replace("Foundation/CMakeLists.txt", "PUBLIC POCO_UNBUNDLED", "PUBLIC POCO_UNBUNDLED PCRE_STATIC")
io.replace("Foundation/CMakeLists.txt", "POCO_SOURCES%(SRCS RegExp.-%)", "")
if package:version():ge("1.12.0") and package:dep("pcre2"):exists() and not package:dep("pcre2"):config("shared") then
io.replace("cmake/FindPCRE2.cmake", "NAMES pcre2-8", "NAMES pcre2-8-static pcre2-8", {plain = true})
io.replace("cmake/FindPCRE2.cmake", "IMPORTED_LOCATION \"${PCRE2_LIBRARY}\"", "IMPORTED_LOCATION \"${PCRE2_LIBRARY}\"\nINTERFACE_COMPILE_DEFINITIONS PCRE2_STATIC", {plain = true})
if package:config("netssl") or package:config("crypto") or package:config("jwt") then
package:add("deps", "openssl")
end
local configs = {"-DPOCO_UNBUNDLED=ON", "-DENABLE_TESTS=OFF", "-DENABLE_PDF=ON"}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
if package:is_plat("windows") and not package:config("shared") then
table.insert(configs, "-DPOCO_MT=" .. (package:has_runtime("MT", "MTd") and "ON" or "OFF"))
if package:config("mysql") then
package:add("deps", "mysql")
end
if package:config("mariadb") then
package:add("deps", "mariadb-connector-c")
end
if package:config("postgresql") then
package:add("deps", "postgresql")
end
-- There is no odbc in xmake for now.
if package:config("odbc") then
package:add("deps", "odbc")
end
-- There is no aprutil and apache2 in xmake for now.
if package:config("apache_connector") then
package:add("deps", "apr")
package:add("deps", "aprutil")
package:add("deps", "apache2")
end
end)
on_check(function (package)
assert(not (package:is_plat("mingw") and package:is_subhost("macos")), "Poco not support mingw@macos")
assert(not (package:is_plat("wasm")), "Poco not support wasm")
assert(not (package:has_runtime("MT", "MTd") and package:config("shared")), "Poco cannot have both BUILD_SHARED_LIBS and POCO_MT")
assert(not (package:config("mysql") and package:config("mariadb")), "Poco's options 'mysql' and 'mariadb' cannot exist together")
-- warning: only works on windows sdk 10.0.18362.0 and later
if package:is_plat("windows") then
local vs_sdkver = package:toolchain("msvc"):config("vs_sdkver")
if vs_sdkver then
local build_ver = string.match(vs_sdkver, "%d+%.%d+%.(%d+)%.?%d*")
assert(tonumber(build_ver) >= 18362, "poco requires Windows SDK to be at least 10.0.18362.0")
table.insert(configs, "-DCMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION=" .. vs_sdkver)
table.insert(configs, "-DCMAKE_SYSTEM_VERSION=" .. vs_sdkver)
end
end
for _, lib in ipairs({"mysql", "postgresql", "odbc", "mongodb"}) do
table.insert(configs, "-DENABLE_DATA_" .. lib:upper() .. "=" .. (package:config(lib) and "ON" or "OFF"))
-- check option's dependencies
local dependencies = {xml = {"foundation"},
json = {"foundation"},
net = {"foundation"},
netssl = {"foundation", "net", "util", "crypto"},
crypto = {"foundation"},
jwt = {"foundation", "json", "crypto"},
data = {"foundation"},
sqlite = {"foundation", "data"},
mysql = {"foundation", "data"},
mariadb = {"foundation", "data"},
postgresql = {"foundation", "data"},
sql_parser = {"foundation"},
odbc = {"foundation", "data"},
mongodb = {"foundation", "net"},
redis = {"foundation", "net"},
pdf = {"foundation", "xml", "json", "util"},
util = {"foundation", "xml", "json"},
zip = {"foundation", "xml"},
sevenzip = {"foundation", "xml"},
apache_connector = {"foundation", "xml", "json", "util", "net"},
cpp_parser = {"foundation"},
encodings = {"foundation"},
encodings_compiler = {"foundation", "xml", "json", "util", "net"},
page_compiler = {"foundation", "xml", "json", "util", "net"},
file2page = {"foundation", "xml", "json", "util", "net"},
netssl_win = {"foundation"},
prometheus = {"foundation", "net"},
active_record = {"foundation", "data", "sqlite"},
active_record_compiler = {"foundation", "xml", "json", "util"}
}
for opt, deps in pairs(dependencies) do
if package:config(opt) then
local flag = true
for _, dep in ipairs(deps) do
flag = flag and package:config(dep)
end
assert(flag, "Option \'" .. opt .. "\' depends on {" .. table.concat(deps, ", ") .. "}. But some options not found")
end
end
end)
on_install(function (package)
local configs = {"-DPOCO_UNBUNDLED=ON"} -- Using external dependencies
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. ((package:debug() or package:has_runtime("MTd", "MDd")) and "Debug" or "Release"))
table.insert(configs, "-DPOCO_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
if package:is_plat("windows") then
table.insert(configs, "-DPOCO_MT=" .. (package:has_runtime("MT", "MTd") and "ON" or "OFF"))
end
-- Todo: need to fix expat
-- expat has a partial problem with the static library, resulting in missing macros in poco's xml module; the shared library has no problems
if not package:dep("expat"):config("shared") then
io.replace("XML/CMakeLists.txt", "EXPAT REQUIRED", "EXPAT CONFIG REQUIRED")
io.replace("XML/CMakeLists.txt", "EXPAT::EXPAT", "expat::expat")
io.replace("XML/CMakeLists.txt", "PUBLIC POCO_UNBUNDLED", "PUBLIC POCO_UNBUNDLED XML_DTD XML_NS")
end
-- Todo: need to fix pcre2
-- pcre2 has a partial problem with the static library, resulting in missing macros in poco's foundation module; the shared library has no problems
if package:version():ge("1.12.0") and not package:dep("pcre2"):config("shared") then
io.replace("Foundation/CMakeLists.txt", "PUBLIC POCO_UNBUNDLED", "PUBLIC POCO_UNBUNDLED PCRE_STATIC")
io.replace("Foundation/CMakeLists.txt", "POCO_SOURCES%(SRCS RegExp.-%)", "")
io.replace("cmake/FindPCRE2.cmake", "NAMES pcre2-8", "NAMES pcre2-8-static pcre2-8", {plain = true})
io.replace("cmake/FindPCRE2.cmake", "IMPORTED_LOCATION \"${PCRE2_LIBRARY}\"", "IMPORTED_LOCATION \"${PCRE2_LIBRARY}\"\nINTERFACE_COMPILE_DEFINITIONS PCRE2_STATIC", {plain = true})
end
if not package:config("install_cpp_runtimes") then
io.replace("CMakeLists.txt", 'include(InstallRequiredSystemLibraries)', '', {plain = true})
end
table.insert(configs, "-DENABLE_XML=" .. (package:config("xml") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_JSON=" .. (package:config("json") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_NET=" .. (package:config("net") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_NETSSL=" .. (package:config("netssl") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_CRYPTO=" .. (package:config("crypto") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_JWT=" .. (package:config("jwt") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_DATA=" .. (package:config("data") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_DATA_SQLITE=" .. (package:config("sqlite") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_DATA_MYSQL=" .. (package:config("mysql") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_DATA_MYSQL=" .. (package:config("mariadb") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_DATA_POSTGRESQL=" .. (package:config("postgresql") and "ON" or "OFF"))
table.insert(configs, "-DPOCO_DATA_NO_SQL_PARSER=" .. (package:config("sql_parser") and "OFF" or "ON"))
table.insert(configs, "-DENABLE_DATA_ODBC=" .. (package:config("odbc") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_MONGODB=" .. (package:config("mongodb") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_REDIS=" .. (package:config("redis") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_PDF=" .. (package:config("pdf") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_UTIL=" .. (package:config("util") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_ZIP=" .. (package:config("zip") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_SEVENZIP=" .. (package:config("sevenzip") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_APACHECONNECTOR=" .. (package:config("apache_connector") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_CPPPARSER=" .. (package:config("cpp_parser") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_ENCODINGS=" .. (package:config("encodings") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_ENCODINGS_COMPILER=" .. (package:config("encodings_compiler") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_PAGECOMPILER=" .. (package:config("page_compiler") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_PAGECOMPILER_FILE2PAGE=" .. (package:config("file2page") and "ON" or "OFF"))
if package:is_plat("windows") then
table.insert(configs, "-DENABLE_NETSSL_WIN=" .. (package:config("netssl_win") and "ON" or "OFF"))
end
table.insert(configs, "-DENABLE_PROMETHEUS=" .. (package:config("prometheus") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_ACTIVERECORD=" .. (package:config("active_record") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_ACTIVERECORD_COMPILER=" .. (package:config("active_record_compiler") and "ON" or "OFF"))
if package:config("mysql") then
io.replace("Data/MySQL/include/Poco/Data/MySQL/MySQL.h", '#pragma comment(lib, "libmysql")', '', {plain = true})
local libmysql = package:dep("mysql"):fetch()
if libmysql then
table.insert(configs, "-DMYSQL_INCLUDE_DIR=" .. table.concat(libmysql.includedirs or libmysql.sysincludedirs, ";"))
table.insert(configs, "-DMYSQL_LIBRARY=" .. table.concat(libmysql.libfiles or {}, ";"))
table.insert(configs, "-DENABLE_POCODOC=" .. (package:config("poco_doc") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_TESTS=" .. (package:config("poco_test") and "ON" or "OFF"))
if package:config("mariadb") then
for _, file in ipairs(os.files("Data/MySQL/include/**")) do
io.replace(file, '#include <mysql/mysql.h>', '#include <mariadb/mysql.h>', {plain = true})
end
for _, file in ipairs(os.files("Data/MySQL/src/**")) do
io.replace(file, '#include <mysql/mysql.h>', '#include <mariadb/mysql.h>', {plain = true})
end
end
if package:config("mysql") or package:config("mariadb") then
io.replace("Data/MySQL/include/Poco/Data/MySQL/MySQL.h", '#pragma comment(lib, "libmysql")', '', {plain = true})
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})
io.replace("cmake/FindMySQL.cmake", 'pkg_check_modules(PC_MARIADB QUIET mariadb)', 'pkg_check_modules(PC_MARIADB QUIET mariadb-connector-c)', {plain = true})
io.replace("cmake/FindMySQL.cmake", 'find_library(MYSQL_LIBRARY NAMES mysqlclient\n', 'find_library(MYSQL_LIBRARY NAMES mysqlclient libmariadb\n', {plain = true})
end
-- warning: only works on windows sdk 10.0.18362.0 and later
import("package.tools.cmake").install(package, configs)
end)
on_test(function (package)
assert(package:has_cxxtypes("Poco::BasicEvent<int>", {configs = {languages = "c++14"}, includes = "Poco/BasicEvent.h"}))
-- option's test
local optiontests = {{"xml", "Poco::XML::Document", "Poco/DOM/Document.h"},
{"json", "Poco::JSON::Parser", "Poco/JSON/Parser.h"},
{"net", "Poco::Net::HTTPServer", "Poco/Net/HTTPServer.h"},
{"netssl", "Poco::Net::HTTPSStreamFactory", "Poco/Net/HTTPSStreamFactory.h"},
{"crypto", "Poco::Crypto::CipherFactory", "Poco/Crypto/CipherFactory.h"},
{"jwt", "Poco::JWT::Token", "Poco/JWT/Token.h"},
{"data", "Poco::Data::Row", "Poco/Data/Row.h"},
{"sqlite", "Poco::Data::SQLite::Connector", "Poco/Data/SQLite/Connector.h"},
{"mysql", "Poco::Data::MySQL::Connector", "Poco/Data/MySQL/Connector.h"},
{"mariadb", "Poco::Data::MySQL::Connector", "Poco/Data/MySQL/Connector.h"},
{"postgresql", "Poco::Data::PostgreSQL::Connector", "Poco/Data/PostgreSQL/Connector.h"},
-- {"sql_parser", "Poco::XML::Document", "Poco/DOM/Document.h"}, -- don't know how to check
{"odbc", "Poco::Data::ODBC::Connector", "Poco/Data/ODBC/Connector.h"},
{"mongodb", "Poco::MongoDB::Connection", "Poco/MongoDB/Connection.h"},
{"redis", "Poco::Redis::Client", "Poco/Redis/Client.h"},
{"pdf", "Poco::PDF::Document", "Poco/PDF/Document.h"},
{"util", "Poco::Util::Application", "Poco/Util/Application.h"},
{"zip", "Poco::Zip::Decompress", "Poco/Zip/Decompress.h"},
{"sevenzip", "Poco::SevenZip::ArchiveEntry", "Poco/SevenZip/ArchiveEntry.h"},
{"apache_connector", "Poco::ApacheConnector", "Poco/ApacheConnector.h"},
{"cpp_parser", "Poco::CppParser::CppToken", "Poco/CppParser/CppToken.h"},
{"encodings", "Poco::MacChineseSimpEncoding", "Poco/MacChineseSimpEncoding.h"},
-- {"encodings_compiler", "Poco::XML::Document", "Poco/DOM/Document.h"}, -- don't know how to check
-- {"page_compiler", "Poco::XML::Document", "Poco/DOM/Document.h"}, -- don't know how to check
-- {"file2page", "Poco::XML::Document", "Poco/DOM/Document.h"}, -- don't know how to check
{"netssl_win", "Poco::Net::HTTPSStreamFactory", "Poco/Net/HTTPSStreamFactory.h"},
{"prometheus", "Poco::Prometheus::CounterSample", "Poco/Prometheus/CounterSample.h"},
{"active_record", "Poco::ActiveRecord::DefaultStatementPlaceholderProvider", "Poco/ActiveRecord/ActiveRecord.h"}
-- {"active_record_compiler", "Poco::XML::Document", "Poco/DOM/Document.h"} -- don't know how to check
}
for _, optiontest in ipairs(optiontests) do
local name = optiontest[1]
local test = optiontest[2]
local file = optiontest[3]
if package:config(name) then
assert(package:has_cxxtypes(test, {configs = {languages = "c++17"}, includes = file}))
end
end
end)

Loading…
Cancel
Save