Add options to launch the compiler through tools like ccache or distcc

Create a <LANG>_COMPILER_LAUNCHER target property (initialized by a
CMAKE_<LANG>_COMPILER_LAUNCHER variable) to specify a compiler launcher
tool.  This will supersede the CMAKE_<LANG>_COMPILER_ARG1 approach to
using such tools.  The old approach set CMAKE_<LANG>_COMPILER to the
launcher tool while the new approach leaves this variable set to the
actual compiler.

Implement this property for Makefile and Ninja generators.  It cannot be
implemented for VS or Xcode generators as the IDE build tools offer no
such hooks.
This commit is contained in:
Bill Hoffman
2015-06-04 15:56:56 -04:00
committed by Brad King
parent d3bb5da929
commit 698f75971b
21 changed files with 119 additions and 0 deletions
+19
View File
@@ -775,6 +775,25 @@ cmMakefileTargetGenerator
}
}
// Maybe insert a compiler launcher like ccache or distcc
if (!compileCommands.empty() && (lang == "C" || lang == "CXX"))
{
std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER";
const char *clauncher = this->Target->GetProperty(clauncher_prop);
if (clauncher && *clauncher)
{
std::vector<std::string> launcher_cmd;
cmSystemTools::ExpandListArgument(clauncher, launcher_cmd, true);
for (std::vector<std::string>::iterator i = launcher_cmd.begin(),
e = launcher_cmd.end(); i != e; ++i)
{
*i = this->LocalGenerator->EscapeForShell(*i);
}
std::string const& run_launcher = cmJoin(launcher_cmd, " ") + " ";
compileCommands.front().insert(0, run_launcher);
}
}
// Expand placeholders in the commands.
for(std::vector<std::string>::iterator i = compileCommands.begin();
i != compileCommands.end(); ++i)
+20
View File
@@ -22,6 +22,7 @@
#include "cmComputeLinkInformation.h"
#include "cmSourceFile.h"
#include "cmCustomCommandGenerator.h"
#include "cmAlgorithms.h"
#include <algorithm>
@@ -475,6 +476,25 @@ cmNinjaTargetGenerator
}
}
// Maybe insert a compiler launcher like ccache or distcc
if (!compileCmds.empty() && (lang == "C" || lang == "CXX"))
{
std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER";
const char *clauncher = this->Target->GetProperty(clauncher_prop);
if (clauncher && *clauncher)
{
std::vector<std::string> launcher_cmd;
cmSystemTools::ExpandListArgument(clauncher, launcher_cmd, true);
for (std::vector<std::string>::iterator i = launcher_cmd.begin(),
e = launcher_cmd.end(); i != e; ++i)
{
*i = this->LocalGenerator->EscapeForShell(*i);
}
std::string const& run_launcher = cmJoin(launcher_cmd, " ") + " ";
compileCmds.front().insert(0, run_launcher);
}
}
if (!compileCmds.empty())
{
compileCmds.front().insert(0, cldeps);
+2
View File
@@ -333,10 +333,12 @@ void cmTarget::SetMakefile(cmMakefile* mf)
this->SetPropertyDefault("MACOSX_BUNDLE", 0);
this->SetPropertyDefault("MACOSX_RPATH", 0);
this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", 0);
this->SetPropertyDefault("C_COMPILER_LAUNCHER", 0);
this->SetPropertyDefault("C_INCLUDE_WHAT_YOU_USE", 0);
this->SetPropertyDefault("C_STANDARD", 0);
this->SetPropertyDefault("C_STANDARD_REQUIRED", 0);
this->SetPropertyDefault("C_EXTENSIONS", 0);
this->SetPropertyDefault("CXX_COMPILER_LAUNCHER", 0);
this->SetPropertyDefault("CXX_INCLUDE_WHAT_YOU_USE", 0);
this->SetPropertyDefault("CXX_STANDARD", 0);
this->SetPropertyDefault("CXX_STANDARD_REQUIRED", 0);