mirror of
https://gitlab.com/shadow_contributor/ntptun.git
synced 2026-10-03 03:46:50 +00:00
74 lines
2.8 KiB
CMake
74 lines
2.8 KiB
CMake
cmake_minimum_required(VERSION 3.16)
|
|
project(ntptun LANGUAGES C CXX)
|
|
|
|
# ---- Standard / defaults ---------------------------------------------------
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Build type" FORCE)
|
|
endif()
|
|
|
|
# The app uses POSIX / Linux system APIs (sockets, TUN, sigaction) on Linux and
|
|
# Winsock on Windows. Expose the POSIX feature set explicitly on non-MSVC
|
|
# toolchains while keeping a strict language standard.
|
|
if(NOT MSVC)
|
|
add_compile_definitions(_GNU_SOURCE)
|
|
endif()
|
|
|
|
# ---- Warnings --------------------------------------------------------------
|
|
add_library(ntptun_warnings INTERFACE)
|
|
if(MSVC)
|
|
target_compile_options(ntptun_warnings INTERFACE /W4 /permissive-)
|
|
# Winsock deprecation/secure-CRT noise is not relevant here.
|
|
target_compile_definitions(ntptun_warnings INTERFACE
|
|
_CRT_SECURE_NO_WARNINGS _WINSOCK_DEPRECATED_NO_WARNINGS)
|
|
else()
|
|
target_compile_options(ntptun_warnings INTERFACE
|
|
-Wall -Wextra -Wpedantic -Wshadow -Wnon-virtual-dtor -Wcast-align
|
|
-Wunused -Wnull-dereference -Wdouble-promotion -Wformat=2)
|
|
endif()
|
|
|
|
# ---- Vendored crypto -------------------------------------------------------
|
|
# RFC 8439 (ChaCha20-Poly1305) AEAD, public-domain (CC0) reference sources under
|
|
# third_party/portable8439. Built as a separate C library so the project's
|
|
# strict C++ warning set is not applied to third-party code.
|
|
add_library(ntptun_crypto STATIC
|
|
third_party/portable8439/src/portable8439.c
|
|
third_party/portable8439/src/chacha-portable/chacha-portable.c
|
|
third_party/portable8439/src/poly1305-donna/poly1305-donna.c)
|
|
target_include_directories(ntptun_crypto PUBLIC
|
|
${CMAKE_CURRENT_SOURCE_DIR}/third_party/portable8439/src)
|
|
|
|
# ---- Core library ----------------------------------------------------------
|
|
set(ntptun_core_sources
|
|
src/Ntp.cpp
|
|
src/Carrier.cpp
|
|
src/Endpoint.cpp
|
|
src/Platform.cpp
|
|
src/UdpSocket.cpp
|
|
src/Config.cpp
|
|
src/Client.cpp
|
|
src/Server.cpp)
|
|
|
|
# The TUN transport is Linux-only; compile it only there.
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|
list(APPEND ntptun_core_sources src/TunDevice.cpp)
|
|
endif()
|
|
|
|
add_library(ntptun_core STATIC ${ntptun_core_sources})
|
|
target_include_directories(ntptun_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
|
target_link_libraries(ntptun_core PUBLIC ntptun_crypto)
|
|
target_link_libraries(ntptun_core PRIVATE ntptun_warnings)
|
|
if(WIN32)
|
|
target_link_libraries(ntptun_core PUBLIC ws2_32)
|
|
endif()
|
|
|
|
# ---- Executable ------------------------------------------------------------
|
|
add_executable(ntptun src/main.cpp)
|
|
target_link_libraries(ntptun PRIVATE ntptun_core ntptun_warnings)
|
|
|
|
# ---- Tests -----------------------------------------------------------------
|
|
enable_testing()
|
|
add_subdirectory(tests)
|