1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 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 "cmBuildCommand.h"
14 #include "cmLocalGenerator.h"
15 #include "cmGlobalGenerator.h"
17 //----------------------------------------------------------------------
19 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
21 // Support the legacy signature of the command:
25 return this->TwoArgsSignature(args);
28 return this->MainSignature(args);
31 //----------------------------------------------------------------------
33 ::MainSignature(std::vector<std::string> const& args)
37 this->SetError("requires at least one argument naming a CMake variable");
41 // The cmake variable in which to store the result.
42 const char* variable = args[0].c_str();
44 // Parse remaining arguments.
45 const char* configuration = 0;
46 const char* project_name = 0;
47 const char* target = 0;
48 enum Doing { DoingNone, DoingConfiguration, DoingProjectName, DoingTarget };
49 Doing doing = DoingNone;
50 for(unsigned int i=1; i < args.size(); ++i)
52 if(args[i] == "CONFIGURATION")
54 doing = DoingConfiguration;
56 else if(args[i] == "PROJECT_NAME")
58 doing = DoingProjectName;
60 else if(args[i] == "TARGET")
64 else if(doing == DoingConfiguration)
67 configuration = args[i].c_str();
69 else if(doing == DoingProjectName)
72 project_name = args[i].c_str();
74 else if(doing == DoingTarget)
77 target = args[i].c_str();
82 e << "unknown argument \"" << args[i] << "\"";
83 this->SetError(e.str().c_str());
88 const char* makeprogram
89 = this->Makefile->GetDefinition("CMAKE_MAKE_PROGRAM");
92 this->Makefile->IssueMessage(
94 "build_command() requires CMAKE_MAKE_PROGRAM to be defined. "
95 "Call project() or enable_language() first.");
99 // If null/empty CONFIGURATION argument, GenerateBuildCommand uses 'Debug'
100 // in the currently implemented multi-configuration global generators...
101 // so we put this code here to end up with the same default configuration
102 // as the original 2-arg build_command signature:
104 if(!configuration || !*configuration)
106 configuration = getenv("CMAKE_CONFIG_TYPE");
108 if(!configuration || !*configuration)
110 configuration = "Release";
113 // If null/empty PROJECT_NAME argument, use the Makefile's project name:
115 if(!project_name || !*project_name)
117 project_name = this->Makefile->GetProjectName();
120 // If null/empty TARGET argument, GenerateBuildCommand omits any mention
121 // of a target name on the build command line...
123 std::string makecommand = this->Makefile->GetLocalGenerator()
124 ->GetGlobalGenerator()->GenerateBuildCommand
125 (makeprogram, project_name, 0, 0, target, configuration, true, false);
127 this->Makefile->AddDefinition(variable, makecommand.c_str());
132 //----------------------------------------------------------------------
134 ::TwoArgsSignature(std::vector<std::string> const& args)
138 this->SetError("called with less than two arguments");
142 const char* define = args[0].c_str();
143 const char* cacheValue
144 = this->Makefile->GetDefinition(define);
145 std::string makeprogram = args[1];
147 std::string configType = "Release";
148 const char* cfg = getenv("CMAKE_CONFIG_TYPE");
154 std::string makecommand = this->Makefile->GetLocalGenerator()
155 ->GetGlobalGenerator()->GenerateBuildCommand
156 (makeprogram.c_str(), this->Makefile->GetProjectName(), 0, 0,
157 0, configType.c_str(), true, false);
163 this->Makefile->AddCacheDefinition(define,
165 "Command used to build entire project "
166 "from the command line.",
167 cmCacheManager::STRING);