1
0

cmake.cxx 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  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 "cmVariableWatch.h"
  21. // include the generator
  22. #if defined(_WIN32) && !defined(__CYGWIN__)
  23. #include "cmGlobalVisualStudio6Generator.h"
  24. #if !defined(__MINGW32__)
  25. #include "cmGlobalVisualStudio7Generator.h"
  26. #include "cmGlobalVisualStudio71Generator.h"
  27. #endif
  28. #include "cmGlobalBorlandMakefileGenerator.h"
  29. #include "cmGlobalNMakeMakefileGenerator.h"
  30. #include "cmGlobalUnixMakefileGenerator.h"
  31. #include "cmWin32ProcessExecution.h"
  32. #else
  33. #include "cmGlobalUnixMakefileGenerator.h"
  34. #endif
  35. #include <stdlib.h> // required for atoi
  36. #ifdef __APPLE__
  37. #include <sys/types.h>
  38. #include <sys/time.h>
  39. #include <sys/resource.h>
  40. #if defined(CMAKE_BUILD_WITH_CMAKE)
  41. #include "cmGlobalCodeWarriorGenerator.h"
  42. #endif
  43. #endif
  44. void cmNeedBackwardsCompatibility(const std::string& variable,
  45. int access_type, void* )
  46. {
  47. if (access_type == cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS)
  48. {
  49. std::string message = "An attempt was made to access a variable: ";
  50. message += variable;
  51. message += " that has not been defined. Some variables were always defined by CMake in versions prior to 1.6. To fix this you might need to set the cache value of CMAKE_BACKWARDS_COMPATIBILITY to 1.4 or less. If you are writing a CMakeList file, (or have already set CMAKE_BACKWARDS_COMPATABILITY to 1.4 or less) then you probably need to include a CMake module to test for the feature this variable defines.";
  52. cmSystemTools::Error(message.c_str());
  53. }
  54. }
  55. cmake::cmake()
  56. {
  57. #ifdef __APPLE__
  58. struct rlimit rlp;
  59. if(!getrlimit(RLIMIT_STACK, &rlp))
  60. {
  61. if(rlp.rlim_cur != rlp.rlim_max)
  62. {
  63. rlp.rlim_cur = rlp.rlim_max;
  64. setrlimit(RLIMIT_STACK, &rlp);
  65. }
  66. }
  67. #endif
  68. // If MAKEFLAGS are given in the environment, remove the environment
  69. // variable. This will prevent try-compile from succeeding when it
  70. // should fail (if "-i" is an option). We cannot simply test
  71. // whether "-i" is given and remove it because some make programs
  72. // encode the MAKEFLAGS variable in a strange way.
  73. if(getenv("MAKEFLAGS"))
  74. {
  75. static char makeflags[] = "MAKEFLAGS=";
  76. putenv(makeflags);
  77. }
  78. m_Local = false;
  79. m_Verbose = false;
  80. m_InTryCompile = false;
  81. m_CacheManager = new cmCacheManager;
  82. m_GlobalGenerator = 0;
  83. m_ProgressCallback = 0;
  84. m_ProgressCallbackClientData = 0;
  85. m_VariableWatch = new cmVariableWatch;
  86. m_ScriptMode = false;
  87. this->AddDefaultGenerators();
  88. this->AddDefaultCommands();
  89. m_VariableWatch->AddWatch("CMAKE_WORDS_BIGENDIAN",
  90. cmNeedBackwardsCompatibility);
  91. m_VariableWatch->AddWatch("CMAKE_SIZEOF_INT",
  92. cmNeedBackwardsCompatibility);
  93. m_VariableWatch->AddWatch("CMAKE_X_LIBS",
  94. cmNeedBackwardsCompatibility);
  95. }
  96. cmake::~cmake()
  97. {
  98. delete m_CacheManager;
  99. if (m_GlobalGenerator)
  100. {
  101. delete m_GlobalGenerator;
  102. m_GlobalGenerator = 0;
  103. }
  104. for(RegisteredCommandsMap::iterator j = m_Commands.begin();
  105. j != m_Commands.end(); ++j)
  106. {
  107. delete (*j).second;
  108. }
  109. delete m_VariableWatch;
  110. }
  111. bool cmake::CommandExists(const char* name) const
  112. {
  113. return (m_Commands.find(name) != m_Commands.end());
  114. }
  115. cmCommand *cmake::GetCommand(const char *name)
  116. {
  117. cmCommand* rm = 0;
  118. RegisteredCommandsMap::iterator pos = m_Commands.find(name);
  119. if (pos != m_Commands.end())
  120. {
  121. rm = (*pos).second;
  122. }
  123. return rm;
  124. }
  125. void cmake::AddCommand(cmCommand* wg)
  126. {
  127. std::string name = wg->GetName();
  128. // if the command already exists, free the old one
  129. RegisteredCommandsMap::iterator pos = m_Commands.find(name);
  130. if (pos != m_Commands.end())
  131. {
  132. delete pos->second;
  133. m_Commands.erase(pos);
  134. }
  135. m_Commands.insert( RegisteredCommandsMap::value_type(name, wg));
  136. }
  137. void cmake::Usage(const char* program)
  138. {
  139. cmOStringStream errorStream;
  140. errorStream << "cmake version " << cmMakefile::GetMajorVersion()
  141. << "." << cmMakefile::GetMinorVersion() << "\n";
  142. errorStream << "Usage: " << program << " [srcdir] [options]\n"
  143. << "Where cmake is run from the directory where you want the object files written. If srcdir is not specified, the current directory is used for both source and object files.\n";
  144. errorStream << "Options are:\n";
  145. errorStream << "\n-i (puts cmake in wizard mode, not available for ccmake)\n";
  146. errorStream << "\n-DVAR:TYPE=VALUE (create a cache file entry)\n";
  147. errorStream << "\n-Cpath_to_initial_cache (a cmake list file that is used to pre-load the cache with values.)\n";
  148. errorStream << "\n[-GgeneratorName] (where generator name can be one of these: ";
  149. std::vector<std::string> names;
  150. this->GetRegisteredGenerators(names);
  151. for(std::vector<std::string>::iterator i =names.begin();
  152. i != names.end(); ++i)
  153. {
  154. errorStream << "\"" << i->c_str() << "\" ";
  155. }
  156. errorStream << ")\n";
  157. cmSystemTools::Error(errorStream.str().c_str());
  158. }
  159. // Parse the args
  160. bool cmake::SetCacheArgs(const std::vector<std::string>& args)
  161. {
  162. for(unsigned int i=1; i < args.size(); ++i)
  163. {
  164. std::string arg = args[i];
  165. if(arg.find("-D",0) == 0)
  166. {
  167. std::string entry = arg.substr(2);
  168. std::string var, value;
  169. cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED;
  170. if(cmCacheManager::ParseEntry(entry.c_str(), var, value, type) ||
  171. cmCacheManager::ParseEntry(entry.c_str(), var, value))
  172. {
  173. this->m_CacheManager->AddCacheEntry(var.c_str(), value.c_str(),
  174. "No help, variable specified on the command line.",
  175. type);
  176. }
  177. else
  178. {
  179. std::cerr << "Parse error in command line argument: " << arg << "\n"
  180. << "Should be: VAR:type=value\n";
  181. cmSystemTools::Error("No cmake scrpt provided.");
  182. return false;
  183. }
  184. }
  185. else if(arg.find("-C",0) == 0)
  186. {
  187. std::string path = arg.substr(2);
  188. if ( path.size() == 0 )
  189. {
  190. cmSystemTools::Error("No initial cache file provided.");
  191. return false;
  192. }
  193. std::cerr << "loading initial cache file " << path.c_str() << "\n";
  194. this->ReadListFile(path.c_str());
  195. }
  196. else if(arg.find("--script",0) == 0)
  197. {
  198. std::string path = arg.substr(strlen("--script"));
  199. if ( path.size() == 0 )
  200. {
  201. cmSystemTools::Error("No cmake scrpt provided.");
  202. return false;
  203. }
  204. std::cerr << "Running cmake script file " << path.c_str() << "\n";
  205. this->ReadListFile(path.c_str());
  206. }
  207. }
  208. return true;
  209. }
  210. void cmake::ReadListFile(const char *path)
  211. {
  212. // if a generator was not yet created, temporarily create one
  213. cmGlobalGenerator *gg = this->GetGlobalGenerator();
  214. bool created = false;
  215. // if a generator was not specified use a generic one
  216. if (!gg)
  217. {
  218. gg = new cmGlobalGenerator;
  219. gg->SetCMakeInstance(this);
  220. created = true;
  221. }
  222. // read in the list file to fill the cache
  223. if(path)
  224. {
  225. cmLocalGenerator *lg = gg->CreateLocalGenerator();
  226. lg->SetGlobalGenerator(gg);
  227. if (!lg->GetMakefile()->ReadListFile(0, path))
  228. {
  229. std::cerr << "Error in reading cmake initial cache file:"
  230. << path << "\n";
  231. }
  232. }
  233. // free generic one if generated
  234. if (created)
  235. {
  236. delete gg;
  237. }
  238. }
  239. // Parse the args
  240. void cmake::SetArgs(const std::vector<std::string>& args)
  241. {
  242. m_Local = false;
  243. bool directoriesSet = false;
  244. for(unsigned int i=1; i < args.size(); ++i)
  245. {
  246. std::string arg = args[i];
  247. if(arg.find("-H",0) == 0)
  248. {
  249. directoriesSet = true;
  250. std::string path = arg.substr(2);
  251. this->SetHomeDirectory(path.c_str());
  252. }
  253. else if(arg.find("-S",0) == 0)
  254. {
  255. directoriesSet = true;
  256. m_Local = true;
  257. std::string path = arg.substr(2);
  258. this->SetStartDirectory(path.c_str());
  259. }
  260. else if(arg.find("-O",0) == 0)
  261. {
  262. directoriesSet = true;
  263. std::string path = arg.substr(2);
  264. this->SetStartOutputDirectory(path.c_str());
  265. }
  266. else if(arg.find("-B",0) == 0)
  267. {
  268. directoriesSet = true;
  269. std::string path = arg.substr(2);
  270. this->SetHomeOutputDirectory(path.c_str());
  271. }
  272. else if(arg.find("-V",0) == 0)
  273. {
  274. m_Verbose = true;
  275. }
  276. else if(arg.find("-D",0) == 0)
  277. {
  278. // skip for now
  279. }
  280. else if(arg.find("-C",0) == 0)
  281. {
  282. // skip for now
  283. }
  284. else if(arg.find("--script",0) == 0)
  285. {
  286. // skip for now
  287. }
  288. else if(arg.find("-G",0) == 0)
  289. {
  290. std::string value = arg.substr(2);
  291. cmGlobalGenerator* gen =
  292. this->CreateGlobalGenerator(value.c_str());
  293. if(!gen)
  294. {
  295. cmSystemTools::Error("Could not create named generator ",
  296. value.c_str());
  297. }
  298. else
  299. {
  300. this->SetGlobalGenerator(gen);
  301. }
  302. }
  303. // no option assume it is the path to the source
  304. else
  305. {
  306. directoriesSet = true;
  307. this->SetDirectoriesFromFile(arg.c_str());
  308. }
  309. }
  310. if(!directoriesSet)
  311. {
  312. this->SetHomeOutputDirectory
  313. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  314. this->SetStartOutputDirectory
  315. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  316. this->SetHomeDirectory
  317. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  318. this->SetStartDirectory
  319. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  320. }
  321. if (!m_Local)
  322. {
  323. this->SetStartDirectory(this->GetHomeDirectory());
  324. this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
  325. }
  326. }
  327. //----------------------------------------------------------------------------
  328. void cmake::SetDirectoriesFromFile(const char* arg)
  329. {
  330. // Check if the argument refers to a CMakeCache.txt or
  331. // CMakeLists.txt file.
  332. std::string listPath;
  333. std::string cachePath;
  334. bool argIsFile = false;
  335. if(cmSystemTools::FileIsDirectory(arg))
  336. {
  337. std::string path = cmSystemTools::CollapseFullPath(arg);
  338. cmSystemTools::ConvertToUnixSlashes(path);
  339. std::string cacheFile = path;
  340. cacheFile += "/CMakeCache.txt";
  341. std::string listFile = path;
  342. listFile += "/CMakeLists.txt";
  343. if(cmSystemTools::FileExists(cacheFile.c_str()))
  344. {
  345. cachePath = path;
  346. }
  347. if(cmSystemTools::FileExists(listFile.c_str()))
  348. {
  349. listPath = path;
  350. }
  351. }
  352. else if(cmSystemTools::FileExists(arg))
  353. {
  354. argIsFile = true;
  355. std::string fullPath = cmSystemTools::CollapseFullPath(arg);
  356. std::string name = cmSystemTools::GetFilenameName(fullPath.c_str());
  357. name = cmSystemTools::LowerCase(name);
  358. if(name == "cmakecache.txt")
  359. {
  360. cachePath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  361. }
  362. else if(name == "cmakelists.txt")
  363. {
  364. listPath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  365. }
  366. }
  367. // If there is a CMakeCache.txt file, use its settings.
  368. if(cachePath.length() > 0)
  369. {
  370. cmCacheManager* cachem = this->GetCacheManager();
  371. cmCacheManager::CacheIterator it = cachem->NewIterator();
  372. if(cachem->LoadCache(cachePath.c_str()) && it.Find("CMAKE_HOME_DIRECTORY"))
  373. {
  374. this->SetHomeOutputDirectory(cachePath.c_str());
  375. this->SetStartOutputDirectory(cachePath.c_str());
  376. this->SetHomeDirectory(it.GetValue());
  377. this->SetStartDirectory(it.GetValue());
  378. return;
  379. }
  380. }
  381. // If there is a CMakeLists.txt file, use it as the source tree.
  382. if(listPath.length() > 0)
  383. {
  384. this->SetHomeDirectory(listPath.c_str());
  385. this->SetStartDirectory(listPath.c_str());
  386. if(argIsFile)
  387. {
  388. // Source CMakeLists.txt file given. It was probably dropped
  389. // onto the executable in a GUI. Default to an in-source build.
  390. this->SetHomeOutputDirectory(listPath.c_str());
  391. this->SetStartOutputDirectory(listPath.c_str());
  392. }
  393. else
  394. {
  395. // Source directory given on command line. Use current working
  396. // directory as build tree.
  397. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  398. this->SetHomeOutputDirectory(cwd.c_str());
  399. this->SetStartOutputDirectory(cwd.c_str());
  400. }
  401. return;
  402. }
  403. // We didn't find a CMakeLists.txt or CMakeCache.txt file from the
  404. // argument. Assume it is the path to the source tree, and use the
  405. // current working directory as the build tree.
  406. std::string full = cmSystemTools::CollapseFullPath(arg);
  407. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  408. this->SetHomeDirectory(full.c_str());
  409. this->SetStartDirectory(full.c_str());
  410. this->SetHomeOutputDirectory(cwd.c_str());
  411. this->SetStartOutputDirectory(cwd.c_str());
  412. }
  413. // at the end of this CMAKE_ROOT and CMAKE_COMMAND should be added to the cache
  414. int cmake::AddCMakePaths(const char *arg0)
  415. {
  416. // Find our own executable.
  417. std::vector<cmStdString> failures;
  418. std::string cMakeSelf = arg0;
  419. cmSystemTools::ConvertToUnixSlashes(cMakeSelf);
  420. failures.push_back(cMakeSelf);
  421. cMakeSelf = cmSystemTools::FindProgram(cMakeSelf.c_str());
  422. if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
  423. {
  424. #ifdef CMAKE_BUILD_DIR
  425. std::string intdir = ".";
  426. #ifdef CMAKE_INTDIR
  427. intdir = CMAKE_INTDIR;
  428. #endif
  429. cMakeSelf = CMAKE_BUILD_DIR;
  430. cMakeSelf += "/bin/";
  431. cMakeSelf += intdir;
  432. cMakeSelf += "/cmake";
  433. cMakeSelf += cmSystemTools::GetExecutableExtension();
  434. #endif
  435. }
  436. #ifdef CMAKE_PREFIX
  437. if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
  438. {
  439. failures.push_back(cMakeSelf);
  440. cMakeSelf = CMAKE_PREFIX "/bin/cmake";
  441. }
  442. #endif
  443. if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
  444. {
  445. failures.push_back(cMakeSelf);
  446. cmOStringStream msg;
  447. msg << "CMAKE can not find the command line program cmake.\n";
  448. msg << " argv[0] = \"" << arg0 << "\"\n";
  449. msg << " Attempted paths:\n";
  450. std::vector<cmStdString>::iterator i;
  451. for(i=failures.begin(); i != failures.end(); ++i)
  452. {
  453. msg << " \"" << i->c_str() << "\"\n";
  454. }
  455. cmSystemTools::Error(msg.str().c_str());
  456. return 0;
  457. }
  458. // Save the value in the cache
  459. this->m_CacheManager->AddCacheEntry
  460. ("CMAKE_COMMAND",cMakeSelf.c_str(), "Path to CMake executable.",
  461. cmCacheManager::INTERNAL);
  462. // Find and save the command to edit the cache
  463. std::string editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  464. "/ccmake" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  465. if( !cmSystemTools::FileExists(editCacheCommand.c_str()))
  466. {
  467. editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  468. "/CMakeSetup" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  469. }
  470. if(cmSystemTools::FileExists(editCacheCommand.c_str()))
  471. {
  472. this->m_CacheManager->AddCacheEntry
  473. ("CMAKE_EDIT_COMMAND", editCacheCommand.c_str(),
  474. "Path to cache edit program executable.", cmCacheManager::INTERNAL);
  475. }
  476. // do CMAKE_ROOT, look for the environment variable first
  477. std::string cMakeRoot;
  478. std::string modules;
  479. if (getenv("CMAKE_ROOT"))
  480. {
  481. cMakeRoot = getenv("CMAKE_ROOT");
  482. modules = cMakeRoot + "/Modules/CMakeDefaultMakeRuleVariables.cmake";
  483. }
  484. if(!cmSystemTools::FileExists(modules.c_str()))
  485. {
  486. // next try exe/..
  487. cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
  488. std::string::size_type slashPos = cMakeRoot.rfind("/");
  489. if(slashPos != std::string::npos)
  490. {
  491. cMakeRoot = cMakeRoot.substr(0, slashPos);
  492. }
  493. // is there no Modules direcory there?
  494. modules = cMakeRoot + "/Modules/CMakeDefaultMakeRuleVariables.cmake";
  495. }
  496. if (!cmSystemTools::FileExists(modules.c_str()))
  497. {
  498. // try exe/../share/cmake
  499. cMakeRoot += CMAKE_DATA_DIR;
  500. modules = cMakeRoot + "/Modules/CMakeDefaultMakeRuleVariables.cmake";
  501. }
  502. #ifdef CMAKE_ROOT_DIR
  503. if (!cmSystemTools::FileExists(modules.c_str()))
  504. {
  505. // try compiled in root directory
  506. cMakeRoot = CMAKE_ROOT_DIR;
  507. modules = cMakeRoot + "/Modules/CMakeDefaultMakeRuleVariables.cmake";
  508. }
  509. #endif
  510. #ifdef CMAKE_PREFIX
  511. if (!cmSystemTools::FileExists(modules.c_str()))
  512. {
  513. // try compiled in install prefix
  514. cMakeRoot = CMAKE_PREFIX CMAKE_DATA_DIR;
  515. modules = cMakeRoot + "/Modules/CMakeDefaultMakeRuleVariables.cmake";
  516. }
  517. #endif
  518. if (!cmSystemTools::FileExists(modules.c_str()))
  519. {
  520. // try
  521. cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
  522. cMakeRoot += CMAKE_DATA_DIR;
  523. modules = cMakeRoot + "/Modules/CMakeDefaultMakeRuleVariables.cmake";
  524. }
  525. if(!cmSystemTools::FileExists(modules.c_str()))
  526. {
  527. // next try exe
  528. cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
  529. // is there no Modules direcory there?
  530. modules = cMakeRoot + "/Modules/CMakeDefaultMakeRuleVariables.cmake";
  531. }
  532. if (!cmSystemTools::FileExists(modules.c_str()))
  533. {
  534. // couldn't find modules
  535. cmSystemTools::Error("Could not find CMAKE_ROOT !!!\n"
  536. "CMake has most likely not been installed correctly.\n"
  537. "Modules directory not found in\n",
  538. cMakeRoot.c_str());
  539. return 0;
  540. }
  541. this->m_CacheManager->AddCacheEntry
  542. ("CMAKE_ROOT", cMakeRoot.c_str(),
  543. "Path to CMake installation.", cmCacheManager::INTERNAL);
  544. #ifdef _WIN32
  545. std::string comspec = "cmw9xcom.exe";
  546. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  547. #endif
  548. return 1;
  549. }
  550. void CMakeCommandUsage(const char* program)
  551. {
  552. cmOStringStream errorStream;
  553. errorStream
  554. << "cmake version " << cmMakefile::GetMajorVersion()
  555. << "." << cmMakefile::GetMinorVersion() << "\n";
  556. errorStream
  557. << "Usage: " << program << " -E [command] [arguments ...]\n"
  558. << "Available commands: \n"
  559. << " chdir dir cmd [args]... - run command in a given directory\n"
  560. << " copy file destination - copy file to destination (either file or directory)\n"
  561. << " copy_if_different in-file out-file - copy file if input has changed\n"
  562. << " echo [string]... - displays arguments as text\n"
  563. << " remove file1 file2 ... - remove the file(s)\n"
  564. << " time command [args] ... - run command and return elapsed time\n";
  565. #if defined(_WIN32) && !defined(__CYGWIN__)
  566. errorStream
  567. << " write_regv key value - write registry value\n"
  568. << " delete_regv key - delete registry value\n"
  569. << " comspec - on windows 9x use this for RunCommand\n";
  570. #endif
  571. cmSystemTools::Error(errorStream.str().c_str());
  572. }
  573. int cmake::CMakeCommand(std::vector<std::string>& args)
  574. {
  575. if (args.size() > 1)
  576. {
  577. // Copy file
  578. if (args[1] == "copy" && args.size() == 4)
  579. {
  580. cmSystemTools::cmCopyFile(args[2].c_str(), args[3].c_str());
  581. return cmSystemTools::GetErrorOccuredFlag();
  582. }
  583. // Copy file if different.
  584. if (args[1] == "copy_if_different" && args.size() == 4)
  585. {
  586. cmSystemTools::CopyFileIfDifferent(args[2].c_str(), args[3].c_str());
  587. return cmSystemTools::GetErrorOccuredFlag();
  588. }
  589. // Echo string
  590. else if (args[1] == "echo" )
  591. {
  592. unsigned int cc;
  593. for ( cc = 2; cc < args.size(); cc ++ )
  594. {
  595. std::cout << args[cc] << " ";
  596. }
  597. std::cout << std::endl;
  598. return 0;
  599. }
  600. // Remove file
  601. else if (args[1] == "remove" && args.size() > 2)
  602. {
  603. for (std::string::size_type cc = 2; cc < args.size(); cc ++)
  604. {
  605. if(args[cc] != "-f")
  606. {
  607. if(args[cc] == "\\-f")
  608. {
  609. args[cc] = "-f";
  610. }
  611. cmSystemTools::RemoveFile(args[cc].c_str());
  612. }
  613. }
  614. return 0;
  615. }
  616. // Clock command
  617. else if (args[1] == "time" && args.size() > 2)
  618. {
  619. std::string command = args[2];
  620. for (std::string::size_type cc = 3; cc < args.size(); cc ++)
  621. {
  622. command += " ";
  623. command += args[cc];
  624. }
  625. clock_t clock_start, clock_finish;
  626. time_t time_start, time_finish;
  627. time(&time_start);
  628. clock_start = clock();
  629. cmSystemTools::RunSingleCommand(command.c_str());
  630. clock_finish = clock();
  631. time(&time_finish);
  632. double clocks_per_sec = (double)CLOCKS_PER_SEC;
  633. std::cout << "Elapsed time: "
  634. << (long)(time_finish - time_start) << " s. (time)"
  635. << ", "
  636. << (double)(clock_finish - clock_start) / clocks_per_sec
  637. << " s. (clock)"
  638. << "\n";
  639. return 0;
  640. }
  641. // Clock command
  642. else if (args[1] == "chdir" && args.size() >= 4)
  643. {
  644. std::string directory = args[2];
  645. std::string command = "\"";
  646. command += args[3];
  647. command += "\"";
  648. for (std::string::size_type cc = 4; cc < args.size(); cc ++)
  649. {
  650. command += " \"";
  651. command += args[cc];
  652. command += "\"";
  653. }
  654. int retval = 0;
  655. int timeout = 0;
  656. if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, &retval,
  657. directory.c_str(), true, timeout) )
  658. {
  659. return retval;
  660. }
  661. return 1;
  662. }
  663. #if defined(_WIN32) && !defined(__CYGWIN__)
  664. // Write registry value
  665. else if (args[1] == "write_regv" && args.size() > 3)
  666. {
  667. return cmSystemTools::WriteRegistryValue(args[2].c_str(),
  668. args[3].c_str()) ? 0 : 1;
  669. }
  670. // Delete registry value
  671. else if (args[1] == "delete_regv" && args.size() > 2)
  672. {
  673. return cmSystemTools::DeleteRegistryValue(args[2].c_str()) ? 0 : 1;
  674. }
  675. // Remove file
  676. else if (args[1] == "comspec" && args.size() > 2)
  677. {
  678. unsigned int cc;
  679. std::string command = args[2];
  680. for ( cc = 3; cc < args.size(); cc ++ )
  681. {
  682. command += " " + args[cc];
  683. }
  684. return cmWin32ProcessExecution::Windows9xHack(command.c_str());
  685. }
  686. #endif
  687. }
  688. ::CMakeCommandUsage(args[0].c_str());
  689. return 1;
  690. }
  691. void cmake::GetRegisteredGenerators(std::vector<std::string>& names)
  692. {
  693. for(RegisteredGeneratorsMap::const_iterator i = m_Generators.begin();
  694. i != m_Generators.end(); ++i)
  695. {
  696. names.push_back(i->first);
  697. }
  698. }
  699. cmGlobalGenerator* cmake::CreateGlobalGenerator(const char* name)
  700. {
  701. RegisteredGeneratorsMap::const_iterator i = m_Generators.find(name);
  702. if(i != m_Generators.end())
  703. {
  704. cmGlobalGenerator* generator = (i->second)();
  705. generator->SetCMakeInstance(this);
  706. return generator;
  707. }
  708. else
  709. {
  710. return 0;
  711. }
  712. }
  713. void cmake::SetHomeDirectory(const char* dir)
  714. {
  715. m_cmHomeDirectory = dir;
  716. cmSystemTools::ConvertToUnixSlashes(m_cmHomeDirectory);
  717. }
  718. void cmake::SetHomeOutputDirectory(const char* lib)
  719. {
  720. m_HomeOutputDirectory = lib;
  721. cmSystemTools::ConvertToUnixSlashes(m_HomeOutputDirectory);
  722. }
  723. void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
  724. {
  725. // delete the old generator
  726. if (m_GlobalGenerator)
  727. {
  728. delete m_GlobalGenerator;
  729. // restore the original environment variables CXX and CC
  730. // Restor CC
  731. static char envCC[5000];
  732. std::string env = "CC=";
  733. if(m_CCEnvironment)
  734. {
  735. env += m_CCEnvironment;
  736. }
  737. std::string::size_type size = env.size();
  738. if(size > 4999)
  739. {
  740. size = 4999;
  741. }
  742. strncpy(envCC, env.c_str(), size);
  743. envCC[4999] = 0;
  744. putenv(envCC);
  745. // Restore CXX
  746. static char envCXX[5000];
  747. env = "CXX=";
  748. if(m_CXXEnvironment)
  749. {
  750. env += m_CXXEnvironment;
  751. }
  752. size = env.size();
  753. if(size > 4999)
  754. {
  755. size = 4999;
  756. }
  757. strncpy(envCXX, env.c_str(), size);
  758. envCXX[4999] = 0;
  759. putenv(envCXX);
  760. }
  761. // set the new
  762. m_GlobalGenerator = gg;
  763. // set the global flag for unix style paths on cmSystemTools as
  764. // soon as the generator is set. This allows gmake to be used
  765. // on windows.
  766. cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
  767. // Save the environment variables CXX and CC
  768. m_CXXEnvironment = getenv("CXX");
  769. m_CCEnvironment = getenv("CC");
  770. // set the cmake instance just to be sure
  771. gg->SetCMakeInstance(this);
  772. }
  773. int cmake::DoPreConfigureChecks()
  774. {
  775. // Make sure the Start directory contains a CMakeLists.txt file.
  776. std::string srcList = this->GetHomeDirectory();
  777. srcList += "/CMakeLists.txt";
  778. if(!cmSystemTools::FileExists(srcList.c_str()))
  779. {
  780. cmOStringStream err;
  781. err << "The source directory \"" << this->GetHomeDirectory()
  782. << "\" does not appear to contain CMakeLists.txt.\n"
  783. << "Specify --help for usage, or press the help button on the CMake GUI.";
  784. cmSystemTools::Error(err.str().c_str());
  785. return -2;
  786. }
  787. // do a sanity check on some values
  788. if(m_CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY"))
  789. {
  790. std::string cacheStart =
  791. m_CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY");
  792. cacheStart += "/CMakeLists.txt";
  793. std::string currentStart = this->GetHomeDirectory();
  794. currentStart += "/CMakeLists.txt";
  795. if(!cmSystemTools::SameFile(cacheStart.c_str(), currentStart.c_str()))
  796. {
  797. std::string message = "The source \"";
  798. message += currentStart;
  799. message += "\" does not match the source \"";
  800. message += cacheStart;
  801. message += "\" used to generate cache. ";
  802. message += "Re-run cmake with a different source directory.";
  803. cmSystemTools::Error(message.c_str());
  804. return -2;
  805. }
  806. }
  807. else
  808. {
  809. return 0;
  810. }
  811. return 1;
  812. }
  813. int cmake::Configure()
  814. {
  815. int res = 0;
  816. if ( !m_ScriptMode )
  817. {
  818. res = this->DoPreConfigureChecks();
  819. }
  820. if ( res < 0 )
  821. {
  822. return -2;
  823. }
  824. if ( !res )
  825. {
  826. m_CacheManager->AddCacheEntry("CMAKE_HOME_DIRECTORY",
  827. this->GetHomeDirectory(),
  828. "Start directory with the top level CMakeLists.txt file for this project",
  829. cmCacheManager::INTERNAL);
  830. }
  831. // set the default BACKWARDS compatibility to the current version
  832. if(!m_CacheManager->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
  833. {
  834. char ver[256];
  835. sprintf(ver,"%i.%i",cmMakefile::GetMajorVersion(),
  836. cmMakefile::GetMinorVersion());
  837. this->m_CacheManager->AddCacheEntry
  838. ("CMAKE_BACKWARDS_COMPATIBILITY",ver,
  839. "For backwards compatibility, what version of CMake commands and syntax should this version of CMake allow.",
  840. cmCacheManager::STRING);
  841. }
  842. // no generator specified on the command line
  843. if(!m_GlobalGenerator)
  844. {
  845. const char* genName = m_CacheManager->GetCacheValue("CMAKE_GENERATOR");
  846. if(genName)
  847. {
  848. m_GlobalGenerator = this->CreateGlobalGenerator(genName);
  849. // set the global flag for unix style paths on cmSystemTools as
  850. // soon as the generator is set. This allows gmake to be used
  851. // on windows.
  852. cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
  853. }
  854. else
  855. {
  856. #if defined(__BORLANDC__) && defined(_WIN32)
  857. this->SetGlobalGenerator(new cmGlobalBorlandMakefileGenerator);
  858. #elif defined(_WIN32) && !defined(__CYGWIN__)
  859. this->SetGlobalGenerator(new cmGlobalVisualStudio6Generator);
  860. #else
  861. this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator);
  862. #endif
  863. }
  864. if(!m_GlobalGenerator)
  865. {
  866. cmSystemTools::Error("Could not create generator");
  867. return -1;
  868. }
  869. }
  870. const char* genName = m_CacheManager->GetCacheValue("CMAKE_GENERATOR");
  871. if(genName)
  872. {
  873. if(strcmp(m_GlobalGenerator->GetName(), genName) != 0)
  874. {
  875. std::string message = "Error: generator : ";
  876. message += m_GlobalGenerator->GetName();
  877. message += "\nDoes not match the generator used previously: ";
  878. message += genName;
  879. message +=
  880. "\nEither remove the CMakeCache.txt file or choose a different"
  881. " binary directory.";
  882. cmSystemTools::Error(message.c_str());
  883. return -2;
  884. }
  885. }
  886. if(!m_CacheManager->GetCacheValue("CMAKE_GENERATOR"))
  887. {
  888. m_CacheManager->AddCacheEntry("CMAKE_GENERATOR", m_GlobalGenerator->GetName(),
  889. "Name of generator.",
  890. cmCacheManager::INTERNAL);
  891. }
  892. // reset any system configuration information, except for when we are
  893. // InTryCompile. With TryCompile the system info is taken from the parent's
  894. // info to save time
  895. if (!m_InTryCompile)
  896. {
  897. m_GlobalGenerator->ClearEnabledLanguages();
  898. }
  899. // actually do the configure
  900. m_GlobalGenerator->Configure();
  901. // Before saving the cache
  902. // if the project did not define one of the entries below, add them now
  903. // so users can edit the values in the cache:
  904. // LIBRARY_OUTPUT_PATH
  905. // EXECUTABLE_OUTPUT_PATH
  906. if(!m_CacheManager->GetCacheValue("LIBRARY_OUTPUT_PATH"))
  907. {
  908. m_CacheManager->AddCacheEntry("LIBRARY_OUTPUT_PATH", "",
  909. "Single output directory for building all libraries.",
  910. cmCacheManager::PATH);
  911. }
  912. if(!m_CacheManager->GetCacheValue("EXECUTABLE_OUTPUT_PATH"))
  913. {
  914. m_CacheManager->AddCacheEntry("EXECUTABLE_OUTPUT_PATH", "",
  915. "Single output directory for building all executables.",
  916. cmCacheManager::PATH);
  917. }
  918. if(cmSystemTools::GetFatalErrorOccured() &&
  919. (!this->m_CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM") ||
  920. cmSystemTools::IsOff(this->m_CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM"))))
  921. {
  922. // We must have a bad generator selection. Wipe the cache entry so the
  923. // user can select another.
  924. m_CacheManager->RemoveCacheEntry("CMAKE_GENERATOR");
  925. }
  926. if ( !m_ScriptMode )
  927. {
  928. this->m_CacheManager->SaveCache(this->GetHomeOutputDirectory());
  929. }
  930. if(cmSystemTools::GetErrorOccuredFlag())
  931. {
  932. return -1;
  933. }
  934. return 0;
  935. }
  936. bool cmake::CacheVersionMatches()
  937. {
  938. const char* majv = m_CacheManager->GetCacheValue("CMAKE_CACHE_MAJOR_VERSION");
  939. const char* minv = m_CacheManager->GetCacheValue("CMAKE_CACHE_MINOR_VERSION");
  940. const char* relv = m_CacheManager->GetCacheValue("CMAKE_CACHE_RELEASE_VERSION");
  941. bool cacheSameCMake = false;
  942. if(majv &&
  943. atoi(majv) == static_cast<int>(cmMakefile::GetMajorVersion())
  944. && minv &&
  945. atoi(minv) == static_cast<int>(cmMakefile::GetMinorVersion())
  946. && relv && (strcmp(relv, cmMakefile::GetReleaseVersion()) == 0))
  947. {
  948. cacheSameCMake = true;
  949. }
  950. return cacheSameCMake;
  951. }
  952. // handle a command line invocation
  953. int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
  954. {
  955. // Process the arguments
  956. this->SetArgs(args);
  957. // set the cmake command
  958. m_CMakeCommand = args[0];
  959. if ( !m_ScriptMode )
  960. {
  961. // load the cache
  962. if(this->LoadCache() < 0)
  963. {
  964. cmSystemTools::Error("Error executing cmake::LoadCache(). Aborting.\n");
  965. return -1;
  966. }
  967. }
  968. // Add any cache args
  969. if ( !this->SetCacheArgs(args) )
  970. {
  971. cmSystemTools::Error("Problem processing arguments. Aborting.\n");
  972. return -1;
  973. }
  974. std::string systemFile = this->GetHomeOutputDirectory();
  975. systemFile += "/CMakeSystem.cmake";
  976. if ( noconfigure )
  977. {
  978. return 0;
  979. }
  980. int ret = 0;
  981. // if not local or the cmake version has changed since the last run
  982. // of cmake, or CMakeSystem.cmake file is not in the root binary
  983. // directory, run a global generate
  984. if(m_ScriptMode || !m_Local || !this->CacheVersionMatches() ||
  985. !cmSystemTools::FileExists(systemFile.c_str()) )
  986. {
  987. // If we are doing global generate, we better set start and start
  988. // output directory to the root of the project.
  989. std::string oldstartdir = this->GetStartDirectory();
  990. std::string oldstartoutputdir = this->GetStartOutputDirectory();
  991. this->SetStartDirectory(this->GetHomeDirectory());
  992. this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
  993. bool saveLocalFlag = m_Local;
  994. m_Local = false;
  995. ret = this->Configure();
  996. if (ret || m_ScriptMode)
  997. {
  998. return ret;
  999. }
  1000. ret = this->Generate();
  1001. if(ret)
  1002. {
  1003. return ret;
  1004. }
  1005. m_Local = saveLocalFlag;
  1006. this->SetStartDirectory(oldstartdir.c_str());
  1007. this->SetStartOutputDirectory(oldstartoutputdir.c_str());
  1008. }
  1009. // if we are local do the local thing
  1010. if (m_Local)
  1011. {
  1012. ret = this->LocalGenerate();
  1013. }
  1014. return ret;
  1015. }
  1016. int cmake::Generate()
  1017. {
  1018. if(!m_GlobalGenerator)
  1019. {
  1020. return -1;
  1021. }
  1022. m_GlobalGenerator->Generate();
  1023. if(cmSystemTools::GetErrorOccuredFlag())
  1024. {
  1025. return -1;
  1026. }
  1027. return 0;
  1028. }
  1029. int cmake::LocalGenerate()
  1030. {
  1031. // Read in the cache
  1032. m_CacheManager->LoadCache(this->GetHomeOutputDirectory());
  1033. // create the generator based on the cache if it isn't already there
  1034. const char* genName = m_CacheManager->GetCacheValue("CMAKE_GENERATOR");
  1035. if(genName)
  1036. {
  1037. m_GlobalGenerator = this->CreateGlobalGenerator(genName);
  1038. // set the global flag for unix style paths on cmSystemTools as
  1039. // soon as the generator is set. This allows gmake to be used
  1040. // on windows.
  1041. cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
  1042. }
  1043. else
  1044. {
  1045. cmSystemTools::Error("Could local Generate called without the GENERATOR being specified in the CMakeCache");
  1046. return -1;
  1047. }
  1048. // do the local generate
  1049. m_GlobalGenerator->LocalGenerate();
  1050. if(cmSystemTools::GetErrorOccuredFlag())
  1051. {
  1052. return -1;
  1053. }
  1054. return 0;
  1055. }
  1056. unsigned int cmake::GetMajorVersion()
  1057. {
  1058. return cmMakefile::GetMajorVersion();
  1059. }
  1060. unsigned int cmake::GetMinorVersion()
  1061. {
  1062. return cmMakefile::GetMinorVersion();
  1063. }
  1064. const char *cmake::GetReleaseVersion()
  1065. {
  1066. return cmMakefile::GetReleaseVersion();
  1067. }
  1068. void cmake::AddCacheEntry(const char* key, const char* value,
  1069. const char* helpString,
  1070. int type)
  1071. {
  1072. m_CacheManager->AddCacheEntry(key, value,
  1073. helpString,
  1074. cmCacheManager::CacheEntryType(type));
  1075. }
  1076. const char* cmake::GetCacheDefinition(const char* name) const
  1077. {
  1078. return m_CacheManager->GetCacheValue(name);
  1079. }
  1080. int cmake::DumpDocumentationToFile(std::ostream& f)
  1081. {
  1082. // Loop over all registered commands and print out documentation
  1083. const char *name;
  1084. const char *terse;
  1085. const char *full;
  1086. char tmp[1024];
  1087. sprintf(tmp,"Version %d.%d", cmake::GetMajorVersion(),
  1088. cmake::GetMinorVersion());
  1089. f << "<html>\n";
  1090. f << "<h1>Documentation for commands of CMake " << tmp << "</h1>\n";
  1091. f << "<ul>\n";
  1092. for(RegisteredCommandsMap::iterator j = m_Commands.begin();
  1093. j != m_Commands.end(); ++j)
  1094. {
  1095. name = (*j).second->GetName();
  1096. terse = (*j).second->GetTerseDocumentation();
  1097. full = (*j).second->GetFullDocumentation();
  1098. f << "<li><b>" << name << "</b> - " << terse << std::endl
  1099. << "<br><i>Usage:</i> " << full << "</li>" << std::endl << std::endl;
  1100. }
  1101. f << "</ul></html>\n";
  1102. return 1;
  1103. }
  1104. void cmake::AddDefaultCommands()
  1105. {
  1106. std::list<cmCommand*> commands;
  1107. GetPredefinedCommands(commands);
  1108. for(std::list<cmCommand*>::iterator i = commands.begin();
  1109. i != commands.end(); ++i)
  1110. {
  1111. this->AddCommand(*i);
  1112. }
  1113. }
  1114. void cmake::AddDefaultGenerators()
  1115. {
  1116. #if defined(_WIN32) && !defined(__CYGWIN__)
  1117. m_Generators[cmGlobalVisualStudio6Generator::GetActualName()] =
  1118. &cmGlobalVisualStudio6Generator::New;
  1119. #if !defined(__MINGW32__)
  1120. m_Generators[cmGlobalVisualStudio7Generator::GetActualName()] =
  1121. &cmGlobalVisualStudio7Generator::New;
  1122. m_Generators[cmGlobalVisualStudio71Generator::GetActualName()] =
  1123. &cmGlobalVisualStudio71Generator::New;
  1124. #endif
  1125. m_Generators[cmGlobalBorlandMakefileGenerator::GetActualName()] =
  1126. &cmGlobalBorlandMakefileGenerator::New;
  1127. m_Generators[cmGlobalNMakeMakefileGenerator::GetActualName()] =
  1128. &cmGlobalNMakeMakefileGenerator::New;
  1129. #else
  1130. # if defined(__APPLE__) && defined(CMAKE_BUILD_WITH_CMAKE)
  1131. m_Generators[cmGlobalCodeWarriorGenerator::GetActualName()] =
  1132. &cmGlobalCodeWarriorGenerator::New;
  1133. # endif
  1134. #endif
  1135. m_Generators[cmGlobalUnixMakefileGenerator::GetActualName()] =
  1136. &cmGlobalUnixMakefileGenerator::New;
  1137. }
  1138. int cmake::LoadCache()
  1139. {
  1140. m_CacheManager->LoadCache(this->GetHomeOutputDirectory());
  1141. if (m_CMakeCommand.size() < 2)
  1142. {
  1143. cmSystemTools::Error("cmake command was not specified prior to loading the cache in cmake.cxx");
  1144. return -1;
  1145. }
  1146. // setup CMAKE_ROOT and CMAKE_COMMAND
  1147. if(!this->AddCMakePaths(m_CMakeCommand.c_str()))
  1148. {
  1149. return -3;
  1150. }
  1151. // set the default BACKWARDS compatibility to the current version
  1152. if(!m_CacheManager->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
  1153. {
  1154. char ver[256];
  1155. sprintf(ver,"%i.%i",cmMakefile::GetMajorVersion(),
  1156. cmMakefile::GetMinorVersion());
  1157. this->m_CacheManager->AddCacheEntry
  1158. ("CMAKE_BACKWARDS_COMPATIBILITY",ver,
  1159. "For backwards compatibility, what version of CMake commands and syntax should this version of CMake allow.",
  1160. cmCacheManager::STRING);
  1161. }
  1162. return 0;
  1163. }
  1164. void cmake::SetProgressCallback(ProgressCallback f, void *cd)
  1165. {
  1166. m_ProgressCallback = f;
  1167. m_ProgressCallbackClientData = cd;
  1168. }
  1169. void cmake::UpdateProgress(const char *msg, float prog)
  1170. {
  1171. if(m_ProgressCallback && !m_InTryCompile)
  1172. {
  1173. (*m_ProgressCallback)(msg, prog, m_ProgressCallbackClientData);
  1174. return;
  1175. }
  1176. }
  1177. void cmake::GetCommandDocumentation(std::vector<cmDocumentationEntry>& v) const
  1178. {
  1179. for(RegisteredCommandsMap::const_iterator j = m_Commands.begin();
  1180. j != m_Commands.end(); ++j)
  1181. {
  1182. cmDocumentationEntry e =
  1183. {
  1184. (*j).second->GetName(),
  1185. (*j).second->GetTerseDocumentation(),
  1186. (*j).second->GetFullDocumentation()
  1187. };
  1188. v.push_back(e);
  1189. }
  1190. cmDocumentationEntry empty = {0,0,0};
  1191. v.push_back(empty);
  1192. }
  1193. void cmake::GetGeneratorDocumentation(std::vector<cmDocumentationEntry>& v)
  1194. {
  1195. for(RegisteredGeneratorsMap::const_iterator i = m_Generators.begin();
  1196. i != m_Generators.end(); ++i)
  1197. {
  1198. cmDocumentationEntry e;
  1199. cmGlobalGenerator* generator = (i->second)();
  1200. generator->GetDocumentation(e);
  1201. delete generator;
  1202. v.push_back(e);
  1203. }
  1204. cmDocumentationEntry empty = {0,0,0};
  1205. v.push_back(empty);
  1206. }