From: Sam James Date: Thu, 9 Jan 2025 11:36:40 +0000 (+0000) Subject: cmake: disable LTO for some configure checks X-Git-Tag: 2.2.4~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d24fb846f5ed7f9eec27283b4e5c576b1390b29;p=thirdparty%2Fzlib-ng.git cmake: disable LTO for some configure checks Some of zlib-ng's configure tests define a function expecting it to be compiled but don't call that function, or don't use its return value. This is risky with LTO where the whole thing may be optimised out, which has happened before: * https://github.com/zlib-ng/zlib-ng/issues/1616 * https://github.com/zlib-ng/zlib-ng/pull/1622 * https://gitlab.kitware.com/cmake/cmake/-/issues/26103 Closes: https://github.com/zlib-ng/zlib-ng/issues/1841 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index b97c2021..f5c86389 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -301,7 +301,7 @@ if(NOT WITH_RUNTIME_CPU_DETECTION) message(STATUS "WARNING: Microsoft Visual Studio does not support compile time detection of CPU features for \"/arch\" before \"AVX\"") # Workaround for MSVC. By default MSVC does not define the __SSE*__ macros. # Fix it if AVX is enabled. - set(CMAKE_REQUIRED_FLAGS "${NATIVEFLAG}") + set(CMAKE_REQUIRED_FLAGS "${NATIVEFLAG} ${ZNOLTOFLAG}") check_c_source_compiles( "#ifndef __AVX__ # error \"AVX is not enabled.\" @@ -491,6 +491,7 @@ endif() # # Check for __builtin_assume_aligned(x,n) support in the compiler # +set(CMAKE_REQUIRED_FLAGS ${ZNOLTOFLAG}) check_c_source_compiles( "char *test(char *buffer) { char *abuffer = __builtin_assume_aligned(buffer,64); @@ -503,10 +504,12 @@ check_c_source_compiles( if(HAVE_BUILTIN_ASSUME_ALIGNED) add_definitions(-DHAVE_BUILTIN_ASSUME_ALIGNED) endif() +set(CMAKE_REQUIRED_FLAGS) # # check for __builtin_ctz() support in the compiler # +set(CMAKE_REQUIRED_FLAGS ${ZNOLTOFLAG}) check_c_source_compiles( "int main(void) { unsigned int zero = 0; @@ -519,10 +522,12 @@ check_c_source_compiles( if(HAVE_BUILTIN_CTZ) add_definitions(-DHAVE_BUILTIN_CTZ) endif() +set(CMAKE_REQUIRED_FLAGS) # # check for __builtin_ctzll() support in the compiler # +set(CMAKE_REQUIRED_FLAGS ${ZNOLTOFLAG}) check_c_source_compiles( "int main(void) { unsigned int zero = 0; @@ -535,6 +540,7 @@ check_c_source_compiles( if(HAVE_BUILTIN_CTZLL) add_definitions(-DHAVE_BUILTIN_CTZLL) endif() +set(CMAKE_REQUIRED_FLAGS) # # check for ptrdiff_t support