Commit b83dd528 authored by Marcus Asteborg's avatar Marcus Asteborg Committed by Ralph Giles

cmake - MINGW check for ssp lib and link if security features is enabled

parent d4b8707b
Pipeline #2098 passed with stage
in 4 minutes and 57 seconds
......@@ -109,12 +109,21 @@ cmake_dependent_option(OPUS_STACK_PROTECTOR
OFF)
add_feature_info(OPUS_STACK_PROTECTOR OPUS_STACK_PROTECTOR ${OPUS_STACK_PROTECTOR_HELP_STR})
if(NOT MSVC AND NOT MINGW)
if(NOT MSVC)
set(OPUS_FORTIFY_SOURCE_HELP_STR "add protection against buffer overflows.")
option(OPUS_FORTIFY_SOURCE ${OPUS_FORTIFY_SOURCE_HELP_STR} ON)
cmake_dependent_option(OPUS_FORTIFY_SOURCE
${OPUS_FORTIFY_SOURCE_HELP_STR}
ON
"FORTIFY_SOURCE_SUPPORTED"
OFF)
add_feature_info(OPUS_FORTIFY_SOURCE OPUS_FORTIFY_SOURCE ${OPUS_FORTIFY_SOURCE_HELP_STR})
endif()
if(MINGW AND (OPUS_FORTIFY_SOURCE OR OPUS_STACK_PROTECTOR))
# ssp lib is needed for security features for MINGW
list(APPEND OPUS_REQUIRED_LIBRARIES ssp)
endif()
if(OPUS_CPU_X86 OR OPUS_CPU_X64)
set(OPUS_X86_MAY_HAVE_SSE_HELP_STR "does runtime check for SSE1 support.")
cmake_dependent_option(OPUS_X86_MAY_HAVE_SSE
......@@ -247,8 +256,9 @@ target_include_directories(
target_link_libraries(opus PRIVATE ${OPUS_REQUIRED_LIBRARIES})
target_compile_definitions(opus PRIVATE OPUS_BUILD ENABLE_HARDENING)
if(OPUS_FORTIFY_SOURCE)
target_compile_definitions(opus PRIVATE _FORTIFY_SOURCE=2)
if(OPUS_FORTIFY_SOURCE AND NOT MSVC)
target_compile_definitions(opus PRIVATE
$<$<NOT:$<CONFIG:debug>>:_FORTIFY_SOURCE=2>)
endif()
if(OPUS_FLOAT_APPROX)
......
......@@ -77,6 +77,18 @@ else()
check_flag(FAST_MATH -ffast-math)
check_flag(STACK_PROTECTOR -fstack-protector-strong)
check_flag(HIDDEN_VISIBILITY -fvisibility=hidden)
set(FORTIFY_SOURCE_SUPPORTED 1)
endif()
if(MINGW)
# For MINGW we need to link ssp lib for security features such as
# stack protector and fortify_sources
check_library_exists(ssp __stack_chk_fail "" HAVE_LIBSSP)
if(NOT HAVE_LIBSSP)
message(WARNING "Could not find libssp in MinGW, disabling STACK_PROTECTOR and FORTIFY_SOURCE")
set(STACK_PROTECTOR_SUPPORTED 0)
set(FORTIFY_SOURCE_SUPPORTED 0)
endif()
endif()
if(NOT MSVC)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment