cmake.cxx 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmake.h"
  11. #include "cmCacheManager.h"
  12. #include "cmMakefile.h"
  13. #include "cmLocalGenerator.h"
  14. #include "cmExternalMakefileProjectGenerator.h"
  15. #include "cmCommands.h"
  16. #include "cmCommand.h"
  17. #include "cmFileTimeComparison.h"
  18. #include "cmSourceFile.h"
  19. #include "cmTest.h"
  20. #include "cmDocumentationFormatter.h"
  21. #include "cmAlgorithms.h"
  22. #include "cmState.h"
  23. #if defined(CMAKE_BUILD_WITH_CMAKE)
  24. # include "cmGraphVizWriter.h"
  25. # include "cmVariableWatch.h"
  26. # include <cmsys/SystemInformation.hxx>
  27. #endif
  28. #include <cmsys/Glob.hxx>
  29. #include <cmsys/RegularExpression.hxx>
  30. #include <cmsys/FStream.hxx>
  31. // only build kdevelop generator on non-windows platforms
  32. // when not bootstrapping cmake
  33. #if !defined(_WIN32)
  34. # if defined(CMAKE_BUILD_WITH_CMAKE)
  35. # define CMAKE_USE_KDEVELOP
  36. # endif
  37. #endif
  38. #if defined(CMAKE_BUILD_WITH_CMAKE)
  39. # define CMAKE_USE_ECLIPSE
  40. #endif
  41. #if defined(__MINGW32__) && !defined(CMAKE_BUILD_WITH_CMAKE)
  42. # define CMAKE_BOOT_MINGW
  43. #endif
  44. // include the generator
  45. #if defined(_WIN32) && !defined(__CYGWIN__)
  46. # if !defined(CMAKE_BOOT_MINGW)
  47. # include "cmGlobalVisualStudio6Generator.h"
  48. # include "cmGlobalVisualStudio7Generator.h"
  49. # include "cmGlobalVisualStudio71Generator.h"
  50. # include "cmGlobalVisualStudio8Generator.h"
  51. # include "cmGlobalVisualStudio9Generator.h"
  52. # include "cmGlobalVisualStudio10Generator.h"
  53. # include "cmGlobalVisualStudio11Generator.h"
  54. # include "cmGlobalVisualStudio12Generator.h"
  55. # include "cmGlobalVisualStudio14Generator.h"
  56. # include "cmGlobalBorlandMakefileGenerator.h"
  57. # include "cmGlobalNMakeMakefileGenerator.h"
  58. # include "cmGlobalJOMMakefileGenerator.h"
  59. # include "cmGlobalGhsMultiGenerator.h"
  60. # define CMAKE_HAVE_VS_GENERATORS
  61. # endif
  62. # include "cmGlobalMSYSMakefileGenerator.h"
  63. # include "cmGlobalMinGWMakefileGenerator.h"
  64. #else
  65. #endif
  66. #if defined(CMAKE_USE_WMAKE)
  67. # include "cmGlobalWatcomWMakeGenerator.h"
  68. #endif
  69. #include "cmGlobalUnixMakefileGenerator3.h"
  70. #include "cmGlobalNinjaGenerator.h"
  71. #include "cmExtraCodeLiteGenerator.h"
  72. #if !defined(CMAKE_BOOT_MINGW)
  73. # include "cmExtraCodeBlocksGenerator.h"
  74. #endif
  75. #include "cmExtraSublimeTextGenerator.h"
  76. #include "cmExtraKateGenerator.h"
  77. #ifdef CMAKE_USE_KDEVELOP
  78. # include "cmGlobalKdevelopGenerator.h"
  79. #endif
  80. #include "cmExtraQbsGenerator.h"
  81. #ifdef CMAKE_USE_ECLIPSE
  82. # include "cmExtraEclipseCDT4Generator.h"
  83. #endif
  84. #include <stdlib.h> // required for atoi
  85. #if defined( __APPLE__ )
  86. # if defined(CMAKE_BUILD_WITH_CMAKE)
  87. # include "cmGlobalXCodeGenerator.h"
  88. # define CMAKE_USE_XCODE 1
  89. # endif
  90. # include <sys/types.h>
  91. # include <sys/time.h>
  92. # include <sys/resource.h>
  93. #endif
  94. #include <sys/stat.h> // struct stat
  95. #include <list>
  96. static bool cmakeCheckStampFile(const char* stampName);
  97. static bool cmakeCheckStampList(const char* stampName);
  98. void cmWarnUnusedCliWarning(const std::string& variable,
  99. int, void* ctx, const char*, const cmMakefile*)
  100. {
  101. cmake* cm = reinterpret_cast<cmake*>(ctx);
  102. cm->MarkCliAsUsed(variable);
  103. }
  104. cmake::cmake()
  105. {
  106. this->Trace = false;
  107. this->WarnUninitialized = false;
  108. this->WarnUnused = false;
  109. this->WarnUnusedCli = true;
  110. this->CheckSystemVars = false;
  111. this->SuppressDevWarnings = false;
  112. this->DoSuppressDevWarnings = false;
  113. this->DebugOutput = false;
  114. this->DebugTryCompile = false;
  115. this->ClearBuildSystem = false;
  116. this->FileComparison = new cmFileTimeComparison;
  117. this->Policies = new cmPolicies();
  118. this->State = new cmState(this);
  119. #ifdef __APPLE__
  120. struct rlimit rlp;
  121. if(!getrlimit(RLIMIT_STACK, &rlp))
  122. {
  123. if(rlp.rlim_cur != rlp.rlim_max)
  124. {
  125. rlp.rlim_cur = rlp.rlim_max;
  126. setrlimit(RLIMIT_STACK, &rlp);
  127. }
  128. }
  129. #endif
  130. this->Verbose = false;
  131. this->CacheManager = new cmCacheManager(this);
  132. this->GlobalGenerator = 0;
  133. this->ProgressCallback = 0;
  134. this->ProgressCallbackClientData = 0;
  135. this->CurrentWorkingMode = NORMAL_MODE;
  136. #ifdef CMAKE_BUILD_WITH_CMAKE
  137. this->VariableWatch = new cmVariableWatch;
  138. #endif
  139. this->AddDefaultGenerators();
  140. this->AddDefaultExtraGenerators();
  141. this->AddDefaultCommands();
  142. // Make sure we can capture the build tool output.
  143. cmSystemTools::EnableVSConsoleOutput();
  144. }
  145. cmake::~cmake()
  146. {
  147. delete this->CacheManager;
  148. delete this->Policies;
  149. delete this->State;
  150. if (this->GlobalGenerator)
  151. {
  152. delete this->GlobalGenerator;
  153. this->GlobalGenerator = 0;
  154. }
  155. cmDeleteAll(this->Generators);
  156. #ifdef CMAKE_BUILD_WITH_CMAKE
  157. delete this->VariableWatch;
  158. #endif
  159. delete this->FileComparison;
  160. }
  161. void cmake::CleanupCommandsAndMacros()
  162. {
  163. this->State->Initialize();
  164. this->State->RemoveUserDefinedCommands();
  165. }
  166. // Parse the args
  167. bool cmake::SetCacheArgs(const std::vector<std::string>& args)
  168. {
  169. bool findPackageMode = false;
  170. for(unsigned int i=1; i < args.size(); ++i)
  171. {
  172. std::string arg = args[i];
  173. if(arg.find("-D",0) == 0)
  174. {
  175. std::string entry = arg.substr(2);
  176. if(entry.empty())
  177. {
  178. ++i;
  179. if(i < args.size())
  180. {
  181. entry = args[i];
  182. }
  183. else
  184. {
  185. cmSystemTools::Error("-D must be followed with VAR=VALUE.");
  186. return false;
  187. }
  188. }
  189. std::string var, value;
  190. cmState::CacheEntryType type = cmState::UNINITIALIZED;
  191. if(cmCacheManager::ParseEntry(entry, var, value, type))
  192. {
  193. // The value is transformed if it is a filepath for example, so
  194. // we can't compare whether the value is already in the cache until
  195. // after we call AddCacheEntry.
  196. bool haveValue = false;
  197. std::string cachedValue;
  198. if(this->WarnUnusedCli)
  199. {
  200. if(const char *v = this->State->GetInitializedCacheValue(var))
  201. {
  202. haveValue = true;
  203. cachedValue = v;
  204. }
  205. }
  206. this->State->AddCacheEntry(var, value.c_str(),
  207. "No help, variable specified on the command line.", type);
  208. if(this->WarnUnusedCli)
  209. {
  210. if (!haveValue ||
  211. cachedValue != this->State->GetInitializedCacheValue(var))
  212. {
  213. this->WatchUnusedCli(var);
  214. }
  215. }
  216. }
  217. else
  218. {
  219. std::cerr << "Parse error in command line argument: " << arg << "\n"
  220. << "Should be: VAR:type=value\n";
  221. cmSystemTools::Error("No cmake script provided.");
  222. return false;
  223. }
  224. }
  225. else if(arg.find("-Wno-dev",0) == 0)
  226. {
  227. this->SuppressDevWarnings = true;
  228. this->DoSuppressDevWarnings = true;
  229. }
  230. else if(arg.find("-Wdev",0) == 0)
  231. {
  232. this->SuppressDevWarnings = false;
  233. this->DoSuppressDevWarnings = true;
  234. }
  235. else if(arg.find("-U",0) == 0)
  236. {
  237. std::string entryPattern = arg.substr(2);
  238. if(entryPattern.empty())
  239. {
  240. ++i;
  241. if(i < args.size())
  242. {
  243. entryPattern = args[i];
  244. }
  245. else
  246. {
  247. cmSystemTools::Error("-U must be followed with VAR.");
  248. return false;
  249. }
  250. }
  251. cmsys::RegularExpression regex(
  252. cmsys::Glob::PatternToRegex(entryPattern, true, true).c_str());
  253. //go through all cache entries and collect the vars which will be removed
  254. std::vector<std::string> entriesToDelete;
  255. std::vector<std::string> cacheKeys = this->State->GetCacheEntryKeys();
  256. for (std::vector<std::string>::const_iterator it = cacheKeys.begin();
  257. it != cacheKeys.end(); ++it)
  258. {
  259. cmState::CacheEntryType t = this->State->GetCacheEntryType(*it);
  260. if(t != cmState::STATIC)
  261. {
  262. if (regex.find(it->c_str()))
  263. {
  264. entriesToDelete.push_back(*it);
  265. }
  266. }
  267. }
  268. // now remove them from the cache
  269. for(std::vector<std::string>::const_iterator currentEntry =
  270. entriesToDelete.begin();
  271. currentEntry != entriesToDelete.end();
  272. ++currentEntry)
  273. {
  274. this->State->RemoveCacheEntry(*currentEntry);
  275. }
  276. }
  277. else if(arg.find("-C",0) == 0)
  278. {
  279. std::string path = arg.substr(2);
  280. if (path.empty())
  281. {
  282. ++i;
  283. if(i < args.size())
  284. {
  285. path = args[i];
  286. }
  287. else
  288. {
  289. cmSystemTools::Error("-C must be followed by a file name.");
  290. return false;
  291. }
  292. }
  293. std::cout << "loading initial cache file " << path << "\n";
  294. this->ReadListFile(args, path.c_str());
  295. }
  296. else if(arg.find("-P",0) == 0)
  297. {
  298. i++;
  299. if(i >= args.size())
  300. {
  301. cmSystemTools::Error("-P must be followed by a file name.");
  302. return false;
  303. }
  304. std::string path = args[i];
  305. if (path.empty())
  306. {
  307. cmSystemTools::Error("No cmake script provided.");
  308. return false;
  309. }
  310. this->ReadListFile(args, path.c_str());
  311. }
  312. else if (arg.find("--find-package",0) == 0)
  313. {
  314. findPackageMode = true;
  315. }
  316. }
  317. if (findPackageMode)
  318. {
  319. return this->FindPackage(args);
  320. }
  321. return true;
  322. }
  323. void cmake::ReadListFile(const std::vector<std::string>& args,
  324. const char *path)
  325. {
  326. // if a generator was not yet created, temporarily create one
  327. cmGlobalGenerator *gg = this->GetGlobalGenerator();
  328. bool created = false;
  329. // if a generator was not specified use a generic one
  330. if (!gg)
  331. {
  332. gg = new cmGlobalGenerator;
  333. gg->SetCMakeInstance(this);
  334. created = true;
  335. }
  336. // read in the list file to fill the cache
  337. if(path)
  338. {
  339. std::string homeDir = this->GetHomeDirectory();
  340. std::string homeOutputDir = this->GetHomeOutputDirectory();
  341. this->SetHomeDirectory(cmSystemTools::GetCurrentWorkingDirectory());
  342. this->SetHomeOutputDirectory(cmSystemTools::GetCurrentWorkingDirectory());
  343. cmsys::auto_ptr<cmLocalGenerator> lg(gg->MakeLocalGenerator());
  344. lg->GetMakefile()->SetCurrentBinaryDirectory
  345. (cmSystemTools::GetCurrentWorkingDirectory());
  346. lg->GetMakefile()->SetCurrentSourceDirectory
  347. (cmSystemTools::GetCurrentWorkingDirectory());
  348. if (this->GetWorkingMode() != NORMAL_MODE)
  349. {
  350. std::string file(cmSystemTools::CollapseFullPath(path));
  351. cmSystemTools::ConvertToUnixSlashes(file);
  352. lg->GetMakefile()->SetScriptModeFile(file.c_str());
  353. lg->GetMakefile()->SetArgcArgv(args);
  354. }
  355. if (!lg->GetMakefile()->ReadListFile(path))
  356. {
  357. cmSystemTools::Error("Error processing file: ", path);
  358. }
  359. this->SetHomeDirectory(homeDir);
  360. this->SetHomeOutputDirectory(homeOutputDir);
  361. }
  362. // free generic one if generated
  363. if (created)
  364. {
  365. delete gg;
  366. }
  367. }
  368. bool cmake::FindPackage(const std::vector<std::string>& args)
  369. {
  370. this->SetHomeDirectory
  371. (cmSystemTools::GetCurrentWorkingDirectory());
  372. this->SetHomeOutputDirectory
  373. (cmSystemTools::GetCurrentWorkingDirectory());
  374. // if a generator was not yet created, temporarily create one
  375. cmGlobalGenerator *gg = new cmGlobalGenerator;
  376. gg->SetCMakeInstance(this);
  377. this->SetGlobalGenerator(gg);
  378. // read in the list file to fill the cache
  379. cmsys::auto_ptr<cmLocalGenerator> lg(gg->MakeLocalGenerator());
  380. cmMakefile* mf = lg->GetMakefile();
  381. mf->SetCurrentBinaryDirectory
  382. (cmSystemTools::GetCurrentWorkingDirectory());
  383. mf->SetCurrentSourceDirectory
  384. (cmSystemTools::GetCurrentWorkingDirectory());
  385. mf->SetArgcArgv(args);
  386. std::string systemFile = mf->GetModulesFile("CMakeFindPackageMode.cmake");
  387. mf->ReadListFile(systemFile.c_str());
  388. std::string language = mf->GetSafeDefinition("LANGUAGE");
  389. std::string mode = mf->GetSafeDefinition("MODE");
  390. std::string packageName = mf->GetSafeDefinition("NAME");
  391. bool packageFound = mf->IsOn("PACKAGE_FOUND");
  392. bool quiet = mf->IsOn("PACKAGE_QUIET");
  393. if (!packageFound)
  394. {
  395. if (!quiet)
  396. {
  397. printf("%s not found.\n", packageName.c_str());
  398. }
  399. }
  400. else if (mode == "EXIST")
  401. {
  402. if (!quiet)
  403. {
  404. printf("%s found.\n", packageName.c_str());
  405. }
  406. }
  407. else if (mode == "COMPILE")
  408. {
  409. std::string includes = mf->GetSafeDefinition("PACKAGE_INCLUDE_DIRS");
  410. std::vector<std::string> includeDirs;
  411. cmSystemTools::ExpandListArgument(includes, includeDirs);
  412. std::string includeFlags = lg->GetIncludeFlags(includeDirs, 0, language);
  413. std::string definitions = mf->GetSafeDefinition("PACKAGE_DEFINITIONS");
  414. printf("%s %s\n", includeFlags.c_str(), definitions.c_str());
  415. }
  416. else if (mode == "LINK")
  417. {
  418. const char* targetName = "dummy";
  419. std::vector<std::string> srcs;
  420. cmTarget* tgt = mf->AddExecutable(targetName, srcs, true);
  421. tgt->SetProperty("LINKER_LANGUAGE", language.c_str());
  422. std::string libs = mf->GetSafeDefinition("PACKAGE_LIBRARIES");
  423. std::vector<std::string> libList;
  424. cmSystemTools::ExpandListArgument(libs, libList);
  425. for(std::vector<std::string>::const_iterator libIt=libList.begin();
  426. libIt != libList.end();
  427. ++libIt)
  428. {
  429. mf->AddLinkLibraryForTarget(targetName, *libIt,
  430. cmTarget::GENERAL);
  431. }
  432. std::string linkLibs;
  433. std::string frameworkPath;
  434. std::string linkPath;
  435. std::string flags;
  436. std::string linkFlags;
  437. gg->CreateGeneratorTargets(mf);
  438. cmGeneratorTarget *gtgt = gg->GetGeneratorTarget(tgt);
  439. lg->GetTargetFlags(linkLibs, frameworkPath, linkPath, flags, linkFlags,
  440. gtgt, false);
  441. linkLibs = frameworkPath + linkPath + linkLibs;
  442. printf("%s\n", linkLibs.c_str() );
  443. /* if ( use_win32 )
  444. {
  445. tgt->SetProperty("WIN32_EXECUTABLE", "ON");
  446. }
  447. if ( use_macbundle)
  448. {
  449. tgt->SetProperty("MACOSX_BUNDLE", "ON");
  450. }*/
  451. }
  452. // free generic one if generated
  453. // this->SetGlobalGenerator(0); // setting 0-pointer is not possible
  454. // delete gg; // this crashes inside the cmake instance
  455. return packageFound;
  456. }
  457. // Parse the args
  458. void cmake::SetArgs(const std::vector<std::string>& args,
  459. bool directoriesSetBefore)
  460. {
  461. bool directoriesSet = directoriesSetBefore;
  462. bool haveToolset = false;
  463. bool havePlatform = false;
  464. for(unsigned int i=1; i < args.size(); ++i)
  465. {
  466. std::string arg = args[i];
  467. if(arg.find("-H",0) == 0)
  468. {
  469. directoriesSet = true;
  470. std::string path = arg.substr(2);
  471. path = cmSystemTools::CollapseFullPath(path);
  472. cmSystemTools::ConvertToUnixSlashes(path);
  473. this->SetHomeDirectory(path);
  474. }
  475. else if(arg.find("-S",0) == 0)
  476. {
  477. // There is no local generate anymore. Ignore -S option.
  478. }
  479. else if(arg.find("-O",0) == 0)
  480. {
  481. // There is no local generate anymore. Ignore -O option.
  482. }
  483. else if(arg.find("-B",0) == 0)
  484. {
  485. directoriesSet = true;
  486. std::string path = arg.substr(2);
  487. path = cmSystemTools::CollapseFullPath(path);
  488. cmSystemTools::ConvertToUnixSlashes(path);
  489. this->SetHomeOutputDirectory(path);
  490. }
  491. else if((i < args.size()-2) && (arg.find("--check-build-system",0) == 0))
  492. {
  493. this->CheckBuildSystemArgument = args[++i];
  494. this->ClearBuildSystem = (atoi(args[++i].c_str()) > 0);
  495. }
  496. else if((i < args.size()-1) && (arg.find("--check-stamp-file",0) == 0))
  497. {
  498. this->CheckStampFile = args[++i];
  499. }
  500. else if((i < args.size()-1) && (arg.find("--check-stamp-list",0) == 0))
  501. {
  502. this->CheckStampList = args[++i];
  503. }
  504. #if defined(CMAKE_HAVE_VS_GENERATORS)
  505. else if((i < args.size()-1) && (arg.find("--vs-solution-file",0) == 0))
  506. {
  507. this->VSSolutionFile = args[++i];
  508. }
  509. #endif
  510. else if(arg.find("-V",0) == 0)
  511. {
  512. this->Verbose = true;
  513. }
  514. else if(arg.find("-D",0) == 0)
  515. {
  516. // skip for now
  517. }
  518. else if(arg.find("-U",0) == 0)
  519. {
  520. // skip for now
  521. }
  522. else if(arg.find("-C",0) == 0)
  523. {
  524. // skip for now
  525. }
  526. else if(arg.find("-P",0) == 0)
  527. {
  528. // skip for now
  529. i++;
  530. }
  531. else if(arg.find("--find-package",0) == 0)
  532. {
  533. // skip for now
  534. i++;
  535. }
  536. else if(arg.find("-Wno-dev",0) == 0)
  537. {
  538. // skip for now
  539. }
  540. else if(arg.find("-Wdev",0) == 0)
  541. {
  542. // skip for now
  543. }
  544. else if(arg.find("--graphviz=",0) == 0)
  545. {
  546. std::string path = arg.substr(strlen("--graphviz="));
  547. path = cmSystemTools::CollapseFullPath(path);
  548. cmSystemTools::ConvertToUnixSlashes(path);
  549. this->GraphVizFile = path;
  550. if ( this->GraphVizFile.empty() )
  551. {
  552. cmSystemTools::Error("No file specified for --graphviz");
  553. }
  554. }
  555. else if(arg.find("--debug-trycompile",0) == 0)
  556. {
  557. std::cout << "debug trycompile on\n";
  558. this->DebugTryCompileOn();
  559. }
  560. else if(arg.find("--debug-output",0) == 0)
  561. {
  562. std::cout << "Running with debug output on.\n";
  563. this->SetDebugOutputOn(true);
  564. }
  565. else if(arg.find("--trace",0) == 0)
  566. {
  567. std::cout << "Running with trace output on.\n";
  568. this->SetTrace(true);
  569. }
  570. else if(arg.find("--warn-uninitialized",0) == 0)
  571. {
  572. std::cout << "Warn about uninitialized values.\n";
  573. this->SetWarnUninitialized(true);
  574. }
  575. else if(arg.find("--warn-unused-vars",0) == 0)
  576. {
  577. std::cout << "Finding unused variables.\n";
  578. this->SetWarnUnused(true);
  579. }
  580. else if(arg.find("--no-warn-unused-cli",0) == 0)
  581. {
  582. std::cout << "Not searching for unused variables given on the " <<
  583. "command line.\n";
  584. this->SetWarnUnusedCli(false);
  585. }
  586. else if(arg.find("--check-system-vars",0) == 0)
  587. {
  588. std::cout << "Also check system files when warning about unused and " <<
  589. "uninitialized variables.\n";
  590. this->SetCheckSystemVars(true);
  591. }
  592. else if(arg.find("-A",0) == 0)
  593. {
  594. std::string value = arg.substr(2);
  595. if(value.empty())
  596. {
  597. ++i;
  598. if(i >= args.size())
  599. {
  600. cmSystemTools::Error("No platform specified for -A");
  601. return;
  602. }
  603. value = args[i];
  604. }
  605. if(havePlatform)
  606. {
  607. cmSystemTools::Error("Multiple -A options not allowed");
  608. return;
  609. }
  610. this->GeneratorPlatform = value;
  611. havePlatform = true;
  612. }
  613. else if(arg.find("-T",0) == 0)
  614. {
  615. std::string value = arg.substr(2);
  616. if(value.empty())
  617. {
  618. ++i;
  619. if(i >= args.size())
  620. {
  621. cmSystemTools::Error("No toolset specified for -T");
  622. return;
  623. }
  624. value = args[i];
  625. }
  626. if(haveToolset)
  627. {
  628. cmSystemTools::Error("Multiple -T options not allowed");
  629. return;
  630. }
  631. this->GeneratorToolset = value;
  632. haveToolset = true;
  633. }
  634. else if(arg.find("-G",0) == 0)
  635. {
  636. std::string value = arg.substr(2);
  637. if(value.empty())
  638. {
  639. ++i;
  640. if(i >= args.size())
  641. {
  642. cmSystemTools::Error("No generator specified for -G");
  643. this->PrintGeneratorList();
  644. return;
  645. }
  646. value = args[i];
  647. }
  648. cmGlobalGenerator* gen =
  649. this->CreateGlobalGenerator(value);
  650. if(!gen)
  651. {
  652. cmSystemTools::Error("Could not create named generator ",
  653. value.c_str());
  654. this->PrintGeneratorList();
  655. }
  656. else
  657. {
  658. this->SetGlobalGenerator(gen);
  659. }
  660. }
  661. // no option assume it is the path to the source
  662. else
  663. {
  664. directoriesSet = true;
  665. this->SetDirectoriesFromFile(arg.c_str());
  666. }
  667. }
  668. if(!directoriesSet)
  669. {
  670. this->SetHomeOutputDirectory
  671. (cmSystemTools::GetCurrentWorkingDirectory());
  672. this->SetHomeDirectory
  673. (cmSystemTools::GetCurrentWorkingDirectory());
  674. }
  675. }
  676. //----------------------------------------------------------------------------
  677. void cmake::SetDirectoriesFromFile(const char* arg)
  678. {
  679. // Check if the argument refers to a CMakeCache.txt or
  680. // CMakeLists.txt file.
  681. std::string listPath;
  682. std::string cachePath;
  683. bool argIsFile = false;
  684. if(cmSystemTools::FileIsDirectory(arg))
  685. {
  686. std::string path = cmSystemTools::CollapseFullPath(arg);
  687. cmSystemTools::ConvertToUnixSlashes(path);
  688. std::string cacheFile = path;
  689. cacheFile += "/CMakeCache.txt";
  690. std::string listFile = path;
  691. listFile += "/CMakeLists.txt";
  692. if(cmSystemTools::FileExists(cacheFile.c_str()))
  693. {
  694. cachePath = path;
  695. }
  696. if(cmSystemTools::FileExists(listFile.c_str()))
  697. {
  698. listPath = path;
  699. }
  700. }
  701. else if(cmSystemTools::FileExists(arg))
  702. {
  703. argIsFile = true;
  704. std::string fullPath = cmSystemTools::CollapseFullPath(arg);
  705. std::string name = cmSystemTools::GetFilenameName(fullPath);
  706. name = cmSystemTools::LowerCase(name);
  707. if(name == "cmakecache.txt")
  708. {
  709. cachePath = cmSystemTools::GetFilenamePath(fullPath);
  710. }
  711. else if(name == "cmakelists.txt")
  712. {
  713. listPath = cmSystemTools::GetFilenamePath(fullPath);
  714. }
  715. }
  716. else
  717. {
  718. // Specified file or directory does not exist. Try to set things
  719. // up to produce a meaningful error message.
  720. std::string fullPath = cmSystemTools::CollapseFullPath(arg);
  721. std::string name = cmSystemTools::GetFilenameName(fullPath);
  722. name = cmSystemTools::LowerCase(name);
  723. if(name == "cmakecache.txt" || name == "cmakelists.txt")
  724. {
  725. argIsFile = true;
  726. listPath = cmSystemTools::GetFilenamePath(fullPath);
  727. }
  728. else
  729. {
  730. listPath = fullPath;
  731. }
  732. }
  733. // If there is a CMakeCache.txt file, use its settings.
  734. if(!cachePath.empty())
  735. {
  736. if(this->LoadCache(cachePath))
  737. {
  738. const char* existingValue =
  739. this->State->GetCacheEntryValue("CMAKE_HOME_DIRECTORY");
  740. if (existingValue)
  741. {
  742. this->SetHomeOutputDirectory(cachePath);
  743. this->SetHomeDirectory(existingValue);
  744. return;
  745. }
  746. }
  747. }
  748. // If there is a CMakeLists.txt file, use it as the source tree.
  749. if(!listPath.empty())
  750. {
  751. this->SetHomeDirectory(listPath);
  752. if(argIsFile)
  753. {
  754. // Source CMakeLists.txt file given. It was probably dropped
  755. // onto the executable in a GUI. Default to an in-source build.
  756. this->SetHomeOutputDirectory(listPath);
  757. }
  758. else
  759. {
  760. // Source directory given on command line. Use current working
  761. // directory as build tree.
  762. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  763. this->SetHomeOutputDirectory(cwd);
  764. }
  765. return;
  766. }
  767. // We didn't find a CMakeLists.txt or CMakeCache.txt file from the
  768. // argument. Assume it is the path to the source tree, and use the
  769. // current working directory as the build tree.
  770. std::string full = cmSystemTools::CollapseFullPath(arg);
  771. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  772. this->SetHomeDirectory(full);
  773. this->SetHomeOutputDirectory(cwd);
  774. }
  775. // at the end of this CMAKE_ROOT and CMAKE_COMMAND should be added to the
  776. // cache
  777. int cmake::AddCMakePaths()
  778. {
  779. // Save the value in the cache
  780. this->CacheManager->AddCacheEntry
  781. ("CMAKE_COMMAND", cmSystemTools::GetCMakeCommand().c_str(),
  782. "Path to CMake executable.", cmState::INTERNAL);
  783. #ifdef CMAKE_BUILD_WITH_CMAKE
  784. this->CacheManager->AddCacheEntry
  785. ("CMAKE_CTEST_COMMAND", cmSystemTools::GetCTestCommand().c_str(),
  786. "Path to ctest program executable.", cmState::INTERNAL);
  787. this->CacheManager->AddCacheEntry
  788. ("CMAKE_CPACK_COMMAND", cmSystemTools::GetCPackCommand().c_str(),
  789. "Path to cpack program executable.", cmState::INTERNAL);
  790. #endif
  791. if(!cmSystemTools::FileExists(
  792. (cmSystemTools::GetCMakeRoot()+"/Modules/CMake.cmake").c_str()))
  793. {
  794. // couldn't find modules
  795. cmSystemTools::Error("Could not find CMAKE_ROOT !!!\n"
  796. "CMake has most likely not been installed correctly.\n"
  797. "Modules directory not found in\n",
  798. cmSystemTools::GetCMakeRoot().c_str());
  799. return 0;
  800. }
  801. this->CacheManager->AddCacheEntry
  802. ("CMAKE_ROOT", cmSystemTools::GetCMakeRoot().c_str(),
  803. "Path to CMake installation.", cmState::INTERNAL);
  804. return 1;
  805. }
  806. void cmake::AddExtraGenerator(const std::string& name,
  807. CreateExtraGeneratorFunctionType newFunction)
  808. {
  809. cmExternalMakefileProjectGenerator* extraGenerator = newFunction();
  810. const std::vector<std::string>& supportedGlobalGenerators =
  811. extraGenerator->GetSupportedGlobalGenerators();
  812. for(std::vector<std::string>::const_iterator
  813. it = supportedGlobalGenerators.begin();
  814. it != supportedGlobalGenerators.end();
  815. ++it )
  816. {
  817. std::string fullName = cmExternalMakefileProjectGenerator::
  818. CreateFullGeneratorName(*it, name);
  819. this->ExtraGenerators[fullName] = newFunction;
  820. }
  821. delete extraGenerator;
  822. }
  823. void cmake::AddDefaultExtraGenerators()
  824. {
  825. #if defined(CMAKE_BUILD_WITH_CMAKE)
  826. #if defined(_WIN32) && !defined(__CYGWIN__)
  827. // e.g. kdevelop4 ?
  828. #endif
  829. this->AddExtraGenerator(cmExtraCodeBlocksGenerator::GetActualName(),
  830. &cmExtraCodeBlocksGenerator::New);
  831. this->AddExtraGenerator(cmExtraCodeLiteGenerator::GetActualName(),
  832. &cmExtraCodeLiteGenerator::New);
  833. this->AddExtraGenerator(cmExtraSublimeTextGenerator::GetActualName(),
  834. &cmExtraSublimeTextGenerator::New);
  835. this->AddExtraGenerator(cmExtraKateGenerator::GetActualName(),
  836. &cmExtraKateGenerator::New);
  837. this->AddExtraGenerator(cmExtraQbsGenerator::GetActualName(),
  838. &cmExtraQbsGenerator::New);
  839. #ifdef CMAKE_USE_ECLIPSE
  840. this->AddExtraGenerator(cmExtraEclipseCDT4Generator::GetActualName(),
  841. &cmExtraEclipseCDT4Generator::New);
  842. #endif
  843. #ifdef CMAKE_USE_KDEVELOP
  844. this->AddExtraGenerator(cmGlobalKdevelopGenerator::GetActualName(),
  845. &cmGlobalKdevelopGenerator::New);
  846. // for kdevelop also add the generator with just the name of the
  847. // extra generator, since it was this way since cmake 2.2
  848. this->ExtraGenerators[cmGlobalKdevelopGenerator::GetActualName()]
  849. = &cmGlobalKdevelopGenerator::New;
  850. #endif
  851. #endif
  852. }
  853. //----------------------------------------------------------------------------
  854. void cmake::GetRegisteredGenerators(std::vector<std::string>& names)
  855. {
  856. for(RegisteredGeneratorsVector::const_iterator i = this->Generators.begin();
  857. i != this->Generators.end(); ++i)
  858. {
  859. (*i)->GetGenerators(names);
  860. }
  861. for(RegisteredExtraGeneratorsMap::const_iterator
  862. i = this->ExtraGenerators.begin();
  863. i != this->ExtraGenerators.end(); ++i)
  864. {
  865. names.push_back(i->first);
  866. }
  867. }
  868. cmGlobalGenerator* cmake::CreateGlobalGenerator(const std::string& gname)
  869. {
  870. cmExternalMakefileProjectGenerator* extraGenerator = 0;
  871. std::string name = gname;
  872. RegisteredExtraGeneratorsMap::const_iterator extraGenIt =
  873. this->ExtraGenerators.find(name);
  874. if (extraGenIt != this->ExtraGenerators.end())
  875. {
  876. extraGenerator = (extraGenIt->second)();
  877. name = extraGenerator->GetGlobalGeneratorName(name);
  878. }
  879. cmGlobalGenerator* generator = 0;
  880. for (RegisteredGeneratorsVector::const_iterator i =
  881. this->Generators.begin(); i != this->Generators.end(); ++i)
  882. {
  883. generator = (*i)->CreateGlobalGenerator(name);
  884. if (generator)
  885. {
  886. break;
  887. }
  888. }
  889. if (generator)
  890. {
  891. generator->SetCMakeInstance(this);
  892. generator->SetExternalMakefileProjectGenerator(extraGenerator);
  893. }
  894. else
  895. {
  896. delete extraGenerator;
  897. }
  898. return generator;
  899. }
  900. void cmake::SetHomeDirectory(const std::string& dir)
  901. {
  902. this->State->SetSourceDirectory(dir);
  903. }
  904. const char* cmake::GetHomeDirectory() const
  905. {
  906. return this->State->GetSourceDirectory();
  907. }
  908. void cmake::SetHomeOutputDirectory(const std::string& dir)
  909. {
  910. this->State->SetBinaryDirectory(dir);
  911. }
  912. const char* cmake::GetHomeOutputDirectory() const
  913. {
  914. return this->State->GetBinaryDirectory();
  915. }
  916. void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
  917. {
  918. if(!gg)
  919. {
  920. cmSystemTools::Error("Error SetGlobalGenerator called with null");
  921. return;
  922. }
  923. // delete the old generator
  924. if (this->GlobalGenerator)
  925. {
  926. delete this->GlobalGenerator;
  927. // restore the original environment variables CXX and CC
  928. // Restore CC
  929. std::string env = "CC=";
  930. if(!this->CCEnvironment.empty())
  931. {
  932. env += this->CCEnvironment;
  933. }
  934. cmSystemTools::PutEnv(env);
  935. env = "CXX=";
  936. if(!this->CXXEnvironment.empty())
  937. {
  938. env += this->CXXEnvironment;
  939. }
  940. cmSystemTools::PutEnv(env);
  941. }
  942. // set the new
  943. this->GlobalGenerator = gg;
  944. // set the global flag for unix style paths on cmSystemTools as soon as
  945. // the generator is set. This allows gmake to be used on windows.
  946. cmSystemTools::SetForceUnixPaths
  947. (this->GlobalGenerator->GetForceUnixPaths());
  948. // Save the environment variables CXX and CC
  949. const char* cxx = getenv("CXX");
  950. const char* cc = getenv("CC");
  951. if(cxx)
  952. {
  953. this->CXXEnvironment = cxx;
  954. }
  955. else
  956. {
  957. this->CXXEnvironment = "";
  958. }
  959. if(cc)
  960. {
  961. this->CCEnvironment = cc;
  962. }
  963. else
  964. {
  965. this->CCEnvironment = "";
  966. }
  967. // set the cmake instance just to be sure
  968. gg->SetCMakeInstance(this);
  969. }
  970. int cmake::DoPreConfigureChecks()
  971. {
  972. // Make sure the Source directory contains a CMakeLists.txt file.
  973. std::string srcList = this->GetHomeDirectory();
  974. srcList += "/CMakeLists.txt";
  975. if(!cmSystemTools::FileExists(srcList.c_str()))
  976. {
  977. std::ostringstream err;
  978. if(cmSystemTools::FileIsDirectory(this->GetHomeDirectory()))
  979. {
  980. err << "The source directory \"" << this->GetHomeDirectory()
  981. << "\" does not appear to contain CMakeLists.txt.\n";
  982. }
  983. else if(cmSystemTools::FileExists(this->GetHomeDirectory()))
  984. {
  985. err << "The source directory \"" << this->GetHomeDirectory()
  986. << "\" is a file, not a directory.\n";
  987. }
  988. else
  989. {
  990. err << "The source directory \"" << this->GetHomeDirectory()
  991. << "\" does not exist.\n";
  992. }
  993. err << "Specify --help for usage, or press the help button on the CMake "
  994. "GUI.";
  995. cmSystemTools::Error(err.str().c_str());
  996. return -2;
  997. }
  998. // do a sanity check on some values
  999. if(this->CacheManager->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY"))
  1000. {
  1001. std::string cacheStart =
  1002. this->CacheManager->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY");
  1003. cacheStart += "/CMakeLists.txt";
  1004. std::string currentStart = this->GetHomeDirectory();
  1005. currentStart += "/CMakeLists.txt";
  1006. if(!cmSystemTools::SameFile(cacheStart, currentStart))
  1007. {
  1008. std::string message = "The source \"";
  1009. message += currentStart;
  1010. message += "\" does not match the source \"";
  1011. message += cacheStart;
  1012. message += "\" used to generate cache. ";
  1013. message += "Re-run cmake with a different source directory.";
  1014. cmSystemTools::Error(message.c_str());
  1015. return -2;
  1016. }
  1017. }
  1018. else
  1019. {
  1020. return 0;
  1021. }
  1022. return 1;
  1023. }
  1024. struct SaveCacheEntry
  1025. {
  1026. std::string key;
  1027. std::string value;
  1028. std::string help;
  1029. cmState::CacheEntryType type;
  1030. };
  1031. int cmake::HandleDeleteCacheVariables(const std::string& var)
  1032. {
  1033. std::vector<std::string> argsSplit;
  1034. cmSystemTools::ExpandListArgument(std::string(var), argsSplit, true);
  1035. // erase the property to avoid infinite recursion
  1036. this->State
  1037. ->SetGlobalProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_", "");
  1038. if(this->State->GetIsInTryCompile())
  1039. {
  1040. return 0;
  1041. }
  1042. std::vector<SaveCacheEntry> saved;
  1043. std::ostringstream warning;
  1044. warning
  1045. << "You have changed variables that require your cache to be deleted.\n"
  1046. << "Configure will be re-run and you may have to reset some variables.\n"
  1047. << "The following variables have changed:\n";
  1048. for(std::vector<std::string>::iterator i = argsSplit.begin();
  1049. i != argsSplit.end(); ++i)
  1050. {
  1051. SaveCacheEntry save;
  1052. save.key = *i;
  1053. warning << *i << "= ";
  1054. i++;
  1055. save.value = *i;
  1056. warning << *i << "\n";
  1057. const char* existingValue =
  1058. this->CacheManager->GetCacheEntryValue(save.key);
  1059. if(existingValue)
  1060. {
  1061. save.type = this->CacheManager->GetCacheEntryType(save.key);
  1062. if(const char* help =
  1063. this->CacheManager->GetCacheEntryProperty(save.key, "HELPSTRING"))
  1064. {
  1065. save.help = help;
  1066. }
  1067. }
  1068. saved.push_back(save);
  1069. }
  1070. // remove the cache
  1071. this->CacheManager->DeleteCache(this->GetHomeOutputDirectory());
  1072. // load the empty cache
  1073. this->LoadCache();
  1074. // restore the changed compilers
  1075. for(std::vector<SaveCacheEntry>::iterator i = saved.begin();
  1076. i != saved.end(); ++i)
  1077. {
  1078. this->AddCacheEntry(i->key, i->value.c_str(),
  1079. i->help.c_str(), i->type);
  1080. }
  1081. cmSystemTools::Message(warning.str().c_str());
  1082. // avoid reconfigure if there were errors
  1083. if(!cmSystemTools::GetErrorOccuredFlag())
  1084. {
  1085. // re-run configure
  1086. return this->Configure();
  1087. }
  1088. return 0;
  1089. }
  1090. int cmake::Configure()
  1091. {
  1092. if(this->DoSuppressDevWarnings)
  1093. {
  1094. if(this->SuppressDevWarnings)
  1095. {
  1096. this->CacheManager->
  1097. AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "TRUE",
  1098. "Suppress Warnings that are meant for"
  1099. " the author of the CMakeLists.txt files.",
  1100. cmState::INTERNAL);
  1101. }
  1102. else
  1103. {
  1104. this->CacheManager->
  1105. AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "FALSE",
  1106. "Suppress Warnings that are meant for"
  1107. " the author of the CMakeLists.txt files.",
  1108. cmState::INTERNAL);
  1109. }
  1110. }
  1111. int ret = this->ActualConfigure();
  1112. const char* delCacheVars = this->State
  1113. ->GetGlobalProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_");
  1114. if(delCacheVars && delCacheVars[0] != 0)
  1115. {
  1116. return this->HandleDeleteCacheVariables(delCacheVars);
  1117. }
  1118. return ret;
  1119. }
  1120. int cmake::ActualConfigure()
  1121. {
  1122. // Construct right now our path conversion table before it's too late:
  1123. this->UpdateConversionPathTable();
  1124. this->CleanupCommandsAndMacros();
  1125. int res = 0;
  1126. if ( this->GetWorkingMode() == NORMAL_MODE )
  1127. {
  1128. res = this->DoPreConfigureChecks();
  1129. }
  1130. if ( res < 0 )
  1131. {
  1132. return -2;
  1133. }
  1134. if ( !res )
  1135. {
  1136. this->CacheManager->AddCacheEntry
  1137. ("CMAKE_HOME_DIRECTORY",
  1138. this->GetHomeDirectory(),
  1139. "Source directory with the top level CMakeLists.txt file for this "
  1140. "project",
  1141. cmState::INTERNAL);
  1142. }
  1143. // no generator specified on the command line
  1144. if(!this->GlobalGenerator)
  1145. {
  1146. const char* genName =
  1147. this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR");
  1148. const char* extraGenName =
  1149. this->CacheManager->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR");
  1150. if(genName)
  1151. {
  1152. std::string fullName = cmExternalMakefileProjectGenerator::
  1153. CreateFullGeneratorName(genName,
  1154. extraGenName ? extraGenName : "");
  1155. this->GlobalGenerator = this->CreateGlobalGenerator(fullName);
  1156. }
  1157. if(this->GlobalGenerator)
  1158. {
  1159. // set the global flag for unix style paths on cmSystemTools as
  1160. // soon as the generator is set. This allows gmake to be used
  1161. // on windows.
  1162. cmSystemTools::SetForceUnixPaths
  1163. (this->GlobalGenerator->GetForceUnixPaths());
  1164. }
  1165. else
  1166. {
  1167. #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
  1168. std::string installedCompiler;
  1169. // Try to find the newest VS installed on the computer and
  1170. // use that as a default if -G is not specified
  1171. const std::string vsregBase =
  1172. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\";
  1173. std::vector<std::string> vsVerions;
  1174. vsVerions.push_back("VisualStudio\\");
  1175. vsVerions.push_back("VCExpress\\");
  1176. vsVerions.push_back("WDExpress\\");
  1177. struct VSRegistryEntryName
  1178. {
  1179. const char* MSVersion;
  1180. const char* GeneratorName;
  1181. };
  1182. VSRegistryEntryName version[] = {
  1183. {"6.0", "Visual Studio 6"},
  1184. {"7.0", "Visual Studio 7"},
  1185. {"7.1", "Visual Studio 7 .NET 2003"},
  1186. {"8.0", "Visual Studio 8 2005"},
  1187. {"9.0", "Visual Studio 9 2008"},
  1188. {"10.0", "Visual Studio 10 2010"},
  1189. {"11.0", "Visual Studio 11 2012"},
  1190. {"12.0", "Visual Studio 12 2013"},
  1191. {"14.0", "Visual Studio 14 2015"},
  1192. {0, 0}};
  1193. for(int i=0; version[i].MSVersion != 0; i++)
  1194. {
  1195. for(size_t b=0; b < vsVerions.size(); b++)
  1196. {
  1197. std::string reg = vsregBase + vsVerions[b] + version[i].MSVersion;
  1198. reg += ";InstallDir]";
  1199. cmSystemTools::ExpandRegistryValues(reg,
  1200. cmSystemTools::KeyWOW64_32);
  1201. if (!(reg == "/registry"))
  1202. {
  1203. installedCompiler = version[i].GeneratorName;
  1204. break;
  1205. }
  1206. }
  1207. }
  1208. cmGlobalGenerator* gen
  1209. = this->CreateGlobalGenerator(installedCompiler.c_str());
  1210. if(!gen)
  1211. {
  1212. gen = new cmGlobalNMakeMakefileGenerator;
  1213. }
  1214. this->SetGlobalGenerator(gen);
  1215. std::cout << "-- Building for: " << gen->GetName() << "\n";
  1216. #else
  1217. this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator3);
  1218. #endif
  1219. }
  1220. if(!this->GlobalGenerator)
  1221. {
  1222. cmSystemTools::Error("Could not create generator");
  1223. return -1;
  1224. }
  1225. }
  1226. const char* genName = this->CacheManager
  1227. ->GetInitializedCacheValue("CMAKE_GENERATOR");
  1228. if(genName)
  1229. {
  1230. if(!this->GlobalGenerator->MatchesGeneratorName(genName))
  1231. {
  1232. std::string message = "Error: generator : ";
  1233. message += this->GlobalGenerator->GetName();
  1234. message += "\nDoes not match the generator used previously: ";
  1235. message += genName;
  1236. message +=
  1237. "\nEither remove the CMakeCache.txt file and CMakeFiles "
  1238. "directory or choose a different binary directory.";
  1239. cmSystemTools::Error(message.c_str());
  1240. return -2;
  1241. }
  1242. }
  1243. if(!this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR"))
  1244. {
  1245. this->CacheManager->AddCacheEntry("CMAKE_GENERATOR",
  1246. this->GlobalGenerator->GetName().c_str(),
  1247. "Name of generator.",
  1248. cmState::INTERNAL);
  1249. this->CacheManager->AddCacheEntry("CMAKE_EXTRA_GENERATOR",
  1250. this->GlobalGenerator->GetExtraGeneratorName().c_str(),
  1251. "Name of external makefile project generator.",
  1252. cmState::INTERNAL);
  1253. }
  1254. if(const char* platformName =
  1255. this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR_PLATFORM"))
  1256. {
  1257. if(this->GeneratorPlatform.empty())
  1258. {
  1259. this->GeneratorPlatform = platformName;
  1260. }
  1261. else if(this->GeneratorPlatform != platformName)
  1262. {
  1263. std::string message = "Error: generator platform: ";
  1264. message += this->GeneratorPlatform;
  1265. message += "\nDoes not match the platform used previously: ";
  1266. message += platformName;
  1267. message +=
  1268. "\nEither remove the CMakeCache.txt file and CMakeFiles "
  1269. "directory or choose a different binary directory.";
  1270. cmSystemTools::Error(message.c_str());
  1271. return -2;
  1272. }
  1273. }
  1274. else
  1275. {
  1276. this->CacheManager->AddCacheEntry("CMAKE_GENERATOR_PLATFORM",
  1277. this->GeneratorPlatform.c_str(),
  1278. "Name of generator platform.",
  1279. cmState::INTERNAL);
  1280. }
  1281. if(const char* tsName =
  1282. this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR_TOOLSET"))
  1283. {
  1284. if(this->GeneratorToolset.empty())
  1285. {
  1286. this->GeneratorToolset = tsName;
  1287. }
  1288. else if(this->GeneratorToolset != tsName)
  1289. {
  1290. std::string message = "Error: generator toolset: ";
  1291. message += this->GeneratorToolset;
  1292. message += "\nDoes not match the toolset used previously: ";
  1293. message += tsName;
  1294. message +=
  1295. "\nEither remove the CMakeCache.txt file and CMakeFiles "
  1296. "directory or choose a different binary directory.";
  1297. cmSystemTools::Error(message.c_str());
  1298. return -2;
  1299. }
  1300. }
  1301. else
  1302. {
  1303. this->CacheManager->AddCacheEntry("CMAKE_GENERATOR_TOOLSET",
  1304. this->GeneratorToolset.c_str(),
  1305. "Name of generator toolset.",
  1306. cmState::INTERNAL);
  1307. }
  1308. // reset any system configuration information, except for when we are
  1309. // InTryCompile. With TryCompile the system info is taken from the parent's
  1310. // info to save time
  1311. if (!this->State->GetIsInTryCompile())
  1312. {
  1313. this->GlobalGenerator->ClearEnabledLanguages();
  1314. this->TruncateOutputLog("CMakeOutput.log");
  1315. this->TruncateOutputLog("CMakeError.log");
  1316. }
  1317. // actually do the configure
  1318. this->GlobalGenerator->Configure();
  1319. // Before saving the cache
  1320. // if the project did not define one of the entries below, add them now
  1321. // so users can edit the values in the cache:
  1322. // We used to always present LIBRARY_OUTPUT_PATH and
  1323. // EXECUTABLE_OUTPUT_PATH. They are now documented as old-style and
  1324. // should no longer be used. Therefore we present them only if the
  1325. // project requires compatibility with CMake 2.4. We detect this
  1326. // here by looking for the old CMAKE_BACKWARDS_COMPATIBILITY
  1327. // variable created when CMP0001 is not set to NEW.
  1328. if(this->State
  1329. ->GetInitializedCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
  1330. {
  1331. if(!this->State->GetInitializedCacheValue("LIBRARY_OUTPUT_PATH"))
  1332. {
  1333. this->State->AddCacheEntry
  1334. ("LIBRARY_OUTPUT_PATH", "",
  1335. "Single output directory for building all libraries.",
  1336. cmState::PATH);
  1337. }
  1338. if(!this->State
  1339. ->GetInitializedCacheValue("EXECUTABLE_OUTPUT_PATH"))
  1340. {
  1341. this->State->AddCacheEntry
  1342. ("EXECUTABLE_OUTPUT_PATH", "",
  1343. "Single output directory for building all executables.",
  1344. cmState::PATH);
  1345. }
  1346. }
  1347. if(!this->State
  1348. ->GetInitializedCacheValue("CMAKE_USE_RELATIVE_PATHS"))
  1349. {
  1350. this->State->AddCacheEntry
  1351. ("CMAKE_USE_RELATIVE_PATHS", "OFF",
  1352. "If true, cmake will use relative paths in makefiles and projects.",
  1353. cmState::BOOL);
  1354. if (!this->State->GetCacheEntryProperty("CMAKE_USE_RELATIVE_PATHS",
  1355. "ADVANCED"))
  1356. {
  1357. this->State->SetCacheEntryProperty("CMAKE_USE_RELATIVE_PATHS",
  1358. "ADVANCED", "1");
  1359. }
  1360. }
  1361. if(cmSystemTools::GetFatalErrorOccured())
  1362. {
  1363. const char* makeProgram =
  1364. this->State->GetInitializedCacheValue("CMAKE_MAKE_PROGRAM");
  1365. if (!makeProgram || cmSystemTools::IsOff(makeProgram))
  1366. {
  1367. // We must have a bad generator selection. Wipe the cache entry so the
  1368. // user can select another.
  1369. this->State->RemoveCacheEntry("CMAKE_GENERATOR");
  1370. this->State->RemoveCacheEntry("CMAKE_EXTRA_GENERATOR");
  1371. }
  1372. }
  1373. cmMakefile* mf=this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
  1374. if (mf->IsOn("CTEST_USE_LAUNCHERS")
  1375. && !this->State->GetGlobalProperty("RULE_LAUNCH_COMPILE"))
  1376. {
  1377. cmSystemTools::Error("CTEST_USE_LAUNCHERS is enabled, but the "
  1378. "RULE_LAUNCH_COMPILE global property is not defined.\n"
  1379. "Did you forget to include(CTest) in the toplevel "
  1380. "CMakeLists.txt ?");
  1381. }
  1382. // only save the cache if there were no fatal errors
  1383. if ( this->GetWorkingMode() == NORMAL_MODE )
  1384. {
  1385. this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
  1386. }
  1387. if(cmSystemTools::GetErrorOccuredFlag())
  1388. {
  1389. return -1;
  1390. }
  1391. return 0;
  1392. }
  1393. void cmake::PreLoadCMakeFiles()
  1394. {
  1395. std::vector<std::string> args;
  1396. std::string pre_load = this->GetHomeDirectory();
  1397. if (!pre_load.empty())
  1398. {
  1399. pre_load += "/PreLoad.cmake";
  1400. if ( cmSystemTools::FileExists(pre_load.c_str()) )
  1401. {
  1402. this->ReadListFile(args, pre_load.c_str());
  1403. }
  1404. }
  1405. pre_load = this->GetHomeOutputDirectory();
  1406. if (!pre_load.empty())
  1407. {
  1408. pre_load += "/PreLoad.cmake";
  1409. if ( cmSystemTools::FileExists(pre_load.c_str()) )
  1410. {
  1411. this->ReadListFile(args, pre_load.c_str());
  1412. }
  1413. }
  1414. }
  1415. // handle a command line invocation
  1416. int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
  1417. {
  1418. // Process the arguments
  1419. this->SetArgs(args);
  1420. if(cmSystemTools::GetErrorOccuredFlag())
  1421. {
  1422. return -1;
  1423. }
  1424. // If we are given a stamp list file check if it is really out of date.
  1425. if(!this->CheckStampList.empty() &&
  1426. cmakeCheckStampList(this->CheckStampList.c_str()))
  1427. {
  1428. return 0;
  1429. }
  1430. // If we are given a stamp file check if it is really out of date.
  1431. if(!this->CheckStampFile.empty() &&
  1432. cmakeCheckStampFile(this->CheckStampFile.c_str()))
  1433. {
  1434. return 0;
  1435. }
  1436. if ( this->GetWorkingMode() == NORMAL_MODE )
  1437. {
  1438. // load the cache
  1439. if(this->LoadCache() < 0)
  1440. {
  1441. cmSystemTools::Error("Error executing cmake::LoadCache(). Aborting.\n");
  1442. return -1;
  1443. }
  1444. }
  1445. else
  1446. {
  1447. this->AddCMakePaths();
  1448. }
  1449. // Add any cache args
  1450. if ( !this->SetCacheArgs(args) )
  1451. {
  1452. cmSystemTools::Error("Problem processing arguments. Aborting.\n");
  1453. return -1;
  1454. }
  1455. // In script mode we terminate after running the script.
  1456. if(this->GetWorkingMode() != NORMAL_MODE)
  1457. {
  1458. if(cmSystemTools::GetErrorOccuredFlag())
  1459. {
  1460. return -1;
  1461. }
  1462. else
  1463. {
  1464. return 0;
  1465. }
  1466. }
  1467. // If MAKEFLAGS are given in the environment, remove the environment
  1468. // variable. This will prevent try-compile from succeeding when it
  1469. // should fail (if "-i" is an option). We cannot simply test
  1470. // whether "-i" is given and remove it because some make programs
  1471. // encode the MAKEFLAGS variable in a strange way.
  1472. if(getenv("MAKEFLAGS"))
  1473. {
  1474. cmSystemTools::PutEnv("MAKEFLAGS=");
  1475. }
  1476. this->PreLoadCMakeFiles();
  1477. if ( noconfigure )
  1478. {
  1479. return 0;
  1480. }
  1481. // now run the global generate
  1482. // Check the state of the build system to see if we need to regenerate.
  1483. if(!this->CheckBuildSystem())
  1484. {
  1485. return 0;
  1486. }
  1487. int ret = this->Configure();
  1488. if (ret || this->GetWorkingMode() != NORMAL_MODE)
  1489. {
  1490. #if defined(CMAKE_HAVE_VS_GENERATORS)
  1491. if(!this->VSSolutionFile.empty() && this->GlobalGenerator)
  1492. {
  1493. // CMake is running to regenerate a Visual Studio build tree
  1494. // during a build from the VS IDE. The build files cannot be
  1495. // regenerated, so we should stop the build.
  1496. cmSystemTools::Message(
  1497. "CMake Configure step failed. "
  1498. "Build files cannot be regenerated correctly. "
  1499. "Attempting to stop IDE build.");
  1500. cmGlobalVisualStudioGenerator* gg =
  1501. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  1502. gg->CallVisualStudioMacro(cmGlobalVisualStudioGenerator::MacroStop,
  1503. this->VSSolutionFile.c_str());
  1504. }
  1505. #endif
  1506. return ret;
  1507. }
  1508. ret = this->Generate();
  1509. std::string message = "Build files have been written to: ";
  1510. message += this->GetHomeOutputDirectory();
  1511. this->UpdateProgress(message.c_str(), -1);
  1512. if(ret)
  1513. {
  1514. return ret;
  1515. }
  1516. return ret;
  1517. }
  1518. int cmake::Generate()
  1519. {
  1520. if(!this->GlobalGenerator)
  1521. {
  1522. return -1;
  1523. }
  1524. this->GlobalGenerator->DoGenerate();
  1525. if ( !this->GraphVizFile.empty() )
  1526. {
  1527. std::cout << "Generate graphviz: " << this->GraphVizFile << std::endl;
  1528. this->GenerateGraphViz(this->GraphVizFile.c_str());
  1529. }
  1530. if(this->WarnUnusedCli)
  1531. {
  1532. this->RunCheckForUnusedVariables();
  1533. }
  1534. if(cmSystemTools::GetErrorOccuredFlag())
  1535. {
  1536. return -1;
  1537. }
  1538. // Save the cache again after a successful Generate so that any internal
  1539. // variables created during Generate are saved. (Specifically target GUIDs
  1540. // for the Visual Studio and Xcode generators.)
  1541. if ( this->GetWorkingMode() == NORMAL_MODE )
  1542. {
  1543. this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
  1544. }
  1545. return 0;
  1546. }
  1547. void cmake::AddCacheEntry(const std::string& key, const char* value,
  1548. const char* helpString,
  1549. int type)
  1550. {
  1551. this->CacheManager->AddCacheEntry(key, value,
  1552. helpString,
  1553. cmState::CacheEntryType(type));
  1554. }
  1555. const char* cmake::GetCacheDefinition(const std::string& name) const
  1556. {
  1557. return this->CacheManager->GetInitializedCacheValue(name);
  1558. }
  1559. void cmake::AddDefaultCommands()
  1560. {
  1561. std::vector<cmCommand*> commands;
  1562. GetBootstrapCommands1(commands);
  1563. GetBootstrapCommands2(commands);
  1564. GetPredefinedCommands(commands);
  1565. for(std::vector<cmCommand*>::iterator i = commands.begin();
  1566. i != commands.end(); ++i)
  1567. {
  1568. this->State->AddCommand(*i);
  1569. }
  1570. }
  1571. void cmake::AddDefaultGenerators()
  1572. {
  1573. #if defined(_WIN32) && !defined(__CYGWIN__)
  1574. # if !defined(CMAKE_BOOT_MINGW)
  1575. this->Generators.push_back(
  1576. cmGlobalVisualStudio14Generator::NewFactory());
  1577. this->Generators.push_back(
  1578. cmGlobalVisualStudio12Generator::NewFactory());
  1579. this->Generators.push_back(
  1580. cmGlobalVisualStudio11Generator::NewFactory());
  1581. this->Generators.push_back(
  1582. cmGlobalVisualStudio10Generator::NewFactory());
  1583. this->Generators.push_back(
  1584. cmGlobalVisualStudio9Generator::NewFactory());
  1585. this->Generators.push_back(
  1586. cmGlobalVisualStudio8Generator::NewFactory());
  1587. this->Generators.push_back(
  1588. cmGlobalVisualStudio71Generator::NewFactory());
  1589. this->Generators.push_back(
  1590. cmGlobalVisualStudio7Generator::NewFactory());
  1591. this->Generators.push_back(
  1592. cmGlobalVisualStudio6Generator::NewFactory());
  1593. this->Generators.push_back(
  1594. cmGlobalBorlandMakefileGenerator::NewFactory());
  1595. this->Generators.push_back(
  1596. cmGlobalNMakeMakefileGenerator::NewFactory());
  1597. this->Generators.push_back(
  1598. cmGlobalJOMMakefileGenerator::NewFactory());
  1599. this->Generators.push_back(
  1600. cmGlobalGhsMultiGenerator::NewFactory());
  1601. # endif
  1602. this->Generators.push_back(
  1603. cmGlobalMSYSMakefileGenerator::NewFactory());
  1604. this->Generators.push_back(
  1605. cmGlobalMinGWMakefileGenerator::NewFactory());
  1606. #endif
  1607. this->Generators.push_back(
  1608. cmGlobalUnixMakefileGenerator3::NewFactory());
  1609. this->Generators.push_back(
  1610. cmGlobalNinjaGenerator::NewFactory());
  1611. #if defined(CMAKE_USE_WMAKE)
  1612. this->Generators.push_back(
  1613. cmGlobalWatcomWMakeGenerator::NewFactory());
  1614. #endif
  1615. #ifdef CMAKE_USE_XCODE
  1616. this->Generators.push_back(
  1617. cmGlobalXCodeGenerator::NewFactory());
  1618. #endif
  1619. }
  1620. bool cmake::ParseCacheEntry(const std::string& entry,
  1621. std::string& var,
  1622. std::string& value,
  1623. cmState::CacheEntryType& type)
  1624. {
  1625. return cmCacheManager::ParseEntry(entry, var, value, type);
  1626. }
  1627. int cmake::LoadCache()
  1628. {
  1629. // could we not read the cache
  1630. if (!this->LoadCache(this->GetHomeOutputDirectory()))
  1631. {
  1632. // if it does exist, but isn't readable then warn the user
  1633. std::string cacheFile = this->GetHomeOutputDirectory();
  1634. cacheFile += "/CMakeCache.txt";
  1635. if(cmSystemTools::FileExists(cacheFile.c_str()))
  1636. {
  1637. cmSystemTools::Error(
  1638. "There is a CMakeCache.txt file for the current binary tree but "
  1639. "cmake does not have permission to read it. Please check the "
  1640. "permissions of the directory you are trying to run CMake on.");
  1641. return -1;
  1642. }
  1643. }
  1644. // setup CMAKE_ROOT and CMAKE_COMMAND
  1645. if(!this->AddCMakePaths())
  1646. {
  1647. return -3;
  1648. }
  1649. return 0;
  1650. }
  1651. bool cmake::LoadCache(const std::string& path)
  1652. {
  1653. return this->CacheManager->LoadCache(path);
  1654. }
  1655. bool cmake::LoadCache(const std::string& path, bool internal,
  1656. std::set<std::string>& excludes,
  1657. std::set<std::string>& includes)
  1658. {
  1659. return this->CacheManager->LoadCache(path, internal, excludes, includes);
  1660. }
  1661. bool cmake::SaveCache(const std::string& path)
  1662. {
  1663. return this->CacheManager->SaveCache(path);
  1664. }
  1665. bool cmake::DeleteCache(const std::string& path)
  1666. {
  1667. return this->CacheManager->DeleteCache(path);
  1668. }
  1669. void cmake::SetProgressCallback(ProgressCallbackType f, void *cd)
  1670. {
  1671. this->ProgressCallback = f;
  1672. this->ProgressCallbackClientData = cd;
  1673. }
  1674. void cmake::UpdateProgress(const char *msg, float prog)
  1675. {
  1676. if(this->ProgressCallback && !this->State->GetIsInTryCompile())
  1677. {
  1678. (*this->ProgressCallback)(msg, prog, this->ProgressCallbackClientData);
  1679. return;
  1680. }
  1681. }
  1682. bool cmake::GetIsInTryCompile() const
  1683. {
  1684. return this->State->GetIsInTryCompile();
  1685. }
  1686. void cmake::SetIsInTryCompile(bool b)
  1687. {
  1688. this->State->SetIsInTryCompile(b);
  1689. }
  1690. void cmake::GetGeneratorDocumentation(std::vector<cmDocumentationEntry>& v)
  1691. {
  1692. for(RegisteredGeneratorsVector::const_iterator i =
  1693. this->Generators.begin(); i != this->Generators.end(); ++i)
  1694. {
  1695. cmDocumentationEntry e;
  1696. (*i)->GetDocumentation(e);
  1697. v.push_back(e);
  1698. }
  1699. for(RegisteredExtraGeneratorsMap::const_iterator i =
  1700. this->ExtraGenerators.begin(); i != this->ExtraGenerators.end(); ++i)
  1701. {
  1702. cmDocumentationEntry e;
  1703. cmExternalMakefileProjectGenerator* generator = (i->second)();
  1704. generator->GetDocumentation(e, i->first);
  1705. e.Name = i->first;
  1706. delete generator;
  1707. v.push_back(e);
  1708. }
  1709. }
  1710. void cmake::PrintGeneratorList()
  1711. {
  1712. #ifdef CMAKE_BUILD_WITH_CMAKE
  1713. cmDocumentation doc;
  1714. std::vector<cmDocumentationEntry> generators;
  1715. this->GetGeneratorDocumentation(generators);
  1716. doc.AppendSection("Generators",generators);
  1717. std::cerr << "\n";
  1718. doc.PrintDocumentation(cmDocumentation::ListGenerators, std::cerr);
  1719. #endif
  1720. }
  1721. void cmake::UpdateConversionPathTable()
  1722. {
  1723. // Update the path conversion table with any specified file:
  1724. const char* tablepath =
  1725. this->CacheManager
  1726. ->GetInitializedCacheValue("CMAKE_PATH_TRANSLATION_FILE");
  1727. if(tablepath)
  1728. {
  1729. cmsys::ifstream table( tablepath );
  1730. if(!table)
  1731. {
  1732. cmSystemTools::Error("CMAKE_PATH_TRANSLATION_FILE set to ", tablepath,
  1733. ". CMake can not open file.");
  1734. cmSystemTools::ReportLastSystemError("CMake can not open file.");
  1735. }
  1736. else
  1737. {
  1738. std::string a, b;
  1739. while(!table.eof())
  1740. {
  1741. // two entries per line
  1742. table >> a; table >> b;
  1743. cmSystemTools::AddTranslationPath( a, b);
  1744. }
  1745. }
  1746. }
  1747. }
  1748. //----------------------------------------------------------------------------
  1749. int cmake::CheckBuildSystem()
  1750. {
  1751. // We do not need to rerun CMake. Check dependency integrity. Use
  1752. // the make system's VERBOSE environment variable to enable verbose
  1753. // output. This can be skipped by setting CMAKE_NO_VERBOSE (which is set
  1754. // by the Eclipse and KDevelop generators).
  1755. bool verbose = ((cmSystemTools::GetEnv("VERBOSE") != 0)
  1756. && (cmSystemTools::GetEnv("CMAKE_NO_VERBOSE") == 0));
  1757. // This method will check the integrity of the build system if the
  1758. // option was given on the command line. It reads the given file to
  1759. // determine whether CMake should rerun.
  1760. // If no file is provided for the check, we have to rerun.
  1761. if(this->CheckBuildSystemArgument.empty())
  1762. {
  1763. if(verbose)
  1764. {
  1765. std::ostringstream msg;
  1766. msg << "Re-run cmake no build system arguments\n";
  1767. cmSystemTools::Stdout(msg.str().c_str());
  1768. }
  1769. return 1;
  1770. }
  1771. // If the file provided does not exist, we have to rerun.
  1772. if(!cmSystemTools::FileExists(this->CheckBuildSystemArgument.c_str()))
  1773. {
  1774. if(verbose)
  1775. {
  1776. std::ostringstream msg;
  1777. msg << "Re-run cmake missing file: "
  1778. << this->CheckBuildSystemArgument << "\n";
  1779. cmSystemTools::Stdout(msg.str().c_str());
  1780. }
  1781. return 1;
  1782. }
  1783. // Read the rerun check file and use it to decide whether to do the
  1784. // global generate.
  1785. cmake cm;
  1786. cm.SetHomeDirectory("");
  1787. cm.SetHomeOutputDirectory("");
  1788. cmGlobalGenerator gg;
  1789. gg.SetCMakeInstance(&cm);
  1790. cmsys::auto_ptr<cmLocalGenerator> lg(gg.MakeLocalGenerator());
  1791. cmMakefile* mf = lg->GetMakefile();
  1792. if(!mf->ReadListFile(this->CheckBuildSystemArgument.c_str()) ||
  1793. cmSystemTools::GetErrorOccuredFlag())
  1794. {
  1795. if(verbose)
  1796. {
  1797. std::ostringstream msg;
  1798. msg << "Re-run cmake error reading : "
  1799. << this->CheckBuildSystemArgument << "\n";
  1800. cmSystemTools::Stdout(msg.str().c_str());
  1801. }
  1802. // There was an error reading the file. Just rerun.
  1803. return 1;
  1804. }
  1805. if(this->ClearBuildSystem)
  1806. {
  1807. // Get the generator used for this build system.
  1808. const char* genName = mf->GetDefinition("CMAKE_DEPENDS_GENERATOR");
  1809. if(!genName || genName[0] == '\0')
  1810. {
  1811. genName = "Unix Makefiles";
  1812. }
  1813. // Create the generator and use it to clear the dependencies.
  1814. cmsys::auto_ptr<cmGlobalGenerator>
  1815. ggd(this->CreateGlobalGenerator(genName));
  1816. if(ggd.get())
  1817. {
  1818. cmsys::auto_ptr<cmLocalGenerator> lgd(ggd->MakeLocalGenerator());
  1819. lgd->ClearDependencies(mf, verbose);
  1820. }
  1821. }
  1822. // If any byproduct of makefile generation is missing we must re-run.
  1823. std::vector<std::string> products;
  1824. if(const char* productStr = mf->GetDefinition("CMAKE_MAKEFILE_PRODUCTS"))
  1825. {
  1826. cmSystemTools::ExpandListArgument(productStr, products);
  1827. }
  1828. for(std::vector<std::string>::const_iterator pi = products.begin();
  1829. pi != products.end(); ++pi)
  1830. {
  1831. if(!(cmSystemTools::FileExists(pi->c_str()) ||
  1832. cmSystemTools::FileIsSymlink(*pi)))
  1833. {
  1834. if(verbose)
  1835. {
  1836. std::ostringstream msg;
  1837. msg << "Re-run cmake, missing byproduct: " << *pi << "\n";
  1838. cmSystemTools::Stdout(msg.str().c_str());
  1839. }
  1840. return 1;
  1841. }
  1842. }
  1843. // Get the set of dependencies and outputs.
  1844. std::vector<std::string> depends;
  1845. std::vector<std::string> outputs;
  1846. const char* dependsStr = mf->GetDefinition("CMAKE_MAKEFILE_DEPENDS");
  1847. const char* outputsStr = mf->GetDefinition("CMAKE_MAKEFILE_OUTPUTS");
  1848. if(dependsStr && outputsStr)
  1849. {
  1850. cmSystemTools::ExpandListArgument(dependsStr, depends);
  1851. cmSystemTools::ExpandListArgument(outputsStr, outputs);
  1852. }
  1853. if(depends.empty() || outputs.empty())
  1854. {
  1855. // Not enough information was provided to do the test. Just rerun.
  1856. if(verbose)
  1857. {
  1858. std::ostringstream msg;
  1859. msg << "Re-run cmake no CMAKE_MAKEFILE_DEPENDS "
  1860. "or CMAKE_MAKEFILE_OUTPUTS :\n";
  1861. cmSystemTools::Stdout(msg.str().c_str());
  1862. }
  1863. return 1;
  1864. }
  1865. // Find the newest dependency.
  1866. std::vector<std::string>::iterator dep = depends.begin();
  1867. std::string dep_newest = *dep++;
  1868. for(;dep != depends.end(); ++dep)
  1869. {
  1870. int result = 0;
  1871. if(this->FileComparison->FileTimeCompare(dep_newest.c_str(),
  1872. dep->c_str(), &result))
  1873. {
  1874. if(result < 0)
  1875. {
  1876. dep_newest = *dep;
  1877. }
  1878. }
  1879. else
  1880. {
  1881. if(verbose)
  1882. {
  1883. std::ostringstream msg;
  1884. msg << "Re-run cmake: build system dependency is missing\n";
  1885. cmSystemTools::Stdout(msg.str().c_str());
  1886. }
  1887. return 1;
  1888. }
  1889. }
  1890. // Find the oldest output.
  1891. std::vector<std::string>::iterator out = outputs.begin();
  1892. std::string out_oldest = *out++;
  1893. for(;out != outputs.end(); ++out)
  1894. {
  1895. int result = 0;
  1896. if(this->FileComparison->FileTimeCompare(out_oldest.c_str(),
  1897. out->c_str(), &result))
  1898. {
  1899. if(result > 0)
  1900. {
  1901. out_oldest = *out;
  1902. }
  1903. }
  1904. else
  1905. {
  1906. if(verbose)
  1907. {
  1908. std::ostringstream msg;
  1909. msg << "Re-run cmake: build system output is missing\n";
  1910. cmSystemTools::Stdout(msg.str().c_str());
  1911. }
  1912. return 1;
  1913. }
  1914. }
  1915. // If any output is older than any dependency then rerun.
  1916. {
  1917. int result = 0;
  1918. if(!this->FileComparison->FileTimeCompare(out_oldest.c_str(),
  1919. dep_newest.c_str(),
  1920. &result) ||
  1921. result < 0)
  1922. {
  1923. if(verbose)
  1924. {
  1925. std::ostringstream msg;
  1926. msg << "Re-run cmake file: " << out_oldest
  1927. << " older than: " << dep_newest << "\n";
  1928. cmSystemTools::Stdout(msg.str().c_str());
  1929. }
  1930. return 1;
  1931. }
  1932. }
  1933. // No need to rerun.
  1934. return 0;
  1935. }
  1936. //----------------------------------------------------------------------------
  1937. void cmake::TruncateOutputLog(const char* fname)
  1938. {
  1939. std::string fullPath = this->GetHomeOutputDirectory();
  1940. fullPath += "/";
  1941. fullPath += fname;
  1942. struct stat st;
  1943. if ( ::stat(fullPath.c_str(), &st) )
  1944. {
  1945. return;
  1946. }
  1947. if (!this->State->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR"))
  1948. {
  1949. cmSystemTools::RemoveFile(fullPath);
  1950. return;
  1951. }
  1952. off_t fsize = st.st_size;
  1953. const off_t maxFileSize = 50 * 1024;
  1954. if ( fsize < maxFileSize )
  1955. {
  1956. //TODO: truncate file
  1957. return;
  1958. }
  1959. }
  1960. inline std::string removeQuotes(const std::string& s)
  1961. {
  1962. if(s[0] == '\"' && s[s.size()-1] == '\"')
  1963. {
  1964. return s.substr(1, s.size()-2);
  1965. }
  1966. return s;
  1967. }
  1968. void cmake::MarkCliAsUsed(const std::string& variable)
  1969. {
  1970. this->UsedCliVariables[variable] = true;
  1971. }
  1972. void cmake::GenerateGraphViz(const char* fileName) const
  1973. {
  1974. #ifdef CMAKE_BUILD_WITH_CMAKE
  1975. cmsys::auto_ptr<cmGraphVizWriter> gvWriter(
  1976. new cmGraphVizWriter(this->GetGlobalGenerator()->GetLocalGenerators()));
  1977. std::string settingsFile = this->GetHomeOutputDirectory();
  1978. settingsFile += "/CMakeGraphVizOptions.cmake";
  1979. std::string fallbackSettingsFile = this->GetHomeDirectory();
  1980. fallbackSettingsFile += "/CMakeGraphVizOptions.cmake";
  1981. gvWriter->ReadSettings(settingsFile.c_str(), fallbackSettingsFile.c_str());
  1982. gvWriter->WritePerTargetFiles(fileName);
  1983. gvWriter->WriteTargetDependersFiles(fileName);
  1984. gvWriter->WriteGlobalFile(fileName);
  1985. #endif
  1986. }
  1987. void cmake::SetProperty(const std::string& prop, const char* value)
  1988. {
  1989. this->State->SetGlobalProperty(prop, value);
  1990. }
  1991. void cmake::AppendProperty(const std::string& prop,
  1992. const char* value, bool asString)
  1993. {
  1994. this->State->AppendGlobalProperty(prop, value, asString);
  1995. }
  1996. const char *cmake::GetProperty(const std::string& prop)
  1997. {
  1998. return this->State->GetGlobalProperty(prop);
  1999. }
  2000. bool cmake::GetPropertyAsBool(const std::string& prop)
  2001. {
  2002. return this->State->GetGlobalPropertyAsBool(prop);
  2003. }
  2004. cmInstalledFile *cmake::GetOrCreateInstalledFile(
  2005. cmMakefile* mf, const std::string& name)
  2006. {
  2007. std::map<std::string, cmInstalledFile>::iterator i =
  2008. this->InstalledFiles.find(name);
  2009. if(i != this->InstalledFiles.end())
  2010. {
  2011. cmInstalledFile &file = i->second;
  2012. return &file;
  2013. }
  2014. else
  2015. {
  2016. cmInstalledFile &file = this->InstalledFiles[name];
  2017. file.SetName(mf, name);
  2018. return &file;
  2019. }
  2020. }
  2021. cmInstalledFile const* cmake::GetInstalledFile(const std::string& name) const
  2022. {
  2023. std::map<std::string, cmInstalledFile>::const_iterator i =
  2024. this->InstalledFiles.find(name);
  2025. if(i != this->InstalledFiles.end())
  2026. {
  2027. cmInstalledFile const& file = i->second;
  2028. return &file;
  2029. }
  2030. else
  2031. {
  2032. return 0;
  2033. }
  2034. }
  2035. int cmake::GetSystemInformation(std::vector<std::string>& args)
  2036. {
  2037. // so create the directory
  2038. std::string resultFile;
  2039. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  2040. std::string destPath = cwd + "/__cmake_systeminformation";
  2041. cmSystemTools::RemoveADirectory(destPath);
  2042. if (!cmSystemTools::MakeDirectory(destPath.c_str()))
  2043. {
  2044. std::cerr << "Error: --system-information must be run from a "
  2045. "writable directory!\n";
  2046. return 1;
  2047. }
  2048. // process the arguments
  2049. bool writeToStdout = true;
  2050. for(unsigned int i=1; i < args.size(); ++i)
  2051. {
  2052. std::string arg = args[i];
  2053. if(arg.find("-V",0) == 0)
  2054. {
  2055. this->Verbose = true;
  2056. }
  2057. else if(arg.find("-G",0) == 0)
  2058. {
  2059. std::string value = arg.substr(2);
  2060. if(value.empty())
  2061. {
  2062. ++i;
  2063. if(i >= args.size())
  2064. {
  2065. cmSystemTools::Error("No generator specified for -G");
  2066. this->PrintGeneratorList();
  2067. return -1;
  2068. }
  2069. value = args[i];
  2070. }
  2071. cmGlobalGenerator* gen =
  2072. this->CreateGlobalGenerator(value);
  2073. if(!gen)
  2074. {
  2075. cmSystemTools::Error("Could not create named generator ",
  2076. value.c_str());
  2077. this->PrintGeneratorList();
  2078. }
  2079. else
  2080. {
  2081. this->SetGlobalGenerator(gen);
  2082. }
  2083. }
  2084. // no option assume it is the output file
  2085. else
  2086. {
  2087. if (!cmSystemTools::FileIsFullPath(arg.c_str()))
  2088. {
  2089. resultFile = cwd;
  2090. resultFile += "/";
  2091. }
  2092. resultFile += arg;
  2093. writeToStdout = false;
  2094. }
  2095. }
  2096. // we have to find the module directory, so we can copy the files
  2097. this->AddCMakePaths();
  2098. std::string modulesPath =
  2099. this->State->GetInitializedCacheValue("CMAKE_ROOT");
  2100. modulesPath += "/Modules";
  2101. std::string inFile = modulesPath;
  2102. inFile += "/SystemInformation.cmake";
  2103. std::string outFile = destPath;
  2104. outFile += "/CMakeLists.txt";
  2105. // Copy file
  2106. if(!cmSystemTools::cmCopyFile(inFile.c_str(), outFile.c_str()))
  2107. {
  2108. std::cerr << "Error copying file \"" << inFile
  2109. << "\" to \"" << outFile << "\".\n";
  2110. return 1;
  2111. }
  2112. // do we write to a file or to stdout?
  2113. if (resultFile.empty())
  2114. {
  2115. resultFile = cwd;
  2116. resultFile += "/__cmake_systeminformation/results.txt";
  2117. }
  2118. // now run cmake on the CMakeLists file
  2119. cmSystemTools::ChangeDirectory(destPath);
  2120. std::vector<std::string> args2;
  2121. args2.push_back(args[0]);
  2122. args2.push_back(destPath);
  2123. std::string resultArg = "-DRESULT_FILE=";
  2124. resultArg += resultFile;
  2125. args2.push_back(resultArg);
  2126. int res = this->Run(args2, false);
  2127. if (res != 0)
  2128. {
  2129. std::cerr << "Error: --system-information failed on internal CMake!\n";
  2130. return res;
  2131. }
  2132. // change back to the original directory
  2133. cmSystemTools::ChangeDirectory(cwd);
  2134. // echo results to stdout if needed
  2135. if (writeToStdout)
  2136. {
  2137. FILE* fin = cmsys::SystemTools::Fopen(resultFile, "r");
  2138. if(fin)
  2139. {
  2140. const int bufferSize = 4096;
  2141. char buffer[bufferSize];
  2142. size_t n;
  2143. while((n = fread(buffer, 1, bufferSize, fin)) > 0)
  2144. {
  2145. for(char* c = buffer; c < buffer+n; ++c)
  2146. {
  2147. putc(*c, stdout);
  2148. }
  2149. fflush(stdout);
  2150. }
  2151. fclose(fin);
  2152. }
  2153. }
  2154. // clean up the directory
  2155. cmSystemTools::RemoveADirectory(destPath);
  2156. return 0;
  2157. }
  2158. //----------------------------------------------------------------------------
  2159. static bool cmakeCheckStampFile(const char* stampName)
  2160. {
  2161. // The stamp file does not exist. Use the stamp dependencies to
  2162. // determine whether it is really out of date. This works in
  2163. // conjunction with cmLocalVisualStudio7Generator to avoid
  2164. // repeatedly re-running CMake when the user rebuilds the entire
  2165. // solution.
  2166. std::string stampDepends = stampName;
  2167. stampDepends += ".depend";
  2168. #if defined(_WIN32) || defined(__CYGWIN__)
  2169. cmsys::ifstream fin(stampDepends.c_str(), std::ios::in | std::ios::binary);
  2170. #else
  2171. cmsys::ifstream fin(stampDepends.c_str(), std::ios::in);
  2172. #endif
  2173. if(!fin)
  2174. {
  2175. // The stamp dependencies file cannot be read. Just assume the
  2176. // build system is really out of date.
  2177. std::cout << "CMake is re-running because " << stampName
  2178. << " dependency file is missing.\n";
  2179. return false;
  2180. }
  2181. // Compare the stamp dependencies against the dependency file itself.
  2182. cmFileTimeComparison ftc;
  2183. std::string dep;
  2184. while(cmSystemTools::GetLineFromStream(fin, dep))
  2185. {
  2186. int result;
  2187. if(!dep.empty() && dep[0] != '#' &&
  2188. (!ftc.FileTimeCompare(stampDepends.c_str(), dep.c_str(), &result)
  2189. || result < 0))
  2190. {
  2191. // The stamp depends file is older than this dependency. The
  2192. // build system is really out of date.
  2193. std::cout << "CMake is re-running because " << stampName
  2194. << " is out-of-date.\n";
  2195. std::cout << " the file '" << dep << "'\n";
  2196. std::cout << " is newer than '" << stampDepends << "'\n";
  2197. std::cout << " result='" << result << "'\n";
  2198. return false;
  2199. }
  2200. }
  2201. // The build system is up to date. The stamp file has been removed
  2202. // by the VS IDE due to a "rebuild" request. Restore it atomically.
  2203. std::ostringstream stampTempStream;
  2204. stampTempStream << stampName << ".tmp" << cmSystemTools::RandomSeed();
  2205. std::string stampTempString = stampTempStream.str();
  2206. const char* stampTemp = stampTempString.c_str();
  2207. {
  2208. // TODO: Teach cmGeneratedFileStream to use a random temp file (with
  2209. // multiple tries in unlikely case of conflict) and use that here.
  2210. cmsys::ofstream stamp(stampTemp);
  2211. stamp << "# CMake generation timestamp file for this directory.\n";
  2212. }
  2213. if(cmSystemTools::RenameFile(stampTemp, stampName))
  2214. {
  2215. // Notify the user why CMake is not re-running. It is safe to
  2216. // just print to stdout here because this code is only reachable
  2217. // through an undocumented flag used by the VS generator.
  2218. std::cout << "CMake does not need to re-run because "
  2219. << stampName << " is up-to-date.\n";
  2220. return true;
  2221. }
  2222. else
  2223. {
  2224. cmSystemTools::RemoveFile(stampTemp);
  2225. cmSystemTools::Error("Cannot restore timestamp ", stampName);
  2226. return false;
  2227. }
  2228. }
  2229. //----------------------------------------------------------------------------
  2230. static bool cmakeCheckStampList(const char* stampList)
  2231. {
  2232. // If the stamp list does not exist CMake must rerun to generate it.
  2233. if(!cmSystemTools::FileExists(stampList))
  2234. {
  2235. std::cout << "CMake is re-running because generate.stamp.list "
  2236. << "is missing.\n";
  2237. return false;
  2238. }
  2239. cmsys::ifstream fin(stampList);
  2240. if(!fin)
  2241. {
  2242. std::cout << "CMake is re-running because generate.stamp.list "
  2243. << "could not be read.\n";
  2244. return false;
  2245. }
  2246. // Check each stamp.
  2247. std::string stampName;
  2248. while(cmSystemTools::GetLineFromStream(fin, stampName))
  2249. {
  2250. if(!cmakeCheckStampFile(stampName.c_str()))
  2251. {
  2252. return false;
  2253. }
  2254. }
  2255. return true;
  2256. }
  2257. bool cmake::PrintMessagePreamble(cmake::MessageType t, std::ostream& msg)
  2258. {
  2259. // Construct the message header.
  2260. if(t == cmake::FATAL_ERROR)
  2261. {
  2262. msg << "CMake Error";
  2263. }
  2264. else if(t == cmake::INTERNAL_ERROR)
  2265. {
  2266. msg << "CMake Internal Error (please report a bug)";
  2267. }
  2268. else if(t == cmake::LOG)
  2269. {
  2270. msg << "CMake Debug Log";
  2271. }
  2272. else if(t == cmake::DEPRECATION_ERROR)
  2273. {
  2274. msg << "CMake Deprecation Error";
  2275. }
  2276. else if (t == cmake::DEPRECATION_WARNING)
  2277. {
  2278. msg << "CMake Deprecation Warning";
  2279. }
  2280. else
  2281. {
  2282. msg << "CMake Warning";
  2283. if(t == cmake::AUTHOR_WARNING)
  2284. {
  2285. // Allow suppression of these warnings.
  2286. const char* suppress = this->State->GetCacheEntryValue(
  2287. "CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
  2288. if(suppress && cmSystemTools::IsOn(suppress))
  2289. {
  2290. return false;
  2291. }
  2292. msg << " (dev)";
  2293. }
  2294. }
  2295. return true;
  2296. }
  2297. void printMessageText(std::ostream& msg, std::string const& text)
  2298. {
  2299. msg << ":\n";
  2300. cmDocumentationFormatter formatter;
  2301. formatter.SetIndent(" ");
  2302. formatter.PrintFormatted(msg, text.c_str());
  2303. }
  2304. void displayMessage(cmake::MessageType t, std::ostringstream& msg)
  2305. {
  2306. // Add a note about warning suppression.
  2307. if(t == cmake::AUTHOR_WARNING)
  2308. {
  2309. msg <<
  2310. "This warning is for project developers. Use -Wno-dev to suppress it.";
  2311. }
  2312. // Add a terminating blank line.
  2313. msg << "\n";
  2314. #if defined(CMAKE_BUILD_WITH_CMAKE)
  2315. // Add a C++ stack trace to internal errors.
  2316. if(t == cmake::INTERNAL_ERROR)
  2317. {
  2318. std::string stack = cmsys::SystemInformation::GetProgramStack(0,0);
  2319. if(!stack.empty())
  2320. {
  2321. if(cmHasLiteralPrefix(stack, "WARNING:"))
  2322. {
  2323. stack = "Note:" + stack.substr(8);
  2324. }
  2325. msg << stack << "\n";
  2326. }
  2327. }
  2328. #endif
  2329. // Output the message.
  2330. if(t == cmake::FATAL_ERROR
  2331. || t == cmake::INTERNAL_ERROR
  2332. || t == cmake::DEPRECATION_ERROR)
  2333. {
  2334. cmSystemTools::SetErrorOccured();
  2335. cmSystemTools::Message(msg.str().c_str(), "Error");
  2336. }
  2337. else
  2338. {
  2339. cmSystemTools::Message(msg.str().c_str(), "Warning");
  2340. }
  2341. }
  2342. //----------------------------------------------------------------------------
  2343. void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
  2344. cmListFileBacktrace const& bt)
  2345. {
  2346. cmListFileBacktrace backtrace = bt;
  2347. backtrace.MakeRelative();
  2348. std::ostringstream msg;
  2349. if (!this->PrintMessagePreamble(t, msg))
  2350. {
  2351. return;
  2352. }
  2353. // Add the immediate context.
  2354. backtrace.PrintTitle(msg);
  2355. printMessageText(msg, text);
  2356. // Add the rest of the context.
  2357. backtrace.PrintCallStack(msg);
  2358. displayMessage(t, msg);
  2359. }
  2360. //----------------------------------------------------------------------------
  2361. void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
  2362. cmListFileContext const& lfc)
  2363. {
  2364. std::ostringstream msg;
  2365. if (!this->PrintMessagePreamble(t, msg))
  2366. {
  2367. return;
  2368. }
  2369. // Add the immediate context.
  2370. msg << (lfc.Line ? " at " : " in ") << lfc;
  2371. printMessageText(msg, text);
  2372. displayMessage(t, msg);
  2373. }
  2374. //----------------------------------------------------------------------------
  2375. std::vector<std::string> cmake::GetDebugConfigs()
  2376. {
  2377. std::vector<std::string> configs;
  2378. if(const char* config_list =
  2379. this->State->GetGlobalProperty("DEBUG_CONFIGURATIONS"))
  2380. {
  2381. // Expand the specified list and convert to upper-case.
  2382. cmSystemTools::ExpandListArgument(config_list, configs);
  2383. std::transform(configs.begin(),
  2384. configs.end(),
  2385. configs.begin(),
  2386. cmSystemTools::UpperCase);
  2387. }
  2388. // If no configurations were specified, use a default list.
  2389. if(configs.empty())
  2390. {
  2391. configs.push_back("DEBUG");
  2392. }
  2393. return configs;
  2394. }
  2395. int cmake::Build(const std::string& dir,
  2396. const std::string& target,
  2397. const std::string& config,
  2398. const std::vector<std::string>& nativeOptions,
  2399. bool clean)
  2400. {
  2401. this->SetHomeDirectory("");
  2402. this->SetHomeOutputDirectory("");
  2403. if(!cmSystemTools::FileIsDirectory(dir))
  2404. {
  2405. std::cerr << "Error: " << dir << " is not a directory\n";
  2406. return 1;
  2407. }
  2408. std::string cachePath = dir;
  2409. cmSystemTools::ConvertToUnixSlashes(cachePath);
  2410. if(!this->LoadCache(cachePath))
  2411. {
  2412. std::cerr << "Error: could not load cache\n";
  2413. return 1;
  2414. }
  2415. const char* cachedGenerator =
  2416. this->State->GetCacheEntryValue("CMAKE_GENERATOR");
  2417. if(!cachedGenerator)
  2418. {
  2419. std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n";
  2420. return 1;
  2421. }
  2422. cmsys::auto_ptr<cmGlobalGenerator> gen(
  2423. this->CreateGlobalGenerator(cachedGenerator));
  2424. if(!gen.get())
  2425. {
  2426. std::cerr << "Error: could create CMAKE_GENERATOR \""
  2427. << cachedGenerator << "\"\n";
  2428. return 1;
  2429. }
  2430. std::string output;
  2431. std::string projName;
  2432. const char* cachedProjectName =
  2433. this->State->GetCacheEntryValue("CMAKE_PROJECT_NAME");
  2434. if(!cachedProjectName)
  2435. {
  2436. std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n";
  2437. return 1;
  2438. }
  2439. projName = cachedProjectName;
  2440. bool verbose = false;
  2441. const char* cachedVerbose =
  2442. this->State->GetCacheEntryValue("CMAKE_VERBOSE_MAKEFILE");
  2443. if(cachedVerbose)
  2444. {
  2445. verbose = cmSystemTools::IsOn(cachedVerbose);
  2446. }
  2447. return gen->Build("", dir,
  2448. projName, target,
  2449. output,
  2450. "",
  2451. config, clean, false, verbose, 0,
  2452. cmSystemTools::OUTPUT_PASSTHROUGH,
  2453. nativeOptions);
  2454. }
  2455. void cmake::WatchUnusedCli(const std::string& var)
  2456. {
  2457. #ifdef CMAKE_BUILD_WITH_CMAKE
  2458. this->VariableWatch->AddWatch(var, cmWarnUnusedCliWarning, this);
  2459. if(this->UsedCliVariables.find(var) == this->UsedCliVariables.end())
  2460. {
  2461. this->UsedCliVariables[var] = false;
  2462. }
  2463. #endif
  2464. }
  2465. void cmake::UnwatchUnusedCli(const std::string& var)
  2466. {
  2467. #ifdef CMAKE_BUILD_WITH_CMAKE
  2468. this->VariableWatch->RemoveWatch(var, cmWarnUnusedCliWarning);
  2469. this->UsedCliVariables.erase(var);
  2470. #endif
  2471. }
  2472. void cmake::RunCheckForUnusedVariables()
  2473. {
  2474. #ifdef CMAKE_BUILD_WITH_CMAKE
  2475. bool haveUnused = false;
  2476. std::ostringstream msg;
  2477. msg << "Manually-specified variables were not used by the project:";
  2478. for(std::map<std::string, bool>::const_iterator
  2479. it = this->UsedCliVariables.begin();
  2480. it != this->UsedCliVariables.end(); ++it)
  2481. {
  2482. if(!it->second)
  2483. {
  2484. haveUnused = true;
  2485. msg << "\n " << it->first;
  2486. }
  2487. }
  2488. if(haveUnused)
  2489. {
  2490. this->IssueMessage(cmake::WARNING, msg.str());
  2491. }
  2492. #endif
  2493. }