From 6baa01c53e3ac9ed8b0aa1d20ff866a7d3f8b6b0 Mon Sep 17 00:00:00 2001 From: hexian000 Date: Tue, 2 Jan 2024 10:44:29 +0800 Subject: [PATCH] build: fix posix builds Signed-off-by: hexian000 --- CMakeLists.txt | 5 +++-- contrib/csnippets/CMakeLists.txt | 2 +- m.sh | 2 +- src/CMakeLists.txt | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d68f34..7d33a2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ message(STATUS "Project version: ${PROJECT_VERSION_STRING}") include(CTest) -option(TARGET_POSIX "Use POSIX API only" OFF) +option(FORCE_POSIX "Use POSIX-compliant APIs only" OFF) option(BUILD_STATIC "Build static executables, link everything statically" OFF) option(LINK_STATIC_LIBS "Link against static libraries" OFF) option(ENABLE_SANITIZERS "Build with sanitizers" OFF) @@ -77,9 +77,10 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "Clang") endif() endif() -if(NOT TARGET_POSIX AND (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")) +if(NOT FORCE_POSIX AND (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")) message(STATUS "Linux system: ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}") list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE") + set(TARGET_LINUX TRUE) else() message(STATUS "POSIX-compliant system: ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}") list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_POSIX_C_SOURCE=200809L") diff --git a/contrib/csnippets/CMakeLists.txt b/contrib/csnippets/CMakeLists.txt index 058eab3..b355b15 100644 --- a/contrib/csnippets/CMakeLists.txt +++ b/contrib/csnippets/CMakeLists.txt @@ -4,7 +4,7 @@ target_compile_options(csnippets PUBLIC "-include${CMAKE_CURRENT_BINARY_DIR}/con target_compile_options(csnippets PRIVATE -pedantic -Wall -Wextra) target_compile_definitions(csnippets PUBLIC MCACHE_STATS=0) -if(NOT TARGET_POSIX AND (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")) +if(TARGET_LINUX) target_compile_definitions(csnippets PRIVATE _GNU_SOURCE) else() target_compile_definitions(csnippets PRIVATE _POSIX_C_SOURCE=200809L) diff --git a/m.sh b/m.sh index a5e2539..143751e 100755 --- a/m.sh +++ b/m.sh @@ -67,7 +67,7 @@ case "$1" in cmake -G "${GENERATOR}" \ -DCMAKE_BUILD_TYPE="Release" \ -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \ - -DTARGET_POSIX=1 \ + -DFORCE_POSIX=1 \ -S "." -B "build" nice cmake --build "build" ls -lh "build/src/kcptun-libev" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bfb5342..9216ab0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,7 +11,7 @@ add_executable(kcptun-libev main.c obfs.c obfs.h event_tcp.c event_kcp.c event_pkt.c event_http.c event_timer.c event.h event_impl.h) -if(NOT TARGET_POSIX AND (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")) +if(TARGET_LINUX) target_compile_definitions(kcptun-libev PRIVATE _GNU_SOURCE) else() target_compile_definitions(kcptun-libev PRIVATE _POSIX_C_SOURCE=200809L) @@ -71,7 +71,7 @@ if(WITH_SODIUM) set(WITH_CRYPTO TRUE) endif() -if(WITH_CRYPTO AND (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")) +if(WITH_CRYPTO AND TARGET_LINUX) set(WITH_OBFS TRUE) endif()