Ninja: Permit control of "deps = gcc" in generated rules.ninja
In our environment we have several projects which build the same set of shared modules. Multiple projects build this code directly. This is in contrast to, say, structuring the modules as a library and sharing them that way. Different projects can re-use each others build artifacts since careful control is exercised over compiler flags and similar.
However, the .ninja_deps file is always-project specific and always older than then shared dependencies when one switches to a project. This causes a full rebuild of shared code. Mostly this is caught by ccache but it still takes a while. CMake unconditionally enables this behavior.
This commit allows users, via the CMAKE_NINJA_DEPTYPE_LANG variable, to control the value of deps, and therefore how dependencies are handled.
Sample Ninja rule output:
rule CXX_COMPILER__hello
depfile = $DEP_FILE
deps = gcc
command = c++ $DEFINES $INCLUDES $FLAGS -MD -MT $out -MF $DEP_FILE -o $out -c $in
description = Building CXX object $out
For a C++ project, the value of CMAKE_NINJA_DEPTYPE_CXX is emitted on the line with deps =. The value gcc is the default. Setting the variable to the empty string removes the line from the rule definition and dependency handling reverts to the default way.
== == == Sample Output == == ==
$ ninja
ninja: no work to do.
$ touch hello.h
$ ninja
[4/4] Linking CXX executable hi
$
== == == Sample Project == == ==
$ tail -n+1 CMakeLists.txt hello.h hello.cxx main.cxx
==> CMakeLists.txt <==
cmake_minimum_required (VERSION 2.8.11)
project (HELLO)
set(CMAKE_NINJA_DEPTYPE_CXX "")
add_library (hello hello.cxx)
target_include_directories (hello PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
add_executable (hi main.cxx)
target_link_libraries (hi LINK_PUBLIC hello)
==> hello.h <==
void greet(const std::string&);
==> hello.cxx <==
void greet(const std::string& name) {
std::cout << "Hello " << name << "\n";
}
==> main.cxx <==
int main() {
greet("Darren");
}