File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -109,10 +109,19 @@ cmake_dependent_option(OPUS_STACK_PROTECTOR
109109 OFF )
110110add_feature_info (OPUS_STACK_PROTECTOR OPUS_STACK_PROTECTOR ${OPUS_STACK_PROTECTOR_HELP_STR} )
111111
112- if (NOT MSVC AND NOT MINGW)
113- set (OPUS_FORTIFY_SOURCE_HELP_STR "add protection against buffer overflows." )
114- option (OPUS_FORTIFY_SOURCE ${OPUS_FORTIFY_SOURCE_HELP_STR} ON )
115- add_feature_info (OPUS_FORTIFY_SOURCE OPUS_FORTIFY_SOURCE ${OPUS_FORTIFY_SOURCE_HELP_STR} )
112+ if (NOT MSVC )
113+ set (OPUS_FORTIFY_SOURCE_HELP_STR "add protection against buffer overflows." )
114+ cmake_dependent_option (OPUS_FORTIFY_SOURCE
115+ ${OPUS_FORTIFY_SOURCE_HELP_STR}
116+ ON
117+ "FORTIFY_SOURCE_SUPPORTED"
118+ OFF )
119+ add_feature_info (OPUS_FORTIFY_SOURCE OPUS_FORTIFY_SOURCE ${OPUS_FORTIFY_SOURCE_HELP_STR} )
120+ endif ()
121+
122+ if (MINGW AND (OPUS_FORTIFY_SOURCE OR OPUS_STACK_PROTECTOR))
123+ # ssp lib is needed for security features for MINGW
124+ list (APPEND OPUS_REQUIRED_LIBRARIES ssp)
116125endif ()
117126
118127if (OPUS_CPU_X86 OR OPUS_CPU_X64)
@@ -247,8 +256,9 @@ target_include_directories(
247256target_link_libraries (opus PRIVATE ${OPUS_REQUIRED_LIBRARIES} )
248257target_compile_definitions (opus PRIVATE OPUS_BUILD ENABLE_HARDENING )
249258
250- if (OPUS_FORTIFY_SOURCE)
251- target_compile_definitions (opus PRIVATE _FORTIFY_SOURCE=2 )
259+ if (OPUS_FORTIFY_SOURCE AND NOT MSVC )
260+ target_compile_definitions (opus PRIVATE
261+ $<$<NOT :$<CONFIG :debug >>:_FORTIFY_SOURCE =2>)
252262endif ()
253263
254264if (OPUS_FLOAT_APPROX)
Original file line number Diff line number Diff line change @@ -77,6 +77,18 @@ else()
7777 check_flag (FAST_MATH -ffast-math )
7878 check_flag (STACK_PROTECTOR -fstack-protector-strong )
7979 check_flag (HIDDEN_VISIBILITY -fvisibility=hidden )
80+ set (FORTIFY_SOURCE_SUPPORTED 1)
81+ endif ()
82+
83+ if (MINGW)
84+ # For MINGW we need to link ssp lib for security features such as
85+ # stack protector and fortify_sources
86+ check_library_exists (ssp __stack_chk_fail "" HAVE_LIBSSP )
87+ if (NOT HAVE_LIBSSP)
88+ message (WARNING "Could not find libssp in MinGW, disabling STACK_PROTECTOR and FORTIFY_SOURCE" )
89+ set (STACK_PROTECTOR_SUPPORTED 0)
90+ set (FORTIFY_SOURCE_SUPPORTED 0)
91+ endif ()
8092endif ()
8193
8294if (NOT MSVC )
You can’t perform that action at this time.
0 commit comments