Skip to content

Commit

Permalink
cmake: add an Utilities library
Browse files Browse the repository at this point in the history
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á <nuno.sa@analog.com>
  • Loading branch information
nunojsa committed Jan 31, 2025
1 parent ec5e036 commit d2786f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
11 changes: 11 additions & 0 deletions cmake/Utilities.cmake
Original file line number Diff line number Diff line change
@@ -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()
11 changes: 2 additions & 9 deletions iiod/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit d2786f4

Please sign in to comment.