From 54c5759471895f820735c232c36e81af96201912 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 2 Jun 2021 11:08:10 -0400 Subject: [PATCH] cmake: use `check_symbol_exists` for browse support Just because `unistd.h` exists does not mean it has the APIs that are needed. This occurs when cross-compiling using Fedora's packaged MinGW toolchain. --- CMakeLists.txt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8de69e8..bc02c4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.15) -include(CheckIncludeFileCXX) +include(CheckSymbolExists) include(CheckIPOSupported) project(ninja) @@ -73,10 +73,15 @@ function(check_platform_supports_browse_mode RESULT) endif() # Now check availability of the unistd header - check_include_file_cxx(unistd.h PLATFORM_HAS_UNISTD_HEADER) - set(${RESULT} "${PLATFORM_HAS_UNISTD_HEADER}" PARENT_SCOPE) - if(NOT PLATFORM_HAS_UNISTD_HEADER) - message(WARNING "browse feature omitted due to missing unistd.h") + check_symbol_exists(fork "unistd.h" HAVE_FORK) + check_symbol_exists(pipe "unistd.h" HAVE_PIPE) + set(browse_supported 0) + if (HAVE_FORK AND HAVE_PIPE) + set(browse_supported 1) + endif () + set(${RESULT} "${browse_supported}" PARENT_SCOPE) + if(NOT browse_supported) + message(WARNING "browse feature omitted due to missing `fork` and `pipe` functions") endif() endfunction()