aboutsummaryrefslogtreecommitdiff
path: root/client/libacron/private
diff options
context:
space:
mode:
authorTrumeet <yuuta@yuuta.moe>2022-07-21 21:47:47 -0700
committerTrumeet <yuuta@yuuta.moe>2022-07-21 21:47:47 -0700
commit609c725cedbeca31ae3aba3a9c39c5030ea1d20f (patch)
tree3c48656480b312ab0ea231a235fc77a47055d5ca /client/libacron/private
parent1635741d1def2228a0b29db987612168d283f28d (diff)
downloadacron-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/private')
-rw-r--r--client/libacron/private/config.h3
-rw-r--r--client/libacron/private/connection.h7
-rw-r--r--client/libacron/private/helpers.c1
-rw-r--r--client/libacron/private/win32.h15
4 files changed, 24 insertions, 2 deletions
diff --git a/client/libacron/private/config.h b/client/libacron/private/config.h
index 3b670df..df907a0 100644
--- a/client/libacron/private/config.h
+++ b/client/libacron/private/config.h
@@ -5,9 +5,10 @@
#ifndef LIBAC_CONFIG_H
#define LIBAC_CONFIG_H
+#include "win32.h"
#include "libac.h"
-#include <json-c/json_tokener.h>
+#include <json_tokener.h>
#include <stdio.h>
extern _Thread_local struct libac_config *config;
diff --git a/client/libacron/private/connection.h b/client/libacron/private/connection.h
index ad65b11..04d7639 100644
--- a/client/libacron/private/connection.h
+++ b/client/libacron/private/connection.h
@@ -5,10 +5,15 @@
#ifndef LIBAC_CONNECTION_H
#define LIBAC_CONNECTION_H
+#include "win32.h"
#include "wic.h"
#include "libac.h"
#include <stdbool.h>
+#ifdef WIN32
+#include <winsock2.h>
+#endif
+
/**
* Used to transfer deserialization result from receive handler to ac_receive().
*/
@@ -24,7 +29,7 @@ struct ac_result {
struct ac_connection {
ac_connection_parameters_t parameters;
struct wic_inst inst;
- int fd;
+ SOCKET fd;
bool established;
/* Result from message handler.
* Message handling will happen at the same thread as ac_receive (lib wic). */
diff --git a/client/libacron/private/helpers.c b/client/libacron/private/helpers.c
index 4d4f3c8..86d65b6 100644
--- a/client/libacron/private/helpers.c
+++ b/client/libacron/private/helpers.c
@@ -2,6 +2,7 @@
* Created by yuuta on 7/19/22.
*/
+#include "win32.h"
#include "helpers.h"
#include "log.h"
#include "common.h"
diff --git a/client/libacron/private/win32.h b/client/libacron/private/win32.h
new file mode 100644
index 0000000..07cdca8
--- /dev/null
+++ b/client/libacron/private/win32.h
@@ -0,0 +1,15 @@
+/*
+ * Created by yuuta on 7/21/22.
+ */
+
+#ifndef LIBAC_WIN32_H
+#define LIBAC_WIN32_H
+
+#ifdef WIN32
+#define _Thread_local __declspec( thread )
+#else
+#define SOCKET int
+#define closesocket(socket) close(socket)
+#endif
+
+#endif /* LIBAC_WIN32_H */