ENH: put the 64 bit paths first
[cmake.git] / Source / CTest / cmCTestBuildCommand.cxx
blob6b7fa389bd61986ec0a9c714347c956cc587699f
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCTestBuildCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2009-02-13 16:49:31 $
7 Version: $Revision: 1.20 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmCTestBuildCommand.h"
19 #include "cmCTest.h"
20 #include "cmCTestGenericHandler.h"
21 #include "cmCTestBuildHandler.h"
22 #include "cmake.h"
23 #include "cmGlobalGenerator.h"
26 //----------------------------------------------------------------------------
27 cmCTestBuildCommand::cmCTestBuildCommand()
29 this->GlobalGenerator = 0;
30 this->Arguments[ctb_NUMBER_ERRORS] = "NUMBER_ERRORS";
31 this->Arguments[ctb_NUMBER_WARNINGS] = "NUMBER_WARNINGS";
32 this->Arguments[ctb_LAST] = 0;
33 this->Last = ctb_LAST;
36 //----------------------------------------------------------------------------
37 cmCTestBuildCommand::~cmCTestBuildCommand()
39 if ( this->GlobalGenerator )
41 delete this->GlobalGenerator;
42 this->GlobalGenerator = 0;
46 //----------------------------------------------------------------------------
47 cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler()
49 cmCTestGenericHandler* handler
50 = this->CTest->GetInitializedHandler("build");
51 if ( !handler )
53 this->SetError("internal CTest error. Cannot instantiate build handler");
54 return 0;
56 this->Handler = (cmCTestBuildHandler*)handler;
57 const char* ctestBuildCommand
58 = this->Makefile->GetDefinition("CTEST_BUILD_COMMAND");
59 if ( ctestBuildCommand && *ctestBuildCommand )
61 this->CTest->SetCTestConfiguration("MakeCommand", ctestBuildCommand);
63 else
65 const char* cmakeGeneratorName
66 = this->Makefile->GetDefinition("CTEST_CMAKE_GENERATOR");
67 const char* cmakeProjectName
68 = this->Makefile->GetDefinition("CTEST_PROJECT_NAME");
69 const char* cmakeBuildConfiguration
70 = this->Makefile->GetDefinition("CTEST_BUILD_CONFIGURATION");
71 const char* cmakeBuildAdditionalFlags
72 = this->Makefile->GetDefinition("CTEST_BUILD_FLAGS");
73 const char* cmakeBuildTarget
74 = this->Makefile->GetDefinition("CTEST_BUILD_TARGET");
75 if ( cmakeGeneratorName && *cmakeGeneratorName &&
76 cmakeProjectName && *cmakeProjectName )
78 if ( !cmakeBuildConfiguration )
80 cmakeBuildConfiguration = "Release";
82 if ( this->GlobalGenerator )
84 if ( strcmp(this->GlobalGenerator->GetName(),
85 cmakeGeneratorName) != 0 )
87 delete this->GlobalGenerator;
88 this->GlobalGenerator = 0;
91 if ( !this->GlobalGenerator )
93 this->GlobalGenerator =
94 this->Makefile->GetCMakeInstance()->CreateGlobalGenerator(
95 cmakeGeneratorName);
97 this->GlobalGenerator->FindMakeProgram(this->Makefile);
98 const char* cmakeMakeProgram
99 = this->Makefile->GetDefinition("CMAKE_MAKE_PROGRAM");
100 if(strlen(cmakeBuildConfiguration) == 0)
102 const char* config = 0;
103 #ifdef CMAKE_INTDIR
104 config = CMAKE_INTDIR;
105 #endif
106 if(!config)
108 config = "Debug";
110 cmakeBuildConfiguration = config;
113 std::string buildCommand
114 = this->GlobalGenerator->
115 GenerateBuildCommand(cmakeMakeProgram,
116 cmakeProjectName,
117 cmakeBuildAdditionalFlags, cmakeBuildTarget,
118 cmakeBuildConfiguration, true, false);
119 cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
120 "SetMakeCommand:"
121 << buildCommand.c_str() << "\n");
122 this->CTest->SetCTestConfiguration("MakeCommand", buildCommand.c_str());
124 else
126 cmOStringStream ostr;
127 ostr << "CTEST_BUILD_COMMAND or CTEST_CMAKE_GENERATOR not specified. "
128 "Please specify the CTEST_CMAKE_GENERATOR and CTEST_PROJECT_NAME if "
129 "this is a CMake project, or specify the CTEST_BUILD_COMMAND for "
130 "cmake or any other project.";
131 this->SetError(ostr.str().c_str());
132 return 0;
136 if(const char* useLaunchers =
137 this->Makefile->GetDefinition("CTEST_USE_LAUNCHERS"))
139 this->CTest->SetCTestConfiguration("UseLaunchers", useLaunchers);
142 return handler;
146 bool cmCTestBuildCommand::InitialPass(std::vector<std::string> const& args,
147 cmExecutionStatus &status)
149 bool ret = cmCTestHandlerCommand::InitialPass(args, status);
150 if ( this->Values[ctb_NUMBER_ERRORS] && *this->Values[ctb_NUMBER_ERRORS])
152 cmOStringStream str;
153 str << this->Handler->GetTotalErrors();
154 this->Makefile->AddDefinition(
155 this->Values[ctb_NUMBER_ERRORS], str.str().c_str());
157 if ( this->Values[ctb_NUMBER_WARNINGS]
158 && *this->Values[ctb_NUMBER_WARNINGS])
160 cmOStringStream str;
161 str << this->Handler->GetTotalWarnings();
162 this->Makefile->AddDefinition(
163 this->Values[ctb_NUMBER_WARNINGS], str.str().c_str());
165 return ret;