From 081c91c7c432a18647cc9d6c1edf2b0209f9108a Mon Sep 17 00:00:00 2001 From: Alexander Richardson Date: Fri, 6 Dec 2024 21:47:49 -0800 Subject: [PATCH] Fix detection of POLLRDHUP value when cross-compiling (#54) When cross-compiling we can't use try_run, instead use check_type_size to detect the value of POLLRDHUP at compile time. --- src/CMakeLists.txt | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e64a3a1..38dbe78 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -126,21 +126,17 @@ target_include_directories( PRIVATE $ PUBLIC $) -file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/pollrdhup.c" - [=[ -#define _GNU_SOURCE -#include -int main() { - printf("0x%x", POLLRDHUP); - return 0; -} -]=]) -try_run(HAVE_POLLRDHUP_RUN_RESULT HAVE_POLLRDHUP - "${CMAKE_CURRENT_BINARY_DIR}" - "${CMAKE_CURRENT_BINARY_DIR}/pollrdhup.c" - RUN_OUTPUT_VARIABLE POLLRDHUP_VALUE) -if(NOT HAVE_POLLRDHUP) +include(CMakePushCheckState) +cmake_push_check_state() +set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) +set(CMAKE_EXTRA_INCLUDE_FILES poll.h) +check_type_size("((struct { char x[POLLRDHUP]\\; }*)0)->x" POLLRDHUP_VALUE) +cmake_pop_check_state() + +if(NOT POLLRDHUP_VALUE) set(POLLRDHUP_VALUE "0x2000") +else() + message(STATUS "Detected value of POLLRDHUP as ${POLLRDHUP_VALUE}") endif() set(_headers