1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2010 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmCustomCommandGenerator.h"
14 #include "cmMakefile.h"
15 #include "cmCustomCommand.h"
16 #include "cmLocalGenerator.h"
17 #include "cmGeneratorExpression.h"
19 //----------------------------------------------------------------------------
20 cmCustomCommandGenerator::cmCustomCommandGenerator(
21 cmCustomCommand const& cc, const char* config, cmMakefile* mf):
22 CC(cc), Config(config), Makefile(mf), LG(mf->GetLocalGenerator()),
23 OldStyle(cc.GetEscapeOldStyle()), MakeVars(cc.GetEscapeAllowMakeVars()),
24 GE(new cmGeneratorExpression(mf, config, cc.GetBacktrace()))
28 //----------------------------------------------------------------------------
29 cmCustomCommandGenerator::~cmCustomCommandGenerator()
34 //----------------------------------------------------------------------------
35 unsigned int cmCustomCommandGenerator::GetNumberOfCommands() const
37 return static_cast<unsigned int>(this->CC.GetCommandLines().size());
40 //----------------------------------------------------------------------------
41 std::string cmCustomCommandGenerator::GetCommand(unsigned int c) const
43 std::string const& argv0 = this->CC.GetCommandLines()[c][0];
44 cmTarget* target = this->Makefile->FindTargetToUse(argv0.c_str());
45 if(target && target->GetType() == cmTarget::EXECUTABLE &&
46 (target->IsImported() || !this->Makefile->IsOn("CMAKE_CROSSCOMPILING")))
48 return target->GetLocation(this->Config);
50 return this->GE->Process(argv0);
53 //----------------------------------------------------------------------------
55 cmCustomCommandGenerator
56 ::AppendArguments(unsigned int c, std::string& cmd) const
58 cmCustomCommandLine const& commandLine = this->CC.GetCommandLines()[c];
59 for(unsigned int j=1;j < commandLine.size(); ++j)
61 std::string arg = this->GE->Process(commandLine[j]);
65 cmd += this->LG->EscapeForShellOldStyle(arg.c_str());
69 cmd += this->LG->EscapeForShell(arg.c_str(), this->MakeVars);