new arch
[cmake.git] / Source / cmGlobalGenerator.cxx
blob413faa402416b01fa8af7a0a5ff392daf8c603a0
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmGlobalGenerator.cxx,v $
5 Language: C++
6 Date: $Date: 2002-09-06 17:05:57 $
7 Version: $Revision: 1.3 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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 "cmGlobalGenerator.h"
18 #include "cmLocalGenerator.h"
19 #include "cmake.h"
20 #include "cmMakefile.h"
22 cmGlobalGenerator::cmGlobalGenerator()
24 m_LanguagesEnabled = false;
27 cmGlobalGenerator::~cmGlobalGenerator()
29 // Delete any existing cmLocalGenerators
30 int i;
31 for (i = 0; i < m_LocalGenerators.size(); ++i)
33 delete m_LocalGenerators[i];
35 m_LocalGenerators.clear();
38 void cmGlobalGenerator::SetLanguageEnabled(const char* l)
40 m_LanguageEnabled[l] = true;
43 bool cmGlobalGenerator::GetLanguageEnabled(const char* l)
45 return (m_LanguageEnabled.count(l) > 0);
48 void cmGlobalGenerator::ClearEnabledLanguages()
50 m_LanguageEnabled.clear();
53 void cmGlobalGenerator::Configure()
55 // reset theLanguages
56 m_LanguagesEnabled = false;
58 // Delete any existing cmLocalGenerators
59 int i;
60 for (i = 0; i < m_LocalGenerators.size(); ++i)
62 delete m_LocalGenerators[i];
64 m_LocalGenerators.clear();
66 // start with this directory
67 cmLocalGenerator *lg = this->CreateLocalGenerator();
68 m_LocalGenerators.push_back(lg);
70 // set the Start directories
71 lg->GetMakefile()->SetStartDirectory(m_CMakeInstance->GetStartDirectory());
72 lg->GetMakefile()->SetStartOutputDirectory(m_CMakeInstance->GetStartOutputDirectory());
73 lg->GetMakefile()->MakeStartDirectoriesCurrent();
75 // now do it
76 this->RecursiveConfigure(lg);
79 // loop through the directories creating cmLocalGenerators and Configure()
80 void cmGlobalGenerator::RecursiveConfigure(cmLocalGenerator *lg)
82 // configure the current directory
83 lg->Configure();
85 // get all the subdirectories
86 std::vector<std::string> subdirs = lg->GetMakefile()->GetSubDirectories();
88 // for each subdir recurse
89 int i;
90 for (i = 0; i < subdirs.size(); ++i)
92 cmLocalGenerator *lg2 = this->CreateLocalGenerator();
93 m_LocalGenerators.push_back(lg2);
95 // add the subdir to the start output directory
96 std::string outdir = lg->GetMakefile()->GetStartOutputDirectory();
97 outdir += "/";
98 outdir += subdirs[i];
99 lg2->GetMakefile()->SetStartOutputDirectory(outdir.c_str());
101 // add the subdir to the start source directory
102 std::string currentDir = lg->GetMakefile()->GetStartDirectory();
103 currentDir += "/";
104 currentDir += subdirs[i];
105 lg2->GetMakefile()->SetStartDirectory(currentDir.c_str());
106 lg2->GetMakefile()->MakeStartDirectoriesCurrent();
108 this->RecursiveConfigure(lg2);
112 void cmGlobalGenerator::Generate()
114 // For each existing cmLocalGenerator
115 int i;
116 for (i = 0; i < m_LocalGenerators.size(); ++i)
118 m_LocalGenerators[i]->Generate(true);
122 void cmGlobalGenerator::LocalGenerate()
124 // for this case we create one LocalGenerator
125 // configure it, and then Generate it
126 // start with this directory
127 cmLocalGenerator *lg = this->CreateLocalGenerator();
129 // set the Start directories
130 lg->GetMakefile()->SetStartDirectory(m_CMakeInstance->GetStartDirectory());
131 lg->GetMakefile()->SetStartOutputDirectory(m_CMakeInstance->GetStartOutputDirectory());
132 lg->GetMakefile()->MakeStartDirectoriesCurrent();
134 // now do trhe configure
135 lg->Configure();
136 lg->Generate(false);
137 delete lg;
140 int cmGlobalGenerator::TryCompile(const char *, const char *bindir,
141 const char *)
143 // now build the test
144 std::string makeCommand =
145 m_CMakeInstance->GetCacheManager()->GetCacheValue("CMAKE_MAKE_PROGRAM");
146 if(makeCommand.size() == 0)
148 cmSystemTools::Error(
149 "Generator cannot find the appropriate make command.");
150 return 1;
152 makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
155 * Run an executable command and put the stdout in output.
157 std::string output;
158 std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
159 cmSystemTools::ChangeDirectory(bindir);
161 // now build
162 makeCommand += " all";
163 if (!cmSystemTools::RunCommand(makeCommand.c_str(), output))
165 cmSystemTools::Error("Generator: execution of make failed.");
166 // return to the original directory
167 cmSystemTools::ChangeDirectory(cwd.c_str());
168 return 1;
170 cmSystemTools::ChangeDirectory(cwd.c_str());
171 return 0;
174 cmLocalGenerator *cmGlobalGenerator::CreateLocalGenerator()
176 cmLocalGenerator *lg = new cmLocalGenerator;
177 lg->SetGlobalGenerator(this);
178 return lg;