From 0b5f5ba91020668856f87f079a61380198540bd7 Mon Sep 17 00:00:00 2001 From: Alastair Harrison Date: Fri, 28 Aug 2020 11:58:43 +0100 Subject: CMake: Add platform checks for browse mode support Browse mode requires a number of POSIX features to be available. This commit adds configure-time checks that the 'unistd.h' header is available and that the `inline.sh` script executes successfully. If the checks pass then browse mode is enabled. --- CMakeLists.txt | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d132965..b0c0911 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,7 @@ cmake_minimum_required(VERSION 3.15) + +include(CheckIncludeFileCXX) + project(ninja) # --- optional link-time optimization @@ -49,16 +52,28 @@ endif() target_include_directories(libninja-re2c PRIVATE src) # --- Check for 'browse' mode support -set(unsupported_browse_platforms - "Windows" - "SunOS" - "AIX" -) -if(${CMAKE_SYSTEM_NAME} IN_LIST unsupported_browse_platforms) - set(platform_supports_ninja_browse FALSE) -else() - set(platform_supports_ninja_browse TRUE) -endif() +function(check_platform_supports_browse_mode RESULT) + # Make sure the inline.sh script works on this platform. + # It uses the shell commands such as 'od', which may not be available. + execute_process( + COMMAND sh -c "echo 'TEST' | src/inline.sh var" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + RESULT_VARIABLE inline_result + OUTPUT_QUIET + ERROR_QUIET + ) + if(NOT inline_result EQUAL "0") + # The inline script failed, so browse mode is not supported. + set(${RESULT} "0" PARENT_SCOPE) + return() + 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) +endfunction() + +check_platform_supports_browse_mode(platform_supports_ninja_browse) # Core source files all build into ninja library. add_library(libninja OBJECT -- cgit v0.12