summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Harrison <aharrison24@gmail.com>2020-08-28 11:58:43 +0100
committerAlastair Harrison <aharrison24@gmail.com>2020-08-28 12:18:58 +0100
commit0b5f5ba91020668856f87f079a61380198540bd7 (patch)
tree09de8cba72a3890af2460bf9b3c40703e6474dfc
parent67f960be1be8099ea1727af8d3361d38274b2bd1 (diff)
downloadninja-0b5f5ba91020668856f87f079a61380198540bd7.tar.gz
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.
-rw-r--r--CMakeLists.txt35
1 files 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