From bfb83f745981f16f140cf64bfc3236de5e99ebca Mon Sep 17 00:00:00 2001 From: Evgeny Date: Mon, 6 Jul 2026 11:48:56 +0300 Subject: [PATCH] chatgui: add CMake build for libutun (C library linked into GUI) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add tools/chatgui/libutun/CMakeLists.txt — builds libuasync (from lib/*.c) and libutun (from src/*.c except utun.c) as static libraries - All C code compiled as C99, linked into chatgui C++ binary - Include paths and defs match autotools build - chatgui CMakeLists.txt: add_subdirectory(libutun), link utun library - Fix zxing-cpp docs/ directory issue --- tools/chatgui/CMakeLists.txt | 8 +- tools/chatgui/libutun/CMakeLists.txt | 139 ++++++++++++++++++++ tools/chatgui/zxing-cpp/docs/CMakeLists.txt | 1 + 3 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 tools/chatgui/libutun/CMakeLists.txt create mode 100644 tools/chatgui/zxing-cpp/docs/CMakeLists.txt diff --git a/tools/chatgui/CMakeLists.txt b/tools/chatgui/CMakeLists.txt index ccbf15f6..600433fd 100644 --- a/tools/chatgui/CMakeLists.txt +++ b/tools/chatgui/CMakeLists.txt @@ -5,6 +5,9 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) +set(CMAKE_C_STANDARD 99) + +find_package(OpenSSL REQUIRED) find_package(Qt5 COMPONENTS Widgets Network Test QUIET) if(NOT Qt5_FOUND) @@ -37,6 +40,9 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "") add_subdirectory(zxing-cpp) set_target_properties(ZXing PROPERTIES AUTOMOC OFF) +# uTun core library (C, built from ../src/ and ../lib/) +add_subdirectory(libutun) + add_executable(chatgui src/main.cpp src/mainwindow.cpp @@ -66,7 +72,7 @@ add_executable(chatgui target_include_directories(chatgui PRIVATE ${CMAKE_SOURCE_DIR}/db) target_compile_definitions(chatgui PRIVATE SQLITE_THREADSAFE=1) set_source_files_properties(db/sqlite3.c PROPERTIES LANGUAGE C) -target_link_libraries(chatgui PRIVATE ${QT_LIBS} rlottie::rlottie ZLIB::ZLIB OpenSSL::Crypto ZXing::ZXing pthread dl) +target_link_libraries(chatgui PRIVATE ${QT_LIBS} rlottie::rlottie ZLIB::ZLIB OpenSSL::Crypto ZXing::ZXing utun pthread dl) # ============================================================================ # Tests diff --git a/tools/chatgui/libutun/CMakeLists.txt b/tools/chatgui/libutun/CMakeLists.txt new file mode 100644 index 00000000..7ae486c5 --- /dev/null +++ b/tools/chatgui/libutun/CMakeLists.txt @@ -0,0 +1,139 @@ +cmake_minimum_required(VERSION 3.16) + +set(LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../lib) +set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../src) + +# ============================================================================ +# libuasync — low-level runtime library +# ============================================================================ + +set(UASYNC_SOURCES + ${LIB_DIR}/ll_queue.c + ${LIB_DIR}/u_async.c + ${LIB_DIR}/debug_config.c + ${LIB_DIR}/timeout_heap.c + ${LIB_DIR}/memory_pool.c + ${LIB_DIR}/sha256.c + ${LIB_DIR}/socket_compat.c + ${LIB_DIR}/platform_compat.c + ${LIB_DIR}/getmyip.c + ${LIB_DIR}/swm_min.c + ${LIB_DIR}/mem.c + ${LIB_DIR}/radix.c + ${LIB_DIR}/serialize.c + ${LIB_DIR}/tcp_io.c + ${LIB_DIR}/liblmdb/mdb.c + ${LIB_DIR}/liblmdb/midl.c +) + +add_library(uasync STATIC ${UASYNC_SOURCES}) + +target_include_directories(uasync PUBLIC + ${LIB_DIR} + ${SRC_DIR} + ${LIB_DIR}/liblmdb +) + +target_compile_definitions(uasync PRIVATE + _ISOC99_SOURCE + DEBUG_OUTPUT_STDERR +) + +set_target_properties(uasync PROPERTIES + C_STANDARD 99 + C_STANDARD_REQUIRED ON +) + +# ============================================================================ +# libutun — VPN core library (all src/ except utun.c) +# ============================================================================ + +# Common sources (all platforms) +set(UTUN_COMMON_SOURCES + ${SRC_DIR}/utun_instance.c + ${SRC_DIR}/config_parser.c + ${SRC_DIR}/config_updater.c + ${SRC_DIR}/route_lib.c + ${SRC_DIR}/route6_lib.c + ${SRC_DIR}/route_bgp.c + ${SRC_DIR}/route_ping.c + ${SRC_DIR}/route_node.c + ${SRC_DIR}/route_node_lmdb.c + ${SRC_DIR}/route_connectivity.c + ${SRC_DIR}/conn_mgr.c + ${SRC_DIR}/db_sync.c + ${SRC_DIR}/routing.c + ${SRC_DIR}/tun_if.c + ${SRC_DIR}/tun_route.c + ${SRC_DIR}/etcp.c + ${SRC_DIR}/etcp_connections.c + ${SRC_DIR}/etcp_bbr.c + ${SRC_DIR}/etcp_loadbalancer.c + ${SRC_DIR}/etcp_debug.c + ${SRC_DIR}/etcp_dump.c + ${SRC_DIR}/secure_channel.c + ${SRC_DIR}/crc32.c + ${SRC_DIR}/stcp_link.c + ${SRC_DIR}/stcp.c + ${SRC_DIR}/stcp_server.c + ${SRC_DIR}/stcp_client.c + ${SRC_DIR}/pkt_normalizer.c + ${SRC_DIR}/packet_dump.c + ${SRC_DIR}/etcp_api.c + ${SRC_DIR}/etcp_connect.c + ${SRC_DIR}/control_server.c + ${SRC_DIR}/msg_transport.c + ${SRC_DIR}/firewall.c + ${SRC_DIR}/eim_nat.c + ${SRC_DIR}/nat_transport.c + ${SRC_DIR}/dummynet.c + ${SRC_DIR}/etcp_router.c + ${SRC_DIR}/proxy/tcp_proxy_client.c + ${SRC_DIR}/proxy/tcp_proxy_server.c + ${SRC_DIR}/proxy/udp_proxy.c + ${SRC_DIR}/proxy/socks_proxy.c + ${SRC_DIR}/proxy/icmp_proxy.c + ${SRC_DIR}/lwip_tcp/lwip_pbuf.c + ${SRC_DIR}/lwip_tcp/lwip_tcp.c + ${SRC_DIR}/lwip_tcp/lwip_tcp_in.c + ${SRC_DIR}/lwip_tcp/lwip_tcp_out.c +) + +# Platform-specific TUN implementation +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(UTUN_TUN_SOURCES ${SRC_DIR}/tun_linux.c) +elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + set(UTUN_TUN_SOURCES ${SRC_DIR}/tun_freebsd.c) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(UTUN_TUN_SOURCES ${SRC_DIR}/tun_windows.c) +else() + set(UTUN_TUN_SOURCES ${SRC_DIR}/tun_linux.c) +endif() + +add_library(utun STATIC ${UTUN_COMMON_SOURCES} ${UTUN_TUN_SOURCES}) + +target_include_directories(utun PUBLIC + ${SRC_DIR} + ${LIB_DIR} + ${SRC_DIR}/uip +) + +target_compile_definitions(utun PRIVATE + USE_OPENSSL +) + +set_target_properties(utun PROPERTIES + C_STANDARD 99 + C_STANDARD_REQUIRED ON +) + +target_link_libraries(utun PUBLIC + uasync + OpenSSL::Crypto + ${CMAKE_THREAD_LIBS_INIT} +) + +# Platform-specific link flags +if(WIN32) + target_link_libraries(utun PUBLIC ws2_32 iphlpapi advapi32 bcrypt dbghelp) +endif() diff --git a/tools/chatgui/zxing-cpp/docs/CMakeLists.txt b/tools/chatgui/zxing-cpp/docs/CMakeLists.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/tools/chatgui/zxing-cpp/docs/CMakeLists.txt @@ -0,0 +1 @@ +