cmake.cxx 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347
  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. // Internal CMake shared library support.
  664. else if (args[1] == "cmake_symlink_library" && args.size() == 5)
  665. {
  666. int result = 0;
  667. std::string realName = args[2];
  668. std::string soName = args[3];
  669. std::string name = args[4];
  670. if(soName != realName)
  671. {
  672. std::string fname = cmSystemTools::GetFilenameName(realName);
  673. if(cmSystemTools::FileExists(soName.c_str()))
  674. {
  675. cmSystemTools::RemoveFile(soName.c_str());
  676. }
  677. if(!cmSystemTools::CreateSymlink(fname.c_str(), soName.c_str()))
  678. {
  679. result = 1;
  680. }
  681. }
  682. if(name != soName)
  683. {
  684. std::string fname = cmSystemTools::GetFilenameName(soName);
  685. if(cmSystemTools::FileExists(soName.c_str()))
  686. {
  687. cmSystemTools::RemoveFile(name.c_str());
  688. }
  689. if(!cmSystemTools::CreateSymlink(fname.c_str(), name.c_str()))
  690. {
  691. result = 1;
  692. }
  693. }
  694. return 0;
  695. }
  696. #if defined(_WIN32) && !defined(__CYGWIN__)
  697. // Write registry value
  698. else if (args[1] == "write_regv" && args.size() > 3)
  699. {
  700. return cmSystemTools::WriteRegistryValue(args[2].c_str(),
  701. args[3].c_str()) ? 0 : 1;
  702. }
  703. // Delete registry value
  704. else if (args[1] == "delete_regv" && args.size() > 2)
  705. {
  706. return cmSystemTools::DeleteRegistryValue(args[2].c_str()) ? 0 : 1;
  707. }
  708. // Remove file
  709. else if (args[1] == "comspec" && args.size() > 2)
  710. {
  711. unsigned int cc;
  712. std::string command = args[2];
  713. for ( cc = 3; cc < args.size(); cc ++ )
  714. {
  715. command += " " + args[cc];
  716. }
  717. return cmWin32ProcessExecution::Windows9xHack(command.c_str());
  718. }
  719. #endif
  720. }
  721. ::CMakeCommandUsage(args[0].c_str());
  722. return 1;
  723. }
  724. void cmake::GetRegisteredGenerators(std::vector<std::string>& names)
  725. {
  726. for(RegisteredGeneratorsMap::const_iterator i = m_Generators.begin();
  727. i != m_Generators.end(); ++i)
  728. {
  729. names.push_back(i->first);
  730. }
  731. }
  732. cmGlobalGenerator* cmake::CreateGlobalGenerator(const char* name)
  733. {
  734. RegisteredGeneratorsMap::const_iterator i = m_Generators.find(name);
  735. if(i != m_Generators.end())
  736. {
  737. cmGlobalGenerator* generator = (i->second)();
  738. generator->SetCMakeInstance(this);
  739. return generator;
  740. }
  741. else
  742. {
  743. return 0;
  744. }
  745. }
  746. void cmake::SetHomeDirectory(const char* dir)
  747. {
  748. m_cmHomeDirectory = dir;
  749. cmSystemTools::ConvertToUnixSlashes(m_cmHomeDirectory);
  750. }
  751. void cmake::SetHomeOutputDirectory(const char* lib)
  752. {
  753. m_HomeOutputDirectory = lib;
  754. cmSystemTools::ConvertToUnixSlashes(m_HomeOutputDirectory);
  755. }
  756. void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
  757. {
  758. // delete the old generator
  759. if (m_GlobalGenerator)
  760. {
  761. delete m_GlobalGenerator;
  762. // restore the original environment variables CXX and CC
  763. // Restor CC
  764. static char envCC[5000];
  765. std::string env = "CC=";
  766. if(m_CCEnvironment)
  767. {
  768. env += m_CCEnvironment;
  769. }
  770. std::string::size_type size = env.size();
  771. if(size > 4999)
  772. {
  773. size = 4999;
  774. }
  775. strncpy(envCC, env.c_str(), size);
  776. envCC[4999] = 0;
  777. putenv(envCC);
  778. // Restore CXX
  779. static char envCXX[5000];
  780. env = "CXX=";
  781. if(m_CXXEnvironment)
  782. {
  783. env += m_CXXEnvironment;
  784. }
  785. size = env.size();
  786. if(size > 4999)
  787. {
  788. size = 4999;
  789. }
  790. strncpy(envCXX, env.c_str(), size);
  791. envCXX[4999] = 0;
  792. putenv(envCXX);
  793. }
  794. // set the new
  795. m_GlobalGenerator = gg;
  796. // set the global flag for unix style paths on cmSystemTools as
  797. // soon as the generator is set. This allows gmake to be used
  798. // on windows.
  799. cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
  800. // Save the environment variables CXX and CC
  801. m_CXXEnvironment = getenv("CXX");
  802. m_CCEnvironment = getenv("CC");
  803. // set the cmake instance just to be sure
  804. gg->SetCMakeInstance(this);
  805. }
  806. int cmake::DoPreConfigureChecks()
  807. {
  808. // Make sure the Start directory contains a CMakeLists.txt file.
  809. std::string srcList = this->GetHomeDirectory();
  810. srcList += "/CMakeLists.txt";
  811. if(!cmSystemTools::FileExists(srcList.c_str()))
  812. {
  813. cmOStringStream err;
  814. err << "The source directory \"" << this->GetHomeDirectory()
  815. << "\" does not appear to contain CMakeLists.txt.\n"
  816. << "Specify --help for usage, or press the help button on the CMake GUI.";
  817. cmSystemTools::Error(err.str().c_str());
  818. return -2;
  819. }
  820. // do a sanity check on some values
  821. if(m_CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY"))
  822. {
  823. std::string cacheStart =
  824. m_CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY");
  825. cacheStart += "/CMakeLists.txt";
  826. std::string currentStart = this->GetHomeDirectory();
  827. currentStart += "/CMakeLists.txt";
  828. if(!cmSystemTools::SameFile(cacheStart.c_str(), currentStart.c_str()))
  829. {
  830. std::string message = "The source \"";
  831. message += currentStart;
  832. message += "\" does not match the source \"";
  833. message += cacheStart;
  834. message += "\" used to generate cache. ";
  835. message += "Re-run cmake with a different source directory.";
  836. cmSystemTools::Error(message.c_str());
  837. return -2;
  838. }
  839. }
  840. else
  841. {
  842. return 0;
  843. }
  844. return 1;
  845. }
  846. int cmake::Configure()
  847. {
  848. int res = 0;
  849. if ( !m_ScriptMode )
  850. {
  851. res = this->DoPreConfigureChecks();
  852. }
  853. if ( res < 0 )
  854. {
  855. return -2;
  856. }
  857. if ( !res )
  858. {
  859. m_CacheManager->AddCacheEntry("CMAKE_HOME_DIRECTORY",
  860. this->GetHomeDirectory(),
  861. "Start directory with the top level CMakeLists.txt file for this project",
  862. cmCacheManager::INTERNAL);
  863. }
  864. // set the default BACKWARDS compatibility to the current version
  865. if(!m_CacheManager->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
  866. {
  867. char ver[256];
  868. sprintf(ver,"%i.%i",cmMakefile::GetMajorVersion(),
  869. cmMakefile::GetMinorVersion());
  870. this->m_CacheManager->AddCacheEntry
  871. ("CMAKE_BACKWARDS_COMPATIBILITY",ver,
  872. "For backwards compatibility, what version of CMake commands and syntax should this version of CMake allow.",
  873. cmCacheManager::STRING);
  874. }
  875. // no generator specified on the command line
  876. if(!m_GlobalGenerator)
  877. {
  878. const char* genName = m_CacheManager->GetCacheValue("CMAKE_GENERATOR");
  879. if(genName)
  880. {
  881. m_GlobalGenerator = this->CreateGlobalGenerator(genName);
  882. // set the global flag for unix style paths on cmSystemTools as
  883. // soon as the generator is set. This allows gmake to be used
  884. // on windows.
  885. cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
  886. }
  887. else
  888. {
  889. #if defined(__BORLANDC__) && defined(_WIN32)
  890. this->SetGlobalGenerator(new cmGlobalBorlandMakefileGenerator);
  891. #elif defined(_WIN32) && !defined(__CYGWIN__)
  892. this->SetGlobalGenerator(new cmGlobalVisualStudio6Generator);
  893. #else
  894. this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator);
  895. #endif
  896. }
  897. if(!m_GlobalGenerator)
  898. {
  899. cmSystemTools::Error("Could not create generator");
  900. return -1;
  901. }
  902. }
  903. const char* genName = m_CacheManager->GetCacheValue("CMAKE_GENERATOR");
  904. if(genName)
  905. {
  906. if(strcmp(m_GlobalGenerator->GetName(), genName) != 0)
  907. {
  908. std::string message = "Error: generator : ";
  909. message += m_GlobalGenerator->GetName();
  910. message += "\nDoes not match the generator used previously: ";
  911. message += genName;
  912. message +=
  913. "\nEither remove the CMakeCache.txt file or choose a different"
  914. " binary directory.";
  915. cmSystemTools::Error(message.c_str());
  916. return -2;
  917. }
  918. }
  919. if(!m_CacheManager->GetCacheValue("CMAKE_GENERATOR"))
  920. {
  921. m_CacheManager->AddCacheEntry("CMAKE_GENERATOR", m_GlobalGenerator->GetName(),
  922. "Name of generator.",
  923. cmCacheManager::INTERNAL);
  924. }
  925. // reset any system configuration information, except for when we are
  926. // InTryCompile. With TryCompile the system info is taken from the parent's
  927. // info to save time
  928. if (!m_InTryCompile)
  929. {
  930. m_GlobalGenerator->ClearEnabledLanguages();
  931. }
  932. // actually do the configure
  933. m_GlobalGenerator->Configure();
  934. // Before saving the cache
  935. // if the project did not define one of the entries below, add them now
  936. // so users can edit the values in the cache:
  937. // LIBRARY_OUTPUT_PATH
  938. // EXECUTABLE_OUTPUT_PATH
  939. if(!m_CacheManager->GetCacheValue("LIBRARY_OUTPUT_PATH"))
  940. {
  941. m_CacheManager->AddCacheEntry("LIBRARY_OUTPUT_PATH", "",
  942. "Single output directory for building all libraries.",
  943. cmCacheManager::PATH);
  944. }
  945. if(!m_CacheManager->GetCacheValue("EXECUTABLE_OUTPUT_PATH"))
  946. {
  947. m_CacheManager->AddCacheEntry("EXECUTABLE_OUTPUT_PATH", "",
  948. "Single output directory for building all executables.",
  949. cmCacheManager::PATH);
  950. }
  951. if(cmSystemTools::GetFatalErrorOccured() &&
  952. (!this->m_CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM") ||
  953. cmSystemTools::IsOff(this->m_CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM"))))
  954. {
  955. // We must have a bad generator selection. Wipe the cache entry so the
  956. // user can select another.
  957. m_CacheManager->RemoveCacheEntry("CMAKE_GENERATOR");
  958. }
  959. if ( !m_ScriptMode )
  960. {
  961. this->m_CacheManager->SaveCache(this->GetHomeOutputDirectory());
  962. }
  963. if(cmSystemTools::GetErrorOccuredFlag())
  964. {
  965. return -1;
  966. }
  967. return 0;
  968. }
  969. bool cmake::CacheVersionMatches()
  970. {
  971. const char* majv = m_CacheManager->GetCacheValue("CMAKE_CACHE_MAJOR_VERSION");
  972. const char* minv = m_CacheManager->GetCacheValue("CMAKE_CACHE_MINOR_VERSION");
  973. const char* relv = m_CacheManager->GetCacheValue("CMAKE_CACHE_RELEASE_VERSION");
  974. bool cacheSameCMake = false;
  975. if(majv &&
  976. atoi(majv) == static_cast<int>(cmMakefile::GetMajorVersion())
  977. && minv &&
  978. atoi(minv) == static_cast<int>(cmMakefile::GetMinorVersion())
  979. && relv && (strcmp(relv, cmMakefile::GetReleaseVersion()) == 0))
  980. {
  981. cacheSameCMake = true;
  982. }
  983. return cacheSameCMake;
  984. }
  985. // handle a command line invocation
  986. int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
  987. {
  988. // Process the arguments
  989. this->SetArgs(args);
  990. // set the cmake command
  991. m_CMakeCommand = args[0];
  992. if ( !m_ScriptMode )
  993. {
  994. // load the cache
  995. if(this->LoadCache() < 0)
  996. {
  997. cmSystemTools::Error("Error executing cmake::LoadCache(). Aborting.\n");
  998. return -1;
  999. }
  1000. }
  1001. // Add any cache args
  1002. if ( !this->SetCacheArgs(args) )
  1003. {
  1004. cmSystemTools::Error("Problem processing arguments. Aborting.\n");
  1005. return -1;
  1006. }
  1007. std::string systemFile = this->GetHomeOutputDirectory();
  1008. systemFile += "/CMakeSystem.cmake";
  1009. if ( noconfigure )
  1010. {
  1011. return 0;
  1012. }
  1013. int ret = 0;
  1014. // if not local or the cmake version has changed since the last run
  1015. // of cmake, or CMakeSystem.cmake file is not in the root binary
  1016. // directory, run a global generate
  1017. if(m_ScriptMode || !m_Local || !this->CacheVersionMatches() ||
  1018. !cmSystemTools::FileExists(systemFile.c_str()) )
  1019. {
  1020. // If we are doing global generate, we better set start and start
  1021. // output directory to the root of the project.
  1022. std::string oldstartdir = this->GetStartDirectory();
  1023. std::string oldstartoutputdir = this->GetStartOutputDirectory();
  1024. this->SetStartDirectory(this->GetHomeDirectory());
  1025. this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
  1026. bool saveLocalFlag = m_Local;
  1027. m_Local = false;
  1028. ret = this->Configure();
  1029. if (ret || m_ScriptMode)
  1030. {
  1031. return ret;
  1032. }
  1033. ret = this->Generate();
  1034. if(ret)
  1035. {
  1036. return ret;
  1037. }
  1038. m_Local = saveLocalFlag;
  1039. this->SetStartDirectory(oldstartdir.c_str());
  1040. this->SetStartOutputDirectory(oldstartoutputdir.c_str());
  1041. }
  1042. // if we are local do the local thing
  1043. if (m_Local)
  1044. {
  1045. ret = this->LocalGenerate();
  1046. }
  1047. return ret;
  1048. }
  1049. int cmake::Generate()
  1050. {
  1051. if(!m_GlobalGenerator)
  1052. {
  1053. return -1;
  1054. }
  1055. m_GlobalGenerator->Generate();
  1056. if(cmSystemTools::GetErrorOccuredFlag())
  1057. {
  1058. return -1;
  1059. }
  1060. return 0;
  1061. }
  1062. int cmake::LocalGenerate()
  1063. {
  1064. // Read in the cache
  1065. m_CacheManager->LoadCache(this->GetHomeOutputDirectory());
  1066. // create the generator based on the cache if it isn't already there
  1067. const char* genName = m_CacheManager->GetCacheValue("CMAKE_GENERATOR");
  1068. if(genName)
  1069. {
  1070. m_GlobalGenerator = this->CreateGlobalGenerator(genName);
  1071. // set the global flag for unix style paths on cmSystemTools as
  1072. // soon as the generator is set. This allows gmake to be used
  1073. // on windows.
  1074. cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
  1075. }
  1076. else
  1077. {
  1078. cmSystemTools::Error("Could local Generate called without the GENERATOR being specified in the CMakeCache");
  1079. return -1;
  1080. }
  1081. // do the local generate
  1082. m_GlobalGenerator->LocalGenerate();
  1083. if(cmSystemTools::GetErrorOccuredFlag())
  1084. {
  1085. return -1;
  1086. }
  1087. return 0;
  1088. }
  1089. unsigned int cmake::GetMajorVersion()
  1090. {
  1091. return cmMakefile::GetMajorVersion();
  1092. }
  1093. unsigned int cmake::GetMinorVersion()
  1094. {
  1095. return cmMakefile::GetMinorVersion();
  1096. }
  1097. const char *cmake::GetReleaseVersion()
  1098. {
  1099. return cmMakefile::GetReleaseVersion();
  1100. }
  1101. void cmake::AddCacheEntry(const char* key, const char* value,
  1102. const char* helpString,
  1103. int type)
  1104. {
  1105. m_CacheManager->AddCacheEntry(key, value,
  1106. helpString,
  1107. cmCacheManager::CacheEntryType(type));
  1108. }
  1109. const char* cmake::GetCacheDefinition(const char* name) const
  1110. {
  1111. return m_CacheManager->GetCacheValue(name);
  1112. }
  1113. int cmake::DumpDocumentationToFile(std::ostream& f)
  1114. {
  1115. // Loop over all registered commands and print out documentation
  1116. const char *name;
  1117. const char *terse;
  1118. const char *full;
  1119. char tmp[1024];
  1120. sprintf(tmp,"Version %d.%d", cmake::GetMajorVersion(),
  1121. cmake::GetMinorVersion());
  1122. f << "<html>\n";
  1123. f << "<h1>Documentation for commands of CMake " << tmp << "</h1>\n";
  1124. f << "<ul>\n";
  1125. for(RegisteredCommandsMap::iterator j = m_Commands.begin();
  1126. j != m_Commands.end(); ++j)
  1127. {
  1128. name = (*j).second->GetName();
  1129. terse = (*j).second->GetTerseDocumentation();
  1130. full = (*j).second->GetFullDocumentation();
  1131. f << "<li><b>" << name << "</b> - " << terse << std::endl
  1132. << "<br><i>Usage:</i> " << full << "</li>" << std::endl << std::endl;
  1133. }
  1134. f << "</ul></html>\n";
  1135. return 1;
  1136. }
  1137. void cmake::AddDefaultCommands()
  1138. {
  1139. std::list<cmCommand*> commands;
  1140. GetPredefinedCommands(commands);
  1141. for(std::list<cmCommand*>::iterator i = commands.begin();
  1142. i != commands.end(); ++i)
  1143. {
  1144. this->AddCommand(*i);
  1145. }
  1146. }
  1147. void cmake::AddDefaultGenerators()
  1148. {
  1149. #if defined(_WIN32) && !defined(__CYGWIN__)
  1150. m_Generators[cmGlobalVisualStudio6Generator::GetActualName()] =
  1151. &cmGlobalVisualStudio6Generator::New;
  1152. #if !defined(__MINGW32__)
  1153. m_Generators[cmGlobalVisualStudio7Generator::GetActualName()] =
  1154. &cmGlobalVisualStudio7Generator::New;
  1155. m_Generators[cmGlobalVisualStudio71Generator::GetActualName()] =
  1156. &cmGlobalVisualStudio71Generator::New;
  1157. #endif
  1158. m_Generators[cmGlobalBorlandMakefileGenerator::GetActualName()] =
  1159. &cmGlobalBorlandMakefileGenerator::New;
  1160. m_Generators[cmGlobalNMakeMakefileGenerator::GetActualName()] =
  1161. &cmGlobalNMakeMakefileGenerator::New;
  1162. #else
  1163. # if defined(__APPLE__) && defined(CMAKE_BUILD_WITH_CMAKE)
  1164. m_Generators[cmGlobalCodeWarriorGenerator::GetActualName()] =
  1165. &cmGlobalCodeWarriorGenerator::New;
  1166. # endif
  1167. #endif
  1168. m_Generators[cmGlobalUnixMakefileGenerator::GetActualName()] =
  1169. &cmGlobalUnixMakefileGenerator::New;
  1170. }
  1171. int cmake::LoadCache()
  1172. {
  1173. m_CacheManager->LoadCache(this->GetHomeOutputDirectory());
  1174. if (m_CMakeCommand.size() < 2)
  1175. {
  1176. cmSystemTools::Error("cmake command was not specified prior to loading the cache in cmake.cxx");
  1177. return -1;
  1178. }
  1179. // setup CMAKE_ROOT and CMAKE_COMMAND
  1180. if(!this->AddCMakePaths(m_CMakeCommand.c_str()))
  1181. {
  1182. return -3;
  1183. }
  1184. // set the default BACKWARDS compatibility to the current version
  1185. if(!m_CacheManager->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
  1186. {
  1187. char ver[256];
  1188. sprintf(ver,"%i.%i",cmMakefile::GetMajorVersion(),
  1189. cmMakefile::GetMinorVersion());
  1190. this->m_CacheManager->AddCacheEntry
  1191. ("CMAKE_BACKWARDS_COMPATIBILITY",ver,
  1192. "For backwards compatibility, what version of CMake commands and syntax should this version of CMake allow.",
  1193. cmCacheManager::STRING);
  1194. }
  1195. return 0;
  1196. }
  1197. void cmake::SetProgressCallback(ProgressCallback f, void *cd)
  1198. {
  1199. m_ProgressCallback = f;
  1200. m_ProgressCallbackClientData = cd;
  1201. }
  1202. void cmake::UpdateProgress(const char *msg, float prog)
  1203. {
  1204. if(m_ProgressCallback && !m_InTryCompile)
  1205. {
  1206. (*m_ProgressCallback)(msg, prog, m_ProgressCallbackClientData);
  1207. return;
  1208. }
  1209. }
  1210. void cmake::GetCommandDocumentation(std::vector<cmDocumentationEntry>& v) const
  1211. {
  1212. for(RegisteredCommandsMap::const_iterator j = m_Commands.begin();
  1213. j != m_Commands.end(); ++j)
  1214. {
  1215. cmDocumentationEntry e =
  1216. {
  1217. (*j).second->GetName(),
  1218. (*j).second->GetTerseDocumentation(),
  1219. (*j).second->GetFullDocumentation()
  1220. };
  1221. v.push_back(e);
  1222. }
  1223. cmDocumentationEntry empty = {0,0,0};
  1224. v.push_back(empty);
  1225. }
  1226. void cmake::GetGeneratorDocumentation(std::vector<cmDocumentationEntry>& v)
  1227. {
  1228. for(RegisteredGeneratorsMap::const_iterator i = m_Generators.begin();
  1229. i != m_Generators.end(); ++i)
  1230. {
  1231. cmDocumentationEntry e;
  1232. cmGlobalGenerator* generator = (i->second)();
  1233. generator->GetDocumentation(e);
  1234. delete generator;
  1235. v.push_back(e);
  1236. }
  1237. cmDocumentationEntry empty = {0,0,0};
  1238. v.push_back(empty);
  1239. }