11cmake_minimum_required (VERSION 3.15 )
22
3- include (CheckIncludeFileCXX )
3+ include (CheckSymbolExists )
44include (CheckIPOSupported )
55
66project (ninja)
@@ -18,16 +18,18 @@ endif()
1818# --- compiler flags
1919if (MSVC )
2020 set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG :Debug >:Debug >" )
21- string (APPEND CMAKE_CXX_FLAGS " /W4 /GR- /Zc:__cplusplus" )
21+ string (REPLACE "/GR" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS } )
22+ add_compile_options (/W4 /wd4100 /wd4267 /wd4706 /wd4702 /wd4244 /GR- /Zc:__cplusplus )
23+ add_compile_definitions (_CRT_SECURE_NO_WARNINGS )
2224else ()
2325 include (CheckCXXCompilerFlag )
2426 check_cxx_compiler_flag (-Wno-deprecated flag_no_deprecated )
2527 if (flag_no_deprecated)
26- string ( APPEND CMAKE_CXX_FLAGS " -Wno-deprecated" )
28+ add_compile_options ( -Wno-deprecated )
2729 endif ()
2830 check_cxx_compiler_flag (-fdiagnostics-color flag_color_diag )
2931 if (flag_color_diag)
30- string ( APPEND CMAKE_CXX_FLAGS " -fdiagnostics-color" )
32+ add_compile_options ( -fdiagnostics-color )
3133 endif ()
3234endif ()
3335
@@ -37,7 +39,7 @@ if(RE2C)
3739 # the depfile parser and ninja lexers are generated using re2c.
3840 function (re2c IN OUT )
3941 add_custom_command (DEPENDS ${IN} OUTPUT ${OUT}
40- COMMAND ${RE2C} -b -i --no-generation-date -o ${OUT} ${IN}
42+ COMMAND ${RE2C} -b -i --no-generation-date --no-version - o ${OUT} ${IN}
4143 )
4244 endfunction ()
4345 re2c (${PROJECT_SOURCE_DIR } /src/depfile_parser.in.cc ${PROJECT_BINARY_DIR } /depfile_parser.cc )
@@ -53,22 +55,35 @@ target_include_directories(libninja-re2c PRIVATE src)
5355function (check_platform_supports_browse_mode RESULT )
5456 # Make sure the inline.sh script works on this platform.
5557 # It uses the shell commands such as 'od', which may not be available.
58+
5659 execute_process (
5760 COMMAND sh -c "echo 'TEST' | src/inline.sh var"
58- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR }
61+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR }
5962 RESULT_VARIABLE inline_result
6063 OUTPUT_QUIET
6164 ERROR_QUIET
6265 )
6366 if (NOT inline_result EQUAL "0" )
6467 # The inline script failed, so browse mode is not supported.
6568 set (${RESULT} "0" PARENT_SCOPE )
69+ if (NOT WIN32 )
70+ message (WARNING "browse feature omitted due to inline script failure" )
71+ endif ()
6672 return ()
6773 endif ()
6874
6975 # Now check availability of the unistd header
70- check_include_file_cxx (unistd.h PLATFORM_HAS_UNISTD_HEADER )
71- set (${RESULT} "${PLATFORM_HAS_UNISTD_HEADER} " PARENT_SCOPE )
76+ check_symbol_exists (fork "unistd.h" HAVE_FORK )
77+ check_symbol_exists (pipe "unistd.h" HAVE_PIPE )
78+ set (browse_supported 0)
79+ if (HAVE_FORK AND HAVE_PIPE)
80+ set (browse_supported 1)
81+ endif ()
82+ set (${RESULT} "${browse_supported} " PARENT_SCOPE )
83+ if (NOT browse_supported)
84+ message (WARNING "browse feature omitted due to missing `fork` and `pipe` functions" )
85+ endif ()
86+
7287endfunction ()
7388
7489check_platform_supports_browse_mode (platform_supports_ninja_browse )
@@ -88,11 +103,14 @@ add_library(libninja OBJECT
88103 src/eval_env.cc
89104 src/graph.cc
90105 src/graphviz.cc
106+ src/json.cc
91107 src/line_printer.cc
92108 src/manifest_parser.cc
93109 src/metrics.cc
110+ src/missing_deps.cc
94111 src/parser.cc
95112 src/state.cc
113+ src/status.cc
96114 src/string_piece_util.cc
97115 src/util.cc
98116 src/version.cc
@@ -104,10 +122,8 @@ if(WIN32)
104122 src/msvc_helper-win32.cc
105123 src/msvc_helper_main-win32.cc
106124 src/getopt.c
125+ src/minidump-win32.cc
107126 )
108- if (MSVC )
109- target_sources (libninja PRIVATE src/minidump-win32.cc )
110- endif ()
111127else ()
112128 target_sources (libninja PRIVATE src/subprocess-posix.cc )
113129 if (CMAKE_SYSTEM_NAME STREQUAL "OS400" OR CMAKE_SYSTEM_NAME STREQUAL "AIX" )
@@ -128,13 +144,17 @@ endif()
128144# On IBM i (identified as "OS400" for compatibility reasons) and AIX, this fixes missing
129145# PRId64 (and others) at compile time in C++ sources
130146if (CMAKE_SYSTEM_NAME STREQUAL "OS400" OR CMAKE_SYSTEM_NAME STREQUAL "AIX" )
131- string ( APPEND CMAKE_CXX_FLAGS " -D__STDC_FORMAT_MACROS" )
147+ add_compile_definitions ( __STDC_FORMAT_MACROS )
132148endif ()
133149
134150# Main executable is library plus main() function.
135151add_executable (ninja src/ninja.cc )
136152target_link_libraries (ninja PRIVATE libninja libninja-re2c )
137153
154+ if (WIN32 )
155+ target_sources (ninja PRIVATE windows/ninja.manifest )
156+ endif ()
157+
138158# Adds browse mode into the ninja binary if it's supported by the host platform.
139159if (platform_supports_ninja_browse)
140160 # Inlines src/browse.py into the browse_py.h header, so that it can be included
@@ -143,20 +163,20 @@ if(platform_supports_ninja_browse)
143163 OUTPUT build /browse_py.h
144164 MAIN_DEPENDENCY src/browse.py
145165 DEPENDS src/inline.sh
146- COMMAND ${CMAKE_COMMAND } -E make_directory ${CMAKE_BINARY_DIR } /build
166+ COMMAND ${CMAKE_COMMAND } -E make_directory ${PROJECT_BINARY_DIR } /build
147167 COMMAND src/inline.sh kBrowsePy
148168 < src/browse.py
149- > ${CMAKE_BINARY_DIR } /build/browse_py.h
150- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR }
169+ > ${PROJECT_BINARY_DIR } /build/browse_py.h
170+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR }
151171 VERBATIM
152172 )
153173
154174 target_compile_definitions (ninja PRIVATE NINJA_HAVE_BROWSE )
155175 target_sources (ninja PRIVATE src/browse.cc )
156176 set_source_files_properties (src/browse.cc
157177 PROPERTIES
158- OBJECT_DEPENDS "${CMAKE_BINARY_DIR } /build/browse_py.h"
159- INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR } "
178+ OBJECT_DEPENDS "${PROJECT_BINARY_DIR } /build/browse_py.h"
179+ INCLUDE_DIRECTORIES "${PROJECT_BINARY_DIR } "
160180 COMPILE_DEFINITIONS NINJA_PYTHON="python"
161181 )
162182endif ()
@@ -175,8 +195,10 @@ if(BUILD_TESTING)
175195 src/dyndep_parser_test.cc
176196 src/edit_distance_test.cc
177197 src/graph_test.cc
198+ src/json_test.cc
178199 src/lexer_test.cc
179200 src/manifest_parser_test.cc
201+ src/missing_deps_test.cc
180202 src/ninja_test.cc
181203 src/state_test.cc
182204 src/string_piece_util_test.cc
@@ -203,11 +225,11 @@ if(BUILD_TESTING)
203225
204226 if (CMAKE_SYSTEM_NAME STREQUAL "AIX" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
205227 # These tests require more memory than will fit in the standard AIX shared stack/heap (256M)
206- target_link_libraries (hash_collision_bench PRIVATE "-Wl,-bmaxdata:0x80000000" )
207- target_link_libraries (manifest_parser_perftest PRIVATE "-Wl,-bmaxdata:0x80000000" )
228+ target_link_options (hash_collision_bench PRIVATE "-Wl,-bmaxdata:0x80000000" )
229+ target_link_options (manifest_parser_perftest PRIVATE "-Wl,-bmaxdata:0x80000000" )
208230 endif ()
209231
210- add_test (NinjaTest ninja_test )
232+ add_test (NAME NinjaTest COMMAND ninja_test )
211233endif ()
212234
213- install (TARGETS ninja DESTINATION bin )
235+ install (TARGETS ninja)
0 commit comments