diff options
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 138 |
1 files changed, 100 insertions, 38 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 65e42a4..b0b2fef 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 @@ -48,6 +51,30 @@ else() endif() target_include_directories(libninja-re2c PRIVATE src) +# --- Check for 'browse' mode support +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 src/build_log.cc @@ -92,49 +119,84 @@ if(MINGW) target_compile_definitions(libninja PRIVATE _WIN32_WINNT=0x0601 __USE_MINGW_ANSI_STDIO=1) endif() +# On IBM i (identified as "OS400" for compatibility reasons), this fixes missing +# PRId64 (and others) at compile time, and links to libutil for getopt_long +if(CMAKE_SYSTEM_NAME STREQUAL "OS400") + string(APPEND CMAKE_CXX_FLAGS " -D__STDC_FORMAT_MACROS") + string(APPEND CMAKE_EXE_LINKER_FLAGS " -lutil") +endif() + # 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) +# 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() -target_link_libraries(ninja_test PRIVATE libninja libninja-re2c) - -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() -enable_testing() -add_test(NinjaTest ninja_test) +include(CTest) +if(BUILD_TESTING) + # 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) + + 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() + + add_test(NinjaTest ninja_test) +endif() install(TARGETS ninja DESTINATION bin) |