From 045c98d8faffbc7fb613eeb0a0bc66135ce450ee Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Wed, 3 Apr 2024 10:30:04 +0000 Subject: [PATCH] build: only use -Werror=lto-type-mismatch on gcc Only pass -Werror=lto-type-mismatch to gcc, clang does not have this option and throws a warning. Also quote some barewords in if() statements. Signed-off-by: Rafael Kitover --- cmake/Toolchain-gcc-clang.cmake | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cmake/Toolchain-gcc-clang.cmake b/cmake/Toolchain-gcc-clang.cmake index ecce8a4e..29c725a2 100644 --- a/cmake/Toolchain-gcc-clang.cmake +++ b/cmake/Toolchain-gcc-clang.cmake @@ -27,7 +27,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") endif() # check if ssp flags are supported. -if(CMAKE_BUILD_TYPE STREQUAL Debug) +if(CMAKE_BUILD_TYPE STREQUAL "Debug") check_cxx_compiler_flag(-fstack-protector-strong STACK_PROTECTOR_SUPPORTED) if(STACK_PROTECTOR_SUPPORTED) @@ -44,14 +44,14 @@ if(NOT ENABLE_ASM) # inline asm is not allowed with -fPIC add_compile_options(-fPIC) endif() -if(CMAKE_BUILD_TYPE STREQUAL Debug) +if(CMAKE_BUILD_TYPE STREQUAL "Debug") add_compile_options(-ggdb3 -Og -fno-omit-frame-pointer -Wall -Wextra) else() add_compile_options(-Ofast -fomit-frame-pointer) endif() # for some reason this is necessary -if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD) +if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") include_directories(/usr/local/include) endif() @@ -60,5 +60,10 @@ if(VBAM_STATIC) endif() # To support LTO, this must always fail. -add_compile_options(-Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing) -add_link_options( -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing) +add_compile_options(-Werror=odr -Werror=strict-aliasing) +add_link_options( -Werror=odr -Werror=strict-aliasing) + +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + add_compile_options(-Werror=lto-type-mismatch) + add_link_options( -Werror=lto-type-mismatch) +endif()