Skip to content

Commit

Permalink
CMake: Add support for "browse" mode
Browse files Browse the repository at this point in the history
Fixes #1822, fixes #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.
  • Loading branch information
aharrison24 authored and Alastair Harrison committed Aug 27, 2020
1 parent 9ddd3c9 commit 5b80abb
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5b80abb

Please sign in to comment.