From: lawadr <3211473+lawadr@users.noreply.github.com> Date: Tue, 4 Apr 2023 13:53:35 +0000 (+0100) Subject: Fix CMake check for posix_memalign and aligned_alloc X-Git-Tag: 2.1.0-beta1~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=58c76217ecefcbeeccb32189ad27d162450a2e7b;p=thirdparty%2Fzlib-ng.git Fix CMake check for posix_memalign and aligned_alloc These two functions were being checked using check_function_exists. This CMake macro does not check to see if the given function is declared in any header as it declares its own function prototype and relies on linking to determine function availability. This causes two issues. Firstly, it will always succeed when the CMake toolchain file sets CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY as no linking will take place. See: https://gitlab.kitware.com/cmake/cmake/-/issues/18121 Secondly, it will not correctly detect macros or inline functions, or whether the function is even declared in a header at all. Switch to check_symbol_exists at CMake's recommendation, the logic of which actually matches the same checks in the configure script. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fba4553..d5f66d6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -331,18 +331,21 @@ check_function_exists(fseeko HAVE_FSEEKO) if(NOT HAVE_FSEEKO) add_definitions(-DNO_FSEEKO) endif() + check_function_exists(strerror HAVE_STRERROR) if(NOT HAVE_STRERROR) add_definitions(-DNO_STRERROR) endif() + set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200112L) -check_function_exists(posix_memalign HAVE_POSIX_MEMALIGN) +check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN) if(HAVE_POSIX_MEMALIGN) add_definitions(-DHAVE_POSIX_MEMALIGN) endif() set(CMAKE_REQUIRED_DEFINITIONS) + set(CMAKE_REQUIRED_DEFINITIONS -D_ISOC11_SOURCE=1) -check_function_exists(aligned_alloc HAVE_ALIGNED_ALLOC) +check_symbol_exists(aligned_alloc stdlib.h HAVE_ALIGNED_ALLOC) if(HAVE_ALIGNED_ALLOC) add_definitions(-DHAVE_ALIGNED_ALLOC) endif()