Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / CTest / cmCTestBuildCommand.cxx
blob17273969d69663791dcca1efa1e7d08f848487d0
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCTestBuildCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2007/09/17 14:40:57 $
7 Version: $Revision: 1.18 $
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 "cmake.h"
22 #include "cmGlobalGenerator.h"
25 //----------------------------------------------------------------------------
26 cmCTestBuildCommand::cmCTestBuildCommand()
28 this->GlobalGenerator = 0;
31 //----------------------------------------------------------------------------
32 cmCTestBuildCommand::~cmCTestBuildCommand()
34 if ( this->GlobalGenerator )
36 delete this->GlobalGenerator;
37 this->GlobalGenerator = 0;
41 //----------------------------------------------------------------------------
42 cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler()
44 cmCTestGenericHandler* handler
45 = this->CTest->GetInitializedHandler("build");
46 if ( !handler )
48 this->SetError("internal CTest error. Cannot instantiate build handler");
49 return 0;
52 const char* ctestBuildCommand
53 = this->Makefile->GetDefinition("CTEST_BUILD_COMMAND");
54 if ( ctestBuildCommand && *ctestBuildCommand )
56 this->CTest->SetCTestConfiguration("MakeCommand", ctestBuildCommand);
58 else
60 const char* cmakeGeneratorName
61 = this->Makefile->GetDefinition("CTEST_CMAKE_GENERATOR");
62 const char* cmakeProjectName
63 = this->Makefile->GetDefinition("CTEST_PROJECT_NAME");
64 const char* cmakeBuildConfiguration
65 = this->Makefile->GetDefinition("CTEST_BUILD_CONFIGURATION");
66 const char* cmakeBuildAdditionalFlags
67 = this->Makefile->GetDefinition("CTEST_BUILD_FLAGS");
68 const char* cmakeBuildTarget
69 = this->Makefile->GetDefinition("CTEST_BUILD_TARGET");
70 if ( cmakeGeneratorName && *cmakeGeneratorName &&
71 cmakeProjectName && *cmakeProjectName )
73 if ( !cmakeBuildConfiguration )
75 cmakeBuildConfiguration = "Release";
77 if ( this->GlobalGenerator )
79 if ( strcmp(this->GlobalGenerator->GetName(),
80 cmakeGeneratorName) != 0 )
82 delete this->GlobalGenerator;
83 this->GlobalGenerator = 0;
86 if ( !this->GlobalGenerator )
88 this->GlobalGenerator =
89 this->Makefile->GetCMakeInstance()->CreateGlobalGenerator(
90 cmakeGeneratorName);
92 this->GlobalGenerator->FindMakeProgram(this->Makefile);
93 const char* cmakeMakeProgram
94 = this->Makefile->GetDefinition("CMAKE_MAKE_PROGRAM");
95 if(strlen(cmakeBuildConfiguration) == 0)
97 const char* config = 0;
98 #ifdef CMAKE_INTDIR
99 config = CMAKE_INTDIR;
100 #endif
101 if(!config)
103 config = "Debug";
105 cmakeBuildConfiguration = config;
108 std::string buildCommand
109 = this->GlobalGenerator->
110 GenerateBuildCommand(cmakeMakeProgram,
111 cmakeProjectName,
112 cmakeBuildAdditionalFlags, cmakeBuildTarget,
113 cmakeBuildConfiguration, true, false);
114 cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
115 "SetMakeCommand:"
116 << buildCommand.c_str() << "\n");
117 this->CTest->SetCTestConfiguration("MakeCommand", buildCommand.c_str());
119 else
121 cmOStringStream ostr;
122 ostr << "CTEST_BUILD_COMMAND or CTEST_CMAKE_GENERATOR not specified. "
123 "Please specify the CTEST_CMAKE_GENERATOR and CTEST_PROJECT_NAME if "
124 "this is a CMake project, or specify the CTEST_BUILD_COMMAND for "
125 "cmake or any other project.";
126 this->SetError(ostr.str().c_str());
127 return 0;
131 return handler;