Skip to content

Commit

Permalink
build: fix posix builds
Browse files Browse the repository at this point in the history
Signed-off-by: hexian000 <[email protected]>
  • Loading branch information
hexian000 committed Jan 2, 2024
1 parent 1d6bf91 commit 6baa01c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion contrib/csnippets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion m.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 6baa01c

Please sign in to comment.