cmGlobalGenerator.cxx 23 KB

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