cmGlobalGenerator.cxx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmGlobalGenerator.h"
  14. #include "cmLocalGenerator.h"
  15. #include "cmake.h"
  16. #include "cmMakefile.h"
  17. #include <stdlib.h> // required for atof
  18. #if defined(_WIN32) && !defined(__CYGWIN__)
  19. #include <windows.h>
  20. #endif
  21. int cmGlobalGenerator::s_TryCompileTimeout = 0;
  22. cmGlobalGenerator::cmGlobalGenerator()
  23. {
  24. // by default use the native paths
  25. m_ForceUnixPaths = false;
  26. }
  27. cmGlobalGenerator::~cmGlobalGenerator()
  28. {
  29. // Delete any existing cmLocalGenerators
  30. unsigned int i;
  31. for (i = 0; i < m_LocalGenerators.size(); ++i)
  32. {
  33. delete m_LocalGenerators[i];
  34. }
  35. m_LocalGenerators.clear();
  36. }
  37. // Find the make program for the generator, required for try compiles
  38. void cmGlobalGenerator::FindMakeProgram(cmMakefile* mf)
  39. {
  40. if(m_FindMakeProgramFile.size() == 0)
  41. {
  42. cmSystemTools::Error(
  43. "Generator implementation error, "
  44. "all generators must specify m_FindMakeProgramFile");
  45. }
  46. if(!mf->GetDefinition("CMAKE_MAKE_PROGRAM")
  47. || cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM")))
  48. {
  49. std::string setMakeProgram = mf->GetModulesFile(m_FindMakeProgramFile.c_str());
  50. if(setMakeProgram.size())
  51. {
  52. mf->ReadListFile(0, setMakeProgram.c_str());
  53. }
  54. }
  55. if(!mf->GetDefinition("CMAKE_MAKE_PROGRAM")
  56. || cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM")))
  57. {
  58. cmOStringStream err;
  59. err << "CMake was unable to find a build program corresponding to \""
  60. << this->GetName() << "\". CMAKE_MAKE_PROGRAM is not set. You "
  61. << "probably need to select a different build tool.";
  62. cmSystemTools::Error(err.str().c_str());
  63. cmSystemTools::SetFatalErrorOccured();
  64. return;
  65. }
  66. std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  67. // if there are spaces in the make program use short path
  68. // but do not short path the actual program name, as
  69. // this can cause trouble with VSExpress
  70. if(makeProgram.find(' ') != makeProgram.npos)
  71. {
  72. std::string dir;
  73. std::string file;
  74. cmSystemTools::SplitProgramPath(makeProgram.c_str(),
  75. dir, file);
  76. std::string saveFile = file;
  77. cmSystemTools::GetShortPath(makeProgram.c_str(), makeProgram);
  78. cmSystemTools::SplitProgramPath(makeProgram.c_str(),
  79. dir, file);
  80. makeProgram = dir;
  81. makeProgram += "/";
  82. makeProgram += saveFile;
  83. this->GetCMakeInstance()->AddCacheEntry("CMAKE_MAKE_PROGRAM", makeProgram.c_str(),
  84. "make program",
  85. cmCacheManager::FILEPATH);
  86. }
  87. }
  88. // enable the given language
  89. void cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages,
  90. cmMakefile *mf)
  91. {
  92. if(languages.size() == 0)
  93. {
  94. cmSystemTools::Error("EnableLanguage must have a lang specified!");
  95. cmSystemTools::SetFatalErrorOccured();
  96. return;
  97. }
  98. // setup some variables for the EnableLanguage function
  99. bool isLocal = m_CMakeInstance->GetLocal();
  100. // if we are from the top, always define this
  101. if(!isLocal)
  102. {
  103. mf->AddDefinition("RUN_CONFIGURE", true);
  104. }
  105. bool needTestLanguage = false;
  106. std::string rootBin = mf->GetHomeOutputDirectory();
  107. // If the configuration files path has been set,
  108. // then we are in a try compile and need to copy the enable language
  109. // files into the try compile directory
  110. if(m_ConfiguredFilesPath.size())
  111. {
  112. std::string src = m_ConfiguredFilesPath;
  113. src += "/CMakeSystem.cmake";
  114. std::string dst = rootBin;
  115. dst += "/CMakeSystem.cmake";
  116. cmSystemTools::CopyFileIfDifferent(src.c_str(), dst.c_str());
  117. for(std::vector<std::string>::const_iterator l = languages.begin();
  118. l != languages.end(); ++l)
  119. {
  120. const char* lang = l->c_str();
  121. std::string src2 = m_ConfiguredFilesPath;
  122. src2 += "/CMake";
  123. src2 += lang;
  124. src2 += "Compiler.cmake";
  125. std::string dst2 = rootBin;
  126. dst2 += "/CMake";
  127. dst2 += lang;
  128. dst2 += "Compiler.cmake";
  129. cmSystemTools::CopyFileIfDifferent(src2.c_str(), dst2.c_str());
  130. }
  131. rootBin = m_ConfiguredFilesPath;
  132. }
  133. // **** Step 1, find and make sure CMAKE_MAKE_PROGRAM is defined
  134. this->FindMakeProgram(mf);
  135. // **** Step 2, Load the CMakeDetermineSystem.cmake file and find out
  136. // what platform we are running on
  137. if (!isLocal && !mf->GetDefinition("CMAKE_SYSTEM_NAME"))
  138. {
  139. #if defined(_WIN32) && !defined(__CYGWIN__)
  140. /* Windows version number data. */
  141. OSVERSIONINFO osvi;
  142. ZeroMemory(&osvi, sizeof(osvi));
  143. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  144. GetVersionEx (&osvi);
  145. cmOStringStream windowsVersionString;
  146. windowsVersionString << osvi.dwMajorVersion << "." << osvi.dwMinorVersion;
  147. windowsVersionString.str();
  148. mf->AddDefinition("CMAKE_SYSTEM_VERSION", windowsVersionString.str().c_str());
  149. #endif
  150. // Read the DetermineSystem file
  151. std::string systemFile = mf->GetModulesFile("CMakeDetermineSystem.cmake");
  152. mf->ReadListFile(0, systemFile.c_str());
  153. }
  154. // **** Step 3, load the CMakeSystem.cmake from the binary directory
  155. // this file is configured by the CMakeDetermineSystem.cmake file
  156. std::string fpath = rootBin;
  157. if(!mf->GetDefinition("CMAKE_SYSTEM_LOADED"))
  158. {
  159. fpath += "/CMakeSystem.cmake";
  160. mf->ReadListFile(0,fpath.c_str());
  161. }
  162. // **** Step 4, foreach language
  163. // load the CMakeDetermine(LANG)Compiler.cmake file to find
  164. // the compiler
  165. for(std::vector<std::string>::const_iterator l = languages.begin();
  166. l != languages.end(); ++l)
  167. {
  168. const char* lang = l->c_str();
  169. if(!isLocal && !this->GetLanguageEnabled(lang) )
  170. {
  171. if (m_CMakeInstance->GetIsInTryCompile())
  172. {
  173. cmSystemTools::Error("This should not have happen. "
  174. "If you see this message, you are probably using a "
  175. "broken CMakeLists.txt file or a problematic release of "
  176. "CMake");
  177. }
  178. needTestLanguage = true; // must test a language after finding it
  179. // read determine LANG compiler
  180. std::string determineCompiler = "CMakeDetermine";
  181. determineCompiler += lang;
  182. determineCompiler += "Compiler.cmake";
  183. std::string determineFile = mf->GetModulesFile(determineCompiler.c_str());
  184. if(!mf->ReadListFile(0,determineFile.c_str()))
  185. {
  186. cmSystemTools::Error("Could not find cmake module file:", determineFile.c_str());
  187. }
  188. // Some generators like visual studio should not use the env variables
  189. // So the global generator can specify that in this variable
  190. if(!mf->GetDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV"))
  191. {
  192. // put ${CMake_(LANG)_COMPILER_ENV_VAR}=${CMAKE_(LANG)_COMPILER into the
  193. // environment, in case user scripts want to run configure, or sub cmakes
  194. std::string compilerName = "CMAKE_";
  195. compilerName += lang;
  196. compilerName += "_COMPILER";
  197. std::string compilerEnv = "CMAKE_";
  198. compilerEnv += lang;
  199. compilerEnv += "_COMPILER_ENV_VAR";
  200. std::string envVar = mf->GetRequiredDefinition(compilerEnv.c_str());
  201. std::string envVarValue = mf->GetRequiredDefinition(compilerName.c_str());
  202. std::string env = envVar;
  203. env += "=";
  204. env += envVarValue;
  205. cmSystemTools::PutEnv(env.c_str());
  206. }
  207. }
  208. // **** Step 5, Load the configured language compiler file, if not loaded.
  209. // look to see if CMAKE_(LANG)_COMPILER_LOADED is set,
  210. // if not then load the CMake(LANG)Compiler.cmake file from the
  211. // binary tree, this is a configured file provided by
  212. // CMakeDetermine(LANG)Compiler.cmake
  213. std::string loadedLang = "CMAKE_";
  214. loadedLang += lang;
  215. loadedLang += "_COMPILER_LOADED";
  216. if(!mf->GetDefinition(loadedLang.c_str()))
  217. {
  218. fpath = rootBin;
  219. fpath += "/CMake";
  220. fpath += lang;
  221. fpath += "Compiler.cmake";
  222. if(!mf->ReadListFile(0,fpath.c_str()))
  223. {
  224. cmSystemTools::Error("Could not find cmake module file:", fpath.c_str());
  225. }
  226. this->SetLanguageEnabled(lang, mf);
  227. }
  228. }
  229. // **** Step 6, Load the system specific information if not yet loaded
  230. if (!mf->GetDefinition("CMAKE_SYSTEM_SPECIFIC_INFORMATION_LOADED"))
  231. {
  232. fpath = mf->GetModulesFile("CMakeSystemSpecificInformation.cmake");
  233. if(!mf->ReadListFile(0,fpath.c_str()))
  234. {
  235. cmSystemTools::Error("Could not find cmake module file:", fpath.c_str());
  236. }
  237. }
  238. for(std::vector<std::string>::const_iterator l = languages.begin();
  239. l != languages.end(); ++l)
  240. {
  241. const char* lang = l->c_str();
  242. std::string langLoadedVar = "CMAKE_";
  243. langLoadedVar += lang;
  244. langLoadedVar += "_INFORMATION_LOADED";
  245. if (!mf->GetDefinition(langLoadedVar.c_str()))
  246. {
  247. fpath = "CMake";
  248. fpath += lang;
  249. fpath += "Information.cmake";
  250. fpath = mf->GetModulesFile(fpath.c_str());
  251. if(!mf->ReadListFile(0,fpath.c_str()))
  252. {
  253. cmSystemTools::Error("Could not find cmake module file:", fpath.c_str());
  254. }
  255. }
  256. // **** Step 7, Test the compiler for the language just setup
  257. // At this point we should have enough info for a try compile
  258. // which is used in the backward stuff
  259. if(!isLocal)
  260. {
  261. if(needTestLanguage)
  262. {
  263. if (!m_CMakeInstance->GetIsInTryCompile())
  264. {
  265. std::string testLang = "CMakeTest";
  266. testLang += lang;
  267. testLang += "Compiler.cmake";
  268. std::string ifpath = mf->GetModulesFile(testLang.c_str());
  269. if(!mf->ReadListFile(0,ifpath.c_str()))
  270. {
  271. cmSystemTools::Error("Could not find cmake module file:", ifpath.c_str());
  272. }
  273. // **** Step 8, load backwards compatibility stuff for C and CXX
  274. // for old versions of CMake ListFiles C and CXX had some
  275. // backwards compatibility files they have to load
  276. const char* versionValue
  277. = mf->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
  278. if (atof(versionValue) <= 1.4)
  279. {
  280. if(strcmp(lang, "C") == 0)
  281. {
  282. ifpath = mf->GetModulesFile("CMakeBackwardCompatibilityC.cmake");
  283. mf->ReadListFile(0,ifpath.c_str());
  284. }
  285. if(strcmp(lang, "CXX") == 0)
  286. {
  287. ifpath = mf->GetModulesFile("CMakeBackwardCompatibilityCXX.cmake");
  288. mf->ReadListFile(0,ifpath.c_str());
  289. }
  290. }
  291. }
  292. }
  293. }
  294. }
  295. }
  296. const char* cmGlobalGenerator::GetLanguageOutputExtensionForLanguage(const char* lang)
  297. {
  298. if(!lang)
  299. {
  300. return "";
  301. }
  302. if(m_LanguageToOutputExtension.count(lang) > 0)
  303. {
  304. return m_LanguageToOutputExtension[lang].c_str();
  305. }
  306. return "";
  307. }
  308. const char* cmGlobalGenerator::GetLanguageOutputExtensionFromExtension(const char* ext)
  309. {
  310. if(!ext)
  311. {
  312. return "";
  313. }
  314. const char* lang = this->GetLanguageFromExtension(ext);
  315. if(!lang || *lang == 0)
  316. {
  317. // if no language is found then check to see if it is already an
  318. // ouput extension for some language. In that case it should be ignored
  319. // and in this map, so it will not be compiled but will just be used.
  320. if(m_OutputExtensions.count(ext))
  321. {
  322. return ext;
  323. }
  324. }
  325. return this->GetLanguageOutputExtensionForLanguage(lang);
  326. }
  327. const char* cmGlobalGenerator::GetLanguageFromExtension(const char* ext)
  328. {
  329. // if there is an extension and it starts with . then
  330. // move past the . because the extensions are not stored with a .
  331. // in the map
  332. if(ext && *ext == '.')
  333. {
  334. ++ext;
  335. }
  336. if(m_ExtensionToLanguage.count(ext) > 0)
  337. {
  338. return m_ExtensionToLanguage[ext].c_str();
  339. }
  340. return 0;
  341. }
  342. void cmGlobalGenerator::SetLanguageEnabled(const char* l, cmMakefile* mf)
  343. {
  344. if(m_LanguageEnabled.count(l) > 0)
  345. {
  346. return;
  347. }
  348. std::string outputExtensionVar = std::string("CMAKE_") +
  349. std::string(l) + std::string("_OUTPUT_EXTENSION");
  350. const char* outputExtension = mf->GetDefinition(outputExtensionVar.c_str());
  351. if(outputExtension)
  352. {
  353. m_LanguageToOutputExtension[l] = outputExtension;
  354. m_OutputExtensions[outputExtension] = outputExtension;
  355. if(outputExtension[0] == '.')
  356. {
  357. m_OutputExtensions[outputExtension+1] = outputExtension+1;
  358. }
  359. }
  360. std::string linkerPrefVar = std::string("CMAKE_") +
  361. std::string(l) + std::string("_LINKER_PREFERENCE");
  362. const char* linkerPref = mf->GetDefinition(linkerPrefVar.c_str());
  363. if(!linkerPref)
  364. {
  365. linkerPref = "None";
  366. }
  367. m_LanguageToLinkerPreference[l] = linkerPref;
  368. std::string extensionsVar = std::string("CMAKE_") +
  369. std::string(l) + std::string("_SOURCE_FILE_EXTENSIONS");
  370. std::string ignoreExtensionsVar = std::string("CMAKE_") +
  371. std::string(l) + std::string("_IGNORE_EXTENSIONS");
  372. std::string ignoreExts = mf->GetSafeDefinition(ignoreExtensionsVar.c_str());
  373. std::string exts = mf->GetSafeDefinition(extensionsVar.c_str());
  374. std::vector<std::string> extensionList;
  375. cmSystemTools::ExpandListArgument(exts, extensionList);
  376. for(std::vector<std::string>::iterator i = extensionList.begin();
  377. i != extensionList.end(); ++i)
  378. {
  379. m_ExtensionToLanguage[*i] = l;
  380. }
  381. cmSystemTools::ExpandListArgument(ignoreExts, extensionList);
  382. for(std::vector<std::string>::iterator i = extensionList.begin();
  383. i != extensionList.end(); ++i)
  384. {
  385. m_IgnoreExtensions[*i] = true;
  386. }
  387. m_LanguageEnabled[l] = true;
  388. }
  389. bool cmGlobalGenerator::IgnoreFile(const char* l)
  390. {
  391. if(this->GetLanguageFromExtension(l))
  392. {
  393. return false;
  394. }
  395. return (m_IgnoreExtensions.count(l) > 0);
  396. }
  397. bool cmGlobalGenerator::GetLanguageEnabled(const char* l)
  398. {
  399. return (m_LanguageEnabled.count(l) > 0);
  400. }
  401. void cmGlobalGenerator::ClearEnabledLanguages()
  402. {
  403. m_LanguageEnabled.clear();
  404. }
  405. void cmGlobalGenerator::Configure()
  406. {
  407. // Delete any existing cmLocalGenerators
  408. unsigned int i;
  409. for (i = 0; i < m_LocalGenerators.size(); ++i)
  410. {
  411. delete m_LocalGenerators[i];
  412. }
  413. m_LocalGenerators.clear();
  414. // start with this directory
  415. cmLocalGenerator *lg = this->CreateLocalGenerator();
  416. m_LocalGenerators.push_back(lg);
  417. // set the Start directories
  418. lg->GetMakefile()->SetStartDirectory(m_CMakeInstance->GetStartDirectory());
  419. lg->GetMakefile()->SetStartOutputDirectory(m_CMakeInstance->GetStartOutputDirectory());
  420. lg->GetMakefile()->MakeStartDirectoriesCurrent();
  421. // now do it
  422. this->RecursiveConfigure(lg,0.0f,0.9f);
  423. std::set<cmStdString> notFoundMap;
  424. // after it is all done do a ConfigureFinalPass
  425. cmCacheManager* manager = 0;
  426. for (i = 0; i < m_LocalGenerators.size(); ++i)
  427. {
  428. manager = m_LocalGenerators[i]->GetMakefile()->GetCacheManager();
  429. m_LocalGenerators[i]->ConfigureFinalPass();
  430. cmTargets const& targets = m_LocalGenerators[i]->GetMakefile()->GetTargets();
  431. for (cmTargets::const_iterator l = targets.begin();
  432. l != targets.end(); l++)
  433. {
  434. cmTarget::LinkLibraries libs = l->second.GetLinkLibraries();
  435. for(cmTarget::LinkLibraries::iterator lib = libs.begin();
  436. lib != libs.end(); ++lib)
  437. {
  438. if(lib->first.size() > 9 &&
  439. cmSystemTools::IsNOTFOUND(lib->first.c_str()))
  440. {
  441. std::string varName = lib->first.substr(0, lib->first.size()-9);
  442. notFoundMap.insert(varName);
  443. }
  444. }
  445. std::vector<std::string>& incs =
  446. m_LocalGenerators[i]->GetMakefile()->GetIncludeDirectories();
  447. for( std::vector<std::string>::iterator lib = incs.begin();
  448. lib != incs.end(); ++lib)
  449. {
  450. if(lib->size() > 9 &&
  451. cmSystemTools::IsNOTFOUND(lib->c_str()))
  452. {
  453. std::string varName = lib->substr(0, lib->size()-9);
  454. notFoundMap.insert(varName);
  455. }
  456. }
  457. m_CMakeInstance->UpdateProgress("Configuring",
  458. 0.9f+0.1f*(i+1.0f)/m_LocalGenerators.size());
  459. m_LocalGenerators[i]->GetMakefile()->CheckInfiniteLoops();
  460. }
  461. }
  462. if(notFoundMap.size())
  463. {
  464. std::string notFoundVars;
  465. for(std::set<cmStdString>::iterator ii = notFoundMap.begin();
  466. ii != notFoundMap.end(); ++ii)
  467. {
  468. notFoundVars += *ii;
  469. if(manager)
  470. {
  471. cmCacheManager::CacheIterator it =
  472. manager->GetCacheIterator(ii->c_str());
  473. if(it.GetPropertyAsBool("ADVANCED"))
  474. {
  475. notFoundVars += " (ADVANCED)";
  476. }
  477. }
  478. notFoundVars += "\n";
  479. }
  480. cmSystemTools::Error("This project requires some variables to be set,\n"
  481. "and cmake can not find them.\n"
  482. "Please set the following variables:\n",
  483. notFoundVars.c_str());
  484. }
  485. if ( !m_CMakeInstance->GetScriptMode() )
  486. {
  487. m_CMakeInstance->UpdateProgress("Configuring done", -1);
  488. }
  489. }
  490. // loop through the directories creating cmLocalGenerators and Configure()
  491. void cmGlobalGenerator::RecursiveConfigure(cmLocalGenerator *lg,
  492. float startProgress,
  493. float endProgress)
  494. {
  495. // configure the current directory
  496. lg->Configure();
  497. // get all the subdirectories
  498. std::vector<std::pair<cmStdString, bool> > subdirs = lg->GetMakefile()->GetSubDirectories();
  499. float progressPiece = (endProgress - startProgress)/(1.0f+subdirs.size());
  500. m_CMakeInstance->UpdateProgress("Configuring",
  501. startProgress + progressPiece);
  502. // for each subdir recurse
  503. unsigned int i;
  504. for (i = 0; i < subdirs.size(); ++i)
  505. {
  506. cmLocalGenerator *lg2 = this->CreateLocalGenerator();
  507. lg2->SetParent(lg);
  508. m_LocalGenerators.push_back(lg2);
  509. // add the subdir to the start output directory
  510. std::string outdir = lg->GetMakefile()->GetStartOutputDirectory();
  511. outdir += "/";
  512. outdir += subdirs[i].first;
  513. lg2->GetMakefile()->SetStartOutputDirectory(outdir.c_str());
  514. lg2->SetExcludeAll(!subdirs[i].second);
  515. // add the subdir to the start source directory
  516. std::string currentDir = lg->GetMakefile()->GetStartDirectory();
  517. currentDir += "/";
  518. currentDir += subdirs[i].first;
  519. lg2->GetMakefile()->SetStartDirectory(currentDir.c_str());
  520. lg2->GetMakefile()->MakeStartDirectoriesCurrent();
  521. this->RecursiveConfigure(lg2,
  522. startProgress + (i+1.0f)*progressPiece,
  523. startProgress + (i+2.0f)*progressPiece);
  524. }
  525. }
  526. void cmGlobalGenerator::Generate()
  527. {
  528. // For each existing cmLocalGenerator
  529. unsigned int i;
  530. for (i = 0; i < m_LocalGenerators.size(); ++i)
  531. {
  532. m_LocalGenerators[i]->Generate(true);
  533. m_LocalGenerators[i]->GenerateInstallRules();
  534. m_CMakeInstance->UpdateProgress("Generating",
  535. (i+1.0f)/m_LocalGenerators.size());
  536. }
  537. m_CMakeInstance->UpdateProgress("Generating done", -1);
  538. }
  539. void cmGlobalGenerator::LocalGenerate()
  540. {
  541. // for this case we create one LocalGenerator
  542. // configure it, and then Generate it
  543. // start with this directory
  544. cmLocalGenerator *lg = this->CreateLocalGenerator();
  545. // set the Start directories
  546. lg->GetMakefile()->SetStartDirectory(m_CMakeInstance->GetStartDirectory());
  547. lg->GetMakefile()->SetStartOutputDirectory(m_CMakeInstance->GetStartOutputDirectory());
  548. lg->GetMakefile()->MakeStartDirectoriesCurrent();
  549. // now do trhe configure
  550. lg->Configure();
  551. lg->ConfigureFinalPass();
  552. lg->Generate(false);
  553. delete lg;
  554. }
  555. int cmGlobalGenerator::TryCompile(const char *, const char *bindir,
  556. const char *, const char *target,
  557. std::string *output, cmMakefile*)
  558. {
  559. // now build the test
  560. std::string makeCommand =
  561. m_CMakeInstance->GetCacheManager()->GetCacheValue("CMAKE_MAKE_PROGRAM");
  562. if(makeCommand.size() == 0)
  563. {
  564. cmSystemTools::Error(
  565. "Generator cannot find the appropriate make command.");
  566. return 1;
  567. }
  568. makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
  569. /**
  570. * Run an executable command and put the stdout in output.
  571. */
  572. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  573. cmSystemTools::ChangeDirectory(bindir);
  574. // Since we have full control over the invocation of nmake, let us
  575. // make it quiet.
  576. if ( strcmp(this->GetName(), "NMake Makefiles") == 0 )
  577. {
  578. makeCommand += " /NOLOGO ";
  579. }
  580. // now build
  581. if (target)
  582. {
  583. makeCommand += " ";
  584. makeCommand += target;
  585. #if defined(_WIN32) || defined(__CYGWIN__)
  586. std::string tmp = target;
  587. // if the target does not already end in . something
  588. // then assume .exe
  589. if(tmp.size() < 4 || tmp[tmp.size()-4] != '.')
  590. {
  591. makeCommand += ".exe";
  592. }
  593. #endif // WIN32
  594. }
  595. else
  596. {
  597. makeCommand += " all";
  598. }
  599. int retVal;
  600. int timeout = cmGlobalGenerator::s_TryCompileTimeout;
  601. bool hideconsole = cmSystemTools::GetRunCommandHideConsole();
  602. cmSystemTools::SetRunCommandHideConsole(true);
  603. if (!cmSystemTools::RunSingleCommand(makeCommand.c_str(), output,
  604. &retVal, 0, false, timeout))
  605. {
  606. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  607. cmSystemTools::Error("Generator: execution of make failed.");
  608. // return to the original directory
  609. cmSystemTools::ChangeDirectory(cwd.c_str());
  610. return 1;
  611. }
  612. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  613. // The SGI MipsPro 7.3 compiler does not return an error code when
  614. // the source has a #error in it! This is a work-around for such
  615. // compilers.
  616. if((retVal == 0) && (output->find("#error") != std::string::npos))
  617. {
  618. retVal = 1;
  619. }
  620. cmSystemTools::ChangeDirectory(cwd.c_str());
  621. return retVal;
  622. }
  623. cmLocalGenerator *cmGlobalGenerator::CreateLocalGenerator()
  624. {
  625. cmLocalGenerator *lg = new cmLocalGenerator;
  626. lg->SetGlobalGenerator(this);
  627. return lg;
  628. }
  629. void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator *gen )
  630. {
  631. this->SetConfiguredFilesPath(
  632. gen->GetCMakeInstance()->GetHomeOutputDirectory());
  633. const char* make =
  634. gen->GetCMakeInstance()->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
  635. this->GetCMakeInstance()->AddCacheEntry("CMAKE_MAKE_PROGRAM", make,
  636. "make program",
  637. cmCacheManager::FILEPATH);
  638. // copy the enabled languages
  639. this->m_LanguageEnabled = gen->m_LanguageEnabled;
  640. this->m_ExtensionToLanguage = gen->m_ExtensionToLanguage;
  641. this->m_IgnoreExtensions = gen->m_IgnoreExtensions;
  642. this->m_LanguageToOutputExtension = gen->m_LanguageToOutputExtension;
  643. this->m_LanguageToLinkerPreference = gen->m_LanguageToLinkerPreference;
  644. this->m_OutputExtensions = gen->m_OutputExtensions;
  645. }
  646. //----------------------------------------------------------------------------
  647. void cmGlobalGenerator::GetDocumentation(cmDocumentationEntry& entry) const
  648. {
  649. entry.name = this->GetName();
  650. entry.brief = "";
  651. entry.full = "";
  652. }
  653. bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
  654. cmLocalGenerator* gen)
  655. {
  656. cmLocalGenerator* cur = gen->GetParent();
  657. while(cur && cur != root)
  658. {
  659. if(cur->GetExcludeAll())
  660. {
  661. return true;
  662. }
  663. cur = cur->GetParent();
  664. }
  665. return false;
  666. }
  667. void cmGlobalGenerator::GetEnabledLanguages(std::vector<std::string>& lang)
  668. {
  669. for(std::map<cmStdString, bool>::iterator i = m_LanguageEnabled.begin();
  670. i != m_LanguageEnabled.end(); ++i)
  671. {
  672. lang.push_back(i->first);
  673. }
  674. }
  675. const char* cmGlobalGenerator::GetLinkerPreference(const char* lang)
  676. {
  677. if(m_LanguageToLinkerPreference.count(lang))
  678. {
  679. return m_LanguageToLinkerPreference[lang].c_str();
  680. }
  681. return "None";
  682. }