libmemif: Fixed strlcpy symbol detection. 22/41722/3
authorAlexander Slesarev <[email protected]>
Thu, 17 Oct 2024 19:52:06 +0000 (15:52 -0400)
committerDave Wallace <[email protected]>
Thu, 20 Feb 2025 17:43:36 +0000 (17:43 +0000)
Type: fix

libmemif can't be compiled with the modern glibc (since 2.38)
and musl as they include strlcpy for _GNU_SOURCE by default now.

The change introduced:

- proper symbol detection for both strlcpy and memfd_create;
- bumped CMake version requirements due to soon-to-be failed
compilation for very old version;
- fixed Unity compilation on the modern compilers (it has warnings,
but compiled with `-Werror`).

Change-Id: I48f9c410aa5405174dc6b65e9c9001e8b11ba276
Signed-off-by: Alexander Slesarev <[email protected]>
extras/libmemif/CMakeLists.txt
extras/libmemif/src/CMakeLists.txt
extras/libmemif/src/memif_private.h
extras/libmemif/test/suite_main/CMakeLists.txt
extras/libmemif/test/suite_socket/CMakeLists.txt

index 1526abd..f2e1008 100644 (file)
@@ -17,7 +17,7 @@ project(memif)
 set(CMAKE_C_STANDARD 11)
 
 include(CheckCCompilerFlag)
-include(CheckFunctionExists)
+include(CheckSymbolExists)
 find_package(Git REQUIRED)
 
 include(ExternalProject)
@@ -26,7 +26,9 @@ set(UNITY unity_project)
 ExternalProject_Add(
     unity_project
     GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git
-    GIT_TAG cf949f45ca6d172a177b00da21310607b97bc7a7
+    # TODO: bump to the stable version as soon as it's available,
+    # current 2.6.0 couldn't be compiled with the modern compilers
+    GIT_TAG 73237c5d224169c7b4d2ec8321f9ac92e8071708
     PREFIX ${PROJECT_BINARY_DIR}/external/${UNITY}
     INSTALL_COMMAND cmake --install . --prefix ${PROJECT_BINARY_DIR}
 
@@ -72,11 +74,17 @@ endif()
 message(STATUS "System Architecture: ${CMAKE_SYSTEM_PROCESSOR}")
 message(STATUS "Libmemif Cacheline Size: ${LIBMEMIF_CACHELINE_SIZE}")
 
-check_function_exists(memfd_create HAVE_MEMFD_CREATE)
+list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
+check_symbol_exists(memfd_create "sys/mman.h" HAVE_MEMFD_CREATE)
 if(${HAVE_MEMFD_CREATE})
   add_definitions(-DHAVE_MEMFD_CREATE)
 endif()
 
+check_symbol_exists(strlcpy "string.h" HAVE_STRLCPY)
+if(${HAVE_STRLCPY})
+  add_definitions(-DHAVE_STRLCPY)
+endif()
+
 include_directories(src)
 
 add_subdirectory(src)
index 8b3223d..0fbcf4b 100644 (file)
@@ -36,12 +36,6 @@ add_library(memif SHARED ${MEMIF_SOURCES})
 target_link_libraries(memif ${CMAKE_THREAD_LIBS_INIT})
 target_compile_definitions(memif PUBLIC MEMIF_CACHELINE_SIZE=${LIBMEMIF_CACHELINE_SIZE})
 
-find_library(LIB_BSD bsd)
-if(LIB_BSD)
-  add_compile_definitions(HAS_LIB_BSD)
-  target_link_libraries(memif ${LIB_BSD})
-endif()
-
 foreach(file ${MEMIF_HEADERS})
   get_filename_component(dir ${file} DIRECTORY)
      install(
index 71a4bc8..4ab8289 100644 (file)
@@ -67,7 +67,7 @@ _Static_assert (strlen (MEMIF_DEFAULT_APP_NAME) <= MEMIF_NAME_LEN,
 #define DBG(...)
 #endif /* MEMIF_DBG */
 
-#ifndef HAS_LIB_BSD
+#ifndef HAVE_STRLCPY
 static inline size_t
 strlcpy (char *dest, const char *src, size_t len)
 {
@@ -90,8 +90,6 @@ strlcpy (char *dest, const char *src, size_t len)
 
   return (s - src - 1);
 }
-#else
-#include <bsd/string.h>
 #endif
 
 typedef enum
index 7a29400..7505b5f 100644 (file)
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.0)
+cmake_minimum_required(VERSION 3.5)
 
 set (This MemifMainTest)
 
index 5ac66a0..3c33095 100644 (file)
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.0)
+cmake_minimum_required(VERSION 3.5)
 
 set (This MemifSocketTest)