aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrumeet <yuuta@yuuta.moe>2022-07-27 15:03:00 -0700
committerTrumeet <yuuta@yuuta.moe>2022-07-27 15:03:00 -0700
commitd935aa8516f2eab5cbde467b9c92400dcf636bcb (patch)
tree49c9a70ea57b4cb3fd74ad9bf6e1ca913da456ae
parent3a450ee1759b3df38d698daabdfafd0447d8223a (diff)
downloadacron-d935aa8516f2eab5cbde467b9c92400dcf636bcb.tar
acron-d935aa8516f2eab5cbde467b9c92400dcf636bcb.tar.gz
acron-d935aa8516f2eab5cbde467b9c92400dcf636bcb.tar.bz2
acron-d935aa8516f2eab5cbde467b9c92400dcf636bcb.zip
build(libacron): switch to Meson
Meson is better on resolving dependencies on various platforms.
-rw-r--r--client/libacron/CMakeLists.txt100
-rw-r--r--client/libacron/README.md34
-rw-r--r--client/libacron/meson.build81
-rw-r--r--client/libacron/private/helpers.c10
-rw-r--r--client/libacron/private/win32.h2
-rw-r--r--client/libacron/setup.bat20
-rw-r--r--client/libacron/subprojects/.gitignore3
-rw-r--r--client/libacron/subprojects/json-c.wrap13
8 files changed, 120 insertions, 143 deletions
diff --git a/client/libacron/CMakeLists.txt b/client/libacron/CMakeLists.txt
deleted file mode 100644
index 57da4af..0000000
--- a/client/libacron/CMakeLists.txt
+++ /dev/null
@@ -1,100 +0,0 @@
-cmake_minimum_required(VERSION 3.22)
-project(libac C)
-
-set(CMAKE_C_STANDARD 11)
-
-if(NOT CMAKE_BUILD_TYPE)
- set(CMAKE_BUILD_TYPE Debug)
-endif()
-
-add_definitions(-D_POSIX_C_SOURCE=200809L)
-IF(CMAKE_BUILD_TYPE MATCHES Debug)
- add_definitions(-DDEBUG)
-ENDIF(CMAKE_BUILD_TYPE MATCHES Debug)
-
-if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
- set(CMAKE_C_FLAGS_DEBUG
- "${CMAKE_C_FLAGS_DEBUG} -g3 -O0 -fsanitize=address")
- set(CMAKE_EXE_LINKER_FLAGS_DEBUG
- "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address")
- set(CMAKE_C_FLAGS
- "${CMAKE_C_FLAGS} -fvisibility=hidden")
-elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
- # TODO: MSVC ASAN
- set(CMAKE_C_FLAGS_DEBUG
- "${CMAKE_C_FLAGS_DEBUG} /DEBUG /Z7 /Od")
- set(CMAKE_EXE_LINKER_FLAGS_DEBUG
- "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
-endif()
-
-set(LIBAC_PUBLIC_HEADERS
- include/incl.h
- include/libac.h
- include/events.h
- include/requests.h
- include/common.h
- include/net.h
- include/ids.h
- )
-
-set(LIBAC_PRIVATE
- private/win32.h
- private/config.h
- private/serializer.h
- private/helpers.c
- private/serializer.h
- private/log.h
- private/connection.h
- wic/include/http_parser.h
- wic/include/wic.h
- private/serializer.c
- private/helpers.c
- private/log.c
- wic/src/http_parser.c
- wic/src/wic.c
- net.c
- ids.c
- library.c
- )
-
-add_library(ac SHARED
- ${LIBAC_PUBLIC_HEADERS}
- ${LIBAC_PRIVATE}
- )
-add_library(ac-static STATIC
- ${LIBAC_PUBLIC_HEADERS}
- ${LIBAC_PRIVATE}
- )
-
-set(LIBAC_INCLUDES "${PROJECT_BINARY_DIR}" include/ private/ wic/include/)
-
-if (EXISTS ${CMAKE_SOURCE_DIR}/json-c/build/install)
- message("Using in-tree JSON-C")
- list(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/json-c/build/install/lib/cmake/")
-else()
- message("Using system-wide JSON-C")
-endif()
-
-if(WIN32)
- set(LIBAC_DEPS ws2_32)
-else()
- set(LIBAC_DEPS m)
-endif()
-
-find_package(json-c CONFIG)
-set(LIBAC_DEPS ${LIBAC_DEPS} json-c::json-c)
-
-target_include_directories(ac PUBLIC ${LIBAC_INCLUDES})
-target_link_libraries(ac ${LIBAC_DEPS})
-target_include_directories(ac-static PUBLIC ${LIBAC_INCLUDES})
-target_link_libraries(ac-static ${LIBAC_DEPS})
-
-install(TARGETS ac ac-static
- EXPORT ${PROJECT_NAME}-targets
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
- INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/libac
-)
-
-install(FILES ${LIBAC_PUBLIC_HEADERS} DESTINATION include/libac)
diff --git a/client/libacron/README.md b/client/libacron/README.md
index 4514e21..5fba5c6 100644
--- a/client/libacron/README.md
+++ b/client/libacron/README.md
@@ -9,7 +9,7 @@ Requirements:
* `json-c` installed and using PkgConfig
* Git
-* CMake
+* Meson
* A C11 or higher C compiler
* Connectivity to this git repository and `github.com`
@@ -20,11 +20,10 @@ git clone https://git.yuuta.moe/Minecraft/acron.git
cd acron
git submodule update --init
cd client/libacron/
-mkdir build
+meson build -Dbuildtype=release
cd build
-cmake -DCMAKE_BUILD_TYPE=Release ..
-cmake --build .
-DESTDIR=$(pwd)/install cmake --install .
+ninja
+DESTDIR=$(pwd)/install meson install
```
The shared library will be at `libac.so` (`ac.dll` on Windows). The static library will be at `libac-static.a` (`ac-static.lib` on Windows).
@@ -33,18 +32,6 @@ The distributable headers are at `install/usr/local/include/libac/`.
To make debug builds, use the Debug build type. Debug builds will have ASAN enabled.
-To build on Windows:
-
-```batch
-git clone https://git.yuuta.moe/Minecraft/acron.git
-CD acron
-git submodule update --init
-CD client/libacron/
-setup.bat
-mkdir build
-cmake -DCMAKE_BUILD_TYPE=Release ..
-cmake --build .
-```
## Usage
@@ -264,6 +251,19 @@ connection-related functions from any threads.
Example `apps/helloworld/main.c` has a naive cross-platform example of how to guard the connection using
a mutex.
+## Development
+
+To make development builds, use the following `meson(1)` command:
+
+```shell
+CC=cc meson build -Dsanitize=address
+```
+
+1. If you have `ccache` installed, you need to manually specify a C compiler to NOT use ccache, as CLion does not recognize ccache.
+2. Use `-Dsanitize` to enable ASAN.
+
+To open in CLion, refer to [https://blog.jetbrains.com/clion/2021/01/working-with-meson-in-clion-using-compilation-db](https://blog.jetbrains.com/clion/2021/01/working-with-meson-in-clion-using-compilation-db/). Be warned that CLion support is still primitive.
+
## Roadmap
* Make unit tests
diff --git a/client/libacron/meson.build b/client/libacron/meson.build
new file mode 100644
index 0000000..bd79834
--- /dev/null
+++ b/client/libacron/meson.build
@@ -0,0 +1,81 @@
+project('libac', 'c',
+ version : '1.0',
+ license : 'GPL-2.0-only',
+ default_options : [
+ 'c_std=gnu11', # c11 won't have ssize_t
+ 'b_lundef=false'
+ ]
+)
+
+xtra_link_args = []
+xtra_c_args = []
+if get_option('debug') == true
+ add_global_arguments('-DDEBUG', language : 'c')
+endif
+
+if meson.get_compiler('c').get_id() != 'msvc'
+ xtra_c_args = [ '-fvisibility=hidden' ]
+endif
+
+add_global_arguments('-D_POSIX_C_SOURCE=200809L', language : 'c')
+
+install_headers([
+ 'include/common.h',
+ 'include/events.h',
+ 'include/ids.h',
+ 'include/incl.h',
+ 'include/libac.h',
+ 'include/net.h',
+ 'include/requests.h'
+ ],
+ subdir : 'libac'
+)
+
+libac_sources = [
+ 'ids.c',
+ 'library.c',
+ 'net.c',
+ 'private/helpers.c',
+ 'private/log.c',
+ 'private/serializer.c',
+ 'wic/src/http_parser.c',
+ 'wic/src/wic.c'
+]
+
+inc = include_directories('include', 'private', 'wic/include')
+
+jsonc_dep = dependency('json-c',
+ fallback : [ 'json-c', 'json_c_dep' ],
+ default_options: [ 'default_library=static' ]
+)
+
+cc = meson.get_compiler('c')
+m_dep = cc.find_library('m', required : false)
+
+libac = library('ac',
+ libac_sources,
+ version : '1.0',
+ soversion : '0',
+ include_directories : inc,
+ dependencies : [ jsonc_dep, m_dep ],
+ link_args : xtra_link_args,
+ c_args : xtra_c_args,
+ install : true
+)
+
+pkg_mod = import('pkgconfig')
+pkg_mod.generate(
+ libraries : libac,
+ version : '1.0',
+ name : 'libac',
+ filebase : 'ac',
+ description : 'Acron client library'
+)
+
+# Warnings
+if get_option('debug') == true
+ message('Debug build')
+ if get_option('b_sanitize') == 'none'
+ message('Make sure to use -Db_sanitize=address to enable ASAN for debug builds.')
+ endif
+endif
diff --git a/client/libacron/private/helpers.c b/client/libacron/private/helpers.c
index 0cb452b..a859e80 100644
--- a/client/libacron/private/helpers.c
+++ b/client/libacron/private/helpers.c
@@ -12,7 +12,7 @@
#include <errno.h>
#include <stdio.h>
-#ifdef WIN32
+#ifdef _WIN32
#include <windows.h>
#endif
@@ -53,14 +53,14 @@ int strdup2(const char *str, char **out) {
return AC_E_OK;
}
-#ifdef WIN32
+#ifdef _WIN32
static _Thread_local LPTSTR err_buf = NULL;
#else
static _Thread_local char err_buf[1024];
#endif
char *strerror2(int errnum) {
-#ifdef WIN32
+#ifdef _WIN32
if (err_buf) {
LocalFree(err_buf);
err_buf = NULL;
@@ -88,10 +88,10 @@ char *strerror2(int errnum) {
}
void helpers_cleanup(void) {
-#ifdef WIN32
+#ifdef _WIN32
if (err_buf) {
LocalFree(err_buf);
err_buf = NULL;
}
#endif
-} \ No newline at end of file
+}
diff --git a/client/libacron/private/win32.h b/client/libacron/private/win32.h
index a907b28..3f39840 100644
--- a/client/libacron/private/win32.h
+++ b/client/libacron/private/win32.h
@@ -5,7 +5,7 @@
#ifndef LIBAC_WIN32_H
#define LIBAC_WIN32_H
-#ifdef WIN32
+#ifdef _WIN32
#define _Thread_local __declspec( thread )
#endif
diff --git a/client/libacron/setup.bat b/client/libacron/setup.bat
deleted file mode 100644
index 52f33d1..0000000
--- a/client/libacron/setup.bat
+++ /dev/null
@@ -1,20 +0,0 @@
-@ECHO OFF
-ECHO Setting up Windows builds ...
-
-git clone --depth 1 --branch json-c-0.16 https://github.com/json-c/json-c.git json-c
-if %errorlevel% neq 0 exit /b %errorlevel%
-
-MKDIR json-c\build\
-if %errorlevel% neq 0 exit /b %errorlevel%
-MKDIR json-c\build\install\
-if %errorlevel% neq 0 exit /b %errorlevel%
-
-CD json-c\build\
-
-cmake -DCMAKE_INSTALL_PREFIX=install -DCMAKE_BUILD_TYPE=release -DBUILD_SHARED_LIBS=OFF ..
-if %errorlevel% neq 0 exit /b %errorlevel%
-
-cmake --build . --target install
-if %errorlevel% neq 0 exit /b %errorlevel%
-
-CD ..\..\ \ No newline at end of file
diff --git a/client/libacron/subprojects/.gitignore b/client/libacron/subprojects/.gitignore
new file mode 100644
index 0000000..3ae03aa
--- /dev/null
+++ b/client/libacron/subprojects/.gitignore
@@ -0,0 +1,3 @@
+*
+*/
+!*.wrap
diff --git a/client/libacron/subprojects/json-c.wrap b/client/libacron/subprojects/json-c.wrap
new file mode 100644
index 0000000..5084932
--- /dev/null
+++ b/client/libacron/subprojects/json-c.wrap
@@ -0,0 +1,13 @@
+[wrap-file]
+directory = json-c-0.16
+source_url = https://s3.amazonaws.com/json-c_releases/releases/json-c-0.16.tar.gz
+source_filename = json-c-0.16.tar.gz
+source_hash = 8e45ac8f96ec7791eaf3bb7ee50e9c2100bbbc87b8d0f1d030c5ba8a0288d96b
+patch_filename = json-c_0.16-1_patch.zip
+patch_url = https://wrapdb.mesonbuild.com/v2/json-c_0.16-1/get_patch
+patch_hash = 69db1e0c391c6a00c42d05c0d845bd551d92db10171f4a40d0b070f29f918101
+wrapdb_version = 0.16-1
+
+[provide]
+json-c = json_c_dep
+