cmake.cxx 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880
  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 "cmake.h"
  14. #include "time.h"
  15. #include "cmCacheManager.h"
  16. #include "cmMakefile.h"
  17. #include "cmLocalGenerator.h"
  18. #include "cmCommands.h"
  19. #include "cmCommand.h"
  20. #include "cmFileTimeComparison.h"
  21. #if defined(CMAKE_BUILD_WITH_CMAKE)
  22. # include "cmDependsFortran.h" // For -E cmake_copy_f90_mod callback.
  23. # include "cmVariableWatch.h"
  24. # include "cmVersion.h"
  25. #endif
  26. // only build kdevelop generator on non-windows platforms
  27. // when not bootstrapping cmake
  28. #if !defined(_WIN32)
  29. # if defined(CMAKE_BUILD_WITH_CMAKE)
  30. # define CMAKE_USE_KDEVELOP
  31. # endif
  32. #endif
  33. #if defined(__MINGW32__) && !defined(CMAKE_BUILD_WITH_CMAKE)
  34. # define CMAKE_BOOT_MINGW
  35. #endif
  36. // include the generator
  37. #if defined(_WIN32) && !defined(__CYGWIN__)
  38. # if !defined(CMAKE_BOOT_MINGW)
  39. # include "cmGlobalVisualStudio6Generator.h"
  40. # include "cmGlobalVisualStudio7Generator.h"
  41. # include "cmGlobalVisualStudio71Generator.h"
  42. # include "cmGlobalVisualStudio8Generator.h"
  43. # include "cmGlobalBorlandMakefileGenerator.h"
  44. # include "cmGlobalNMakeMakefileGenerator.h"
  45. # include "cmGlobalWatcomWMakeGenerator.h"
  46. # endif
  47. # include "cmGlobalMSYSMakefileGenerator.h"
  48. # include "cmGlobalMinGWMakefileGenerator.h"
  49. # include "cmWin32ProcessExecution.h"
  50. #else
  51. #endif
  52. #include "cmGlobalUnixMakefileGenerator3.h"
  53. #ifdef CMAKE_USE_KDEVELOP
  54. # include "cmGlobalKdevelopGenerator.h"
  55. #endif
  56. #include <stdlib.h> // required for atoi
  57. #ifdef __APPLE__
  58. # include "cmGlobalXCodeGenerator.h"
  59. # define CMAKE_USE_XCODE 1
  60. # include <sys/types.h>
  61. # include <sys/time.h>
  62. # include <sys/resource.h>
  63. #endif
  64. #include <sys/stat.h> // struct stat
  65. #include <memory> // auto_ptr
  66. void cmNeedBackwardsCompatibility(const std::string& variable,
  67. int access_type, void* )
  68. {
  69. #ifdef CMAKE_BUILD_WITH_CMAKE
  70. if (access_type == cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS)
  71. {
  72. std::string message = "An attempt was made to access a variable: ";
  73. message += variable;
  74. message += " that has not been defined. Some variables were always defined "
  75. "by CMake in versions prior to 1.6. To fix this you might need to set the "
  76. "cache value of CMAKE_BACKWARDS_COMPATIBILITY to 1.4 or less. If you are "
  77. "writing a CMakeList file, (or have already set "
  78. "CMAKE_BACKWARDS_COMPATABILITY to 1.4 or less) then you probably need to "
  79. "include a CMake module to test for the feature this variable defines.";
  80. cmSystemTools::Error(message.c_str());
  81. }
  82. #else
  83. (void)variable;
  84. (void)access_type;
  85. #endif
  86. }
  87. cmake::cmake()
  88. {
  89. m_DebugTryCompile = false;
  90. m_ClearBuildSystem = false;
  91. m_FileComparison = new cmFileTimeComparison;
  92. #ifdef __APPLE__
  93. struct rlimit rlp;
  94. if(!getrlimit(RLIMIT_STACK, &rlp))
  95. {
  96. if(rlp.rlim_cur != rlp.rlim_max)
  97. {
  98. rlp.rlim_cur = rlp.rlim_max;
  99. setrlimit(RLIMIT_STACK, &rlp);
  100. }
  101. }
  102. #endif
  103. // If MAKEFLAGS are given in the environment, remove the environment
  104. // variable. This will prevent try-compile from succeeding when it
  105. // should fail (if "-i" is an option). We cannot simply test
  106. // whether "-i" is given and remove it because some make programs
  107. // encode the MAKEFLAGS variable in a strange way.
  108. if(getenv("MAKEFLAGS"))
  109. {
  110. cmSystemTools::PutEnv("MAKEFLAGS=");
  111. }
  112. m_Verbose = false;
  113. m_InTryCompile = false;
  114. m_CacheManager = new cmCacheManager;
  115. m_GlobalGenerator = 0;
  116. m_ProgressCallback = 0;
  117. m_ProgressCallbackClientData = 0;
  118. m_ScriptMode = false;
  119. #ifdef CMAKE_BUILD_WITH_CMAKE
  120. m_VariableWatch = new cmVariableWatch;
  121. m_VariableWatch->AddWatch("CMAKE_WORDS_BIGENDIAN",
  122. cmNeedBackwardsCompatibility);
  123. m_VariableWatch->AddWatch("CMAKE_SIZEOF_INT",
  124. cmNeedBackwardsCompatibility);
  125. m_VariableWatch->AddWatch("CMAKE_X_LIBS",
  126. cmNeedBackwardsCompatibility);
  127. #endif
  128. this->AddDefaultGenerators();
  129. this->AddDefaultCommands();
  130. }
  131. cmake::~cmake()
  132. {
  133. delete m_CacheManager;
  134. if (m_GlobalGenerator)
  135. {
  136. delete m_GlobalGenerator;
  137. m_GlobalGenerator = 0;
  138. }
  139. for(RegisteredCommandsMap::iterator j = m_Commands.begin();
  140. j != m_Commands.end(); ++j)
  141. {
  142. delete (*j).second;
  143. }
  144. #ifdef CMAKE_BUILD_WITH_CMAKE
  145. delete m_VariableWatch;
  146. #endif
  147. delete m_FileComparison;
  148. }
  149. void cmake::CleanupCommandsAndMacros()
  150. {
  151. std::vector<cmCommand*> commands;
  152. for(RegisteredCommandsMap::iterator j = m_Commands.begin();
  153. j != m_Commands.end(); ++j)
  154. {
  155. if ( !j->second->IsA("cmMacroHelperCommand") )
  156. {
  157. commands.push_back(j->second);
  158. }
  159. else
  160. {
  161. delete j->second;
  162. }
  163. }
  164. m_Commands.erase(m_Commands.begin(), m_Commands.end());
  165. std::vector<cmCommand*>::iterator it;
  166. for ( it = commands.begin(); it != commands.end();
  167. ++ it )
  168. {
  169. m_Commands[cmSystemTools::LowerCase((*it)->GetName())] = *it;
  170. }
  171. }
  172. bool cmake::CommandExists(const char* name) const
  173. {
  174. std::string sName = cmSystemTools::LowerCase(name);
  175. return (m_Commands.find(sName) != m_Commands.end());
  176. }
  177. cmCommand *cmake::GetCommand(const char *name)
  178. {
  179. cmCommand* rm = 0;
  180. std::string sName = cmSystemTools::LowerCase(name);
  181. RegisteredCommandsMap::iterator pos = m_Commands.find(sName);
  182. if (pos != m_Commands.end())
  183. {
  184. rm = (*pos).second;
  185. }
  186. return rm;
  187. }
  188. void cmake::RenameCommand(const char*oldName, const char* newName)
  189. {
  190. // if the command already exists, free the old one
  191. std::string sOldName = cmSystemTools::LowerCase(oldName);
  192. std::string sNewName = cmSystemTools::LowerCase(newName);
  193. RegisteredCommandsMap::iterator pos = m_Commands.find(sOldName);
  194. if ( pos == m_Commands.end() )
  195. {
  196. return;
  197. }
  198. cmCommand* cmd = pos->second;
  199. pos = m_Commands.find(sNewName);
  200. if (pos != m_Commands.end())
  201. {
  202. delete pos->second;
  203. m_Commands.erase(pos);
  204. }
  205. m_Commands.insert(RegisteredCommandsMap::value_type(sNewName, cmd));
  206. pos = m_Commands.find(sOldName);
  207. m_Commands.erase(pos);
  208. }
  209. void cmake::AddCommand(cmCommand* wg)
  210. {
  211. std::string name = cmSystemTools::LowerCase(wg->GetName());
  212. // if the command already exists, free the old one
  213. RegisteredCommandsMap::iterator pos = m_Commands.find(name);
  214. if (pos != m_Commands.end())
  215. {
  216. delete pos->second;
  217. m_Commands.erase(pos);
  218. }
  219. m_Commands.insert( RegisteredCommandsMap::value_type(name, wg));
  220. }
  221. // Parse the args
  222. bool cmake::SetCacheArgs(const std::vector<std::string>& args)
  223. {
  224. for(unsigned int i=1; i < args.size(); ++i)
  225. {
  226. std::string arg = args[i];
  227. if(arg.find("-D",0) == 0)
  228. {
  229. std::string entry = arg.substr(2);
  230. if(entry.size() == 0)
  231. {
  232. entry = args[++i];
  233. }
  234. std::string var, value;
  235. cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED;
  236. if(cmCacheManager::ParseEntry(entry.c_str(), var, value, type) ||
  237. cmCacheManager::ParseEntry(entry.c_str(), var, value))
  238. {
  239. this->m_CacheManager->AddCacheEntry(var.c_str(), value.c_str(),
  240. "No help, variable specified on the command line.",
  241. type);
  242. }
  243. else
  244. {
  245. std::cerr << "Parse error in command line argument: " << arg << "\n"
  246. << "Should be: VAR:type=value\n";
  247. cmSystemTools::Error("No cmake scrpt provided.");
  248. return false;
  249. }
  250. }
  251. else if(arg.find("-C",0) == 0)
  252. {
  253. std::string path = arg.substr(2);
  254. if ( path.size() == 0 )
  255. {
  256. path = args[++i];
  257. }
  258. std::cerr << "loading initial cache file " << path.c_str() << "\n";
  259. this->ReadListFile(path.c_str());
  260. }
  261. else if(arg.find("-P",0) == 0)
  262. {
  263. i++;
  264. std::string path = args[i];
  265. if ( path.size() == 0 )
  266. {
  267. cmSystemTools::Error("No cmake script provided.");
  268. return false;
  269. }
  270. std::cerr << "Running cmake script file " << path.c_str() << "\n";
  271. this->ReadListFile(path.c_str());
  272. }
  273. }
  274. return true;
  275. }
  276. void cmake::ReadListFile(const char *path)
  277. {
  278. // if a generator was not yet created, temporarily create one
  279. cmGlobalGenerator *gg = this->GetGlobalGenerator();
  280. bool created = false;
  281. // if a generator was not specified use a generic one
  282. if (!gg)
  283. {
  284. gg = new cmGlobalGenerator;
  285. gg->SetCMakeInstance(this);
  286. created = true;
  287. }
  288. // read in the list file to fill the cache
  289. if(path)
  290. {
  291. std::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator());
  292. lg->SetGlobalGenerator(gg);
  293. lg->GetMakefile()->SetHomeOutputDirectory
  294. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  295. lg->GetMakefile()->SetStartOutputDirectory
  296. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  297. lg->GetMakefile()->SetHomeDirectory
  298. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  299. lg->GetMakefile()->SetStartDirectory
  300. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  301. if (!lg->GetMakefile()->ReadListFile(0, path))
  302. {
  303. std::cerr << "Error processing file:" << path << "\n";
  304. }
  305. }
  306. // free generic one if generated
  307. if (created)
  308. {
  309. delete gg;
  310. }
  311. }
  312. // Parse the args
  313. void cmake::SetArgs(const std::vector<std::string>& args)
  314. {
  315. bool directoriesSet = false;
  316. for(unsigned int i=1; i < args.size(); ++i)
  317. {
  318. std::string arg = args[i];
  319. if(arg.find("-H",0) == 0)
  320. {
  321. directoriesSet = true;
  322. std::string path = arg.substr(2);
  323. path = cmSystemTools::CollapseFullPath(path.c_str());
  324. cmSystemTools::ConvertToUnixSlashes(path);
  325. this->SetHomeDirectory(path.c_str());
  326. }
  327. else if(arg.find("-S",0) == 0)
  328. {
  329. // There is no local generate anymore. Ignore -S option.
  330. }
  331. else if(arg.find("-O",0) == 0)
  332. {
  333. // There is no local generate anymore. Ignore -O option.
  334. }
  335. else if(arg.find("-B",0) == 0)
  336. {
  337. directoriesSet = true;
  338. std::string path = arg.substr(2);
  339. path = cmSystemTools::CollapseFullPath(path.c_str());
  340. cmSystemTools::ConvertToUnixSlashes(path);
  341. this->SetHomeOutputDirectory(path.c_str());
  342. }
  343. else if((i < args.size()-1) && (arg.find("--check-build-system",0) == 0))
  344. {
  345. m_CheckBuildSystem = args[++i];
  346. m_ClearBuildSystem = (atoi(args[++i].c_str()) > 0);
  347. }
  348. else if(arg.find("-V",0) == 0)
  349. {
  350. m_Verbose = true;
  351. }
  352. else if(arg.find("-D",0) == 0)
  353. {
  354. // skip for now
  355. }
  356. else if(arg.find("-C",0) == 0)
  357. {
  358. // skip for now
  359. }
  360. else if(arg.find("-P",0) == 0)
  361. {
  362. // skip for now
  363. i++;
  364. }
  365. else if(arg.find("--debug-trycompile",0) == 0)
  366. {
  367. std::cout << "debug trycompile on\n";
  368. this->DebugTryCompileOn();
  369. }
  370. else if(arg.find("-G",0) == 0)
  371. {
  372. std::string value = arg.substr(2);
  373. if(value.size() == 0)
  374. {
  375. value = args[++i];
  376. }
  377. cmGlobalGenerator* gen =
  378. this->CreateGlobalGenerator(value.c_str());
  379. if(!gen)
  380. {
  381. cmSystemTools::Error("Could not create named generator ",
  382. value.c_str());
  383. }
  384. else
  385. {
  386. this->SetGlobalGenerator(gen);
  387. }
  388. }
  389. // no option assume it is the path to the source
  390. else
  391. {
  392. directoriesSet = true;
  393. this->SetDirectoriesFromFile(arg.c_str());
  394. }
  395. }
  396. if(!directoriesSet)
  397. {
  398. this->SetHomeOutputDirectory
  399. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  400. this->SetStartOutputDirectory
  401. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  402. this->SetHomeDirectory
  403. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  404. this->SetStartDirectory
  405. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  406. }
  407. this->SetStartDirectory(this->GetHomeDirectory());
  408. this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
  409. }
  410. //----------------------------------------------------------------------------
  411. void cmake::SetDirectoriesFromFile(const char* arg)
  412. {
  413. // Check if the argument refers to a CMakeCache.txt or
  414. // CMakeLists.txt file.
  415. std::string listPath;
  416. std::string cachePath;
  417. bool argIsFile = false;
  418. if(cmSystemTools::FileIsDirectory(arg))
  419. {
  420. std::string path = cmSystemTools::CollapseFullPath(arg);
  421. cmSystemTools::ConvertToUnixSlashes(path);
  422. std::string cacheFile = path;
  423. cacheFile += "/CMakeCache.txt";
  424. std::string listFile = path;
  425. listFile += "/CMakeLists.txt";
  426. if(cmSystemTools::FileExists(cacheFile.c_str()))
  427. {
  428. cachePath = path;
  429. }
  430. if(cmSystemTools::FileExists(listFile.c_str()))
  431. {
  432. listPath = path;
  433. }
  434. }
  435. else if(cmSystemTools::FileExists(arg))
  436. {
  437. argIsFile = true;
  438. std::string fullPath = cmSystemTools::CollapseFullPath(arg);
  439. std::string name = cmSystemTools::GetFilenameName(fullPath.c_str());
  440. name = cmSystemTools::LowerCase(name);
  441. if(name == "cmakecache.txt")
  442. {
  443. cachePath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  444. }
  445. else if(name == "cmakelists.txt")
  446. {
  447. listPath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  448. }
  449. }
  450. else
  451. {
  452. // Specified file or directory does not exist. Try to set things
  453. // up to produce a meaningful error message.
  454. std::string fullPath = cmSystemTools::CollapseFullPath(arg);
  455. std::string name = cmSystemTools::GetFilenameName(fullPath.c_str());
  456. name = cmSystemTools::LowerCase(name);
  457. if(name == "cmakecache.txt" || name == "cmakelists.txt")
  458. {
  459. argIsFile = true;
  460. listPath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  461. }
  462. else
  463. {
  464. listPath = fullPath;
  465. }
  466. }
  467. // If there is a CMakeCache.txt file, use its settings.
  468. if(cachePath.length() > 0)
  469. {
  470. cmCacheManager* cachem = this->GetCacheManager();
  471. cmCacheManager::CacheIterator it = cachem->NewIterator();
  472. if(cachem->LoadCache(cachePath.c_str()) && it.Find("CMAKE_HOME_DIRECTORY"))
  473. {
  474. this->SetHomeOutputDirectory(cachePath.c_str());
  475. this->SetStartOutputDirectory(cachePath.c_str());
  476. this->SetHomeDirectory(it.GetValue());
  477. this->SetStartDirectory(it.GetValue());
  478. return;
  479. }
  480. }
  481. // If there is a CMakeLists.txt file, use it as the source tree.
  482. if(listPath.length() > 0)
  483. {
  484. this->SetHomeDirectory(listPath.c_str());
  485. this->SetStartDirectory(listPath.c_str());
  486. if(argIsFile)
  487. {
  488. // Source CMakeLists.txt file given. It was probably dropped
  489. // onto the executable in a GUI. Default to an in-source build.
  490. this->SetHomeOutputDirectory(listPath.c_str());
  491. this->SetStartOutputDirectory(listPath.c_str());
  492. }
  493. else
  494. {
  495. // Source directory given on command line. Use current working
  496. // directory as build tree.
  497. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  498. this->SetHomeOutputDirectory(cwd.c_str());
  499. this->SetStartOutputDirectory(cwd.c_str());
  500. }
  501. return;
  502. }
  503. // We didn't find a CMakeLists.txt or CMakeCache.txt file from the
  504. // argument. Assume it is the path to the source tree, and use the
  505. // current working directory as the build tree.
  506. std::string full = cmSystemTools::CollapseFullPath(arg);
  507. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  508. this->SetHomeDirectory(full.c_str());
  509. this->SetStartDirectory(full.c_str());
  510. this->SetHomeOutputDirectory(cwd.c_str());
  511. this->SetStartOutputDirectory(cwd.c_str());
  512. }
  513. // at the end of this CMAKE_ROOT and CMAKE_COMMAND should be added to the cache
  514. int cmake::AddCMakePaths(const char *arg0)
  515. {
  516. // Find our own executable.
  517. std::vector<cmStdString> failures;
  518. std::string cMakeSelf = arg0;
  519. cmSystemTools::ConvertToUnixSlashes(cMakeSelf);
  520. failures.push_back(cMakeSelf);
  521. cMakeSelf = cmSystemTools::FindProgram(cMakeSelf.c_str());
  522. cmSystemTools::ConvertToUnixSlashes(cMakeSelf);
  523. if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
  524. {
  525. #ifdef CMAKE_BUILD_DIR
  526. std::string intdir = ".";
  527. #ifdef CMAKE_INTDIR
  528. intdir = CMAKE_INTDIR;
  529. #endif
  530. cMakeSelf = CMAKE_BUILD_DIR;
  531. cMakeSelf += "/bin/";
  532. cMakeSelf += intdir;
  533. cMakeSelf += "/cmake";
  534. cMakeSelf += cmSystemTools::GetExecutableExtension();
  535. #endif
  536. }
  537. #ifdef CMAKE_PREFIX
  538. if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
  539. {
  540. failures.push_back(cMakeSelf);
  541. cMakeSelf = CMAKE_PREFIX "/bin/cmake";
  542. }
  543. #endif
  544. if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
  545. {
  546. failures.push_back(cMakeSelf);
  547. cmOStringStream msg;
  548. msg << "CMAKE can not find the command line program cmake.\n";
  549. msg << " argv[0] = \"" << arg0 << "\"\n";
  550. msg << " Attempted paths:\n";
  551. std::vector<cmStdString>::iterator i;
  552. for(i=failures.begin(); i != failures.end(); ++i)
  553. {
  554. msg << " \"" << i->c_str() << "\"\n";
  555. }
  556. cmSystemTools::Error(msg.str().c_str());
  557. return 0;
  558. }
  559. // Save the value in the cache
  560. this->m_CacheManager->AddCacheEntry
  561. ("CMAKE_COMMAND",cMakeSelf.c_str(), "Path to CMake executable.",
  562. cmCacheManager::INTERNAL);
  563. // Find and save the command to edit the cache
  564. std::string editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  565. "/ccmake" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  566. if( !cmSystemTools::FileExists(editCacheCommand.c_str()))
  567. {
  568. editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  569. "/CMakeSetup" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  570. }
  571. std::string ctestCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  572. "/ctest" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  573. if(cmSystemTools::FileExists(ctestCommand.c_str()))
  574. {
  575. this->m_CacheManager->AddCacheEntry
  576. ("CMAKE_CTEST_COMMAND", ctestCommand.c_str(),
  577. "Path to ctest program executable.", cmCacheManager::INTERNAL);
  578. }
  579. if(cmSystemTools::FileExists(editCacheCommand.c_str()))
  580. {
  581. this->m_CacheManager->AddCacheEntry
  582. ("CMAKE_EDIT_COMMAND", editCacheCommand.c_str(),
  583. "Path to cache edit program executable.", cmCacheManager::INTERNAL);
  584. }
  585. // do CMAKE_ROOT, look for the environment variable first
  586. std::string cMakeRoot;
  587. std::string modules;
  588. if (getenv("CMAKE_ROOT"))
  589. {
  590. cMakeRoot = getenv("CMAKE_ROOT");
  591. modules = cMakeRoot + "/Modules/CMake.cmake";
  592. }
  593. if(!cmSystemTools::FileExists(modules.c_str()))
  594. {
  595. // next try exe/..
  596. cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
  597. std::string::size_type slashPos = cMakeRoot.rfind("/");
  598. if(slashPos != std::string::npos)
  599. {
  600. cMakeRoot = cMakeRoot.substr(0, slashPos);
  601. }
  602. // is there no Modules direcory there?
  603. modules = cMakeRoot + "/Modules/CMake.cmake";
  604. }
  605. if (!cmSystemTools::FileExists(modules.c_str()))
  606. {
  607. // try exe/../share/cmake
  608. cMakeRoot += CMAKE_DATA_DIR;
  609. modules = cMakeRoot + "/Modules/CMake.cmake";
  610. }
  611. #ifdef CMAKE_ROOT_DIR
  612. if (!cmSystemTools::FileExists(modules.c_str()))
  613. {
  614. // try compiled in root directory
  615. cMakeRoot = CMAKE_ROOT_DIR;
  616. modules = cMakeRoot + "/Modules/CMake.cmake";
  617. }
  618. #endif
  619. #ifdef CMAKE_PREFIX
  620. if (!cmSystemTools::FileExists(modules.c_str()))
  621. {
  622. // try compiled in install prefix
  623. cMakeRoot = CMAKE_PREFIX CMAKE_DATA_DIR;
  624. modules = cMakeRoot + "/Modules/CMake.cmake";
  625. }
  626. #endif
  627. if (!cmSystemTools::FileExists(modules.c_str()))
  628. {
  629. // try
  630. cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
  631. cMakeRoot += CMAKE_DATA_DIR;
  632. modules = cMakeRoot + "/Modules/CMake.cmake";
  633. }
  634. if(!cmSystemTools::FileExists(modules.c_str()))
  635. {
  636. // next try exe
  637. cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
  638. // is there no Modules direcory there?
  639. modules = cMakeRoot + "/Modules/CMake.cmake";
  640. }
  641. if (!cmSystemTools::FileExists(modules.c_str()))
  642. {
  643. // couldn't find modules
  644. cmSystemTools::Error("Could not find CMAKE_ROOT !!!\n"
  645. "CMake has most likely not been installed correctly.\n"
  646. "Modules directory not found in\n",
  647. cMakeRoot.c_str());
  648. return 0;
  649. }
  650. this->m_CacheManager->AddCacheEntry
  651. ("CMAKE_ROOT", cMakeRoot.c_str(),
  652. "Path to CMake installation.", cmCacheManager::INTERNAL);
  653. #ifdef _WIN32
  654. std::string comspec = "cmw9xcom.exe";
  655. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  656. #endif
  657. return 1;
  658. }
  659. void CMakeCommandUsage(const char* program)
  660. {
  661. cmOStringStream errorStream;
  662. #ifdef CMAKE_BUILD_WITH_CMAKE
  663. errorStream
  664. << "cmake version " << cmVersion::GetCMakeVersion() << "\n";
  665. #else
  666. errorStream
  667. << "cmake bootstrap\n";
  668. #endif
  669. errorStream
  670. << "Usage: " << program << " -E [command] [arguments ...]\n"
  671. << "Available commands: \n"
  672. << " chdir dir cmd [args]... - run command in a given directory\n"
  673. << " copy file destination - copy file to destination (either file or directory)\n"
  674. << " copy_if_different in-file out-file - copy file if input has changed\n"
  675. << " copy_directory source destination - copy directory 'source' content to directory 'destination'\n"
  676. << " compare_files file1 file2 - check if file1 is same as file2\n"
  677. << " echo [string]... - displays arguments as text\n"
  678. << " remove file1 file2 ... - remove the file(s)\n"
  679. << " tar [cxt][vfz] file.tar file/dir1 file/dir2 ... - create a tar.\n"
  680. << " time command [args] ... - run command and return elapsed time\n";
  681. #if defined(_WIN32) && !defined(__CYGWIN__)
  682. errorStream
  683. << " write_regv key value - write registry value\n"
  684. << " delete_regv key - delete registry value\n"
  685. << " comspec - on windows 9x use this for RunCommand\n";
  686. #else
  687. errorStream
  688. << " create_symlink old new - create a symbolic link new -> old\n";
  689. #endif
  690. cmSystemTools::Error(errorStream.str().c_str());
  691. }
  692. int cmake::CMakeCommand(std::vector<std::string>& args)
  693. {
  694. if (args.size() > 1)
  695. {
  696. // Copy file
  697. if (args[1] == "copy" && args.size() == 4)
  698. {
  699. if(!cmSystemTools::cmCopyFile(args[2].c_str(), args[3].c_str()))
  700. {
  701. std::cerr << "Error copying file \"" << args[2].c_str()
  702. << "\" to \"" << args[3].c_str() << "\".\n";
  703. return 1;
  704. }
  705. return 0;
  706. }
  707. // Copy file if different.
  708. if (args[1] == "copy_if_different" && args.size() == 4)
  709. {
  710. if(!cmSystemTools::CopyFileIfDifferent(args[2].c_str(), args[3].c_str()))
  711. {
  712. std::cerr << "Error copying file (if different) from \""
  713. << args[2].c_str() << "\" to \"" << args[3].c_str()
  714. << "\".\n";
  715. return 1;
  716. }
  717. return 0;
  718. }
  719. // Copy directory content
  720. if (args[1] == "copy_directory" && args.size() == 4)
  721. {
  722. if(!cmSystemTools::CopyADirectory(args[2].c_str(), args[3].c_str()))
  723. {
  724. std::cerr << "Error copying directory from \""
  725. << args[2].c_str() << "\" to \"" << args[3].c_str()
  726. << "\".\n";
  727. return 1;
  728. }
  729. return 0;
  730. }
  731. // Compare files
  732. if (args[1] == "compare_files" && args.size() == 4)
  733. {
  734. if(cmSystemTools::FilesDiffer(args[2].c_str(), args[3].c_str()))
  735. {
  736. std::cerr << "Files \""
  737. << args[2].c_str() << "\" to \"" << args[3].c_str()
  738. << "\" are different.\n";
  739. return 1;
  740. }
  741. return 0;
  742. }
  743. // Echo string
  744. else if (args[1] == "echo" )
  745. {
  746. unsigned int cc;
  747. const char* space = "";
  748. for ( cc = 2; cc < args.size(); cc ++ )
  749. {
  750. std::cout << space << args[cc];
  751. space = " ";
  752. }
  753. std::cout << std::endl;
  754. return 0;
  755. }
  756. // Remove file
  757. else if (args[1] == "remove" && args.size() > 2)
  758. {
  759. for (std::string::size_type cc = 2; cc < args.size(); cc ++)
  760. {
  761. if(args[cc] != "-f")
  762. {
  763. if(args[cc] == "\\-f")
  764. {
  765. args[cc] = "-f";
  766. }
  767. cmSystemTools::RemoveFile(args[cc].c_str());
  768. }
  769. }
  770. return 0;
  771. }
  772. // Clock command
  773. else if (args[1] == "time" && args.size() > 2)
  774. {
  775. std::string command = args[2];
  776. for (std::string::size_type cc = 3; cc < args.size(); cc ++)
  777. {
  778. command += " ";
  779. command += args[cc];
  780. }
  781. clock_t clock_start, clock_finish;
  782. time_t time_start, time_finish;
  783. time(&time_start);
  784. clock_start = clock();
  785. cmSystemTools::RunSingleCommand(command.c_str());
  786. clock_finish = clock();
  787. time(&time_finish);
  788. double clocks_per_sec = (double)CLOCKS_PER_SEC;
  789. std::cout << "Elapsed time: "
  790. << (long)(time_finish - time_start) << " s. (time)"
  791. << ", "
  792. << (double)(clock_finish - clock_start) / clocks_per_sec
  793. << " s. (clock)"
  794. << "\n";
  795. return 0;
  796. }
  797. // Command to change directory and run a program.
  798. else if (args[1] == "chdir" && args.size() >= 4)
  799. {
  800. std::string directory = args[2];
  801. if(!cmSystemTools::FileExists(directory.c_str()))
  802. {
  803. cmSystemTools::Error("Directory does not exist for chdir command: ",
  804. args[2].c_str());
  805. return 0;
  806. }
  807. std::string command = "\"";
  808. command += args[3];
  809. command += "\"";
  810. for (std::string::size_type cc = 4; cc < args.size(); cc ++)
  811. {
  812. command += " \"";
  813. command += args[cc];
  814. command += "\"";
  815. }
  816. int retval = 0;
  817. int timeout = 0;
  818. if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, &retval,
  819. directory.c_str(), true, timeout) )
  820. {
  821. return retval;
  822. }
  823. return 1;
  824. }
  825. // Command to create a symbolic link. Fails on platforms not
  826. // supporting them.
  827. else if (args[1] == "create_symlink" && args.size() == 4)
  828. {
  829. return cmSystemTools::CreateSymlink(args[2].c_str(),
  830. args[3].c_str())? 0:1;
  831. }
  832. // Internal CMake shared library support.
  833. else if (args[1] == "cmake_symlink_library" && args.size() == 5)
  834. {
  835. int result = 0;
  836. std::string realName = args[2];
  837. std::string soName = args[3];
  838. std::string name = args[4];
  839. if(soName != realName)
  840. {
  841. std::string fname = cmSystemTools::GetFilenameName(realName);
  842. if(cmSystemTools::FileExists(soName.c_str()))
  843. {
  844. cmSystemTools::RemoveFile(soName.c_str());
  845. }
  846. if(!cmSystemTools::CreateSymlink(fname.c_str(), soName.c_str()))
  847. {
  848. result = 1;
  849. }
  850. }
  851. if(name != soName)
  852. {
  853. std::string fname = cmSystemTools::GetFilenameName(soName);
  854. if(cmSystemTools::FileExists(soName.c_str()))
  855. {
  856. cmSystemTools::RemoveFile(name.c_str());
  857. }
  858. if(!cmSystemTools::CreateSymlink(fname.c_str(), name.c_str()))
  859. {
  860. result = 1;
  861. }
  862. }
  863. return result;
  864. }
  865. // Internal CMake versioned executable support.
  866. else if (args[1] == "cmake_symlink_executable" && args.size() == 4)
  867. {
  868. int result = 0;
  869. std::string realName = args[2];
  870. std::string name = args[3];
  871. if(name != realName)
  872. {
  873. std::string fname = cmSystemTools::GetFilenameName(realName);
  874. if(cmSystemTools::FileExists(realName.c_str()))
  875. {
  876. cmSystemTools::RemoveFile(name.c_str());
  877. }
  878. if(!cmSystemTools::CreateSymlink(fname.c_str(), name.c_str()))
  879. {
  880. result = 1;
  881. }
  882. }
  883. return result;
  884. }
  885. // Internal CMake dependency scanning support.
  886. else if (args[1] == "cmake_depends" && args.size() >= 6)
  887. {
  888. cmake cm;
  889. cmGlobalGenerator *ggd = cm.CreateGlobalGenerator(args[2].c_str());
  890. if (ggd)
  891. {
  892. ggd->SetCMakeInstance(&cm);
  893. std::auto_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator());
  894. lgd->SetGlobalGenerator(ggd);
  895. return lgd->ScanDependencies(args)? 0 : 2;
  896. }
  897. return 1;
  898. }
  899. // Tar files
  900. else if (args[1] == "tar" && args.size() > 3)
  901. {
  902. std::string flags = args[2];
  903. std::string outFile = args[3];
  904. std::vector<cmStdString> files;
  905. for (std::string::size_type cc = 4; cc < args.size(); cc ++)
  906. {
  907. files.push_back(args[cc]);
  908. }
  909. bool gzip = false;
  910. bool verbose = false;
  911. if ( flags.find_first_of('z') != flags.npos )
  912. {
  913. gzip = true;
  914. }
  915. if ( flags.find_first_of('v') != flags.npos )
  916. {
  917. verbose = true;
  918. }
  919. if ( flags.find_first_of('t') != flags.npos )
  920. {
  921. if ( !cmSystemTools::ListTar(outFile.c_str(), files, gzip, verbose) )
  922. {
  923. cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
  924. return 1;
  925. }
  926. }
  927. else if ( flags.find_first_of('c') != flags.npos )
  928. {
  929. if ( !cmSystemTools::CreateTar(outFile.c_str(), files, gzip, verbose) )
  930. {
  931. cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
  932. return 1;
  933. }
  934. }
  935. else if ( flags.find_first_of('x') != flags.npos )
  936. {
  937. if ( !cmSystemTools::ExtractTar(outFile.c_str(), files, gzip, verbose) )
  938. {
  939. cmSystemTools::Error("Problem extracting tar: ", outFile.c_str());
  940. return 1;
  941. }
  942. }
  943. return 0;
  944. }
  945. #if defined(CMAKE_BUILD_WITH_CMAKE)
  946. // Internal CMake Fortran module support.
  947. else if (args[1] == "cmake_copy_f90_mod" && args.size() >= 4)
  948. {
  949. return cmDependsFortran::CopyModule(args)? 0 : 1;
  950. }
  951. #endif
  952. #if defined(_WIN32) && !defined(__CYGWIN__)
  953. // Write registry value
  954. else if (args[1] == "write_regv" && args.size() > 3)
  955. {
  956. return cmSystemTools::WriteRegistryValue(args[2].c_str(),
  957. args[3].c_str()) ? 0 : 1;
  958. }
  959. // Delete registry value
  960. else if (args[1] == "delete_regv" && args.size() > 2)
  961. {
  962. return cmSystemTools::DeleteRegistryValue(args[2].c_str()) ? 0 : 1;
  963. }
  964. // Remove file
  965. else if (args[1] == "comspec" && args.size() > 2)
  966. {
  967. unsigned int cc;
  968. std::string command = args[2];
  969. for ( cc = 3; cc < args.size(); cc ++ )
  970. {
  971. command += " " + args[cc];
  972. }
  973. return cmWin32ProcessExecution::Windows9xHack(command.c_str());
  974. }
  975. #endif
  976. }
  977. ::CMakeCommandUsage(args[0].c_str());
  978. return 1;
  979. }
  980. void cmake::GetRegisteredGenerators(std::vector<std::string>& names)
  981. {
  982. for(RegisteredGeneratorsMap::const_iterator i = m_Generators.begin();
  983. i != m_Generators.end(); ++i)
  984. {
  985. names.push_back(i->first);
  986. }
  987. }
  988. cmGlobalGenerator* cmake::CreateGlobalGenerator(const char* name)
  989. {
  990. RegisteredGeneratorsMap::const_iterator i = m_Generators.find(name);
  991. if(i != m_Generators.end())
  992. {
  993. cmGlobalGenerator* generator = (i->second)();
  994. generator->SetCMakeInstance(this);
  995. return generator;
  996. }
  997. else
  998. {
  999. return 0;
  1000. }
  1001. }
  1002. void cmake::SetHomeDirectory(const char* dir)
  1003. {
  1004. m_cmHomeDirectory = dir;
  1005. cmSystemTools::ConvertToUnixSlashes(m_cmHomeDirectory);
  1006. }
  1007. void cmake::SetHomeOutputDirectory(const char* lib)
  1008. {
  1009. m_HomeOutputDirectory = lib;
  1010. cmSystemTools::ConvertToUnixSlashes(m_HomeOutputDirectory);
  1011. }
  1012. void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
  1013. {
  1014. // delete the old generator
  1015. if (m_GlobalGenerator)
  1016. {
  1017. delete m_GlobalGenerator;
  1018. // restore the original environment variables CXX and CC
  1019. // Restor CC
  1020. std::string env = "CC=";
  1021. if(m_CCEnvironment.size())
  1022. {
  1023. env += m_CCEnvironment;
  1024. }
  1025. cmSystemTools::PutEnv(env.c_str());
  1026. env = "CXX=";
  1027. if(m_CXXEnvironment.size())
  1028. {
  1029. env += m_CXXEnvironment;
  1030. }
  1031. cmSystemTools::PutEnv(env.c_str());
  1032. }
  1033. // set the new
  1034. m_GlobalGenerator = gg;
  1035. // set the global flag for unix style paths on cmSystemTools as
  1036. // soon as the generator is set. This allows gmake to be used
  1037. // on windows.
  1038. cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
  1039. // Save the environment variables CXX and CC
  1040. const char* cxx = getenv("CXX");
  1041. const char* cc = getenv("CC");
  1042. if(cxx)
  1043. {
  1044. m_CXXEnvironment = cxx;
  1045. }
  1046. else
  1047. {
  1048. m_CXXEnvironment = "";
  1049. }
  1050. if(cc)
  1051. {
  1052. m_CCEnvironment = cc;
  1053. }
  1054. else
  1055. {
  1056. m_CCEnvironment = "";
  1057. }
  1058. // set the cmake instance just to be sure
  1059. gg->SetCMakeInstance(this);
  1060. }
  1061. int cmake::DoPreConfigureChecks()
  1062. {
  1063. // Make sure the Start directory contains a CMakeLists.txt file.
  1064. std::string srcList = this->GetHomeDirectory();
  1065. srcList += "/CMakeLists.txt";
  1066. if(!cmSystemTools::FileExists(srcList.c_str()))
  1067. {
  1068. cmOStringStream err;
  1069. if(cmSystemTools::FileIsDirectory(this->GetHomeDirectory()))
  1070. {
  1071. err << "The source directory \"" << this->GetHomeDirectory()
  1072. << "\" does not appear to contain CMakeLists.txt.\n";
  1073. }
  1074. else if(cmSystemTools::FileExists(this->GetHomeDirectory()))
  1075. {
  1076. err << "The source directory \"" << this->GetHomeDirectory()
  1077. << "\" is a file, not a directory.\n";
  1078. }
  1079. else
  1080. {
  1081. err << "The source directory \"" << this->GetHomeDirectory()
  1082. << "\" does not exist.\n";
  1083. }
  1084. err << "Specify --help for usage, or press the help button on the CMake GUI.";
  1085. cmSystemTools::Error(err.str().c_str());
  1086. return -2;
  1087. }
  1088. // do a sanity check on some values
  1089. if(m_CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY"))
  1090. {
  1091. std::string cacheStart =
  1092. m_CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY");
  1093. cacheStart += "/CMakeLists.txt";
  1094. std::string currentStart = this->GetHomeDirectory();
  1095. currentStart += "/CMakeLists.txt";
  1096. if(!cmSystemTools::SameFile(cacheStart.c_str(), currentStart.c_str()))
  1097. {
  1098. std::string message = "The source \"";
  1099. message += currentStart;
  1100. message += "\" does not match the source \"";
  1101. message += cacheStart;
  1102. message += "\" used to generate cache. ";
  1103. message += "Re-run cmake with a different source directory.";
  1104. cmSystemTools::Error(message.c_str());
  1105. return -2;
  1106. }
  1107. }
  1108. else
  1109. {
  1110. return 0;
  1111. }
  1112. return 1;
  1113. }
  1114. int cmake::Configure()
  1115. {
  1116. // Construct right now our path conversion table before it's too late:
  1117. this->UpdateConversionPathTable();
  1118. this->CleanupCommandsAndMacros();
  1119. int res = 0;
  1120. if ( !m_ScriptMode )
  1121. {
  1122. res = this->DoPreConfigureChecks();
  1123. }
  1124. if ( res < 0 )
  1125. {
  1126. return -2;
  1127. }
  1128. if ( !res )
  1129. {
  1130. m_CacheManager->AddCacheEntry("CMAKE_HOME_DIRECTORY",
  1131. this->GetHomeDirectory(),
  1132. "Start directory with the top level CMakeLists.txt file for this project",
  1133. cmCacheManager::INTERNAL);
  1134. }
  1135. // set the default BACKWARDS compatibility to the current version
  1136. if(!m_CacheManager->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
  1137. {
  1138. char ver[256];
  1139. sprintf(ver,"%i.%i",cmMakefile::GetMajorVersion(),
  1140. cmMakefile::GetMinorVersion());
  1141. this->m_CacheManager->AddCacheEntry
  1142. ("CMAKE_BACKWARDS_COMPATIBILITY",ver,
  1143. "For backwards compatibility, what version of CMake commands and syntax should this version of CMake allow.",
  1144. cmCacheManager::STRING);
  1145. }
  1146. // no generator specified on the command line
  1147. if(!m_GlobalGenerator)
  1148. {
  1149. const char* genName = m_CacheManager->GetCacheValue("CMAKE_GENERATOR");
  1150. if(genName)
  1151. {
  1152. m_GlobalGenerator = this->CreateGlobalGenerator(genName);
  1153. }
  1154. if(m_GlobalGenerator)
  1155. {
  1156. // set the global flag for unix style paths on cmSystemTools as
  1157. // soon as the generator is set. This allows gmake to be used
  1158. // on windows.
  1159. cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
  1160. }
  1161. else
  1162. {
  1163. #if defined(__BORLANDC__) && defined(_WIN32)
  1164. this->SetGlobalGenerator(new cmGlobalBorlandMakefileGenerator);
  1165. #elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
  1166. std::string installedCompiler;
  1167. std::string mp = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\Setup;Dbghelp_path]";
  1168. cmSystemTools::ExpandRegistryValues(mp);
  1169. if (!(mp == "/registry"))
  1170. {
  1171. installedCompiler = "Visual Studio 8 2005";
  1172. }
  1173. else
  1174. {
  1175. mp = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\7.1;InstallDir]";
  1176. cmSystemTools::ExpandRegistryValues(mp);
  1177. if (!(mp == "/registry"))
  1178. {
  1179. installedCompiler = "Visual Studio 7 .NET 2003";
  1180. }
  1181. else
  1182. {
  1183. mp = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\7.0;InstallDir]";
  1184. cmSystemTools::ExpandRegistryValues(mp);
  1185. if (!(mp == "/registry"))
  1186. {
  1187. installedCompiler = "Visual Studio 7";
  1188. }
  1189. else
  1190. {
  1191. installedCompiler = "Visual Studio 6";
  1192. }
  1193. }
  1194. }
  1195. cmGlobalGenerator* gen = this->CreateGlobalGenerator(installedCompiler.c_str());
  1196. if(!gen)
  1197. {
  1198. gen = new cmGlobalNMakeMakefileGenerator;
  1199. }
  1200. this->SetGlobalGenerator(gen);
  1201. #else
  1202. this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator3);
  1203. #endif
  1204. }
  1205. if(!m_GlobalGenerator)
  1206. {
  1207. cmSystemTools::Error("Could not create generator");
  1208. return -1;
  1209. }
  1210. }
  1211. const char* genName = m_CacheManager->GetCacheValue("CMAKE_GENERATOR");
  1212. if(genName)
  1213. {
  1214. if(strcmp(m_GlobalGenerator->GetName(), genName) != 0)
  1215. {
  1216. std::string message = "Error: generator : ";
  1217. message += m_GlobalGenerator->GetName();
  1218. message += "\nDoes not match the generator used previously: ";
  1219. message += genName;
  1220. message +=
  1221. "\nEither remove the CMakeCache.txt file or choose a different"
  1222. " binary directory.";
  1223. cmSystemTools::Error(message.c_str());
  1224. return -2;
  1225. }
  1226. }
  1227. if(!m_CacheManager->GetCacheValue("CMAKE_GENERATOR"))
  1228. {
  1229. m_CacheManager->AddCacheEntry("CMAKE_GENERATOR", m_GlobalGenerator->GetName(),
  1230. "Name of generator.",
  1231. cmCacheManager::INTERNAL);
  1232. }
  1233. // reset any system configuration information, except for when we are
  1234. // InTryCompile. With TryCompile the system info is taken from the parent's
  1235. // info to save time
  1236. if (!m_InTryCompile)
  1237. {
  1238. m_GlobalGenerator->ClearEnabledLanguages();
  1239. }
  1240. this->CleanupWrittenFiles();
  1241. // Truncate log files
  1242. if (!m_InTryCompile)
  1243. {
  1244. this->TruncateOutputLog("CMakeOutput.log");
  1245. this->TruncateOutputLog("CMakeError.log");
  1246. }
  1247. // actually do the configure
  1248. m_GlobalGenerator->Configure();
  1249. // Before saving the cache
  1250. // if the project did not define one of the entries below, add them now
  1251. // so users can edit the values in the cache:
  1252. // LIBRARY_OUTPUT_PATH
  1253. // EXECUTABLE_OUTPUT_PATH
  1254. if(!m_CacheManager->GetCacheValue("LIBRARY_OUTPUT_PATH"))
  1255. {
  1256. m_CacheManager->AddCacheEntry("LIBRARY_OUTPUT_PATH", "",
  1257. "Single output directory for building all libraries.",
  1258. cmCacheManager::PATH);
  1259. }
  1260. if(!m_CacheManager->GetCacheValue("EXECUTABLE_OUTPUT_PATH"))
  1261. {
  1262. m_CacheManager->AddCacheEntry("EXECUTABLE_OUTPUT_PATH", "",
  1263. "Single output directory for building all executables.",
  1264. cmCacheManager::PATH);
  1265. }
  1266. if(!m_CacheManager->GetCacheValue("CMAKE_USE_RELATIVE_PATHS"))
  1267. {
  1268. m_CacheManager->AddCacheEntry("CMAKE_USE_RELATIVE_PATHS", false,
  1269. "If true, cmake will use relative paths in makefiles and projects.");
  1270. cmCacheManager::CacheIterator it =
  1271. m_CacheManager->GetCacheIterator("CMAKE_USE_RELATIVE_PATHS");
  1272. if ( !it.PropertyExists("ADVANCED") )
  1273. {
  1274. it.SetProperty("ADVANCED", "1");
  1275. }
  1276. }
  1277. if(cmSystemTools::GetFatalErrorOccured() &&
  1278. (!this->m_CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM") ||
  1279. cmSystemTools::IsOff(this->m_CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM"))))
  1280. {
  1281. // We must have a bad generator selection. Wipe the cache entry so the
  1282. // user can select another.
  1283. m_CacheManager->RemoveCacheEntry("CMAKE_GENERATOR");
  1284. }
  1285. // only save the cache if there were no fatal errors
  1286. if ( !m_ScriptMode && !cmSystemTools::GetFatalErrorOccured() )
  1287. {
  1288. this->m_CacheManager->SaveCache(this->GetHomeOutputDirectory());
  1289. }
  1290. if(cmSystemTools::GetErrorOccuredFlag())
  1291. {
  1292. return -1;
  1293. }
  1294. return 0;
  1295. }
  1296. bool cmake::CacheVersionMatches()
  1297. {
  1298. const char* majv = m_CacheManager->GetCacheValue("CMAKE_CACHE_MAJOR_VERSION");
  1299. const char* minv = m_CacheManager->GetCacheValue("CMAKE_CACHE_MINOR_VERSION");
  1300. const char* relv = m_CacheManager->GetCacheValue("CMAKE_CACHE_RELEASE_VERSION");
  1301. bool cacheSameCMake = false;
  1302. if(majv &&
  1303. atoi(majv) == static_cast<int>(cmMakefile::GetMajorVersion())
  1304. && minv &&
  1305. atoi(minv) == static_cast<int>(cmMakefile::GetMinorVersion())
  1306. && relv && (strcmp(relv, cmMakefile::GetReleaseVersion()) == 0))
  1307. {
  1308. cacheSameCMake = true;
  1309. }
  1310. return cacheSameCMake;
  1311. }
  1312. void cmake::PreLoadCMakeFiles()
  1313. {
  1314. std::string pre_load = this->GetHomeDirectory();
  1315. if ( pre_load.size() > 0 )
  1316. {
  1317. pre_load += "/PreLoad.cmake";
  1318. if ( cmSystemTools::FileExists(pre_load.c_str()) )
  1319. {
  1320. this->ReadListFile(pre_load.c_str());
  1321. }
  1322. }
  1323. pre_load = this->GetHomeOutputDirectory();
  1324. if ( pre_load.size() > 0 )
  1325. {
  1326. pre_load += "/PreLoad.cmake";
  1327. if ( cmSystemTools::FileExists(pre_load.c_str()) )
  1328. {
  1329. this->ReadListFile(pre_load.c_str());
  1330. }
  1331. }
  1332. }
  1333. // handle a command line invocation
  1334. int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
  1335. {
  1336. // Process the arguments
  1337. this->SetArgs(args);
  1338. if(cmSystemTools::GetErrorOccuredFlag())
  1339. {
  1340. CMakeCommandUsage(args[0].c_str());
  1341. return -1;
  1342. }
  1343. // set the cmake command
  1344. m_CMakeCommand = args[0];
  1345. if ( !m_ScriptMode )
  1346. {
  1347. // load the cache
  1348. if(this->LoadCache() < 0)
  1349. {
  1350. cmSystemTools::Error("Error executing cmake::LoadCache(). Aborting.\n");
  1351. return -1;
  1352. }
  1353. }
  1354. // Add any cache args
  1355. if ( !this->SetCacheArgs(args) )
  1356. {
  1357. cmSystemTools::Error("Problem processing arguments. Aborting.\n");
  1358. return -1;
  1359. }
  1360. // In script mode we terminate after running the script.
  1361. if(m_ScriptMode)
  1362. {
  1363. if(cmSystemTools::GetErrorOccuredFlag())
  1364. {
  1365. return -1;
  1366. }
  1367. else
  1368. {
  1369. return 0;
  1370. }
  1371. }
  1372. this->PreLoadCMakeFiles();
  1373. std::string systemFile = this->GetHomeOutputDirectory();
  1374. systemFile += "/CMakeSystem.cmake";
  1375. if ( noconfigure )
  1376. {
  1377. return 0;
  1378. }
  1379. // now run the global generate
  1380. // Check the state of the build system to see if we need to regenerate.
  1381. if(!this->CheckBuildSystem())
  1382. {
  1383. return 0;
  1384. }
  1385. // If we are doing global generate, we better set start and start
  1386. // output directory to the root of the project.
  1387. std::string oldstartdir = this->GetStartDirectory();
  1388. std::string oldstartoutputdir = this->GetStartOutputDirectory();
  1389. this->SetStartDirectory(this->GetHomeDirectory());
  1390. this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
  1391. int ret = this->Configure();
  1392. if (ret || m_ScriptMode)
  1393. {
  1394. return ret;
  1395. }
  1396. ret = this->Generate();
  1397. std::string message = "Build files have been written to: ";
  1398. message += this->GetHomeOutputDirectory();
  1399. this->UpdateProgress(message.c_str(), -1);
  1400. if(ret)
  1401. {
  1402. return ret;
  1403. }
  1404. this->SetStartDirectory(oldstartdir.c_str());
  1405. this->SetStartOutputDirectory(oldstartoutputdir.c_str());
  1406. return ret;
  1407. }
  1408. int cmake::Generate()
  1409. {
  1410. if(!m_GlobalGenerator)
  1411. {
  1412. return -1;
  1413. }
  1414. m_GlobalGenerator->Generate();
  1415. if(cmSystemTools::GetErrorOccuredFlag())
  1416. {
  1417. return -1;
  1418. }
  1419. return 0;
  1420. }
  1421. unsigned int cmake::GetMajorVersion()
  1422. {
  1423. return cmMakefile::GetMajorVersion();
  1424. }
  1425. unsigned int cmake::GetMinorVersion()
  1426. {
  1427. return cmMakefile::GetMinorVersion();
  1428. }
  1429. const char *cmake::GetReleaseVersion()
  1430. {
  1431. return cmMakefile::GetReleaseVersion();
  1432. }
  1433. void cmake::AddCacheEntry(const char* key, const char* value,
  1434. const char* helpString,
  1435. int type)
  1436. {
  1437. m_CacheManager->AddCacheEntry(key, value,
  1438. helpString,
  1439. cmCacheManager::CacheEntryType(type));
  1440. }
  1441. const char* cmake::GetCacheDefinition(const char* name) const
  1442. {
  1443. return m_CacheManager->GetCacheValue(name);
  1444. }
  1445. int cmake::DumpDocumentationToFile(std::ostream& f)
  1446. {
  1447. #ifdef CMAKE_BUILD_WITH_CMAKE
  1448. // Loop over all registered commands and print out documentation
  1449. const char *name;
  1450. const char *terse;
  1451. const char *full;
  1452. char tmp[1024];
  1453. sprintf(tmp,"Version %d.%d (%s)", cmake::GetMajorVersion(),
  1454. cmake::GetMinorVersion(), cmVersion::GetReleaseVersion().c_str());
  1455. f << "<html>\n";
  1456. f << "<h1>Documentation for commands of CMake " << tmp << "</h1>\n";
  1457. f << "<ul>\n";
  1458. for(RegisteredCommandsMap::iterator j = m_Commands.begin();
  1459. j != m_Commands.end(); ++j)
  1460. {
  1461. name = (*j).second->GetName();
  1462. terse = (*j).second->GetTerseDocumentation();
  1463. full = (*j).second->GetFullDocumentation();
  1464. f << "<li><b>" << name << "</b> - " << terse << std::endl
  1465. << "<br><i>Usage:</i> " << full << "</li>" << std::endl << std::endl;
  1466. }
  1467. f << "</ul></html>\n";
  1468. #else
  1469. (void)f;
  1470. #endif
  1471. return 1;
  1472. }
  1473. void cmake::AddDefaultCommands()
  1474. {
  1475. std::list<cmCommand*> commands;
  1476. GetBootstrapCommands(commands);
  1477. GetPredefinedCommands(commands);
  1478. for(std::list<cmCommand*>::iterator i = commands.begin();
  1479. i != commands.end(); ++i)
  1480. {
  1481. this->AddCommand(*i);
  1482. }
  1483. }
  1484. void cmake::AddDefaultGenerators()
  1485. {
  1486. #if defined(_WIN32) && !defined(__CYGWIN__)
  1487. # if !defined(CMAKE_BOOT_MINGW)
  1488. m_Generators[cmGlobalVisualStudio6Generator::GetActualName()] =
  1489. &cmGlobalVisualStudio6Generator::New;
  1490. m_Generators[cmGlobalVisualStudio7Generator::GetActualName()] =
  1491. &cmGlobalVisualStudio7Generator::New;
  1492. m_Generators[cmGlobalVisualStudio71Generator::GetActualName()] =
  1493. &cmGlobalVisualStudio71Generator::New;
  1494. m_Generators[cmGlobalVisualStudio8Generator::GetActualName()] =
  1495. &cmGlobalVisualStudio8Generator::New;
  1496. m_Generators[cmGlobalBorlandMakefileGenerator::GetActualName()] =
  1497. &cmGlobalBorlandMakefileGenerator::New;
  1498. m_Generators[cmGlobalNMakeMakefileGenerator::GetActualName()] =
  1499. &cmGlobalNMakeMakefileGenerator::New;
  1500. m_Generators[cmGlobalWatcomWMakeGenerator::GetActualName()] =
  1501. &cmGlobalWatcomWMakeGenerator::New;
  1502. # endif
  1503. m_Generators[cmGlobalMSYSMakefileGenerator::GetActualName()] =
  1504. &cmGlobalMSYSMakefileGenerator::New;
  1505. m_Generators[cmGlobalMinGWMakefileGenerator::GetActualName()] =
  1506. &cmGlobalMinGWMakefileGenerator::New;
  1507. #endif
  1508. m_Generators[cmGlobalUnixMakefileGenerator3::GetActualName()] =
  1509. &cmGlobalUnixMakefileGenerator3::New;
  1510. #ifdef CMAKE_USE_XCODE
  1511. m_Generators[cmGlobalXCodeGenerator::GetActualName()] =
  1512. &cmGlobalXCodeGenerator::New;
  1513. #endif
  1514. #ifdef CMAKE_USE_KDEVELOP
  1515. m_Generators[cmGlobalKdevelopGenerator::GetActualName()] =
  1516. &cmGlobalKdevelopGenerator::New;
  1517. #endif
  1518. }
  1519. int cmake::LoadCache()
  1520. {
  1521. // could we not read the cache
  1522. if (!m_CacheManager->LoadCache(this->GetHomeOutputDirectory()))
  1523. {
  1524. // if it does exist, but isn;t readable then warn the user
  1525. std::string cacheFile = this->GetHomeOutputDirectory();
  1526. cacheFile += "/CMakeCache.txt";
  1527. if(cmSystemTools::FileExists(cacheFile.c_str()))
  1528. {
  1529. cmSystemTools::Error("There is a CMakeCache.txt file for the current binary tree but cmake does not have permission to read it. Please check the permissions of the directory you are trying to run CMake on.");
  1530. return -1;
  1531. }
  1532. }
  1533. if (m_CMakeCommand.size() < 2)
  1534. {
  1535. cmSystemTools::Error("cmake command was not specified prior to loading the cache in cmake.cxx");
  1536. return -1;
  1537. }
  1538. // setup CMAKE_ROOT and CMAKE_COMMAND
  1539. if(!this->AddCMakePaths(m_CMakeCommand.c_str()))
  1540. {
  1541. return -3;
  1542. }
  1543. // set the default BACKWARDS compatibility to the current version
  1544. if(!m_CacheManager->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
  1545. {
  1546. char ver[256];
  1547. sprintf(ver,"%i.%i",cmMakefile::GetMajorVersion(),
  1548. cmMakefile::GetMinorVersion());
  1549. this->m_CacheManager->AddCacheEntry
  1550. ("CMAKE_BACKWARDS_COMPATIBILITY",ver,
  1551. "For backwards compatibility, what version of CMake commands and syntax should this version of CMake allow.",
  1552. cmCacheManager::STRING);
  1553. }
  1554. return 0;
  1555. }
  1556. void cmake::SetProgressCallback(ProgressCallback f, void *cd)
  1557. {
  1558. m_ProgressCallback = f;
  1559. m_ProgressCallbackClientData = cd;
  1560. }
  1561. void cmake::UpdateProgress(const char *msg, float prog)
  1562. {
  1563. if(m_ProgressCallback && !m_InTryCompile)
  1564. {
  1565. (*m_ProgressCallback)(msg, prog, m_ProgressCallbackClientData);
  1566. return;
  1567. }
  1568. }
  1569. void cmake::GetCommandDocumentation(std::vector<cmDocumentationEntry>& v) const
  1570. {
  1571. for(RegisteredCommandsMap::const_iterator j = m_Commands.begin();
  1572. j != m_Commands.end(); ++j)
  1573. {
  1574. cmDocumentationEntry e =
  1575. {
  1576. (*j).second->GetName(),
  1577. (*j).second->GetTerseDocumentation(),
  1578. (*j).second->GetFullDocumentation()
  1579. };
  1580. v.push_back(e);
  1581. }
  1582. cmDocumentationEntry empty = {0,0,0};
  1583. v.push_back(empty);
  1584. }
  1585. void cmake::GetGeneratorDocumentation(std::vector<cmDocumentationEntry>& v)
  1586. {
  1587. for(RegisteredGeneratorsMap::const_iterator i = m_Generators.begin();
  1588. i != m_Generators.end(); ++i)
  1589. {
  1590. cmDocumentationEntry e;
  1591. cmGlobalGenerator* generator = (i->second)();
  1592. generator->GetDocumentation(e);
  1593. delete generator;
  1594. v.push_back(e);
  1595. }
  1596. cmDocumentationEntry empty = {0,0,0};
  1597. v.push_back(empty);
  1598. }
  1599. void cmake::AddWrittenFile(const char* file)
  1600. {
  1601. m_WrittenFiles.insert(file);
  1602. }
  1603. bool cmake::HasWrittenFile(const char* file)
  1604. {
  1605. return m_WrittenFiles.find(file) != m_WrittenFiles.end();
  1606. }
  1607. void cmake::CleanupWrittenFiles()
  1608. {
  1609. m_WrittenFiles.clear();
  1610. }
  1611. void cmake::UpdateConversionPathTable()
  1612. {
  1613. // Update the path conversion table with any specified file:
  1614. const char* tablepath =
  1615. m_CacheManager->GetCacheValue("CMAKE_PATH_TRANSLATION_FILE");
  1616. if(tablepath)
  1617. {
  1618. std::ifstream table( tablepath );
  1619. if(!table)
  1620. {
  1621. cmSystemTools::Error("CMAKE_PATH_TRANSLATION_FILE set to ", tablepath, ". CMake can not open file.");
  1622. cmSystemTools::ReportLastSystemError("CMake can not open file.");
  1623. }
  1624. else
  1625. {
  1626. std::string a, b;
  1627. while(!table.eof())
  1628. {
  1629. // two entries per line
  1630. table >> a; table >> b;
  1631. cmSystemTools::AddTranslationPath( a.c_str(), b.c_str());
  1632. }
  1633. }
  1634. }
  1635. }
  1636. //----------------------------------------------------------------------------
  1637. int cmake::CheckBuildSystem()
  1638. {
  1639. // This method will check the integrity of the build system if the
  1640. // option was given on the command line. It reads the given file to
  1641. // determine whether CMake should rerun. If it does rerun then the
  1642. // generation step will check the integrity of dependencies. If it
  1643. // does not then we need to check the integrity here.
  1644. // If no file is provided for the check, we have to rerun.
  1645. if(m_CheckBuildSystem.size() == 0)
  1646. {
  1647. return 1;
  1648. }
  1649. // If the file provided does not exist, we have to rerun.
  1650. if(!cmSystemTools::FileExists(m_CheckBuildSystem.c_str()))
  1651. {
  1652. return 1;
  1653. }
  1654. // Read the rerun check file and use it to decide whether to do the
  1655. // global generate.
  1656. cmake cm;
  1657. cmGlobalGenerator gg;
  1658. gg.SetCMakeInstance(&cm);
  1659. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  1660. lg->SetGlobalGenerator(&gg);
  1661. cmMakefile* mf = lg->GetMakefile();
  1662. if(!mf->ReadListFile(0, m_CheckBuildSystem.c_str()) ||
  1663. cmSystemTools::GetErrorOccuredFlag())
  1664. {
  1665. // There was an error reading the file. Just rerun.
  1666. return 1;
  1667. }
  1668. // Get the set of dependencies and outputs.
  1669. const char* dependsStr = mf->GetDefinition("CMAKE_MAKEFILE_DEPENDS");
  1670. const char* outputsStr = mf->GetDefinition("CMAKE_MAKEFILE_OUTPUTS");
  1671. if(!dependsStr || !outputsStr)
  1672. {
  1673. // Not enough information was provided to do the test. Just rerun.
  1674. return 1;
  1675. }
  1676. std::vector<std::string> depends;
  1677. std::vector<std::string> outputs;
  1678. cmSystemTools::ExpandListArgument(dependsStr, depends);
  1679. cmSystemTools::ExpandListArgument(outputsStr, outputs);
  1680. // If any output is older than any dependency then rerun.
  1681. for(std::vector<std::string>::iterator dep = depends.begin();
  1682. dep != depends.end(); ++dep)
  1683. {
  1684. for(std::vector<std::string>::iterator out = outputs.begin();
  1685. out != outputs.end(); ++out)
  1686. {
  1687. int result = 0;
  1688. if(!m_FileComparison->FileTimeCompare(out->c_str(),
  1689. dep->c_str(), &result) ||
  1690. result < 0)
  1691. {
  1692. return 1;
  1693. }
  1694. }
  1695. }
  1696. // We do not need to rerun CMake. Check dependency integrity. Use
  1697. // the make system's VERBOSE environment variable to enable verbose
  1698. // output.
  1699. bool verbose = cmSystemTools::GetEnv("VERBOSE") != 0;
  1700. // compute depends based on the generator specified
  1701. const char* genName = mf->GetDefinition("CMAKE_DEPENDS_GENERATOR");
  1702. if (!genName || genName[0] == '\0')
  1703. {
  1704. genName = "Unix Makefiles";
  1705. }
  1706. cmGlobalGenerator *ggd = this->CreateGlobalGenerator(genName);
  1707. if (ggd)
  1708. {
  1709. std::auto_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator());
  1710. lgd->SetGlobalGenerator(ggd);
  1711. lgd->CheckDependencies(mf, verbose, m_ClearBuildSystem);
  1712. }
  1713. // No need to rerun.
  1714. return 0;
  1715. }
  1716. //----------------------------------------------------------------------------
  1717. void cmake::TruncateOutputLog(const char* fname)
  1718. {
  1719. std::string fullPath = this->GetHomeOutputDirectory();
  1720. fullPath += "/";
  1721. fullPath += fname;
  1722. struct stat st;
  1723. if ( ::stat(fullPath.c_str(), &st) )
  1724. {
  1725. return;
  1726. }
  1727. if ( !m_CacheManager->GetCacheValue("CMAKE_CACHEFILE_DIR") )
  1728. {
  1729. cmSystemTools::RemoveFile(fullPath.c_str());
  1730. return;
  1731. }
  1732. size_t fsize = st.st_size;
  1733. const size_t maxFileSize = 50 * 1024;
  1734. if ( fsize < maxFileSize )
  1735. {
  1736. //TODO: truncate file
  1737. return;
  1738. }
  1739. }