cmGlobalGenerator.cxx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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. return this->GetLanguageOutputExtensionForLanguage(lang);
  316. }
  317. const char* cmGlobalGenerator::GetLanguageFromExtension(const char* ext)
  318. {
  319. // if there is an extension and it starts with . then
  320. // move past the . because the extensions are not stored with a .
  321. // in the map
  322. if(ext && *ext == '.')
  323. {
  324. ++ext;
  325. }
  326. if(m_ExtensionToLanguage.count(ext) > 0)
  327. {
  328. return m_ExtensionToLanguage[ext].c_str();
  329. }
  330. return 0;
  331. }
  332. void cmGlobalGenerator::SetLanguageEnabled(const char* l, cmMakefile* mf)
  333. {
  334. if(m_LanguageEnabled.count(l) > 0)
  335. {
  336. return;
  337. }
  338. std::string outputExtensionVar = std::string("CMAKE_") +
  339. std::string(l) + std::string("_OUTPUT_EXTENSION");
  340. const char* outputExtension = mf->GetDefinition(outputExtensionVar.c_str());
  341. if(outputExtension)
  342. {
  343. m_LanguageToOutputExtension[l] = outputExtension;
  344. }
  345. std::string linkerPrefVar = std::string("CMAKE_") +
  346. std::string(l) + std::string("_LINKER_PREFERENCE");
  347. const char* linkerPref = mf->GetDefinition(linkerPrefVar.c_str());
  348. if(!linkerPref)
  349. {
  350. linkerPref = "None";
  351. }
  352. m_LanguageToLinkerPreference[l] = linkerPref;
  353. std::string extensionsVar = std::string("CMAKE_") +
  354. std::string(l) + std::string("_SOURCE_FILE_EXTENSIONS");
  355. std::string ignoreExtensionsVar = std::string("CMAKE_") +
  356. std::string(l) + std::string("_IGNORE_EXTENSIONS");
  357. std::string ignoreExts = mf->GetSafeDefinition(ignoreExtensionsVar.c_str());
  358. std::string exts = mf->GetSafeDefinition(extensionsVar.c_str());
  359. std::vector<std::string> extensionList;
  360. cmSystemTools::ExpandListArgument(exts, extensionList);
  361. for(std::vector<std::string>::iterator i = extensionList.begin();
  362. i != extensionList.end(); ++i)
  363. {
  364. m_ExtensionToLanguage[*i] = l;
  365. }
  366. cmSystemTools::ExpandListArgument(ignoreExts, extensionList);
  367. for(std::vector<std::string>::iterator i = extensionList.begin();
  368. i != extensionList.end(); ++i)
  369. {
  370. m_IgnoreExtensions[*i] = true;
  371. }
  372. m_LanguageEnabled[l] = true;
  373. }
  374. bool cmGlobalGenerator::IgnoreFile(const char* l)
  375. {
  376. if(this->GetLanguageFromExtension(l))
  377. {
  378. return false;
  379. }
  380. return (m_IgnoreExtensions.count(l) > 0);
  381. }
  382. bool cmGlobalGenerator::GetLanguageEnabled(const char* l)
  383. {
  384. return (m_LanguageEnabled.count(l) > 0);
  385. }
  386. void cmGlobalGenerator::ClearEnabledLanguages()
  387. {
  388. m_LanguageEnabled.clear();
  389. }
  390. void cmGlobalGenerator::Configure()
  391. {
  392. // Delete any existing cmLocalGenerators
  393. unsigned int i;
  394. for (i = 0; i < m_LocalGenerators.size(); ++i)
  395. {
  396. delete m_LocalGenerators[i];
  397. }
  398. m_LocalGenerators.clear();
  399. // start with this directory
  400. cmLocalGenerator *lg = this->CreateLocalGenerator();
  401. m_LocalGenerators.push_back(lg);
  402. // set the Start directories
  403. lg->GetMakefile()->SetStartDirectory(m_CMakeInstance->GetStartDirectory());
  404. lg->GetMakefile()->SetStartOutputDirectory(m_CMakeInstance->GetStartOutputDirectory());
  405. lg->GetMakefile()->MakeStartDirectoriesCurrent();
  406. // now do it
  407. this->RecursiveConfigure(lg,0.0f,0.9f);
  408. std::set<cmStdString> notFoundMap;
  409. // after it is all done do a ConfigureFinalPass
  410. cmCacheManager* manager = 0;
  411. for (i = 0; i < m_LocalGenerators.size(); ++i)
  412. {
  413. manager = m_LocalGenerators[i]->GetMakefile()->GetCacheManager();
  414. m_LocalGenerators[i]->ConfigureFinalPass();
  415. cmTargets const& targets = m_LocalGenerators[i]->GetMakefile()->GetTargets();
  416. for (cmTargets::const_iterator l = targets.begin();
  417. l != targets.end(); l++)
  418. {
  419. cmTarget::LinkLibraries libs = l->second.GetLinkLibraries();
  420. for(cmTarget::LinkLibraries::iterator lib = libs.begin();
  421. lib != libs.end(); ++lib)
  422. {
  423. if(lib->first.size() > 9 &&
  424. cmSystemTools::IsNOTFOUND(lib->first.c_str()))
  425. {
  426. std::string varName = lib->first.substr(0, lib->first.size()-9);
  427. notFoundMap.insert(varName);
  428. }
  429. }
  430. std::vector<std::string>& incs =
  431. m_LocalGenerators[i]->GetMakefile()->GetIncludeDirectories();
  432. for( std::vector<std::string>::iterator lib = incs.begin();
  433. lib != incs.end(); ++lib)
  434. {
  435. if(lib->size() > 9 &&
  436. cmSystemTools::IsNOTFOUND(lib->c_str()))
  437. {
  438. std::string varName = lib->substr(0, lib->size()-9);
  439. notFoundMap.insert(varName);
  440. }
  441. }
  442. m_CMakeInstance->UpdateProgress("Configuring",
  443. 0.9f+0.1f*(i+1.0f)/m_LocalGenerators.size());
  444. m_LocalGenerators[i]->GetMakefile()->CheckInfiniteLoops();
  445. }
  446. }
  447. if(notFoundMap.size())
  448. {
  449. std::string notFoundVars;
  450. for(std::set<cmStdString>::iterator ii = notFoundMap.begin();
  451. ii != notFoundMap.end(); ++ii)
  452. {
  453. notFoundVars += *ii;
  454. if(manager)
  455. {
  456. cmCacheManager::CacheIterator it =
  457. manager->GetCacheIterator(ii->c_str());
  458. if(it.GetPropertyAsBool("ADVANCED"))
  459. {
  460. notFoundVars += " (ADVANCED)";
  461. }
  462. }
  463. notFoundVars += "\n";
  464. }
  465. cmSystemTools::Error("This project requires some variables to be set,\n"
  466. "and cmake can not find them.\n"
  467. "Please set the following variables:\n",
  468. notFoundVars.c_str());
  469. }
  470. if ( !m_CMakeInstance->GetScriptMode() )
  471. {
  472. m_CMakeInstance->UpdateProgress("Configuring done", -1);
  473. }
  474. }
  475. // loop through the directories creating cmLocalGenerators and Configure()
  476. void cmGlobalGenerator::RecursiveConfigure(cmLocalGenerator *lg,
  477. float startProgress,
  478. float endProgress)
  479. {
  480. // configure the current directory
  481. lg->Configure();
  482. // get all the subdirectories
  483. std::vector<std::pair<cmStdString, bool> > subdirs = lg->GetMakefile()->GetSubDirectories();
  484. float progressPiece = (endProgress - startProgress)/(1.0f+subdirs.size());
  485. m_CMakeInstance->UpdateProgress("Configuring",
  486. startProgress + progressPiece);
  487. // for each subdir recurse
  488. unsigned int i;
  489. for (i = 0; i < subdirs.size(); ++i)
  490. {
  491. cmLocalGenerator *lg2 = this->CreateLocalGenerator();
  492. lg2->SetParent(lg);
  493. m_LocalGenerators.push_back(lg2);
  494. // add the subdir to the start output directory
  495. std::string outdir = lg->GetMakefile()->GetStartOutputDirectory();
  496. outdir += "/";
  497. outdir += subdirs[i].first;
  498. lg2->GetMakefile()->SetStartOutputDirectory(outdir.c_str());
  499. lg2->SetExcludeAll(!subdirs[i].second);
  500. // add the subdir to the start source directory
  501. std::string currentDir = lg->GetMakefile()->GetStartDirectory();
  502. currentDir += "/";
  503. currentDir += subdirs[i].first;
  504. lg2->GetMakefile()->SetStartDirectory(currentDir.c_str());
  505. lg2->GetMakefile()->MakeStartDirectoriesCurrent();
  506. this->RecursiveConfigure(lg2,
  507. startProgress + (i+1.0f)*progressPiece,
  508. startProgress + (i+2.0f)*progressPiece);
  509. }
  510. }
  511. void cmGlobalGenerator::Generate()
  512. {
  513. // For each existing cmLocalGenerator
  514. unsigned int i;
  515. for (i = 0; i < m_LocalGenerators.size(); ++i)
  516. {
  517. m_LocalGenerators[i]->Generate(true);
  518. m_LocalGenerators[i]->GenerateInstallRules();
  519. m_CMakeInstance->UpdateProgress("Generating",
  520. (i+1.0f)/m_LocalGenerators.size());
  521. }
  522. m_CMakeInstance->UpdateProgress("Generating done", -1);
  523. }
  524. void cmGlobalGenerator::LocalGenerate()
  525. {
  526. // for this case we create one LocalGenerator
  527. // configure it, and then Generate it
  528. // start with this directory
  529. cmLocalGenerator *lg = this->CreateLocalGenerator();
  530. // set the Start directories
  531. lg->GetMakefile()->SetStartDirectory(m_CMakeInstance->GetStartDirectory());
  532. lg->GetMakefile()->SetStartOutputDirectory(m_CMakeInstance->GetStartOutputDirectory());
  533. lg->GetMakefile()->MakeStartDirectoriesCurrent();
  534. // now do trhe configure
  535. lg->Configure();
  536. lg->ConfigureFinalPass();
  537. lg->Generate(false);
  538. delete lg;
  539. }
  540. int cmGlobalGenerator::TryCompile(const char *, const char *bindir,
  541. const char *, const char *target,
  542. std::string *output, cmMakefile*)
  543. {
  544. // now build the test
  545. std::string makeCommand =
  546. m_CMakeInstance->GetCacheManager()->GetCacheValue("CMAKE_MAKE_PROGRAM");
  547. if(makeCommand.size() == 0)
  548. {
  549. cmSystemTools::Error(
  550. "Generator cannot find the appropriate make command.");
  551. return 1;
  552. }
  553. makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
  554. /**
  555. * Run an executable command and put the stdout in output.
  556. */
  557. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  558. cmSystemTools::ChangeDirectory(bindir);
  559. // Since we have full control over the invocation of nmake, let us
  560. // make it quiet.
  561. if ( strcmp(this->GetName(), "NMake Makefiles") == 0 )
  562. {
  563. makeCommand += " /NOLOGO ";
  564. }
  565. // now build
  566. if (target)
  567. {
  568. makeCommand += " ";
  569. makeCommand += target;
  570. #if defined(_WIN32) || defined(__CYGWIN__)
  571. std::string tmp = target;
  572. // if the target does not already end in . something
  573. // then assume .exe
  574. if(tmp.size() < 4 || tmp[tmp.size()-4] != '.')
  575. {
  576. makeCommand += ".exe";
  577. }
  578. #endif // WIN32
  579. }
  580. else
  581. {
  582. makeCommand += " all";
  583. }
  584. int retVal;
  585. int timeout = cmGlobalGenerator::s_TryCompileTimeout;
  586. bool hideconsole = cmSystemTools::GetRunCommandHideConsole();
  587. cmSystemTools::SetRunCommandHideConsole(true);
  588. if (!cmSystemTools::RunSingleCommand(makeCommand.c_str(), output,
  589. &retVal, 0, false, timeout))
  590. {
  591. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  592. cmSystemTools::Error("Generator: execution of make failed.");
  593. // return to the original directory
  594. cmSystemTools::ChangeDirectory(cwd.c_str());
  595. return 1;
  596. }
  597. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  598. // The SGI MipsPro 7.3 compiler does not return an error code when
  599. // the source has a #error in it! This is a work-around for such
  600. // compilers.
  601. if((retVal == 0) && (output->find("#error") != std::string::npos))
  602. {
  603. retVal = 1;
  604. }
  605. cmSystemTools::ChangeDirectory(cwd.c_str());
  606. return retVal;
  607. }
  608. cmLocalGenerator *cmGlobalGenerator::CreateLocalGenerator()
  609. {
  610. cmLocalGenerator *lg = new cmLocalGenerator;
  611. lg->SetGlobalGenerator(this);
  612. return lg;
  613. }
  614. void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator *gen )
  615. {
  616. this->SetConfiguredFilesPath(
  617. gen->GetCMakeInstance()->GetHomeOutputDirectory());
  618. const char* make =
  619. gen->GetCMakeInstance()->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
  620. this->GetCMakeInstance()->AddCacheEntry("CMAKE_MAKE_PROGRAM", make,
  621. "make program",
  622. cmCacheManager::FILEPATH);
  623. // copy the enabled languages
  624. this->m_LanguageEnabled = gen->m_LanguageEnabled;
  625. this->m_ExtensionToLanguage = gen->m_ExtensionToLanguage;
  626. this->m_IgnoreExtensions = gen->m_IgnoreExtensions;
  627. this->m_LanguageToOutputExtension = gen->m_LanguageToOutputExtension;
  628. this->m_LanguageToLinkerPreference = gen->m_LanguageToLinkerPreference;
  629. }
  630. //----------------------------------------------------------------------------
  631. void cmGlobalGenerator::GetDocumentation(cmDocumentationEntry& entry) const
  632. {
  633. entry.name = this->GetName();
  634. entry.brief = "";
  635. entry.full = "";
  636. }
  637. bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
  638. cmLocalGenerator* gen)
  639. {
  640. cmLocalGenerator* cur = gen->GetParent();
  641. while(cur && cur != root)
  642. {
  643. if(cur->GetExcludeAll())
  644. {
  645. return true;
  646. }
  647. cur = cur->GetParent();
  648. }
  649. return false;
  650. }
  651. void cmGlobalGenerator::GetEnabledLanguages(std::vector<std::string>& lang)
  652. {
  653. for(std::map<cmStdString, bool>::iterator i = m_LanguageEnabled.begin();
  654. i != m_LanguageEnabled.end(); ++i)
  655. {
  656. lang.push_back(i->first);
  657. }
  658. }
  659. const char* cmGlobalGenerator::GetLinkerPreference(const char* lang)
  660. {
  661. if(m_LanguageToLinkerPreference.count(lang))
  662. {
  663. return m_LanguageToLinkerPreference[lang].c_str();
  664. }
  665. return "None";
  666. }