Skip to content

Commit

Permalink
build: Allow non-strict aliasing and overflow optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
jcm93 committed Jan 6, 2025
1 parent 2ed2ed3 commit bddf4c4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cmake/common/compiler_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE)
# clang options for C, C++, ObjC, and ObjC++
set(
_ares_clang_common_options
-fno-strict-aliasing
-Wblock-capture-autoreleasing
# -Wswitch
-Wdeprecated
Expand Down Expand Up @@ -99,6 +100,12 @@ set(
-Wno-delete-non-abstract-non-virtual-dtor
)

set(
_ares_gcc_common_options
-fwrapv
-fno-strict-aliasing
)

if(NOT DEFINED CMAKE_COMPILE_WARNING_AS_ERROR)
set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)
endif()
5 changes: 5 additions & 0 deletions cmake/linux/compilerconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(
"$<$<COMPILE_LANGUAGE:C>:${_ares_clang_c_options}>"
"$<$<COMPILE_LANGUAGE:CXX>:${_ares_clang_cxx_options}>"
-fwrapv
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(
${_ares_gcc_common_options}
)
endif()
1 change: 1 addition & 0 deletions cmake/macos/compilerconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if(NOT XCODE)
add_compile_options(
"$<$<COMPILE_LANGUAGE:C>:${_ares_clang_c_options}>"
"$<$<COMPILE_LANGUAGE:CXX>:${_ares_clang_cxx_options}>"
-fwrapv
-mmacos-version-min=10.13
)
endif()
1 change: 1 addition & 0 deletions cmake/macos/xcode.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VALUE YES)
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VARIABLE NO) # todo
set(CMAKE_XCODE_ATTRIBUTE_GCC_NO_COMMON_BLOCKS YES)
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_64_TO_32_BIT_CONVERSION NO) # todo
set(CMAKE_XCODE_ATTRIBUTE_GCC_STRICT_ALIASING NO)

set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS NO)
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_SHADOW NO)
Expand Down
9 changes: 8 additions & 1 deletion cmake/windows/compilerconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,16 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
"$<$<COMPILE_LANGUAGE:C,CXX>:${_ares_clang_cl_c_cxx_options}>"
)
if(NOT MSVC)
# statically link libstdc++ if compiling under msys2/mingw
# we are on msys2 clang
# statically link libc++
add_link_options(-static-libstdc++)
# msys2/mingw-specific invocations to make clang emit debug symbols
set(_ares_mingw_clang_debug_compile_options -g -gcodeview)
set(_ares_mingw_clang_debug_link_options -fuse-ld=lld -g -Wl,--pdb=)
add_compile_options("$<$<CONFIG:Debug,RelWithDebInfo>:${_ares_mingw_clang_debug_compile_options}>")
add_link_options("$<$<CONFIG:Debug,RelWithDebInfo>:${_ares_mingw_clang_debug_link_options}>")
# clang-cl does not understand -fwrapv, but we do want it on msys2 clang
add_compile_options(-fwrapv)
else()
# generate PDBs rather than embed debug symbols
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT ProgramDatabase)
Expand Down Expand Up @@ -114,6 +117,10 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if(CMAKE_COMPILE_WARNING_AS_ERROR)
add_link_options(/WX)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(
${_ares_gcc_common_options}
)
endif()

if(NOT MINGW)
Expand Down

0 comments on commit bddf4c4

Please sign in to comment.