From d2786f4ba3ea15be3fab58036c8cf1e4fe95bbb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20S=C3=A1?= Date: Fri, 31 Jan 2025 14:46:28 +0000 Subject: [PATCH] cmake: add an Utilities library MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Create a cmake utilities library for functions or macros that will be shared across CMake files. For now, just add a function to check the availability of pthread_setname_np(3). This is in preparation of adding support for thread names where we'll also check this from the top level CMake file. Signed-off-by: Nuno Sá --- cmake/Utilities.cmake | 11 +++++++++++ iiod/CMakeLists.txt | 11 ++--------- 2 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 cmake/Utilities.cmake diff --git a/cmake/Utilities.cmake b/cmake/Utilities.cmake new file mode 100644 index 000000000..32f2febe9 --- /dev/null +++ b/cmake/Utilities.cmake @@ -0,0 +1,11 @@ +function(check_pthread_set_name HAS_PTHREAD) + include(CheckSymbolExists) + set(CMAKE_REQUIRED_LIBRARIES ${PTHREAD_LIBRARIES}) + set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) + set(TMP_FLAGS "${CMAKE_C_FLAGS}") + set(CMAKE_C_FLAGS "") + check_symbol_exists(pthread_setname_np "pthread.h" ${HAS_PTHREAD}) + set(CMAKE_C_FLAGS "${TMP_FLAGS}") + set(CMAKE_REQUIRED_LIBRARIES) + set(CMAKE_REQUIRED_DEFINITIONS) +endfunction() \ No newline at end of file diff --git a/iiod/CMakeLists.txt b/iiod/CMakeLists.txt index 7d7dfee43..cbae9a1c4 100644 --- a/iiod/CMakeLists.txt +++ b/iiod/CMakeLists.txt @@ -1,15 +1,8 @@ cmake_minimum_required(VERSION 3.10) project(iiod C) -include(CheckSymbolExists) -set(CMAKE_REQUIRED_LIBRARIES ${PTHREAD_LIBRARIES}) -set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) -set(TMP_FLAGS "${CMAKE_C_FLAGS}") -set(CMAKE_C_FLAGS "") -check_symbol_exists(pthread_setname_np "pthread.h" HAS_PTHREAD_SETNAME_NP) -set(CMAKE_C_FLAGS "${TMP_FLAGS}") -set(CMAKE_REQUIRED_LIBRARIES) -set(CMAKE_REQUIRED_DEFINITIONS) +include(${CMAKE_SOURCE_DIR}/cmake/Utilities.cmake) +CHECK_PTHREAD_SET_NAME(HAS_PTHREAD_SETNAME_NP) add_executable(iiod iiod.c interpreter.c responder.c rw.c thread-pool.c