cmake.cxx 41 KB

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