cmake.cxx 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  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("-P",0) == 0)
  197. {
  198. std::string path = arg.substr(strlen("-P"));
  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. else
  368. {
  369. // Specified file or directory does not exist. Try to set things
  370. // up to produce a meaningful error message.
  371. std::string fullPath = cmSystemTools::CollapseFullPath(arg);
  372. std::string name = cmSystemTools::GetFilenameName(fullPath.c_str());
  373. name = cmSystemTools::LowerCase(name);
  374. if(name == "cmakecache.txt" || name == "cmakelists.txt")
  375. {
  376. argIsFile = true;
  377. listPath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  378. }
  379. else
  380. {
  381. listPath = fullPath;
  382. }
  383. }
  384. // If there is a CMakeCache.txt file, use its settings.
  385. if(cachePath.length() > 0)
  386. {
  387. cmCacheManager* cachem = this->GetCacheManager();
  388. cmCacheManager::CacheIterator it = cachem->NewIterator();
  389. if(cachem->LoadCache(cachePath.c_str()) && it.Find("CMAKE_HOME_DIRECTORY"))
  390. {
  391. this->SetHomeOutputDirectory(cachePath.c_str());
  392. this->SetStartOutputDirectory(cachePath.c_str());
  393. this->SetHomeDirectory(it.GetValue());
  394. this->SetStartDirectory(it.GetValue());
  395. return;
  396. }
  397. }
  398. // If there is a CMakeLists.txt file, use it as the source tree.
  399. if(listPath.length() > 0)
  400. {
  401. this->SetHomeDirectory(listPath.c_str());
  402. this->SetStartDirectory(listPath.c_str());
  403. if(argIsFile)
  404. {
  405. // Source CMakeLists.txt file given. It was probably dropped
  406. // onto the executable in a GUI. Default to an in-source build.
  407. this->SetHomeOutputDirectory(listPath.c_str());
  408. this->SetStartOutputDirectory(listPath.c_str());
  409. }
  410. else
  411. {
  412. // Source directory given on command line. Use current working
  413. // directory as build tree.
  414. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  415. this->SetHomeOutputDirectory(cwd.c_str());
  416. this->SetStartOutputDirectory(cwd.c_str());
  417. }
  418. return;
  419. }
  420. // We didn't find a CMakeLists.txt or CMakeCache.txt file from the
  421. // argument. Assume it is the path to the source tree, and use the
  422. // current working directory as the build tree.
  423. std::string full = cmSystemTools::CollapseFullPath(arg);
  424. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  425. this->SetHomeDirectory(full.c_str());
  426. this->SetStartDirectory(full.c_str());
  427. this->SetHomeOutputDirectory(cwd.c_str());
  428. this->SetStartOutputDirectory(cwd.c_str());
  429. }
  430. // at the end of this CMAKE_ROOT and CMAKE_COMMAND should be added to the cache
  431. int cmake::AddCMakePaths(const char *arg0)
  432. {
  433. // Find our own executable.
  434. std::vector<cmStdString> failures;
  435. std::string cMakeSelf = arg0;
  436. cmSystemTools::ConvertToUnixSlashes(cMakeSelf);
  437. failures.push_back(cMakeSelf);
  438. cMakeSelf = cmSystemTools::FindProgram(cMakeSelf.c_str());
  439. if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
  440. {
  441. #ifdef CMAKE_BUILD_DIR
  442. std::string intdir = ".";
  443. #ifdef CMAKE_INTDIR
  444. intdir = CMAKE_INTDIR;
  445. #endif
  446. cMakeSelf = CMAKE_BUILD_DIR;
  447. cMakeSelf += "/bin/";
  448. cMakeSelf += intdir;
  449. cMakeSelf += "/cmake";
  450. cMakeSelf += cmSystemTools::GetExecutableExtension();
  451. #endif
  452. }
  453. #ifdef CMAKE_PREFIX
  454. if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
  455. {
  456. failures.push_back(cMakeSelf);
  457. cMakeSelf = CMAKE_PREFIX "/bin/cmake";
  458. }
  459. #endif
  460. if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
  461. {
  462. failures.push_back(cMakeSelf);
  463. cmOStringStream msg;
  464. msg << "CMAKE can not find the command line program cmake.\n";
  465. msg << " argv[0] = \"" << arg0 << "\"\n";
  466. msg << " Attempted paths:\n";
  467. std::vector<cmStdString>::iterator i;
  468. for(i=failures.begin(); i != failures.end(); ++i)
  469. {
  470. msg << " \"" << i->c_str() << "\"\n";
  471. }
  472. cmSystemTools::Error(msg.str().c_str());
  473. return 0;
  474. }
  475. // Save the value in the cache
  476. this->m_CacheManager->AddCacheEntry
  477. ("CMAKE_COMMAND",cMakeSelf.c_str(), "Path to CMake executable.",
  478. cmCacheManager::INTERNAL);
  479. // Find and save the command to edit the cache
  480. std::string editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  481. "/ccmake" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  482. if( !cmSystemTools::FileExists(editCacheCommand.c_str()))
  483. {
  484. editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  485. "/CMakeSetup" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  486. }
  487. if(cmSystemTools::FileExists(editCacheCommand.c_str()))
  488. {
  489. this->m_CacheManager->AddCacheEntry
  490. ("CMAKE_EDIT_COMMAND", editCacheCommand.c_str(),
  491. "Path to cache edit program executable.", cmCacheManager::INTERNAL);
  492. }
  493. // do CMAKE_ROOT, look for the environment variable first
  494. std::string cMakeRoot;
  495. std::string modules;
  496. if (getenv("CMAKE_ROOT"))
  497. {
  498. cMakeRoot = getenv("CMAKE_ROOT");
  499. modules = cMakeRoot + "/Modules/CMakeDefaultMakeRuleVariables.cmake";
  500. }
  501. if(!cmSystemTools::FileExists(modules.c_str()))
  502. {
  503. // next try exe/..
  504. cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
  505. std::string::size_type slashPos = cMakeRoot.rfind("/");
  506. if(slashPos != std::string::npos)
  507. {
  508. cMakeRoot = cMakeRoot.substr(0, slashPos);
  509. }
  510. // is there no Modules direcory there?
  511. modules = cMakeRoot + "/Modules/CMakeDefaultMakeRuleVariables.cmake";
  512. }
  513. if (!cmSystemTools::FileExists(modules.c_str()))
  514. {
  515. // try exe/../share/cmake
  516. cMakeRoot += CMAKE_DATA_DIR;
  517. modules = cMakeRoot + "/Modules/CMakeDefaultMakeRuleVariables.cmake";
  518. }
  519. #ifdef CMAKE_ROOT_DIR
  520. if (!cmSystemTools::FileExists(modules.c_str()))
  521. {
  522. // try compiled in root directory
  523. cMakeRoot = CMAKE_ROOT_DIR;
  524. modules = cMakeRoot + "/Modules/CMakeDefaultMakeRuleVariables.cmake";
  525. }
  526. #endif
  527. #ifdef CMAKE_PREFIX
  528. if (!cmSystemTools::FileExists(modules.c_str()))
  529. {
  530. // try compiled in install prefix
  531. cMakeRoot = CMAKE_PREFIX CMAKE_DATA_DIR;
  532. modules = cMakeRoot + "/Modules/CMakeDefaultMakeRuleVariables.cmake";
  533. }
  534. #endif
  535. if (!cmSystemTools::FileExists(modules.c_str()))
  536. {
  537. // try
  538. cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
  539. cMakeRoot += CMAKE_DATA_DIR;
  540. modules = cMakeRoot + "/Modules/CMakeDefaultMakeRuleVariables.cmake";
  541. }
  542. if(!cmSystemTools::FileExists(modules.c_str()))
  543. {
  544. // next try exe
  545. cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
  546. // is there no Modules direcory there?
  547. modules = cMakeRoot + "/Modules/CMakeDefaultMakeRuleVariables.cmake";
  548. }
  549. if (!cmSystemTools::FileExists(modules.c_str()))
  550. {
  551. // couldn't find modules
  552. cmSystemTools::Error("Could not find CMAKE_ROOT !!!\n"
  553. "CMake has most likely not been installed correctly.\n"
  554. "Modules directory not found in\n",
  555. cMakeRoot.c_str());
  556. return 0;
  557. }
  558. this->m_CacheManager->AddCacheEntry
  559. ("CMAKE_ROOT", cMakeRoot.c_str(),
  560. "Path to CMake installation.", cmCacheManager::INTERNAL);
  561. #ifdef _WIN32
  562. std::string comspec = "cmw9xcom.exe";
  563. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  564. #endif
  565. return 1;
  566. }
  567. void CMakeCommandUsage(const char* program)
  568. {
  569. cmOStringStream errorStream;
  570. errorStream
  571. << "cmake version " << cmMakefile::GetMajorVersion()
  572. << "." << cmMakefile::GetMinorVersion() << "\n";
  573. errorStream
  574. << "Usage: " << program << " -E [command] [arguments ...]\n"
  575. << "Available commands: \n"
  576. << " chdir dir cmd [args]... - run command in a given directory\n"
  577. << " copy file destination - copy file to destination (either file or directory)\n"
  578. << " copy_if_different in-file out-file - copy file if input has changed\n"
  579. << " echo [string]... - displays arguments as text\n"
  580. << " remove file1 file2 ... - remove the file(s)\n"
  581. << " time command [args] ... - run command and return elapsed time\n";
  582. #if defined(_WIN32) && !defined(__CYGWIN__)
  583. errorStream
  584. << " write_regv key value - write registry value\n"
  585. << " delete_regv key - delete registry value\n"
  586. << " comspec - on windows 9x use this for RunCommand\n";
  587. #endif
  588. cmSystemTools::Error(errorStream.str().c_str());
  589. }
  590. int cmake::CMakeCommand(std::vector<std::string>& args)
  591. {
  592. if (args.size() > 1)
  593. {
  594. // Copy file
  595. if (args[1] == "copy" && args.size() == 4)
  596. {
  597. cmSystemTools::cmCopyFile(args[2].c_str(), args[3].c_str());
  598. return cmSystemTools::GetErrorOccuredFlag();
  599. }
  600. // Copy file if different.
  601. if (args[1] == "copy_if_different" && args.size() == 4)
  602. {
  603. cmSystemTools::CopyFileIfDifferent(args[2].c_str(), args[3].c_str());
  604. return cmSystemTools::GetErrorOccuredFlag();
  605. }
  606. // Echo string
  607. else if (args[1] == "echo" )
  608. {
  609. unsigned int cc;
  610. for ( cc = 2; cc < args.size(); cc ++ )
  611. {
  612. std::cout << args[cc] << " ";
  613. }
  614. std::cout << std::endl;
  615. return 0;
  616. }
  617. // Remove file
  618. else if (args[1] == "remove" && args.size() > 2)
  619. {
  620. for (std::string::size_type cc = 2; cc < args.size(); cc ++)
  621. {
  622. if(args[cc] != "-f")
  623. {
  624. if(args[cc] == "\\-f")
  625. {
  626. args[cc] = "-f";
  627. }
  628. cmSystemTools::RemoveFile(args[cc].c_str());
  629. }
  630. }
  631. return 0;
  632. }
  633. // Clock command
  634. else if (args[1] == "time" && args.size() > 2)
  635. {
  636. std::string command = args[2];
  637. for (std::string::size_type cc = 3; cc < args.size(); cc ++)
  638. {
  639. command += " ";
  640. command += args[cc];
  641. }
  642. clock_t clock_start, clock_finish;
  643. time_t time_start, time_finish;
  644. time(&time_start);
  645. clock_start = clock();
  646. cmSystemTools::RunSingleCommand(command.c_str());
  647. clock_finish = clock();
  648. time(&time_finish);
  649. double clocks_per_sec = (double)CLOCKS_PER_SEC;
  650. std::cout << "Elapsed time: "
  651. << (long)(time_finish - time_start) << " s. (time)"
  652. << ", "
  653. << (double)(clock_finish - clock_start) / clocks_per_sec
  654. << " s. (clock)"
  655. << "\n";
  656. return 0;
  657. }
  658. // Clock command
  659. else if (args[1] == "chdir" && args.size() >= 4)
  660. {
  661. std::string directory = args[2];
  662. std::string command = "\"";
  663. command += args[3];
  664. command += "\"";
  665. for (std::string::size_type cc = 4; cc < args.size(); cc ++)
  666. {
  667. command += " \"";
  668. command += args[cc];
  669. command += "\"";
  670. }
  671. int retval = 0;
  672. int timeout = 0;
  673. if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, &retval,
  674. directory.c_str(), true, timeout) )
  675. {
  676. return retval;
  677. }
  678. return 1;
  679. }
  680. // Internal CMake shared library support.
  681. else if (args[1] == "cmake_symlink_library" && args.size() == 5)
  682. {
  683. int result = 0;
  684. std::string realName = args[2];
  685. std::string soName = args[3];
  686. std::string name = args[4];
  687. if(soName != realName)
  688. {
  689. std::string fname = cmSystemTools::GetFilenameName(realName);
  690. if(cmSystemTools::FileExists(soName.c_str()))
  691. {
  692. cmSystemTools::RemoveFile(soName.c_str());
  693. }
  694. if(!cmSystemTools::CreateSymlink(fname.c_str(), soName.c_str()))
  695. {
  696. result = 1;
  697. }
  698. }
  699. if(name != soName)
  700. {
  701. std::string fname = cmSystemTools::GetFilenameName(soName);
  702. if(cmSystemTools::FileExists(soName.c_str()))
  703. {
  704. cmSystemTools::RemoveFile(name.c_str());
  705. }
  706. if(!cmSystemTools::CreateSymlink(fname.c_str(), name.c_str()))
  707. {
  708. result = 1;
  709. }
  710. }
  711. return result;
  712. }
  713. #if defined(_WIN32) && !defined(__CYGWIN__)
  714. // Write registry value
  715. else if (args[1] == "write_regv" && args.size() > 3)
  716. {
  717. return cmSystemTools::WriteRegistryValue(args[2].c_str(),
  718. args[3].c_str()) ? 0 : 1;
  719. }
  720. // Delete registry value
  721. else if (args[1] == "delete_regv" && args.size() > 2)
  722. {
  723. return cmSystemTools::DeleteRegistryValue(args[2].c_str()) ? 0 : 1;
  724. }
  725. // Remove file
  726. else if (args[1] == "comspec" && args.size() > 2)
  727. {
  728. unsigned int cc;
  729. std::string command = args[2];
  730. for ( cc = 3; cc < args.size(); cc ++ )
  731. {
  732. command += " " + args[cc];
  733. }
  734. return cmWin32ProcessExecution::Windows9xHack(command.c_str());
  735. }
  736. #endif
  737. }
  738. ::CMakeCommandUsage(args[0].c_str());
  739. return 1;
  740. }
  741. void cmake::GetRegisteredGenerators(std::vector<std::string>& names)
  742. {
  743. for(RegisteredGeneratorsMap::const_iterator i = m_Generators.begin();
  744. i != m_Generators.end(); ++i)
  745. {
  746. names.push_back(i->first);
  747. }
  748. }
  749. cmGlobalGenerator* cmake::CreateGlobalGenerator(const char* name)
  750. {
  751. RegisteredGeneratorsMap::const_iterator i = m_Generators.find(name);
  752. if(i != m_Generators.end())
  753. {
  754. cmGlobalGenerator* generator = (i->second)();
  755. generator->SetCMakeInstance(this);
  756. return generator;
  757. }
  758. else
  759. {
  760. return 0;
  761. }
  762. }
  763. void cmake::SetHomeDirectory(const char* dir)
  764. {
  765. m_cmHomeDirectory = dir;
  766. cmSystemTools::ConvertToUnixSlashes(m_cmHomeDirectory);
  767. }
  768. void cmake::SetHomeOutputDirectory(const char* lib)
  769. {
  770. m_HomeOutputDirectory = lib;
  771. cmSystemTools::ConvertToUnixSlashes(m_HomeOutputDirectory);
  772. }
  773. void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
  774. {
  775. // delete the old generator
  776. if (m_GlobalGenerator)
  777. {
  778. delete m_GlobalGenerator;
  779. // restore the original environment variables CXX and CC
  780. // Restor CC
  781. static char envCC[5000];
  782. std::string env = "CC=";
  783. if(m_CCEnvironment)
  784. {
  785. env += m_CCEnvironment;
  786. }
  787. std::string::size_type size = env.size();
  788. if(size > 4999)
  789. {
  790. size = 4999;
  791. }
  792. strncpy(envCC, env.c_str(), size);
  793. envCC[4999] = 0;
  794. putenv(envCC);
  795. // Restore CXX
  796. static char envCXX[5000];
  797. env = "CXX=";
  798. if(m_CXXEnvironment)
  799. {
  800. env += m_CXXEnvironment;
  801. }
  802. size = env.size();
  803. if(size > 4999)
  804. {
  805. size = 4999;
  806. }
  807. strncpy(envCXX, env.c_str(), size);
  808. envCXX[4999] = 0;
  809. putenv(envCXX);
  810. }
  811. // set the new
  812. m_GlobalGenerator = gg;
  813. // set the global flag for unix style paths on cmSystemTools as
  814. // soon as the generator is set. This allows gmake to be used
  815. // on windows.
  816. cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
  817. // Save the environment variables CXX and CC
  818. m_CXXEnvironment = getenv("CXX");
  819. m_CCEnvironment = getenv("CC");
  820. // set the cmake instance just to be sure
  821. gg->SetCMakeInstance(this);
  822. }
  823. int cmake::DoPreConfigureChecks()
  824. {
  825. // Make sure the Start directory contains a CMakeLists.txt file.
  826. std::string srcList = this->GetHomeDirectory();
  827. srcList += "/CMakeLists.txt";
  828. if(!cmSystemTools::FileExists(srcList.c_str()))
  829. {
  830. cmOStringStream err;
  831. if(cmSystemTools::FileIsDirectory(this->GetHomeDirectory()))
  832. {
  833. err << "The source directory \"" << this->GetHomeDirectory()
  834. << "\" does not appear to contain CMakeLists.txt.\n";
  835. }
  836. else if(cmSystemTools::FileExists(this->GetHomeDirectory()))
  837. {
  838. err << "The source directory \"" << this->GetHomeDirectory()
  839. << "\" is a file, not a directory.\n";
  840. }
  841. else
  842. {
  843. err << "The source directory \"" << this->GetHomeDirectory()
  844. << "\" does not exist.\n";
  845. }
  846. err << "Specify --help for usage, or press the help button on the CMake GUI.";
  847. cmSystemTools::Error(err.str().c_str());
  848. return -2;
  849. }
  850. // do a sanity check on some values
  851. if(m_CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY"))
  852. {
  853. std::string cacheStart =
  854. m_CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY");
  855. cacheStart += "/CMakeLists.txt";
  856. std::string currentStart = this->GetHomeDirectory();
  857. currentStart += "/CMakeLists.txt";
  858. if(!cmSystemTools::SameFile(cacheStart.c_str(), currentStart.c_str()))
  859. {
  860. std::string message = "The source \"";
  861. message += currentStart;
  862. message += "\" does not match the source \"";
  863. message += cacheStart;
  864. message += "\" used to generate cache. ";
  865. message += "Re-run cmake with a different source directory.";
  866. cmSystemTools::Error(message.c_str());
  867. return -2;
  868. }
  869. }
  870. else
  871. {
  872. return 0;
  873. }
  874. return 1;
  875. }
  876. int cmake::Configure()
  877. {
  878. int res = 0;
  879. if ( !m_ScriptMode )
  880. {
  881. res = this->DoPreConfigureChecks();
  882. }
  883. if ( res < 0 )
  884. {
  885. return -2;
  886. }
  887. if ( !res )
  888. {
  889. m_CacheManager->AddCacheEntry("CMAKE_HOME_DIRECTORY",
  890. this->GetHomeDirectory(),
  891. "Start directory with the top level CMakeLists.txt file for this project",
  892. cmCacheManager::INTERNAL);
  893. }
  894. // set the default BACKWARDS compatibility to the current version
  895. if(!m_CacheManager->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
  896. {
  897. char ver[256];
  898. sprintf(ver,"%i.%i",cmMakefile::GetMajorVersion(),
  899. cmMakefile::GetMinorVersion());
  900. this->m_CacheManager->AddCacheEntry
  901. ("CMAKE_BACKWARDS_COMPATIBILITY",ver,
  902. "For backwards compatibility, what version of CMake commands and syntax should this version of CMake allow.",
  903. cmCacheManager::STRING);
  904. }
  905. // no generator specified on the command line
  906. if(!m_GlobalGenerator)
  907. {
  908. const char* genName = m_CacheManager->GetCacheValue("CMAKE_GENERATOR");
  909. if(genName)
  910. {
  911. m_GlobalGenerator = this->CreateGlobalGenerator(genName);
  912. // set the global flag for unix style paths on cmSystemTools as
  913. // soon as the generator is set. This allows gmake to be used
  914. // on windows.
  915. cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
  916. }
  917. else
  918. {
  919. #if defined(__BORLANDC__) && defined(_WIN32)
  920. this->SetGlobalGenerator(new cmGlobalBorlandMakefileGenerator);
  921. #elif defined(_WIN32) && !defined(__CYGWIN__)
  922. this->SetGlobalGenerator(new cmGlobalVisualStudio6Generator);
  923. #else
  924. this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator);
  925. #endif
  926. }
  927. if(!m_GlobalGenerator)
  928. {
  929. cmSystemTools::Error("Could not create generator");
  930. return -1;
  931. }
  932. }
  933. const char* genName = m_CacheManager->GetCacheValue("CMAKE_GENERATOR");
  934. if(genName)
  935. {
  936. if(strcmp(m_GlobalGenerator->GetName(), genName) != 0)
  937. {
  938. std::string message = "Error: generator : ";
  939. message += m_GlobalGenerator->GetName();
  940. message += "\nDoes not match the generator used previously: ";
  941. message += genName;
  942. message +=
  943. "\nEither remove the CMakeCache.txt file or choose a different"
  944. " binary directory.";
  945. cmSystemTools::Error(message.c_str());
  946. return -2;
  947. }
  948. }
  949. if(!m_CacheManager->GetCacheValue("CMAKE_GENERATOR"))
  950. {
  951. m_CacheManager->AddCacheEntry("CMAKE_GENERATOR", m_GlobalGenerator->GetName(),
  952. "Name of generator.",
  953. cmCacheManager::INTERNAL);
  954. }
  955. // reset any system configuration information, except for when we are
  956. // InTryCompile. With TryCompile the system info is taken from the parent's
  957. // info to save time
  958. if (!m_InTryCompile)
  959. {
  960. m_GlobalGenerator->ClearEnabledLanguages();
  961. }
  962. // actually do the configure
  963. m_GlobalGenerator->Configure();
  964. // Before saving the cache
  965. // if the project did not define one of the entries below, add them now
  966. // so users can edit the values in the cache:
  967. // LIBRARY_OUTPUT_PATH
  968. // EXECUTABLE_OUTPUT_PATH
  969. if(!m_CacheManager->GetCacheValue("LIBRARY_OUTPUT_PATH"))
  970. {
  971. m_CacheManager->AddCacheEntry("LIBRARY_OUTPUT_PATH", "",
  972. "Single output directory for building all libraries.",
  973. cmCacheManager::PATH);
  974. }
  975. if(!m_CacheManager->GetCacheValue("EXECUTABLE_OUTPUT_PATH"))
  976. {
  977. m_CacheManager->AddCacheEntry("EXECUTABLE_OUTPUT_PATH", "",
  978. "Single output directory for building all executables.",
  979. cmCacheManager::PATH);
  980. }
  981. if(cmSystemTools::GetFatalErrorOccured() &&
  982. (!this->m_CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM") ||
  983. cmSystemTools::IsOff(this->m_CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM"))))
  984. {
  985. // We must have a bad generator selection. Wipe the cache entry so the
  986. // user can select another.
  987. m_CacheManager->RemoveCacheEntry("CMAKE_GENERATOR");
  988. }
  989. if ( !m_ScriptMode )
  990. {
  991. this->m_CacheManager->SaveCache(this->GetHomeOutputDirectory());
  992. }
  993. if(cmSystemTools::GetErrorOccuredFlag())
  994. {
  995. return -1;
  996. }
  997. return 0;
  998. }
  999. bool cmake::CacheVersionMatches()
  1000. {
  1001. const char* majv = m_CacheManager->GetCacheValue("CMAKE_CACHE_MAJOR_VERSION");
  1002. const char* minv = m_CacheManager->GetCacheValue("CMAKE_CACHE_MINOR_VERSION");
  1003. const char* relv = m_CacheManager->GetCacheValue("CMAKE_CACHE_RELEASE_VERSION");
  1004. bool cacheSameCMake = false;
  1005. if(majv &&
  1006. atoi(majv) == static_cast<int>(cmMakefile::GetMajorVersion())
  1007. && minv &&
  1008. atoi(minv) == static_cast<int>(cmMakefile::GetMinorVersion())
  1009. && relv && (strcmp(relv, cmMakefile::GetReleaseVersion()) == 0))
  1010. {
  1011. cacheSameCMake = true;
  1012. }
  1013. return cacheSameCMake;
  1014. }
  1015. // handle a command line invocation
  1016. int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
  1017. {
  1018. // Process the arguments
  1019. this->SetArgs(args);
  1020. // set the cmake command
  1021. m_CMakeCommand = args[0];
  1022. if ( !m_ScriptMode )
  1023. {
  1024. // load the cache
  1025. if(this->LoadCache() < 0)
  1026. {
  1027. cmSystemTools::Error("Error executing cmake::LoadCache(). Aborting.\n");
  1028. return -1;
  1029. }
  1030. }
  1031. // Add any cache args
  1032. if ( !this->SetCacheArgs(args) )
  1033. {
  1034. cmSystemTools::Error("Problem processing arguments. Aborting.\n");
  1035. return -1;
  1036. }
  1037. std::string systemFile = this->GetHomeOutputDirectory();
  1038. systemFile += "/CMakeSystem.cmake";
  1039. if ( noconfigure )
  1040. {
  1041. return 0;
  1042. }
  1043. int ret = 0;
  1044. // if not local or the cmake version has changed since the last run
  1045. // of cmake, or CMakeSystem.cmake file is not in the root binary
  1046. // directory, run a global generate
  1047. if(m_ScriptMode || !m_Local || !this->CacheVersionMatches() ||
  1048. !cmSystemTools::FileExists(systemFile.c_str()) )
  1049. {
  1050. // If we are doing global generate, we better set start and start
  1051. // output directory to the root of the project.
  1052. std::string oldstartdir = this->GetStartDirectory();
  1053. std::string oldstartoutputdir = this->GetStartOutputDirectory();
  1054. this->SetStartDirectory(this->GetHomeDirectory());
  1055. this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
  1056. bool saveLocalFlag = m_Local;
  1057. m_Local = false;
  1058. ret = this->Configure();
  1059. if (ret || m_ScriptMode)
  1060. {
  1061. return ret;
  1062. }
  1063. ret = this->Generate();
  1064. if(ret)
  1065. {
  1066. return ret;
  1067. }
  1068. m_Local = saveLocalFlag;
  1069. this->SetStartDirectory(oldstartdir.c_str());
  1070. this->SetStartOutputDirectory(oldstartoutputdir.c_str());
  1071. }
  1072. // if we are local do the local thing
  1073. if (m_Local)
  1074. {
  1075. ret = this->LocalGenerate();
  1076. }
  1077. return ret;
  1078. }
  1079. int cmake::Generate()
  1080. {
  1081. if(!m_GlobalGenerator)
  1082. {
  1083. return -1;
  1084. }
  1085. m_GlobalGenerator->Generate();
  1086. if(cmSystemTools::GetErrorOccuredFlag())
  1087. {
  1088. return -1;
  1089. }
  1090. return 0;
  1091. }
  1092. int cmake::LocalGenerate()
  1093. {
  1094. // Read in the cache
  1095. m_CacheManager->LoadCache(this->GetHomeOutputDirectory());
  1096. // create the generator based on the cache if it isn't already there
  1097. const char* genName = m_CacheManager->GetCacheValue("CMAKE_GENERATOR");
  1098. if(genName)
  1099. {
  1100. m_GlobalGenerator = this->CreateGlobalGenerator(genName);
  1101. // set the global flag for unix style paths on cmSystemTools as
  1102. // soon as the generator is set. This allows gmake to be used
  1103. // on windows.
  1104. cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
  1105. }
  1106. else
  1107. {
  1108. cmSystemTools::Error("Could local Generate called without the GENERATOR being specified in the CMakeCache");
  1109. return -1;
  1110. }
  1111. // do the local generate
  1112. m_GlobalGenerator->LocalGenerate();
  1113. if(cmSystemTools::GetErrorOccuredFlag())
  1114. {
  1115. return -1;
  1116. }
  1117. return 0;
  1118. }
  1119. unsigned int cmake::GetMajorVersion()
  1120. {
  1121. return cmMakefile::GetMajorVersion();
  1122. }
  1123. unsigned int cmake::GetMinorVersion()
  1124. {
  1125. return cmMakefile::GetMinorVersion();
  1126. }
  1127. const char *cmake::GetReleaseVersion()
  1128. {
  1129. return cmMakefile::GetReleaseVersion();
  1130. }
  1131. void cmake::AddCacheEntry(const char* key, const char* value,
  1132. const char* helpString,
  1133. int type)
  1134. {
  1135. m_CacheManager->AddCacheEntry(key, value,
  1136. helpString,
  1137. cmCacheManager::CacheEntryType(type));
  1138. }
  1139. const char* cmake::GetCacheDefinition(const char* name) const
  1140. {
  1141. return m_CacheManager->GetCacheValue(name);
  1142. }
  1143. int cmake::DumpDocumentationToFile(std::ostream& f)
  1144. {
  1145. // Loop over all registered commands and print out documentation
  1146. const char *name;
  1147. const char *terse;
  1148. const char *full;
  1149. char tmp[1024];
  1150. sprintf(tmp,"Version %d.%d", cmake::GetMajorVersion(),
  1151. cmake::GetMinorVersion());
  1152. f << "<html>\n";
  1153. f << "<h1>Documentation for commands of CMake " << tmp << "</h1>\n";
  1154. f << "<ul>\n";
  1155. for(RegisteredCommandsMap::iterator j = m_Commands.begin();
  1156. j != m_Commands.end(); ++j)
  1157. {
  1158. name = (*j).second->GetName();
  1159. terse = (*j).second->GetTerseDocumentation();
  1160. full = (*j).second->GetFullDocumentation();
  1161. f << "<li><b>" << name << "</b> - " << terse << std::endl
  1162. << "<br><i>Usage:</i> " << full << "</li>" << std::endl << std::endl;
  1163. }
  1164. f << "</ul></html>\n";
  1165. return 1;
  1166. }
  1167. void cmake::AddDefaultCommands()
  1168. {
  1169. std::list<cmCommand*> commands;
  1170. GetPredefinedCommands(commands);
  1171. for(std::list<cmCommand*>::iterator i = commands.begin();
  1172. i != commands.end(); ++i)
  1173. {
  1174. this->AddCommand(*i);
  1175. }
  1176. }
  1177. void cmake::AddDefaultGenerators()
  1178. {
  1179. #if defined(_WIN32) && !defined(__CYGWIN__)
  1180. m_Generators[cmGlobalVisualStudio6Generator::GetActualName()] =
  1181. &cmGlobalVisualStudio6Generator::New;
  1182. #if !defined(__MINGW32__)
  1183. m_Generators[cmGlobalVisualStudio7Generator::GetActualName()] =
  1184. &cmGlobalVisualStudio7Generator::New;
  1185. m_Generators[cmGlobalVisualStudio71Generator::GetActualName()] =
  1186. &cmGlobalVisualStudio71Generator::New;
  1187. #endif
  1188. m_Generators[cmGlobalBorlandMakefileGenerator::GetActualName()] =
  1189. &cmGlobalBorlandMakefileGenerator::New;
  1190. m_Generators[cmGlobalNMakeMakefileGenerator::GetActualName()] =
  1191. &cmGlobalNMakeMakefileGenerator::New;
  1192. #else
  1193. # if defined(__APPLE__) && defined(CMAKE_BUILD_WITH_CMAKE)
  1194. m_Generators[cmGlobalCodeWarriorGenerator::GetActualName()] =
  1195. &cmGlobalCodeWarriorGenerator::New;
  1196. # endif
  1197. #endif
  1198. m_Generators[cmGlobalUnixMakefileGenerator::GetActualName()] =
  1199. &cmGlobalUnixMakefileGenerator::New;
  1200. }
  1201. int cmake::LoadCache()
  1202. {
  1203. m_CacheManager->LoadCache(this->GetHomeOutputDirectory());
  1204. if (m_CMakeCommand.size() < 2)
  1205. {
  1206. cmSystemTools::Error("cmake command was not specified prior to loading the cache in cmake.cxx");
  1207. return -1;
  1208. }
  1209. // setup CMAKE_ROOT and CMAKE_COMMAND
  1210. if(!this->AddCMakePaths(m_CMakeCommand.c_str()))
  1211. {
  1212. return -3;
  1213. }
  1214. // set the default BACKWARDS compatibility to the current version
  1215. if(!m_CacheManager->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
  1216. {
  1217. char ver[256];
  1218. sprintf(ver,"%i.%i",cmMakefile::GetMajorVersion(),
  1219. cmMakefile::GetMinorVersion());
  1220. this->m_CacheManager->AddCacheEntry
  1221. ("CMAKE_BACKWARDS_COMPATIBILITY",ver,
  1222. "For backwards compatibility, what version of CMake commands and syntax should this version of CMake allow.",
  1223. cmCacheManager::STRING);
  1224. }
  1225. return 0;
  1226. }
  1227. void cmake::SetProgressCallback(ProgressCallback f, void *cd)
  1228. {
  1229. m_ProgressCallback = f;
  1230. m_ProgressCallbackClientData = cd;
  1231. }
  1232. void cmake::UpdateProgress(const char *msg, float prog)
  1233. {
  1234. if(m_ProgressCallback && !m_InTryCompile)
  1235. {
  1236. (*m_ProgressCallback)(msg, prog, m_ProgressCallbackClientData);
  1237. return;
  1238. }
  1239. }
  1240. void cmake::GetCommandDocumentation(std::vector<cmDocumentationEntry>& v) const
  1241. {
  1242. for(RegisteredCommandsMap::const_iterator j = m_Commands.begin();
  1243. j != m_Commands.end(); ++j)
  1244. {
  1245. cmDocumentationEntry e =
  1246. {
  1247. (*j).second->GetName(),
  1248. (*j).second->GetTerseDocumentation(),
  1249. (*j).second->GetFullDocumentation()
  1250. };
  1251. v.push_back(e);
  1252. }
  1253. cmDocumentationEntry empty = {0,0,0};
  1254. v.push_back(empty);
  1255. }
  1256. void cmake::GetGeneratorDocumentation(std::vector<cmDocumentationEntry>& v)
  1257. {
  1258. for(RegisteredGeneratorsMap::const_iterator i = m_Generators.begin();
  1259. i != m_Generators.end(); ++i)
  1260. {
  1261. cmDocumentationEntry e;
  1262. cmGlobalGenerator* generator = (i->second)();
  1263. generator->GetDocumentation(e);
  1264. delete generator;
  1265. v.push_back(e);
  1266. }
  1267. cmDocumentationEntry empty = {0,0,0};
  1268. v.push_back(empty);
  1269. }