Skip to content

Commit 081c91c

Browse files
authored
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.
1 parent 5187f4b commit 081c91c

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/CMakeLists.txt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,17 @@ target_include_directories(
126126
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
127127
PUBLIC $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/install-include>)
128128

129-
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/pollrdhup.c"
130-
[=[
131-
#define _GNU_SOURCE
132-
#include <poll.h>
133-
int main() {
134-
printf("0x%x", POLLRDHUP);
135-
return 0;
136-
}
137-
]=])
138-
try_run(HAVE_POLLRDHUP_RUN_RESULT HAVE_POLLRDHUP
139-
"${CMAKE_CURRENT_BINARY_DIR}"
140-
"${CMAKE_CURRENT_BINARY_DIR}/pollrdhup.c"
141-
RUN_OUTPUT_VARIABLE POLLRDHUP_VALUE)
142-
if(NOT HAVE_POLLRDHUP)
129+
include(CMakePushCheckState)
130+
cmake_push_check_state()
131+
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
132+
set(CMAKE_EXTRA_INCLUDE_FILES poll.h)
133+
check_type_size("((struct { char x[POLLRDHUP]\\; }*)0)->x" POLLRDHUP_VALUE)
134+
cmake_pop_check_state()
135+
136+
if(NOT POLLRDHUP_VALUE)
143137
set(POLLRDHUP_VALUE "0x2000")
138+
else()
139+
message(STATUS "Detected value of POLLRDHUP as ${POLLRDHUP_VALUE}")
144140
endif()
145141

146142
set(_headers

0 commit comments

Comments
 (0)