diff options
author | Trumeet <yuuta@yuuta.moe> | 2022-07-21 21:47:47 -0700 |
---|---|---|
committer | Trumeet <yuuta@yuuta.moe> | 2022-07-21 21:47:47 -0700 |
commit | 609c725cedbeca31ae3aba3a9c39c5030ea1d20f (patch) | |
tree | 3c48656480b312ab0ea231a235fc77a47055d5ca /client/libacron/acronc | |
parent | 1635741d1def2228a0b29db987612168d283f28d (diff) | |
download | acron-609c725cedbeca31ae3aba3a9c39c5030ea1d20f.tar acron-609c725cedbeca31ae3aba3a9c39c5030ea1d20f.tar.gz acron-609c725cedbeca31ae3aba3a9c39c5030ea1d20f.tar.bz2 acron-609c725cedbeca31ae3aba3a9c39c5030ea1d20f.zip |
fix(libacron/acronc): complete cross-platform build
This patch made several changes to correctly build libac on Windows:
1. Deprecated PkgConfig on Unix. On both platforms, libac requires the JSON-C CMake module to locate libraries (whether is dynamic or static) and headers. On Windows, the common practice is to statically link the library, so libac now provides setup.bat to automatically clone JSON-C and build it. In CMakeLists.txt, libac will automatically pick up the in-tree JSON-C build if it presents. Otherwise, it will use the system default's. Users can override the CMAKE_PREFIX_PATH to supply a custom JSON-C library if it is not found in-tree.
2. Switched from #include <json-c/xxx.h> to <xxx.h>, as the former (current) approach is non-standard and depends on the system header locations. The later (new) approach relies on CMake to supply header search paths, which works on Windows as well.
3. Deprecated --version-script on Unix linkers. Instead, libac now uses -fvisibility (https://gcc.gnu.org/wiki/Visibility) on GCC or LLVM, as well as __declspec(dllexport) on MSVC to export selected symbols. A new macro, LIBAC_EXPORT, is defined in incl.h (new), and all functions needed to export are marked with that macro.
4. Changed several codes (mostly socket-related) to work on Windows.
5. Massive rewrite of CMake in preparation of further installation and static library support.
Signed-off-by: Trumeet <yuuta@yuuta.moe>
Diffstat (limited to 'client/libacron/acronc')
-rw-r--r-- | client/libacron/acronc/main.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/client/libacron/acronc/main.c b/client/libacron/acronc/main.c index ef3bb38..21958fd 100644 --- a/client/libacron/acronc/main.c +++ b/client/libacron/acronc/main.c @@ -5,7 +5,10 @@ #include "libac.h" #include <stdio.h> -#include <unistd.h> +#ifdef WIN32 +#include <winsock2.h> +#include <windef.h> +#endif static const char *world_name(const enum ac_world world) { switch (world) { @@ -120,6 +123,20 @@ static void handle_response(const ac_response_t *response) { int main(int argc, char **argv) { int r; +#ifdef WIN32 + WORD wVersionRequested; + WSADATA wsaData; + wVersionRequested = MAKEWORD(2, 2); + if ((r = WSAStartup(wVersionRequested, &wsaData))) { + fprintf(stderr, "WSAStartup failed with error: %d\n", r); + return r; + } + if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) { + fprintf(stderr, "Could not find a usable version of Winsock.dll\n"); + WSACleanup(); + return 1; + } +#endif libac_config_t config = { #ifdef DEBUG .out = stderr, @@ -165,5 +182,8 @@ int main(int argc, char **argv) { } ac_disconnect(connection); ac_free(); +#ifdef WIN32 + WSACleanup(); +#endif return r; }
\ No newline at end of file |