|
| 1 | +-- libevent 2.1.13-stable: configure headers with upstream CMake, then compile |
| 2 | +-- core and extra sources with mcpp's C toolchain on Linux, macOS and Windows. |
| 3 | +package = { |
| 4 | + spec = "1", |
| 5 | + namespace = "compat", |
| 6 | + name = "libevent", |
| 7 | + description = "Libevent asynchronous event notification and networking library", |
| 8 | + licenses = {"BSD-3-Clause", "ISC", "MIT"}, |
| 9 | + repo = "https://github.com/libevent/libevent", |
| 10 | + type = "package", |
| 11 | + |
| 12 | + xpm = { |
| 13 | + linux = { |
| 14 | + deps = { "xim:cmake@latest" }, |
| 15 | + ["2.1.13"] = { |
| 16 | + url = "https://github.com/libevent/libevent/archive/refs/tags/release-2.1.13-stable.tar.gz", |
| 17 | + sha256 = "1a0885e17dc78afbaeddf13cf849f9238bbc24acdc178464a0d1934d7c5ffbd5", |
| 18 | + }, |
| 19 | + }, |
| 20 | + macosx = { |
| 21 | + deps = { "xim:cmake@latest" }, |
| 22 | + ["2.1.13"] = { |
| 23 | + url = "https://github.com/libevent/libevent/archive/refs/tags/release-2.1.13-stable.tar.gz", |
| 24 | + sha256 = "1a0885e17dc78afbaeddf13cf849f9238bbc24acdc178464a0d1934d7c5ffbd5", |
| 25 | + }, |
| 26 | + }, |
| 27 | + windows = { |
| 28 | + deps = { "xim:cmake@latest" }, |
| 29 | + ["2.1.13"] = { |
| 30 | + url = "https://github.com/libevent/libevent/archive/refs/tags/release-2.1.13-stable.tar.gz", |
| 31 | + sha256 = "1a0885e17dc78afbaeddf13cf849f9238bbc24acdc178464a0d1934d7c5ffbd5", |
| 32 | + }, |
| 33 | + }, |
| 34 | + }, |
| 35 | + |
| 36 | + mcpp = { |
| 37 | + language = "c++23", |
| 38 | + import_std = false, |
| 39 | + c_standard = "c11", |
| 40 | + include_dirs = { "*/include", "config/include", "*/compat", "*/WIN32-Code" }, |
| 41 | + cflags = { "-DHAVE_CONFIG_H" }, |
| 42 | + sources = { |
| 43 | + "*/buffer.c", "*/bufferevent.c", "*/bufferevent_filter.c", |
| 44 | + "*/bufferevent_pair.c", "*/bufferevent_ratelim.c", |
| 45 | + "*/bufferevent_sock.c", "*/event.c", "*/evmap.c", |
| 46 | + "*/evthread.c", "*/evutil.c", "*/evutil_rand.c", |
| 47 | + "*/evutil_time.c", "*/listener.c", "*/log.c", |
| 48 | + "*/signal.c", "*/strlcpy.c", "*/event_tagging.c", |
| 49 | + "*/http.c", "*/evdns.c", "*/evrpc.c", |
| 50 | + }, |
| 51 | + targets = { ["event"] = { kind = "lib" } }, |
| 52 | + deps = {}, |
| 53 | + linux = { |
| 54 | + sources = { "*/select.c", "*/poll.c", "*/epoll.c", "*/evthread_pthread.c" }, |
| 55 | + }, |
| 56 | + macosx = { |
| 57 | + sources = { "*/select.c", "*/poll.c", "*/kqueue.c", "*/evthread_pthread.c" }, |
| 58 | + }, |
| 59 | + windows = { |
| 60 | + sources = { "*/buffer_iocp.c", "*/bufferevent_async.c", "*/event_iocp.c", |
| 61 | + "*/win32select.c", "*/evthread_win32.c" }, |
| 62 | + cflags = { "-D_CRT_SECURE_NO_WARNINGS", "-D_CRT_NONSTDC_NO_DEPRECATE" }, |
| 63 | + ldflags = { "-lws2_32", "-lshell32", "-ladvapi32", "-liphlpapi" }, |
| 64 | + }, |
| 65 | + }, |
| 66 | +} |
| 67 | + |
| 68 | +import("xim.libxpkg.pkginfo") |
| 69 | +import("xim.libxpkg.log") |
| 70 | + |
| 71 | +local function quote(s) |
| 72 | + return '"' .. tostring(s):gsub('"', '\\"') .. '"' |
| 73 | +end |
| 74 | + |
| 75 | +function install() |
| 76 | + local wrap = "libevent-release-" .. pkginfo.version() .. "-stable" |
| 77 | + if not os.isfile(path.join(wrap, "CMakeLists.txt")) then |
| 78 | + log.error("compat.libevent: expected %s/CMakeLists.txt", wrap) |
| 79 | + return false |
| 80 | + end |
| 81 | + local prefix = pkginfo.install_dir() |
| 82 | + os.tryrm(prefix) |
| 83 | + os.mkdir(prefix) |
| 84 | + local srcroot = path.join(prefix, wrap) |
| 85 | + os.mv(wrap, srcroot) |
| 86 | + |
| 87 | + local pkg = pkginfo.build_dep("xim:cmake") |
| 88 | + local cmake |
| 89 | + if pkg then |
| 90 | + for _, candidate in ipairs({ |
| 91 | + pkg.bin and path.join(pkg.bin, "cmake") or "", |
| 92 | + pkg.bin and path.join(pkg.bin, "cmake.exe") or "", |
| 93 | + pkg.path and path.join(pkg.path, "cmake.app/Contents/bin/cmake") or "", |
| 94 | + pkg.path and path.join(pkg.path, "CMake.app/Contents/bin/cmake") or "", |
| 95 | + }) do |
| 96 | + if os.isfile(candidate) then cmake = candidate; break end |
| 97 | + end |
| 98 | + end |
| 99 | + if not cmake then |
| 100 | + log.error("compat.libevent: xim:cmake executable not found") |
| 101 | + return false |
| 102 | + end |
| 103 | + local command = quote(cmake) .. " -S " .. quote(srcroot) |
| 104 | + .. " -B " .. quote(path.join(prefix, "config")) |
| 105 | + .. " -DCMAKE_POLICY_VERSION_MINIMUM=3.5" |
| 106 | + -- Probe the native platform with its system compiler, not a toolchain |
| 107 | + -- wrapper whose sysroot may differ from the generated headers' ABI. |
| 108 | + .. (os.host() == "windows" and "" or " -DCMAKE_C_COMPILER=/usr/bin/cc") |
| 109 | + .. " -DEVENT__DISABLE_OPENSSL=ON -DEVENT__DISABLE_MBEDTLS=ON" |
| 110 | + .. " -DEVENT__DISABLE_TESTS=ON -DEVENT__DISABLE_SAMPLES=ON" |
| 111 | + .. " -DEVENT__DISABLE_BENCHMARK=ON -DEVENT__LIBRARY_TYPE=STATIC" |
| 112 | + local logfile = path.join(prefix, "mcpp_cmake_configure.log") |
| 113 | + if os.host() == "windows" then |
| 114 | + -- Windows xlings does not reliably execute a quoted .exe directly. |
| 115 | + -- Drive it through cmd as compat.openssl does, and inspect its output. |
| 116 | + local bat = path.join(prefix, "mcpp_configure.bat") |
| 117 | + io.writefile(bat, "@echo off\r\n" .. command .. " > " .. quote(logfile) |
| 118 | + .. " 2>&1\r\nif errorlevel 1 exit /b 1\r\n") |
| 119 | + command = "cmd /c " .. quote(bat) |
| 120 | + end |
| 121 | + local ok, result = pcall(os.exec, command) |
| 122 | + if not ok or not result then |
| 123 | + log.error("compat.libevent: CMake configuration failed: %s; log: %s", |
| 124 | + tostring(result), os.isfile(logfile) and io.readfile(logfile) or "<not written>") |
| 125 | + return false |
| 126 | + end |
| 127 | + local generated = path.join(prefix, "config/include/event2/event-config.h") |
| 128 | + if not os.isfile(generated) then |
| 129 | + log.error("compat.libevent: CMake did not generate %s", generated) |
| 130 | + return false |
| 131 | + end |
| 132 | + return true |
| 133 | +end |
0 commit comments