]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Fix CMake check for posix_memalign and aligned_alloc
authorlawadr <3211473+lawadr@users.noreply.github.com>
Tue, 4 Apr 2023 13:53:35 +0000 (14:53 +0100)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sat, 15 Apr 2023 13:23:05 +0000 (15:23 +0200)
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.

CMakeLists.txt

index 8fba45535ee91945a71114078fd4a5a21a500bc0..d5f66d6dc8acaf43c8cd17a83867fabc2d7b1bf6 100644 (file)
@@ -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()