cmLocalUnixMakefileGenerator3.cxx 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmLocalUnixMakefileGenerator3.h"
  14. #include "cmDepends.h"
  15. #include "cmGeneratedFileStream.h"
  16. #include "cmGlobalUnixMakefileGenerator3.h"
  17. #include "cmMakefile.h"
  18. #include "cmMakefileTargetGenerator.h"
  19. #include "cmSourceFile.h"
  20. #include "cmake.h"
  21. // Include dependency scanners for supported languages. Only the
  22. // C/C++ scanner is needed for bootstrapping CMake.
  23. #include "cmDependsC.h"
  24. #ifdef CMAKE_BUILD_WITH_CMAKE
  25. # include "cmDependsFortran.h"
  26. # include "cmDependsJava.h"
  27. #endif
  28. #include <memory> // auto_ptr
  29. #include <queue>
  30. //----------------------------------------------------------------------------
  31. cmLocalUnixMakefileGenerator3::cmLocalUnixMakefileGenerator3()
  32. {
  33. this->SilentNoColon = false;
  34. this->WindowsShell = false;
  35. this->IncludeDirective = "include";
  36. this->MakefileVariableSize = 0;
  37. this->IgnoreLibPrefix = false;
  38. this->PassMakeflags = false;
  39. this->EchoNeedsQuote = true;
  40. this->DefineWindowsNULL = false;
  41. this->UnixCD = true;
  42. this->ForceVerboseMakefiles=false;
  43. }
  44. //----------------------------------------------------------------------------
  45. cmLocalUnixMakefileGenerator3::~cmLocalUnixMakefileGenerator3()
  46. {
  47. }
  48. //----------------------------------------------------------------------------
  49. void cmLocalUnixMakefileGenerator3::Configure()
  50. {
  51. // Include the rule file for each object.
  52. this->HomeRelativeOutputPath =
  53. cmSystemTools::RelativePath(this->Makefile->GetHomeOutputDirectory(),
  54. this->Makefile->GetStartOutputDirectory());
  55. if (this->HomeRelativeOutputPath.size())
  56. {
  57. this->HomeRelativeOutputPath += "/";
  58. }
  59. this->cmLocalGenerator::Configure();
  60. }
  61. //----------------------------------------------------------------------------
  62. void cmLocalUnixMakefileGenerator3::Generate()
  63. {
  64. // Setup our configuration variables for this directory.
  65. this->ConfigureOutputPaths();
  66. // Generate the rule files for each target.
  67. cmTargets& targets = this->Makefile->GetTargets();
  68. std::string empty;
  69. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  70. {
  71. cmMakefileTargetGenerator *tg =
  72. cmMakefileTargetGenerator::New(this, t->first, &(t->second));
  73. if (tg)
  74. {
  75. this->TargetGenerators.push_back(tg);
  76. t->second.TraceVSDependencies(empty, this->Makefile);
  77. tg->WriteRuleFiles();
  78. }
  79. }
  80. // write the local Makefile
  81. this->WriteLocalMakefile();
  82. // Write the cmake file with information for this directory.
  83. this->WriteDirectoryInformationFile();
  84. // delete the makefile target generator objects
  85. for (std::vector<cmMakefileTargetGenerator *>::iterator mtgIter =
  86. this->TargetGenerators.begin();
  87. mtgIter != this->TargetGenerators.end(); ++mtgIter)
  88. {
  89. delete *mtgIter;
  90. }
  91. this->TargetGenerators.clear();
  92. }
  93. //----------------------------------------------------------------------------
  94. void cmLocalUnixMakefileGenerator3::ConfigureOutputPaths()
  95. {
  96. // Format the library and executable output paths.
  97. if(const char* libOut = this->Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  98. {
  99. this->LibraryOutputPath = libOut;
  100. this->FormatOutputPath(this->LibraryOutputPath, "LIBRARY");
  101. }
  102. if(const char* exeOut = this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  103. {
  104. this->ExecutableOutputPath = exeOut;
  105. this->FormatOutputPath(this->ExecutableOutputPath, "EXECUTABLE");
  106. }
  107. // Store the configuration name that will be generated.
  108. if(const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"))
  109. {
  110. // Use the build type given by the user.
  111. this->ConfigurationName = config;
  112. }
  113. else
  114. {
  115. // No configuration type given.
  116. this->ConfigurationName = "";
  117. }
  118. }
  119. //----------------------------------------------------------------------------
  120. void cmLocalUnixMakefileGenerator3::FormatOutputPath(std::string& path,
  121. const char* name)
  122. {
  123. if(!path.empty())
  124. {
  125. // Convert the output path to a full path in case it is
  126. // specified as a relative path. Treat a relative path as
  127. // relative to the current output directory for this makefile.
  128. path =
  129. cmSystemTools::CollapseFullPath(path.c_str(),
  130. this->Makefile->GetStartOutputDirectory());
  131. // Add a trailing slash for easy appending later.
  132. if(path.empty() || path[path.size()-1] != '/')
  133. {
  134. path += "/";
  135. }
  136. // Make sure the output path exists on disk.
  137. if(!cmSystemTools::MakeDirectory(path.c_str()))
  138. {
  139. cmSystemTools::Error("Error failed to create ",
  140. name, "_OUTPUT_PATH directory:", path.c_str());
  141. }
  142. // Add this as a link directory automatically.
  143. this->Makefile->AddLinkDirectory(path.c_str());
  144. }
  145. }
  146. //----------------------------------------------------------------------------
  147. void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
  148. {
  149. // generate the includes
  150. std::string ruleFileName = "Makefile";
  151. // Open the rule file. This should be copy-if-different because the
  152. // rules may depend on this file itself.
  153. std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
  154. cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
  155. if(!ruleFileStream)
  156. {
  157. return;
  158. }
  159. // always write the top makefile
  160. if (this->Parent)
  161. {
  162. ruleFileStream.SetCopyIfDifferent(true);
  163. }
  164. // write the all rules
  165. this->WriteLocalAllRules(ruleFileStream);
  166. // only write local targets unless at the top Keep track of targets already
  167. // listed.
  168. std::set<cmStdString> emittedTargets;
  169. if (this->Parent)
  170. {
  171. // write our targets, and while doing it collect up the object
  172. // file rules
  173. this->WriteLocalMakefileTargets(ruleFileStream,emittedTargets);
  174. }
  175. else
  176. {
  177. cmGlobalUnixMakefileGenerator3 *gg =
  178. static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
  179. gg->WriteConvenienceRules(ruleFileStream,emittedTargets);
  180. }
  181. std::vector<std::string> depends;
  182. std::vector<std::string> commands;
  183. // now write out the object rules
  184. // for each object file name
  185. for (std::map<cmStdString,std::vector<cmTarget *> >::iterator lo =
  186. this->LocalObjectFiles.begin();
  187. lo != this->LocalObjectFiles.end(); ++lo)
  188. {
  189. commands.clear();
  190. // for each target using the object file
  191. for (std::vector<cmTarget *>::iterator to =
  192. lo->second.begin(); to != lo->second.end(); ++to)
  193. {
  194. std::string tgtMakefileName = this->GetRelativeTargetDirectory(**to);
  195. std::string targetName = tgtMakefileName;
  196. tgtMakefileName += "/build.make";
  197. targetName += "/";
  198. targetName += lo->first.c_str();
  199. commands.push_back(this->GetRecursiveMakeCall
  200. (tgtMakefileName.c_str(),targetName.c_str()));
  201. this->CreateCDCommand(commands,
  202. this->Makefile->GetHomeOutputDirectory(),
  203. this->Makefile->GetStartOutputDirectory());
  204. }
  205. this->WriteMakeRule(ruleFileStream,
  206. "target for object file",
  207. lo->first.c_str(), depends, commands, false);
  208. }
  209. // add a help target as long as there isn;t a real target named help
  210. if(emittedTargets.insert("help").second)
  211. {
  212. cmGlobalUnixMakefileGenerator3 *gg =
  213. static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
  214. gg->WriteHelpRule(ruleFileStream,this);
  215. }
  216. this->WriteSpecialTargetsBottom(ruleFileStream);
  217. }
  218. void cmLocalUnixMakefileGenerator3
  219. ::WriteLocalMakefileTargets(std::ostream& ruleFileStream,
  220. std::set<cmStdString> &emitted)
  221. {
  222. std::vector<std::string> depends;
  223. std::vector<std::string> commands;
  224. // for each target we just provide a rule to cd up to the top and do a make
  225. // on the target
  226. cmTargets& targets = this->Makefile->GetTargets();
  227. std::string localName;
  228. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  229. {
  230. if((t->second.GetType() == cmTarget::EXECUTABLE) ||
  231. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  232. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  233. (t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
  234. (t->second.GetType() == cmTarget::UTILITY))
  235. {
  236. emitted.insert(t->second.GetName());
  237. // for subdirs add a rule to build this specific target by name.
  238. localName = this->GetRelativeTargetDirectory(t->second);
  239. localName += "/rule";
  240. commands.clear();
  241. depends.clear();
  242. // Build the target for this pass.
  243. commands.push_back(this->GetRecursiveMakeCall
  244. ("CMakeFiles/Makefile2",localName.c_str()));
  245. this->CreateCDCommand(commands,
  246. this->Makefile->GetHomeOutputDirectory(),
  247. this->Makefile->GetStartOutputDirectory());
  248. this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  249. localName.c_str(), depends, commands, true);
  250. // Add a target with the canonical name (no prefix, suffix or path).
  251. if(localName != t->second.GetName())
  252. {
  253. commands.clear();
  254. depends.push_back(localName);
  255. this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  256. t->second.GetName(), depends, commands, true);
  257. }
  258. }
  259. }
  260. }
  261. //----------------------------------------------------------------------------
  262. void cmLocalUnixMakefileGenerator3::WriteDirectoryInformationFile()
  263. {
  264. std::string infoFileName = this->Makefile->GetStartOutputDirectory();
  265. infoFileName += "/CMakeFiles/CMakeDirectoryInformation.cmake";
  266. // Open the output file.
  267. cmGeneratedFileStream infoFileStream(infoFileName.c_str());
  268. if(!infoFileStream)
  269. {
  270. return;
  271. }
  272. // Write the do not edit header.
  273. this->WriteDisclaimer(infoFileStream);
  274. // Tell the dependency scanner to use unix paths if necessary.
  275. if(cmSystemTools::GetForceUnixPaths())
  276. {
  277. infoFileStream
  278. << "# Force unix paths in dependencies.\n"
  279. << "SET(CMAKE_FORCE_UNIX_PATHS 1)\n"
  280. << "\n";
  281. }
  282. // Store the include search path for this directory.
  283. infoFileStream
  284. << "# The C and CXX include file search paths:\n";
  285. infoFileStream
  286. << "SET(CMAKE_C_INCLUDE_PATH\n";
  287. std::vector<std::string> includeDirs;
  288. this->GetIncludeDirectories(includeDirs);
  289. for(std::vector<std::string>::iterator i = includeDirs.begin();
  290. i != includeDirs.end(); ++i)
  291. {
  292. // Note: This path conversion must match that used for
  293. // CMAKE_GENERATED_FILES so that the file names match.
  294. infoFileStream
  295. << " \"" << this->Convert(i->c_str(),HOME_OUTPUT).c_str() << "\"\n";
  296. }
  297. infoFileStream
  298. << " )\n";
  299. infoFileStream
  300. << "SET(CMAKE_CXX_INCLUDE_PATH ${CMAKE_C_INCLUDE_PATH})\n";
  301. // Store the include regular expressions for this directory.
  302. infoFileStream
  303. << "\n"
  304. << "# The C and CXX include file regular expressions for this directory.\n";
  305. infoFileStream
  306. << "SET(CMAKE_C_INCLUDE_REGEX_SCAN ";
  307. this->WriteCMakeArgument(infoFileStream,
  308. this->Makefile->GetIncludeRegularExpression());
  309. infoFileStream
  310. << ")\n";
  311. infoFileStream
  312. << "SET(CMAKE_C_INCLUDE_REGEX_COMPLAIN ";
  313. this->WriteCMakeArgument(infoFileStream,
  314. this->Makefile->GetComplainRegularExpression());
  315. infoFileStream
  316. << ")\n";
  317. infoFileStream
  318. << "SET(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN})\n";
  319. infoFileStream
  320. << "SET(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN})\n";
  321. // Store the set of available generated files.
  322. infoFileStream
  323. << "\n"
  324. << "# The set of files generated by rules in this directory:\n";
  325. infoFileStream
  326. << "SET(CMAKE_GENERATED_FILES\n";
  327. for(std::vector<cmSourceFile*>::const_iterator
  328. i = this->Makefile->GetSourceFiles().begin();
  329. i != this->Makefile->GetSourceFiles().end(); ++i)
  330. {
  331. cmSourceFile* src = *i;
  332. if(src->GetPropertyAsBool("GENERATED"))
  333. {
  334. // Note: This path conversion must match that used for
  335. // CMAKE_C_INCLUDE_PATH so that the file names match.
  336. infoFileStream
  337. << " \""
  338. << this->Convert(src->GetFullPath().c_str(), HOME_OUTPUT)
  339. << "\"\n";
  340. }
  341. }
  342. infoFileStream
  343. << ")\n";
  344. }
  345. //----------------------------------------------------------------------------
  346. std::string
  347. cmLocalUnixMakefileGenerator3
  348. ::ConvertToFullPath(const std::string& localPath)
  349. {
  350. std::string dir = this->Makefile->GetStartOutputDirectory();
  351. dir += "/";
  352. dir += localPath;
  353. return dir;
  354. }
  355. const std::string &cmLocalUnixMakefileGenerator3::GetHomeRelativeOutputPath()
  356. {
  357. return this->HomeRelativeOutputPath;
  358. }
  359. //----------------------------------------------------------------------------
  360. void
  361. cmLocalUnixMakefileGenerator3
  362. ::WriteMakeRule(std::ostream& os,
  363. const char* comment,
  364. const char* target,
  365. const std::vector<std::string>& depends,
  366. const std::vector<std::string>& commands,
  367. bool symbolic)
  368. {
  369. // Make sure there is a target.
  370. if(!target || !*target)
  371. {
  372. cmSystemTools::Error("No target for WriteMakeRule! called with comment: ",
  373. comment);
  374. return;
  375. }
  376. std::string replace;
  377. // Write the comment describing the rule in the makefile.
  378. if(comment)
  379. {
  380. replace = comment;
  381. std::string::size_type lpos = 0;
  382. std::string::size_type rpos;
  383. while((rpos = replace.find('\n', lpos)) != std::string::npos)
  384. {
  385. os << "# " << replace.substr(lpos, rpos-lpos) << "\n";
  386. lpos = rpos+1;
  387. }
  388. os << "# " << replace.substr(lpos) << "\n";
  389. }
  390. // Construct the left hand side of the rule.
  391. replace = target;
  392. std::string tgt = this->Convert(replace.c_str(),HOME_OUTPUT,MAKEFILE);
  393. tgt = this->ConvertToMakeTarget(tgt.c_str());
  394. const char* space = "";
  395. if(tgt.size() == 1)
  396. {
  397. // Add a space before the ":" to avoid drive letter confusion on
  398. // Windows.
  399. space = " ";
  400. }
  401. // Mark the rule as symbolic if requested.
  402. if(symbolic)
  403. {
  404. if(const char* sym =
  405. this->Makefile->GetDefinition("CMAKE_MAKE_SYMBOLIC_RULE"))
  406. {
  407. os << tgt.c_str() << space << ": " << sym << "\n";
  408. }
  409. }
  410. // Write the rule.
  411. if(depends.empty())
  412. {
  413. // No dependencies. The commands will always run.
  414. os << tgt.c_str() << space << ":\n";
  415. }
  416. else
  417. {
  418. // Split dependencies into multiple rule lines. This allows for
  419. // very long dependency lists even on older make implementations.
  420. for(std::vector<std::string>::const_iterator dep = depends.begin();
  421. dep != depends.end(); ++dep)
  422. {
  423. replace = *dep;
  424. replace = this->Convert(replace.c_str(),HOME_OUTPUT,MAKEFILE);
  425. replace = this->ConvertToMakeTarget(replace.c_str());
  426. os << tgt.c_str() << space << ": " << replace.c_str() << "\n";
  427. }
  428. }
  429. // Write the list of commands.
  430. for(std::vector<std::string>::const_iterator i = commands.begin();
  431. i != commands.end(); ++i)
  432. {
  433. replace = *i;
  434. os << "\t" << replace.c_str() << "\n";
  435. }
  436. os << "\n";
  437. }
  438. //----------------------------------------------------------------------------
  439. void
  440. cmLocalUnixMakefileGenerator3
  441. ::WriteMakeVariables(std::ostream& makefileStream)
  442. {
  443. this->WriteDivider(makefileStream);
  444. makefileStream
  445. << "# Set environment variables for the build.\n"
  446. << "\n";
  447. if(this->DefineWindowsNULL)
  448. {
  449. makefileStream
  450. << "!IF \"$(OS)\" == \"Windows_NT\"\n"
  451. << "NULL=\n"
  452. << "!ELSE\n"
  453. << "NULL=nul\n"
  454. << "!ENDIF\n";
  455. }
  456. if(this->WindowsShell)
  457. {
  458. makefileStream
  459. << "SHELL = cmd.exe\n"
  460. << "\n";
  461. }
  462. else
  463. {
  464. makefileStream
  465. << "# The shell in which to execute make rules.\n"
  466. << "SHELL = /bin/sh\n"
  467. << "\n";
  468. }
  469. std::string cmakecommand =
  470. this->Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  471. makefileStream
  472. << "# The CMake executable.\n"
  473. << "CMAKE_COMMAND = "
  474. << this->Convert(cmakecommand.c_str(), FULL, SHELL).c_str()
  475. << "\n"
  476. << "\n";
  477. makefileStream
  478. << "# The command to remove a file.\n"
  479. << "RM = "
  480. << this->Convert(cmakecommand.c_str(),FULL,SHELL).c_str()
  481. << " -E remove -f\n"
  482. << "\n";
  483. if(this->Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  484. {
  485. makefileStream
  486. << "# The program to use to edit the cache.\n"
  487. << "CMAKE_EDIT_COMMAND = "
  488. << (this->ConvertToOutputForExisting(
  489. this->Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))) << "\n"
  490. << "\n";
  491. }
  492. makefileStream
  493. << "# The top-level source directory on which CMake was run.\n"
  494. << "CMAKE_SOURCE_DIR = "
  495. << this->Convert(this->Makefile->GetHomeDirectory(), FULL, SHELL)
  496. << "\n"
  497. << "\n";
  498. makefileStream
  499. << "# The top-level build directory on which CMake was run.\n"
  500. << "CMAKE_BINARY_DIR = "
  501. << this->Convert(this->Makefile->GetHomeOutputDirectory(), FULL, SHELL)
  502. << "\n"
  503. << "\n";
  504. }
  505. //----------------------------------------------------------------------------
  506. void
  507. cmLocalUnixMakefileGenerator3
  508. ::WriteSpecialTargetsTop(std::ostream& makefileStream)
  509. {
  510. this->WriteDivider(makefileStream);
  511. makefileStream
  512. << "# Special targets provided by cmake.\n"
  513. << "\n";
  514. // Write special target to silence make output. This must be after
  515. // the default target in case VERBOSE is set (which changes the
  516. // name). The setting of CMAKE_VERBOSE_MAKEFILE to ON will cause a
  517. // "VERBOSE=1" to be added as a make variable which will change the
  518. // name of this special target. This gives a make-time choice to
  519. // the user.
  520. std::vector<std::string> commands;
  521. std::vector<std::string> no_depends;
  522. commands.clear();
  523. if((this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE")) || (this->ForceVerboseMakefiles))
  524. {
  525. makefileStream
  526. << "# Produce verbose output by default.\n"
  527. << "VERBOSE = 1\n"
  528. << "\n";
  529. }
  530. if(this->SilentNoColon)
  531. {
  532. makefileStream << "$(VERBOSE).SILENT\n";
  533. }
  534. else
  535. {
  536. this->WriteMakeRule(makefileStream,
  537. "Suppress display of executed commands.",
  538. "$(VERBOSE).SILENT",
  539. no_depends,
  540. commands, false);
  541. }
  542. // Special target to cleanup operation of make tool.
  543. std::vector<std::string> depends;
  544. this->WriteMakeRule(makefileStream,
  545. "Disable implicit rules so canoncical targets will work.",
  546. ".SUFFIXES",
  547. depends,
  548. commands, false);
  549. // Add a fake suffix to keep HP happy. Must be max 32 chars for SGI make.
  550. depends.push_back(".hpux_make_needs_suffix_list");
  551. this->WriteMakeRule(makefileStream, 0,
  552. ".SUFFIXES", depends, commands, false);
  553. }
  554. //----------------------------------------------------------------------------
  555. void
  556. cmLocalUnixMakefileGenerator3
  557. ::WriteSpecialTargetsBottom(std::ostream& makefileStream)
  558. {
  559. this->WriteDivider(makefileStream);
  560. makefileStream
  561. << "# Special targets to cleanup operation of make.\n"
  562. << "\n";
  563. // Write special "cmake_check_build_system" target to run cmake with
  564. // the --check-build-system flag.
  565. {
  566. // Build command to run CMake to check if anything needs regenerating.
  567. std::string cmakefileName = "CMakeFiles/Makefile.cmake";
  568. std::string runRule =
  569. "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
  570. runRule += " --check-build-system ";
  571. runRule += this->Convert(cmakefileName.c_str(),NONE,SHELL);
  572. runRule += " 0";
  573. std::vector<std::string> no_depends;
  574. std::vector<std::string> commands;
  575. commands.push_back(runRule);
  576. if(this->Parent)
  577. {
  578. this->CreateCDCommand(commands,
  579. this->Makefile->GetHomeOutputDirectory(),
  580. this->Makefile->GetStartOutputDirectory());
  581. }
  582. this->WriteMakeRule(makefileStream,
  583. "Special rule to run CMake to check the build system "
  584. "integrity.\n"
  585. "No rule that depends on this can have "
  586. "commands that come from listfiles\n"
  587. "because they might be regenerated.",
  588. "cmake_check_build_system",
  589. no_depends,
  590. commands, true);
  591. }
  592. std::vector<std::string> no_commands;
  593. }
  594. //----------------------------------------------------------------------------
  595. void
  596. cmLocalUnixMakefileGenerator3
  597. ::WriteConvenienceRule(std::ostream& ruleFileStream,
  598. const char* realTarget,
  599. const char* helpTarget)
  600. {
  601. // A rule is only needed if the names are different.
  602. if(strcmp(realTarget, helpTarget) != 0)
  603. {
  604. // The helper target depends on the real target.
  605. std::vector<std::string> depends;
  606. depends.push_back(realTarget);
  607. // There are no commands.
  608. std::vector<std::string> no_commands;
  609. // Write the rule.
  610. this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  611. helpTarget, depends, no_commands, true);
  612. }
  613. }
  614. //----------------------------------------------------------------------------
  615. std::string
  616. cmLocalUnixMakefileGenerator3::GetRelativeTargetDirectory(cmTarget& target)
  617. {
  618. std::string dir = this->HomeRelativeOutputPath;
  619. dir += this->GetTargetDirectory(target);
  620. return this->Convert(dir.c_str(),NONE,MAKEFILE);
  621. }
  622. //----------------------------------------------------------------------------
  623. void
  624. cmLocalUnixMakefileGenerator3
  625. ::AppendRuleDepend(std::vector<std::string>& depends,
  626. const char* ruleFileName)
  627. {
  628. // Add a dependency on the rule file itself unless an option to skip
  629. // it is specifically enabled by the user or project.
  630. const char* nodep = this->Makefile->GetDefinition("CMAKE_SKIP_RULE_DEPENDENCY");
  631. if(!nodep || cmSystemTools::IsOff(nodep))
  632. {
  633. depends.push_back(ruleFileName);
  634. }
  635. }
  636. //----------------------------------------------------------------------------
  637. void
  638. cmLocalUnixMakefileGenerator3
  639. ::AppendCustomDepends(std::vector<std::string>& depends,
  640. const std::vector<cmCustomCommand>& ccs)
  641. {
  642. for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
  643. i != ccs.end(); ++i)
  644. {
  645. this->AppendCustomDepend(depends, *i);
  646. }
  647. }
  648. //----------------------------------------------------------------------------
  649. void
  650. cmLocalUnixMakefileGenerator3
  651. ::AppendCustomDepend(std::vector<std::string>& depends,
  652. const cmCustomCommand& cc)
  653. {
  654. for(std::vector<std::string>::const_iterator d = cc.GetDepends().begin();
  655. d != cc.GetDepends().end(); ++d)
  656. {
  657. // Lookup the real name of the dependency in case it is a CMake target.
  658. std::string dep = this->GetRealDependency(d->c_str(),
  659. this->ConfigurationName.c_str());
  660. depends.push_back(dep);
  661. }
  662. }
  663. //----------------------------------------------------------------------------
  664. void
  665. cmLocalUnixMakefileGenerator3
  666. ::AppendCustomCommands(std::vector<std::string>& commands,
  667. const std::vector<cmCustomCommand>& ccs)
  668. {
  669. for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
  670. i != ccs.end(); ++i)
  671. {
  672. this->AppendCustomCommand(commands, *i);
  673. }
  674. }
  675. //----------------------------------------------------------------------------
  676. void
  677. cmLocalUnixMakefileGenerator3
  678. ::AppendCustomCommand(std::vector<std::string>& commands,
  679. const cmCustomCommand& cc)
  680. {
  681. std::vector<std::string> commands1;
  682. // Add each command line to the set of commands.
  683. for(cmCustomCommandLines::const_iterator cl = cc.GetCommandLines().begin();
  684. cl != cc.GetCommandLines().end(); ++cl)
  685. {
  686. // Build the command line in a single string.
  687. const cmCustomCommandLine& commandLine = *cl;
  688. std::string cmd = commandLine[0];
  689. if (cmd.size())
  690. {
  691. cmSystemTools::ReplaceString(cmd, "/./", "/");
  692. cmd = this->Convert(cmd.c_str(),START_OUTPUT);
  693. if(cmd.find("/") == cmd.npos &&
  694. commandLine[0].find("/") != cmd.npos)
  695. {
  696. // Add a leading "./" for executables in the current directory.
  697. cmd = "./" + cmd;
  698. }
  699. cmd = this->Convert(cmd.c_str(),NONE,SHELL);
  700. for(unsigned int j=1; j < commandLine.size(); ++j)
  701. {
  702. cmd += " ";
  703. bool forceOn = cmSystemTools::GetForceUnixPaths();
  704. if(forceOn && this->WindowsShell)
  705. {
  706. cmSystemTools::SetForceUnixPaths(false);
  707. }
  708. cmd += cmSystemTools::EscapeSpaces(commandLine[j].c_str());
  709. if(forceOn && this->WindowsShell)
  710. {
  711. cmSystemTools::SetForceUnixPaths(true);
  712. }
  713. }
  714. commands1.push_back(cmd);
  715. }
  716. }
  717. // push back the custom commands
  718. const char* dir = this->Makefile->GetStartOutputDirectory();
  719. // if the command specified a working directory use it.
  720. if(cc.GetWorkingDirectory())
  721. {
  722. dir = cc.GetWorkingDirectory();
  723. }
  724. this->CreateCDCommand(commands1, dir,
  725. this->Makefile->GetHomeOutputDirectory());
  726. commands.insert(commands.end(), commands1.begin(), commands1.end());
  727. }
  728. //----------------------------------------------------------------------------
  729. void
  730. cmLocalUnixMakefileGenerator3
  731. ::AppendCleanCommand(std::vector<std::string>& commands,
  732. const std::vector<std::string>& files,
  733. cmTarget& target, const char* filename)
  734. {
  735. if(!files.empty())
  736. {
  737. std::string cleanfile = this->Makefile->GetCurrentOutputDirectory();
  738. cleanfile += "/";
  739. cleanfile += this->GetTargetDirectory(target);
  740. cleanfile += "/cmake_clean";
  741. if(filename)
  742. {
  743. cleanfile += "_";
  744. cleanfile += filename;
  745. }
  746. cleanfile += ".cmake";
  747. std::string cleanfilePath = this->Convert(cleanfile.c_str(), FULL);
  748. std::ofstream fout(cleanfilePath.c_str());
  749. if(!fout)
  750. {
  751. cmSystemTools::Error("Could not create ", cleanfilePath.c_str());
  752. }
  753. fout << "FILE(REMOVE\n";
  754. std::string remove = "$(CMAKE_COMMAND) -P ";
  755. remove += this->Convert(cleanfile.c_str(), START_OUTPUT, SHELL);
  756. for(std::vector<std::string>::const_iterator f = files.begin();
  757. f != files.end(); ++f)
  758. {
  759. fout << "\"" << this->Convert(f->c_str(),START_OUTPUT,UNCHANGED)
  760. << "\"\n";
  761. }
  762. fout << ")\n";
  763. commands.push_back(remove);
  764. }
  765. }
  766. //----------------------------------------------------------------------------
  767. void
  768. cmLocalUnixMakefileGenerator3::AppendEcho(std::vector<std::string>& commands,
  769. const char* text,
  770. EchoColor color)
  771. {
  772. // Choose the color for the text.
  773. std::string color_name;
  774. #ifdef CMAKE_BUILD_WITH_CMAKE
  775. if(this->GlobalGenerator->GetToolSupportsColor() &&
  776. this->Makefile->IsOn("CMAKE_COLOR_MAKEFILE"))
  777. {
  778. // See cmake::ExecuteEchoColor in cmake.cxx for these options.
  779. // This color set is readable on both black and white backgrounds.
  780. switch(color)
  781. {
  782. case EchoNormal:
  783. break;
  784. case EchoDepend:
  785. color_name = "--magenta --bold ";
  786. break;
  787. case EchoBuild:
  788. color_name = "--green ";
  789. break;
  790. case EchoLink:
  791. color_name = "--red --bold ";
  792. break;
  793. case EchoGenerate:
  794. color_name = "--blue --bold ";
  795. break;
  796. case EchoGlobal:
  797. color_name = "--cyan ";
  798. break;
  799. }
  800. }
  801. #endif
  802. // Echo one line at a time.
  803. std::string line;
  804. line.reserve(200);
  805. for(const char* c = text;; ++c)
  806. {
  807. if(*c == '\n' || *c == '\0')
  808. {
  809. // Avoid writing a blank last line on end-of-string.
  810. if(*c != '\0' || !line.empty())
  811. {
  812. // Add a command to echo this line.
  813. std::string cmd;
  814. if(color_name.empty())
  815. {
  816. // Use the native echo command.
  817. cmd = "@echo ";
  818. if(this->EchoNeedsQuote)
  819. {
  820. cmd += "\"";
  821. }
  822. cmd += line;
  823. if(this->EchoNeedsQuote)
  824. {
  825. cmd += "\"";
  826. }
  827. }
  828. else
  829. {
  830. // Use cmake to echo the text in color.
  831. cmd = "@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) ";
  832. cmd += color_name;
  833. cmd += "\"";
  834. cmd += line;
  835. cmd += "\"";
  836. }
  837. commands.push_back(cmd);
  838. }
  839. // Reset the line to emtpy.
  840. line = "";
  841. // Terminate on end-of-string.
  842. if(*c == '\0')
  843. {
  844. return;
  845. }
  846. }
  847. else if(*c != '\r')
  848. {
  849. // Append this character to the current line.
  850. line += *c;
  851. }
  852. }
  853. }
  854. //----------------------------------------------------------------------------
  855. // take a tgt path and convert it into a make target, it could be full, or relative
  856. std::string
  857. cmLocalUnixMakefileGenerator3
  858. ::ConvertToMakeTarget(const char* tgt)
  859. {
  860. // Make targets should not have a leading './' for a file in the
  861. // directory containing the makefile.
  862. std::string ret = tgt;
  863. if(ret.size() > 2 && (ret[0] == '.') &&
  864. ( (ret[1] == '/') || ret[1] == '\\'))
  865. {
  866. std::string upath = ret;
  867. cmSystemTools::ConvertToUnixSlashes(upath);
  868. if(upath.find(2, '/') == upath.npos)
  869. {
  870. ret = ret.substr(2, ret.size()-2);
  871. }
  872. }
  873. return ret;
  874. }
  875. //----------------------------------------------------------------------------
  876. std::string&
  877. cmLocalUnixMakefileGenerator3::CreateSafeUniqueObjectFileName(const char* sin)
  878. {
  879. // Look for an existing mapped name for this object file.
  880. std::map<cmStdString,cmStdString>::iterator it =
  881. this->UniqueObjectNamesMap.find(sin);
  882. // If no entry exists create one.
  883. if(it == this->UniqueObjectNamesMap.end())
  884. {
  885. // Start with the original name.
  886. std::string ssin = sin;
  887. // Avoid full paths by removing leading slashes.
  888. std::string::size_type pos = 0;
  889. for(;pos < ssin.size() && ssin[pos] == '/'; ++pos);
  890. ssin = ssin.substr(pos);
  891. // Avoid full paths by removing colons.
  892. cmSystemTools::ReplaceString(ssin, ":", "_");
  893. // Avoid relative paths that go up the tree.
  894. cmSystemTools::ReplaceString(ssin, "../", "__/");
  895. // Avoid spaces.
  896. cmSystemTools::ReplaceString(ssin, " ", "_");
  897. // Mangle the name if necessary.
  898. if(this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES"))
  899. {
  900. bool done;
  901. int cc = 0;
  902. char rpstr[100];
  903. sprintf(rpstr, "_p_");
  904. cmSystemTools::ReplaceString(ssin, "+", rpstr);
  905. std::string sssin = sin;
  906. do
  907. {
  908. done = true;
  909. for ( it = this->UniqueObjectNamesMap.begin();
  910. it != this->UniqueObjectNamesMap.end();
  911. ++ it )
  912. {
  913. if ( it->second == ssin )
  914. {
  915. done = false;
  916. }
  917. }
  918. if ( done )
  919. {
  920. break;
  921. }
  922. sssin = ssin;
  923. cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
  924. sprintf(rpstr, "_p%d_", cc++);
  925. }
  926. while ( !done );
  927. }
  928. // Insert the newly mapped object file name.
  929. std::map<cmStdString, cmStdString>::value_type e(sin, ssin);
  930. it = this->UniqueObjectNamesMap.insert(e).first;
  931. }
  932. // Return the map entry.
  933. return it->second;
  934. }
  935. //----------------------------------------------------------------------------
  936. std::string
  937. cmLocalUnixMakefileGenerator3
  938. ::CreateMakeVariable(const char* sin, const char* s2in)
  939. {
  940. std::string s = sin;
  941. std::string s2 = s2in;
  942. std::string unmodified = s;
  943. unmodified += s2;
  944. // if there is no restriction on the length of make variables
  945. // and there are no "." charactors in the string, then return the
  946. // unmodified combination.
  947. if((!this->MakefileVariableSize && unmodified.find('.') == s.npos)
  948. && (!this->MakefileVariableSize && unmodified.find('-') == s.npos))
  949. {
  950. return unmodified;
  951. }
  952. // see if the variable has been defined before and return
  953. // the modified version of the variable
  954. std::map<cmStdString, cmStdString>::iterator i = this->MakeVariableMap.find(unmodified);
  955. if(i != this->MakeVariableMap.end())
  956. {
  957. return i->second;
  958. }
  959. // start with the unmodified variable
  960. std::string ret = unmodified;
  961. // if this there is no value for this->MakefileVariableSize then
  962. // the string must have bad characters in it
  963. if(!this->MakefileVariableSize)
  964. {
  965. cmSystemTools::ReplaceString(ret, ".", "_");
  966. cmSystemTools::ReplaceString(ret, "-", "__");
  967. int ni = 0;
  968. char buffer[5];
  969. // make sure the _ version is not already used, if
  970. // it is used then add number to the end of the variable
  971. while(this->ShortMakeVariableMap.count(ret) && ni < 1000)
  972. {
  973. ++ni;
  974. sprintf(buffer, "%04d", ni);
  975. ret = unmodified + buffer;
  976. }
  977. this->ShortMakeVariableMap[ret] = "1";
  978. this->MakeVariableMap[unmodified] = ret;
  979. return ret;
  980. }
  981. // if the string is greater the 32 chars it is an invalid vairable name
  982. // for borland make
  983. if(static_cast<int>(ret.size()) > this->MakefileVariableSize)
  984. {
  985. int keep = this->MakefileVariableSize - 8;
  986. int size = keep + 3;
  987. std::string str1 = s;
  988. std::string str2 = s2;
  989. // we must shorten the combined string by 4 charactors
  990. // keep no more than 24 charactors from the second string
  991. if(static_cast<int>(str2.size()) > keep)
  992. {
  993. str2 = str2.substr(0, keep);
  994. }
  995. if(static_cast<int>(str1.size()) + static_cast<int>(str2.size()) > size)
  996. {
  997. str1 = str1.substr(0, size - str2.size());
  998. }
  999. char buffer[5];
  1000. int ni = 0;
  1001. sprintf(buffer, "%04d", ni);
  1002. ret = str1 + str2 + buffer;
  1003. while(this->ShortMakeVariableMap.count(ret) && ni < 1000)
  1004. {
  1005. ++ni;
  1006. sprintf(buffer, "%04d", ni);
  1007. ret = str1 + str2 + buffer;
  1008. }
  1009. if(ni == 1000)
  1010. {
  1011. cmSystemTools::Error("Borland makefile variable length too long");
  1012. return unmodified;
  1013. }
  1014. // once an unused variable is found
  1015. this->ShortMakeVariableMap[ret] = "1";
  1016. }
  1017. // always make an entry into the unmodified to variable map
  1018. this->MakeVariableMap[unmodified] = ret;
  1019. return ret;
  1020. }
  1021. //----------------------------------------------------------------------------
  1022. bool
  1023. cmLocalUnixMakefileGenerator3
  1024. ::ScanDependencies(std::vector<std::string> const& args)
  1025. {
  1026. // Format of arguments is:
  1027. // $(CMAKE_COMMAND), cmake_depends, GeneratorName, home_output_dir, start_output_dir, info file
  1028. // The caller has ensured that all required arguments exist.
  1029. // The info file for this target
  1030. std::string const& infoFile = args[5];
  1031. // Read the directory information file.
  1032. cmake cm;
  1033. cmGlobalGenerator gg;
  1034. gg.SetCMakeInstance(&cm);
  1035. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  1036. lg->SetGlobalGenerator(&gg);
  1037. cmMakefile* mf = lg->GetMakefile();
  1038. mf->SetHomeOutputDirectory(args[3].c_str());
  1039. mf->SetStartOutputDirectory(args[4].c_str());
  1040. lg->SetupPathConversions();
  1041. bool haveDirectoryInfo = false;
  1042. std::string dirInfoFile = args[4];
  1043. dirInfoFile += "/CMakeFiles/CMakeDirectoryInformation.cmake";
  1044. if(mf->ReadListFile(0, dirInfoFile.c_str()) &&
  1045. !cmSystemTools::GetErrorOccuredFlag())
  1046. {
  1047. haveDirectoryInfo = true;
  1048. }
  1049. // read in the target info file
  1050. if(!mf->ReadListFile(0, infoFile.c_str()) ||
  1051. cmSystemTools::GetErrorOccuredFlag())
  1052. {
  1053. cmSystemTools::Error("Target DependInfo.cmake file not found");
  1054. }
  1055. // Test whether we need to force Unix paths.
  1056. if(haveDirectoryInfo)
  1057. {
  1058. if(const char* force = mf->GetDefinition("CMAKE_FORCE_UNIX_PATHS"))
  1059. {
  1060. if(!cmSystemTools::IsOff(force))
  1061. {
  1062. cmSystemTools::SetForceUnixPaths(true);
  1063. }
  1064. }
  1065. }
  1066. else
  1067. {
  1068. cmSystemTools::Error("Directory Information file not found");
  1069. }
  1070. // create the file stream for the depends file
  1071. std::string dir = cmSystemTools::GetFilenamePath(infoFile);
  1072. // Open the rule file. This should be copy-if-different because the
  1073. // rules may depend on this file itself.
  1074. std::string ruleFileNameFull = dir;
  1075. ruleFileNameFull += "/depend.make";
  1076. cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
  1077. ruleFileStream.SetCopyIfDifferent(true);
  1078. if(!ruleFileStream)
  1079. {
  1080. return false;
  1081. }
  1082. std::string internalRuleFileNameFull = dir;
  1083. internalRuleFileNameFull += "/depend.internal";
  1084. cmGeneratedFileStream internalRuleFileStream(internalRuleFileNameFull.c_str());
  1085. internalRuleFileStream.SetCopyIfDifferent(true);
  1086. if(!internalRuleFileStream)
  1087. {
  1088. return false;
  1089. }
  1090. this->WriteDisclaimer(ruleFileStream);
  1091. this->WriteDisclaimer(internalRuleFileStream);
  1092. // Get the set of generated files.
  1093. std::vector<std::string> generatedFilesVec;
  1094. if(haveDirectoryInfo)
  1095. {
  1096. if(const char* generated = mf->GetDefinition("CMAKE_GENERATED_FILES"))
  1097. {
  1098. cmSystemTools::ExpandListArgument(generated, generatedFilesVec);
  1099. }
  1100. }
  1101. // Sort for efficient lookup.
  1102. std::set<cmStdString> generatedFiles;
  1103. for(std::vector<std::string>::iterator gfi = generatedFilesVec.begin();
  1104. gfi != generatedFilesVec.end(); ++gfi)
  1105. {
  1106. generatedFiles.insert(*gfi);
  1107. }
  1108. // for each language we need to scan, scan it
  1109. const char *langStr = mf->GetSafeDefinition("CMAKE_DEPENDS_LANGUAGES");
  1110. std::vector<std::string> langs;
  1111. cmSystemTools::ExpandListArgument(langStr, langs);
  1112. for (std::vector<std::string>::iterator li =
  1113. langs.begin(); li != langs.end(); ++li)
  1114. {
  1115. // construct the checker
  1116. std::string lang = li->c_str();
  1117. // Get the set of include directories.
  1118. std::vector<std::string> includes;
  1119. if(haveDirectoryInfo)
  1120. {
  1121. std::string includePathVar = "CMAKE_";
  1122. includePathVar += lang;
  1123. includePathVar += "_INCLUDE_PATH";
  1124. if(const char* includePath = mf->GetDefinition(includePathVar.c_str()))
  1125. {
  1126. cmSystemTools::ExpandListArgument(includePath, includes);
  1127. }
  1128. }
  1129. // Get the include file regular expression.
  1130. std::string includeRegexScan = "^.*$";
  1131. std::string includeRegexComplain = "^$";
  1132. if(haveDirectoryInfo)
  1133. {
  1134. std::string scanRegexVar = "CMAKE_";
  1135. scanRegexVar += lang;
  1136. scanRegexVar += "_INCLUDE_REGEX_SCAN";
  1137. if(const char* scanRegex = mf->GetDefinition(scanRegexVar.c_str()))
  1138. {
  1139. includeRegexScan = scanRegex;
  1140. }
  1141. std::string complainRegexVar = "CMAKE_";
  1142. complainRegexVar += lang;
  1143. complainRegexVar += "_INCLUDE_REGEX_COMPLAIN";
  1144. if(const char* complainRegex = mf->GetDefinition(complainRegexVar.c_str()))
  1145. {
  1146. includeRegexComplain = complainRegex;
  1147. }
  1148. }
  1149. // Create the scanner for this language
  1150. cmDepends *scanner = 0;
  1151. if(lang == "C" || lang == "CXX" || lang == "RC")
  1152. {
  1153. std::string includeCacheFileName = dir;
  1154. includeCacheFileName += "/includecache.";
  1155. includeCacheFileName += lang;
  1156. // TODO: Handle RC (resource files) dependencies correctly.
  1157. scanner = new cmDependsC(includes,
  1158. includeRegexScan.c_str(),
  1159. includeRegexComplain.c_str(),
  1160. generatedFiles, includeCacheFileName);
  1161. scanner->SetHomeOutputDirectory(mf->GetHomeOutputDirectory());
  1162. }
  1163. #ifdef CMAKE_BUILD_WITH_CMAKE
  1164. else if(lang == "Fortran")
  1165. {
  1166. scanner = new cmDependsFortran(includes);
  1167. }
  1168. else if(lang == "Java")
  1169. {
  1170. scanner = new cmDependsJava();
  1171. }
  1172. #endif
  1173. if (scanner)
  1174. {
  1175. scanner->SetFileComparison(this->GlobalGenerator->GetCMakeInstance()->GetFileComparison());
  1176. // for each file we need to scan
  1177. std::string srcLang = "CMAKE_DEPENDS_CHECK_";
  1178. srcLang += lang;
  1179. const char *srcStr = mf->GetSafeDefinition(srcLang.c_str());
  1180. std::vector<std::string> srcs;
  1181. cmSystemTools::ExpandListArgument(srcStr, srcs);
  1182. for (std::vector<std::string>::iterator si =
  1183. srcs.begin(); si != srcs.end(); ++si)
  1184. {
  1185. std::string &src = *si;
  1186. ++si;
  1187. // make sure the object file is relative to home output
  1188. std::string obj = *si;
  1189. obj = lg->Convert(obj.c_str(),HOME_OUTPUT,MAKEFILE);
  1190. scanner->Write(src.c_str(),obj.c_str(),ruleFileStream, internalRuleFileStream);
  1191. }
  1192. // free the scanner for this language
  1193. delete scanner;
  1194. }
  1195. }
  1196. // dependencies were generated, so touch the mark file
  1197. ruleFileNameFull += ".mark";
  1198. std::ofstream fmark(ruleFileNameFull.c_str());
  1199. fmark << "Dependencies updated>" << std::endl;
  1200. return true;
  1201. }
  1202. //----------------------------------------------------------------------------
  1203. void cmLocalUnixMakefileGenerator3
  1204. ::WriteLocalAllRules(std::ostream& ruleFileStream)
  1205. {
  1206. this->WriteDisclaimer(ruleFileStream);
  1207. this->WriteMakeVariables(ruleFileStream);
  1208. // Write the main entry point target. This must be the VERY first
  1209. // target so that make with no arguments will run it.
  1210. {
  1211. // Just depend on the all target to drive the build.
  1212. std::vector<std::string> depends;
  1213. std::vector<std::string> no_commands;
  1214. depends.push_back("all");
  1215. // Write the rule.
  1216. this->WriteMakeRule(ruleFileStream,
  1217. "Default target executed when no arguments are "
  1218. "given to make.",
  1219. "default_target",
  1220. depends,
  1221. no_commands, true);
  1222. }
  1223. // Write all global targets
  1224. cmTargets* targets = &(this->Makefile->GetTargets());
  1225. cmTargets::iterator glIt;
  1226. for ( glIt = targets->begin(); glIt != targets->end(); ++ glIt )
  1227. {
  1228. if ( glIt->second.GetType() == cmTarget::GLOBAL_TARGET )
  1229. {
  1230. std::string targetString = "Special rule for the target " + glIt->first;
  1231. std::vector<std::string> commands;
  1232. std::vector<std::string> depends;
  1233. const char* text = glIt->second.GetProperty("EchoString");
  1234. if ( !text )
  1235. {
  1236. text = "Running external command ...";
  1237. }
  1238. std::set<cmStdString>::const_iterator dit;
  1239. for ( dit = glIt->second.GetUtilities().begin();
  1240. dit != glIt->second.GetUtilities().end();
  1241. ++ dit )
  1242. {
  1243. depends.push_back(dit->c_str());
  1244. }
  1245. this->AppendEcho(commands, text,
  1246. cmLocalUnixMakefileGenerator3::EchoGlobal);
  1247. // Utility targets store their rules in pre- and post-build commands.
  1248. this->AppendCustomDepends(depends,
  1249. glIt->second.GetPreBuildCommands());
  1250. this->AppendCustomDepends(depends,
  1251. glIt->second.GetPostBuildCommands());
  1252. this->AppendCustomCommands(commands,
  1253. glIt->second.GetPreBuildCommands());
  1254. this->AppendCustomCommands(commands,
  1255. glIt->second.GetPostBuildCommands());
  1256. this->WriteMakeRule(ruleFileStream, targetString.c_str(),
  1257. glIt->first.c_str(), depends, commands, true);
  1258. }
  1259. }
  1260. this->WriteSpecialTargetsTop(ruleFileStream);
  1261. std::vector<std::string> depends;
  1262. std::vector<std::string> commands;
  1263. // Write the all rule.
  1264. std::string dir = this->Makefile->GetStartOutputDirectory();
  1265. dir += "/all";
  1266. dir = this->Convert(dir.c_str(),HOME_OUTPUT,MAKEFILE);
  1267. depends.push_back("cmake_check_build_system");
  1268. commands.push_back
  1269. (this->GetRecursiveMakeCall("CMakeFiles/Makefile2",dir.c_str()));
  1270. this->CreateCDCommand(commands,
  1271. this->Makefile->GetHomeOutputDirectory(),
  1272. this->Makefile->GetStartOutputDirectory());
  1273. this->WriteMakeRule(ruleFileStream, "The main all target", "all",
  1274. depends, commands, true);
  1275. // Write the clean rule.
  1276. dir = this->Makefile->GetStartOutputDirectory();
  1277. dir += "/clean";
  1278. dir = this->Convert(dir.c_str(),HOME_OUTPUT,MAKEFILE);
  1279. commands.clear();
  1280. depends.clear();
  1281. commands.push_back
  1282. (this->GetRecursiveMakeCall("CMakeFiles/Makefile2",dir.c_str()));
  1283. this->CreateCDCommand(commands,
  1284. this->Makefile->GetHomeOutputDirectory(),
  1285. this->Makefile->GetStartOutputDirectory());
  1286. this->WriteMakeRule(ruleFileStream, "The main clean target", "clean",
  1287. depends, commands, true);
  1288. commands.clear();
  1289. depends.clear();
  1290. depends.push_back("clean");
  1291. this->WriteMakeRule(ruleFileStream, "The main clean target", "clean/fast",
  1292. depends, commands, true);
  1293. // Write the preinstall rule.
  1294. dir = this->Makefile->GetStartOutputDirectory();
  1295. dir += "/preinstall";
  1296. dir = this->Convert(dir.c_str(), HOME_OUTPUT,MAKEFILE);
  1297. commands.clear();
  1298. depends.clear();
  1299. const char* noall =
  1300. this->Makefile->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
  1301. if(!noall || cmSystemTools::IsOff(noall))
  1302. {
  1303. // Drive the build before installing.
  1304. depends.push_back("all");
  1305. }
  1306. else
  1307. {
  1308. // At least make sure the build system is up to date.
  1309. depends.push_back("cmake_check_build_system");
  1310. }
  1311. commands.push_back
  1312. (this->GetRecursiveMakeCall("CMakeFiles/Makefile2", dir.c_str()));
  1313. this->CreateCDCommand(commands,
  1314. this->Makefile->GetHomeOutputDirectory(),
  1315. this->Makefile->GetStartOutputDirectory());
  1316. this->WriteMakeRule(ruleFileStream, "Prepare targets for installation.",
  1317. "preinstall", depends, commands, true);
  1318. commands.clear();
  1319. depends.push_back("preinstall");
  1320. this->WriteMakeRule(ruleFileStream, "Prepare targets for installation.",
  1321. "preinstall/fast", depends, commands, true);
  1322. // write the depend rule, really a recompute depends rule
  1323. depends.clear();
  1324. commands.clear();
  1325. std::string cmakefileName = "CMakeFiles/Makefile.cmake";
  1326. this->Convert(cmakefileName.c_str(),HOME_OUTPUT,
  1327. cmLocalGenerator::MAKEFILE);
  1328. std::string runRule =
  1329. "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
  1330. runRule += " --check-build-system ";
  1331. runRule += this->Convert(cmakefileName.c_str(),cmLocalGenerator::NONE,
  1332. cmLocalGenerator::SHELL);
  1333. runRule += " 1";
  1334. commands.push_back(runRule);
  1335. this->WriteMakeRule(ruleFileStream, "clear depends",
  1336. "depend",
  1337. depends, commands, true);
  1338. }
  1339. //----------------------------------------------------------------------------
  1340. void cmLocalUnixMakefileGenerator3::CheckDependencies(cmMakefile* mf,
  1341. bool verbose,
  1342. bool clear)
  1343. {
  1344. // Get the list of target files to check
  1345. const char* infoDef = mf->GetDefinition("CMAKE_DEPEND_INFO_FILES");
  1346. if(!infoDef)
  1347. {
  1348. return;
  1349. }
  1350. std::vector<std::string> files;
  1351. cmSystemTools::ExpandListArgument(infoDef, files);
  1352. // For each info file run the check
  1353. cmDependsC checker;
  1354. checker.SetVerbose(verbose);
  1355. checker.SetFileComparison(this->GlobalGenerator->GetCMakeInstance()->GetFileComparison());
  1356. for(std::vector<std::string>::iterator l = files.begin();
  1357. l != files.end(); ++l)
  1358. {
  1359. // either clear or check the files
  1360. std::string dir = cmSystemTools::GetFilenamePath(l->c_str());
  1361. std::string internalDependFile = dir + "/depend.internal";
  1362. std::string dependFile = dir + "/depend.make";
  1363. if (clear)
  1364. {
  1365. checker.Clear(internalDependFile.c_str());
  1366. checker.Clear(dependFile.c_str());
  1367. }
  1368. else
  1369. {
  1370. checker.Check(dependFile.c_str(), internalDependFile.c_str());
  1371. }
  1372. }
  1373. }
  1374. void cmLocalUnixMakefileGenerator3
  1375. ::WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &target)
  1376. {
  1377. // now write all the language stuff
  1378. // Set the set of files to check for dependency integrity.
  1379. std::set<cmStdString> checkSetLangs;
  1380. std::map<cmStdString,cmLocalUnixMakefileGenerator3::IntegrityCheckSet>&
  1381. checkSet = this->GetIntegrityCheckSet()[target.GetName()];
  1382. for(std::map<cmStdString,
  1383. cmLocalUnixMakefileGenerator3::IntegrityCheckSet>::const_iterator
  1384. l = checkSet.begin(); l != checkSet.end(); ++l)
  1385. {
  1386. checkSetLangs.insert(l->first);
  1387. }
  1388. // list the languages
  1389. cmakefileStream
  1390. << "# The set of files whose dependency integrity should be checked:\n";
  1391. cmakefileStream
  1392. << "SET(CMAKE_DEPENDS_LANGUAGES\n";
  1393. for(std::set<cmStdString>::iterator
  1394. l = checkSetLangs.begin(); l != checkSetLangs.end(); ++l)
  1395. {
  1396. cmakefileStream << " \"" << l->c_str() << "\"\n";
  1397. }
  1398. cmakefileStream << " )\n";
  1399. // now list the files for each language
  1400. for(std::set<cmStdString>::iterator
  1401. l = checkSetLangs.begin(); l != checkSetLangs.end(); ++l)
  1402. {
  1403. cmakefileStream
  1404. << "SET(CMAKE_DEPENDS_CHECK_" << l->c_str() << "\n";
  1405. // get the check set for this local gen and language
  1406. cmLocalUnixMakefileGenerator3::IntegrityCheckSet iCheckSet =
  1407. checkSet[*l];
  1408. // for each file
  1409. for(cmLocalUnixMakefileGenerator3::IntegrityCheckSet::const_iterator
  1410. csIter = iCheckSet.begin();
  1411. csIter != iCheckSet.end(); ++csIter)
  1412. {
  1413. cmakefileStream << " \"" << (*csIter)->GetFullPath() << "\"\n";
  1414. // Get the full path name of the object file.
  1415. std::string obj = this->Makefile->GetStartOutputDirectory();
  1416. obj += "/";
  1417. obj += this->GetObjectFileName(target, **csIter);
  1418. cmakefileStream << " \"" <<
  1419. this->Convert(obj.c_str(),
  1420. cmLocalGenerator::FULL).c_str() << "\"\n";
  1421. }
  1422. cmakefileStream << " )\n";
  1423. }
  1424. }
  1425. //----------------------------------------------------------------------------
  1426. std::string
  1427. cmLocalUnixMakefileGenerator3
  1428. ::GetObjectFileName(cmTarget& target,
  1429. const cmSourceFile& source,
  1430. std::string* nameWithoutTargetDir)
  1431. {
  1432. // If the source file is located below the current binary directory
  1433. // then use that relative path for the object file name.
  1434. std::string objectName = this->Convert(source.GetFullPath().c_str(),
  1435. START_OUTPUT);
  1436. if(cmSystemTools::FileIsFullPath(objectName.c_str()) ||
  1437. objectName.empty() || objectName[0] == '.')
  1438. {
  1439. // If the source file is located below the current source
  1440. // directory then use that relative path for the object file name.
  1441. // Otherwise just use the relative path from the current binary
  1442. // directory.
  1443. std::string relFromSource = this->Convert(source.GetFullPath().c_str(),
  1444. START);
  1445. if(!cmSystemTools::FileIsFullPath(relFromSource.c_str()) &&
  1446. !relFromSource.empty() && relFromSource[0] != '.')
  1447. {
  1448. objectName = relFromSource;
  1449. }
  1450. }
  1451. // Replace the original source file extension with the object file
  1452. // extension.
  1453. std::string::size_type dot_pos = objectName.rfind(".");
  1454. if(dot_pos != std::string::npos)
  1455. {
  1456. objectName = objectName.substr(0, dot_pos);
  1457. }
  1458. if ( source.GetPropertyAsBool("KEEP_EXTENSION") )
  1459. {
  1460. if ( !source.GetSourceExtension().empty() )
  1461. {
  1462. objectName += "." + source.GetSourceExtension();
  1463. }
  1464. }
  1465. else
  1466. {
  1467. objectName +=
  1468. this->GlobalGenerator->GetLanguageOutputExtensionFromExtension(
  1469. source.GetSourceExtension().c_str());
  1470. }
  1471. // Convert to a safe name.
  1472. objectName = this->CreateSafeUniqueObjectFileName(objectName.c_str());
  1473. // Prepend the target directory.
  1474. std::string obj;
  1475. const char* fileTargetDirectory = source.GetProperty("MACOSX_PACKAGE_LOCATION");
  1476. if ( fileTargetDirectory )
  1477. {
  1478. std::string targetName;
  1479. std::string targetNameReal;
  1480. target.GetExecutableNames(targetName, targetNameReal,
  1481. this->ConfigurationName.c_str());
  1482. if ( target.GetPropertyAsBool("MACOSX_BUNDLE") )
  1483. {
  1484. // Construct the full path version of the names.
  1485. obj = this->ExecutableOutputPath;
  1486. if(obj.empty())
  1487. {
  1488. obj = this->Makefile->GetStartOutputDirectory();
  1489. obj += "/";
  1490. }
  1491. obj += targetName + ".app/Contents/";
  1492. obj += fileTargetDirectory;
  1493. }
  1494. else
  1495. {
  1496. // Framework not handled yet
  1497. abort();
  1498. }
  1499. obj = cmSystemTools::RelativePath(this->Makefile->GetHomeOutputDirectory(), obj.c_str());
  1500. }
  1501. else
  1502. {
  1503. obj = this->GetTargetDirectory(target);
  1504. }
  1505. obj += "/";
  1506. obj += objectName;
  1507. if(nameWithoutTargetDir)
  1508. {
  1509. *nameWithoutTargetDir = objectName;
  1510. }
  1511. return obj;
  1512. }
  1513. //----------------------------------------------------------------------------
  1514. void cmLocalUnixMakefileGenerator3::WriteDisclaimer(std::ostream& os)
  1515. {
  1516. os
  1517. << "# CMAKE generated file: DO NOT EDIT!\n"
  1518. << "# Generated by \"" << this->GlobalGenerator->GetName() << "\""
  1519. << " Generator, CMake Version "
  1520. << cmMakefile::GetMajorVersion() << "."
  1521. << cmMakefile::GetMinorVersion() << "\n\n";
  1522. }
  1523. //----------------------------------------------------------------------------
  1524. std::string
  1525. cmLocalUnixMakefileGenerator3
  1526. ::GetRecursiveMakeCall(const char *makefile, const char* tgt)
  1527. {
  1528. // Call make on the given file.
  1529. std::string cmd;
  1530. cmd += "$(MAKE) -f ";
  1531. cmd += makefile;
  1532. cmd += " ";
  1533. // Passg down verbosity level.
  1534. if(this->GetMakeSilentFlag().size())
  1535. {
  1536. cmd += this->GetMakeSilentFlag();
  1537. cmd += " ";
  1538. }
  1539. // Most unix makes will pass the command line flags to make down to
  1540. // sub-invoked makes via an environment variable. However, some
  1541. // makes do not support that, so you have to pass the flags
  1542. // explicitly.
  1543. if(this->GetPassMakeflags())
  1544. {
  1545. cmd += "-$(MAKEFLAGS) ";
  1546. }
  1547. // Add the target.
  1548. if (tgt && tgt[0] != '\0')
  1549. {
  1550. std::string tgt2 = this->Convert(tgt,HOME_OUTPUT,MAKEFILE);
  1551. tgt2 = this->ConvertToMakeTarget(tgt2.c_str());
  1552. cmd += tgt2;
  1553. }
  1554. return cmd;
  1555. }
  1556. //----------------------------------------------------------------------------
  1557. void cmLocalUnixMakefileGenerator3::WriteDivider(std::ostream& os)
  1558. {
  1559. os
  1560. << "#======================================"
  1561. << "=======================================\n";
  1562. }
  1563. //----------------------------------------------------------------------------
  1564. void
  1565. cmLocalUnixMakefileGenerator3
  1566. ::WriteCMakeArgument(std::ostream& os, const char* s)
  1567. {
  1568. // Write the given string to the stream with escaping to get it back
  1569. // into CMake through the lexical scanner.
  1570. os << "\"";
  1571. for(const char* c = s; *c; ++c)
  1572. {
  1573. if(*c == '\\')
  1574. {
  1575. os << "\\\\";
  1576. }
  1577. else if(*c == '"')
  1578. {
  1579. os << "\\\"";
  1580. }
  1581. else
  1582. {
  1583. os << *c;
  1584. }
  1585. }
  1586. os << "\"";
  1587. }
  1588. //----------------------------------------------------------------------------
  1589. std::string
  1590. cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p)
  1591. {
  1592. // Split the path into its components.
  1593. std::vector<std::string> components;
  1594. cmSystemTools::SplitPath(p, components);
  1595. // Return an empty path if there are no components.
  1596. if(components.empty())
  1597. {
  1598. return "\"\"";
  1599. }
  1600. // Choose a slash direction and fix root component.
  1601. const char* slash = "/";
  1602. #if defined(_WIN32) && !defined(__CYGWIN__)
  1603. if(!cmSystemTools::GetForceUnixPaths())
  1604. {
  1605. slash = "\\";
  1606. for(std::string::iterator i = components[0].begin();
  1607. i != components[0].end(); ++i)
  1608. {
  1609. if(*i == '/')
  1610. {
  1611. *i = '\\';
  1612. }
  1613. }
  1614. }
  1615. #endif
  1616. // Begin the quoted result with the root component.
  1617. std::string result = "\"";
  1618. result += components[0];
  1619. // Now add the rest of the components separated by the proper slash
  1620. // direction for this platform.
  1621. bool first = true;
  1622. for(unsigned int i=1; i < components.size(); ++i)
  1623. {
  1624. // Only the last component can be empty to avoid double slashes.
  1625. if(components[i].length() > 0 || (i == (components.size()-1)))
  1626. {
  1627. if(!first)
  1628. {
  1629. result += slash;
  1630. }
  1631. result += components[i];
  1632. first = false;
  1633. }
  1634. }
  1635. // Close the quoted result.
  1636. result += "\"";
  1637. return result;
  1638. }
  1639. //----------------------------------------------------------------------------
  1640. std::string
  1641. cmLocalUnixMakefileGenerator3::GetTargetDirectory(cmTarget& target)
  1642. {
  1643. std::string dir = "CMakeFiles/";
  1644. dir += target.GetName();
  1645. dir += ".dir";
  1646. return dir;
  1647. }
  1648. void cmLocalUnixMakefileGenerator3
  1649. ::CreateCDCommand(std::vector<std::string>& commands, const char *tgtDir,
  1650. const char *retDir)
  1651. {
  1652. // do we need to cd?
  1653. if (!strcmp(tgtDir,retDir))
  1654. {
  1655. return;
  1656. }
  1657. if(!this->UnixCD)
  1658. {
  1659. // On Windows we must perform each step separately and then change
  1660. // back because the shell keeps the working directory between
  1661. // commands.
  1662. std::string cmd = "cd ";
  1663. cmd += this->ConvertToOutputForExisting(tgtDir);
  1664. commands.insert(commands.begin(),cmd);
  1665. // Change back to the starting directory. Any trailing slash must be
  1666. // removed to avoid problems with Borland Make.
  1667. std::string back = retDir;
  1668. if(back.size() && back[back.size()-1] == '/')
  1669. {
  1670. back = back.substr(0, back.size()-1);
  1671. }
  1672. cmd = "cd ";
  1673. cmd += this->ConvertToOutputForExisting(back.c_str());
  1674. commands.push_back(cmd);
  1675. }
  1676. else
  1677. {
  1678. // On UNIX we must construct a single shell command to change
  1679. // directory and build because make resets the directory between
  1680. // each command.
  1681. std::vector<std::string>::iterator i = commands.begin();
  1682. for (; i != commands.end(); ++i)
  1683. {
  1684. std::string cmd = "cd ";
  1685. cmd += this->ConvertToOutputForExisting(tgtDir);
  1686. cmd += " && ";
  1687. cmd += *i;
  1688. *i = cmd;
  1689. }
  1690. }
  1691. }
  1692. //----------------------------------------------------------------------------
  1693. const char*
  1694. cmLocalUnixMakefileGenerator3
  1695. ::GetSourceFileLanguage(const cmSourceFile& source)
  1696. {
  1697. const char* lang = source.GetProperty("LANGUAGE");
  1698. if ( lang )
  1699. {
  1700. return lang;
  1701. }
  1702. // Identify the language of the source file.
  1703. return (this->GlobalGenerator
  1704. ->GetLanguageFromExtension(source.GetSourceExtension().c_str()));
  1705. }