2020-01-16 14:57:23 +00:00
|
|
|
cmake_minimum_required(VERSION 3.15)
|
|
|
|
cmake_policy(SET CMP0091 NEW)
|
2019-04-18 09:04:56 +00:00
|
|
|
project(ninja)
|
|
|
|
|
2019-12-03 21:46:56 +00:00
|
|
|
if(CMAKE_BUILD_TYPE MATCHES "Release")
|
|
|
|
cmake_policy(SET CMP0069 NEW)
|
|
|
|
include(CheckIPOSupported)
|
|
|
|
check_ipo_supported(RESULT lto_supported OUTPUT error)
|
|
|
|
|
|
|
|
if(lto_supported)
|
|
|
|
message(STATUS "IPO / LTO enabled")
|
|
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
|
|
else()
|
|
|
|
message(STATUS "IPO / LTO not supported: <${error}>")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-04-18 09:04:56 +00:00
|
|
|
if(MSVC)
|
2020-01-16 14:57:23 +00:00
|
|
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
2019-09-21 20:55:25 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /GR- /Zc:__cplusplus")
|
2019-04-18 09:04:56 +00:00
|
|
|
else()
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -fdiagnostics-color")
|
|
|
|
endif()
|
|
|
|
|
2019-05-10 15:03:20 +00:00
|
|
|
find_program(RE2C re2c)
|
|
|
|
if(RE2C)
|
|
|
|
# the depfile parser and ninja lexers are generated using re2c.
|
|
|
|
function(re2c IN OUT)
|
|
|
|
add_custom_command(DEPENDS ${IN} OUTPUT ${OUT}
|
|
|
|
COMMAND ${RE2C} -b -i --no-generation-date -o ${OUT} ${IN}
|
|
|
|
)
|
|
|
|
endfunction()
|
|
|
|
re2c(${CMAKE_SOURCE_DIR}/src/depfile_parser.in.cc ${CMAKE_BINARY_DIR}/depfile_parser.cc)
|
|
|
|
re2c(${CMAKE_SOURCE_DIR}/src/lexer.in.cc ${CMAKE_BINARY_DIR}/lexer.cc)
|
|
|
|
add_library(libninja-re2c OBJECT ${CMAKE_BINARY_DIR}/depfile_parser.cc ${CMAKE_BINARY_DIR}/lexer.cc)
|
|
|
|
else()
|
|
|
|
message(WARNING "re2c was not found; changes to src/*.in.cc will not affect your build.")
|
|
|
|
add_library(libninja-re2c OBJECT src/depfile_parser.cc src/lexer.cc)
|
|
|
|
endif()
|
2019-04-18 09:04:56 +00:00
|
|
|
target_include_directories(libninja-re2c PRIVATE src)
|
|
|
|
|
|
|
|
# Core source files all build into ninja library.
|
|
|
|
add_library(libninja OBJECT
|
|
|
|
src/build_log.cc
|
|
|
|
src/build.cc
|
|
|
|
src/clean.cc
|
|
|
|
src/clparser.cc
|
|
|
|
src/dyndep.cc
|
|
|
|
src/dyndep_parser.cc
|
|
|
|
src/debug_flags.cc
|
|
|
|
src/deps_log.cc
|
|
|
|
src/disk_interface.cc
|
|
|
|
src/edit_distance.cc
|
|
|
|
src/eval_env.cc
|
|
|
|
src/graph.cc
|
|
|
|
src/graphviz.cc
|
|
|
|
src/line_printer.cc
|
|
|
|
src/manifest_parser.cc
|
|
|
|
src/metrics.cc
|
|
|
|
src/parser.cc
|
|
|
|
src/state.cc
|
|
|
|
src/string_piece_util.cc
|
|
|
|
src/util.cc
|
|
|
|
src/version.cc
|
|
|
|
)
|
|
|
|
if(WIN32)
|
|
|
|
target_sources(libninja PRIVATE
|
|
|
|
src/subprocess-win32.cc
|
|
|
|
src/includes_normalize-win32.cc
|
|
|
|
src/msvc_helper-win32.cc
|
|
|
|
src/msvc_helper_main-win32.cc
|
2019-05-13 07:29:19 +00:00
|
|
|
src/getopt.c
|
2019-04-18 09:04:56 +00:00
|
|
|
)
|
2019-05-13 07:29:19 +00:00
|
|
|
if(MSVC)
|
|
|
|
target_sources(libninja PRIVATE src/minidump-win32.cc)
|
|
|
|
endif()
|
2019-04-18 09:04:56 +00:00
|
|
|
else()
|
|
|
|
target_sources(libninja PRIVATE src/subprocess-posix.cc)
|
|
|
|
endif()
|
|
|
|
|
2019-11-02 12:13:58 +00:00
|
|
|
#Fixes GetActiveProcessorCount on MinGW
|
|
|
|
if(MINGW)
|
2019-11-23 09:47:44 +00:00
|
|
|
target_compile_definitions(libninja PRIVATE _WIN32_WINNT=0x0601 __USE_MINGW_ANSI_STDIO=1)
|
2019-11-02 12:13:58 +00:00
|
|
|
endif()
|
|
|
|
|
2019-04-18 09:04:56 +00:00
|
|
|
# Main executable is library plus main() function.
|
|
|
|
add_executable(ninja src/ninja.cc)
|
|
|
|
target_link_libraries(ninja PRIVATE libninja libninja-re2c)
|
|
|
|
|
|
|
|
# Tests all build into ninja_test executable.
|
|
|
|
add_executable(ninja_test
|
|
|
|
src/build_log_test.cc
|
|
|
|
src/build_test.cc
|
|
|
|
src/clean_test.cc
|
|
|
|
src/clparser_test.cc
|
|
|
|
src/depfile_parser_test.cc
|
|
|
|
src/deps_log_test.cc
|
|
|
|
src/disk_interface_test.cc
|
|
|
|
src/dyndep_parser_test.cc
|
|
|
|
src/edit_distance_test.cc
|
|
|
|
src/graph_test.cc
|
|
|
|
src/lexer_test.cc
|
|
|
|
src/manifest_parser_test.cc
|
|
|
|
src/ninja_test.cc
|
|
|
|
src/state_test.cc
|
|
|
|
src/string_piece_util_test.cc
|
|
|
|
src/subprocess_test.cc
|
|
|
|
src/test.cc
|
|
|
|
src/util_test.cc
|
|
|
|
)
|
|
|
|
if(WIN32)
|
|
|
|
target_sources(ninja_test PRIVATE src/includes_normalize_test.cc src/msvc_helper_test.cc)
|
|
|
|
endif()
|
|
|
|
target_link_libraries(ninja_test PRIVATE libninja libninja-re2c)
|
2019-05-13 07:29:19 +00:00
|
|
|
|
2020-01-08 10:22:56 +00:00
|
|
|
foreach(perftest
|
|
|
|
build_log_perftest
|
|
|
|
canon_perftest
|
|
|
|
clparser_perftest
|
|
|
|
depfile_parser_perftest
|
|
|
|
hash_collision_bench
|
|
|
|
manifest_parser_perftest
|
|
|
|
)
|
|
|
|
add_executable(${perftest} src/${perftest}.cc)
|
|
|
|
target_link_libraries(${perftest} PRIVATE libninja libninja-re2c)
|
|
|
|
endforeach()
|
|
|
|
|
2019-05-13 07:29:19 +00:00
|
|
|
enable_testing()
|
|
|
|
add_test(NinjaTest ninja_test)
|
2020-02-08 18:08:06 +00:00
|
|
|
|
|
|
|
install(TARGETS ninja DESTINATION bin)
|