summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Harrison <aharrison24@gmail.com>2020-08-27 21:47:27 +0100
committerAlastair Harrison <alastair@oxbotica.com>2020-08-27 21:50:35 +0100
commit5b80abbc729e94abb5f5776a3438ad57d480c097 (patch)
tree675d35e300dc9913cad7c44b20d353208d50e317
parent9ddd3c917793bb97eb19d571429cdedf07501c03 (diff)
downloadninja-5b80abbc729e94abb5f5776a3438ad57d480c097.tar.gz
CMake: Add support for "browse" mode
Fixes ninja-build/ninja#1822, fixes ninja-build/ninja#1853 Adds support for `ninja -t browse` to CMake builds. The platform support logic is copied from configure.py, so Windows, Solaris and AIX are treated as 'unsupported' platforms. All other platforms are assumed to be supported. As discussed in #1853, when built via CMake the `ninja` executable looks for a binary called `python` in the current path, in order to launch the "browse" mode. The behaviour differs from that of the configure.py script, which looks for a python executable that has the *same name* as the python executable that invoked the configure script.
-rw-r--r--CMakeLists.txt38
1 files changed, 38 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 65e42a4..d132965 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,6 +48,18 @@ else()
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()
+
# Core source files all build into ninja library.
add_library(libninja OBJECT
src/build_log.cc
@@ -96,6 +108,32 @@ endif()
add_executable(ninja src/ninja.cc)
target_link_libraries(ninja PRIVATE libninja libninja-re2c)
+# Adds browse mode into the ninja binary if it's supported by the host platform.
+if(platform_supports_ninja_browse)
+ # Inlines src/browse.py into the browse_py.h header, so that it can be included
+ # by src/browse.cc
+ add_custom_command(
+ OUTPUT build/browse_py.h
+ MAIN_DEPENDENCY src/browse.py
+ DEPENDS src/inline.sh
+ COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/build
+ COMMAND src/inline.sh kBrowsePy
+ < src/browse.py
+ > ${CMAKE_BINARY_DIR}/build/browse_py.h
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ VERBATIM
+ )
+
+ target_compile_definitions(ninja PRIVATE NINJA_HAVE_BROWSE)
+ target_sources(ninja PRIVATE src/browse.cc)
+ set_source_files_properties(src/browse.cc
+ PROPERTIES
+ OBJECT_DEPENDS "${CMAKE_BINARY_DIR}/build/browse_py.h"
+ INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR}"
+ COMPILE_DEFINITIONS NINJA_PYTHON="python"
+ )
+endif()
+
# Tests all build into ninja_test executable.
add_executable(ninja_test
src/build_log_test.cc