mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-21 14:33:55 +00:00
Add CXX to the project with C++20 (no extensions) and build C++ sources with -Wextra -fno-exceptions -fno-rtti -fno-threadsafe-statics on top of the existing warning flags. Give every toolchain a C++ compiler: the zig Windows toolchain, the static macOS/Windows CI jobs, the static musl image (clang++ plus libstdc++ headers) and the RPM spec.
57 lines
2.5 KiB
CMake
57 lines
2.5 KiB
CMake
include(CheckCCompilerFlag)
|
|
option(DISABLE_SSP "Disable stack protector" OFF)
|
|
if(NOT DISABLE_SSP AND NOT MSVC)
|
|
check_c_compiler_flag(-fstack-protector-strong HAS_STACK_PROTECTOR)
|
|
endif()
|
|
|
|
function(ss_project_options target)
|
|
set_property(TARGET ${target} PROPERTY NO_SYSTEM_FROM_IMPORTED TRUE)
|
|
target_include_directories(${target} BEFORE PRIVATE ${MBEDTLS_INCLUDE_DIRS})
|
|
if(WIN32)
|
|
target_compile_definitions(${target} PRIVATE WIN32_LEAN_AND_MEAN __USE_MINGW_ANSI_STDIO=1)
|
|
# MinGW can otherwise pull in libwinpthread/libgcc from the toolchain,
|
|
# even when all explicitly selected dependencies are static archives.
|
|
get_target_property(ss_target_type ${target} TYPE)
|
|
# Zig already supplies its own runtime for DLLs; its -static switch
|
|
# changes the output kind instead of just selecting static libraries.
|
|
if(NOT ss_target_type STREQUAL "SHARED_LIBRARY" OR CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
|
target_link_options(${target} PRIVATE -static)
|
|
endif()
|
|
endif()
|
|
if(MSVC)
|
|
target_compile_options(${target} PRIVATE /W4)
|
|
if(SS_WARNINGS_AS_ERRORS)
|
|
target_compile_options(${target} PRIVATE /WX)
|
|
endif()
|
|
else()
|
|
target_compile_options(${target} PRIVATE -Wall -Wno-deprecated-declarations -fno-strict-aliasing)
|
|
# C++ sources: no exceptions or RTTI, and no locks around function
|
|
# statics (the event loop is single-threaded).
|
|
target_compile_options(${target} PRIVATE
|
|
$<$<COMPILE_LANGUAGE:CXX>:-Wextra -fno-exceptions -fno-rtti -fno-threadsafe-statics>)
|
|
if(SS_WARNINGS_AS_ERRORS)
|
|
target_compile_options(${target} PRIVATE -Werror)
|
|
endif()
|
|
if(HAS_STACK_PROTECTOR)
|
|
target_compile_options(${target} PRIVATE -fstack-protector-strong)
|
|
endif()
|
|
if(MINGW OR CYGWIN)
|
|
target_compile_options(${target} PRIVATE -mno-ms-bitfields)
|
|
endif()
|
|
endif()
|
|
if(LINUX)
|
|
target_compile_definitions(${target} PRIVATE _GNU_SOURCE)
|
|
endif()
|
|
if(ENABLE_SANITIZERS)
|
|
if(MSVC)
|
|
message(FATAL_ERROR "ASan + UBSan requires GCC or Clang")
|
|
endif()
|
|
target_compile_options(${target} PRIVATE -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer)
|
|
target_link_options(${target} PRIVATE -fsanitize=address,undefined)
|
|
endif()
|
|
if(ENABLE_COVERAGE)
|
|
target_compile_options(${target} PRIVATE -O0 --coverage)
|
|
target_link_options(${target} PRIVATE --coverage)
|
|
endif()
|
|
endfunction()
|