cmMakefileTargetGenerator.cxx 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  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 "cmMakefileTargetGenerator.h"
  14. #include "cmGeneratedFileStream.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmGlobalUnixMakefileGenerator3.h"
  17. #include "cmLocalUnixMakefileGenerator3.h"
  18. #include "cmMakefile.h"
  19. #include "cmSourceFile.h"
  20. #include "cmTarget.h"
  21. #include "cmake.h"
  22. #include "cmMakefileExecutableTargetGenerator.h"
  23. #include "cmMakefileLibraryTargetGenerator.h"
  24. #include "cmMakefileUtilityTargetGenerator.h"
  25. cmMakefileTargetGenerator::cmMakefileTargetGenerator()
  26. {
  27. this->BuildFileStream = 0;
  28. this->InfoFileStream = 0;
  29. this->FlagFileStream = 0;
  30. this->CustomCommandDriver = OnBuild;
  31. }
  32. cmMakefileTargetGenerator *
  33. cmMakefileTargetGenerator::New(cmLocalUnixMakefileGenerator3 *lg,
  34. cmStdString tgtName, cmTarget *tgt)
  35. {
  36. cmMakefileTargetGenerator *result = 0;
  37. switch (tgt->GetType())
  38. {
  39. case cmTarget::EXECUTABLE:
  40. result = new cmMakefileExecutableTargetGenerator;
  41. break;
  42. case cmTarget::STATIC_LIBRARY:
  43. case cmTarget::SHARED_LIBRARY:
  44. case cmTarget::MODULE_LIBRARY:
  45. result = new cmMakefileLibraryTargetGenerator;
  46. break;
  47. case cmTarget::UTILITY:
  48. result = new cmMakefileUtilityTargetGenerator;
  49. break;
  50. default:
  51. return result;
  52. // break; /* unreachable */
  53. }
  54. result->TargetName = tgtName;
  55. result->Target = tgt;
  56. result->LocalGenerator = lg;
  57. result->GlobalGenerator =
  58. static_cast<cmGlobalUnixMakefileGenerator3*>(lg->GetGlobalGenerator());
  59. result->Makefile = lg->GetMakefile();
  60. return result;
  61. }
  62. //----------------------------------------------------------------------------
  63. void cmMakefileTargetGenerator::CreateRuleFile()
  64. {
  65. // Create a directory for this target.
  66. this->TargetBuildDirectory =
  67. this->LocalGenerator->GetTargetDirectory(*this->Target);
  68. this->TargetBuildDirectoryFull =
  69. this->LocalGenerator->ConvertToFullPath(this->TargetBuildDirectory);
  70. cmSystemTools::MakeDirectory(this->TargetBuildDirectoryFull.c_str());
  71. // Construct the rule file name.
  72. this->BuildFileName = this->TargetBuildDirectory;
  73. this->BuildFileName += "/build.make";
  74. this->BuildFileNameFull = this->TargetBuildDirectoryFull;
  75. this->BuildFileNameFull += "/build.make";
  76. // Construct the rule file name.
  77. this->ProgressFileName = this->TargetBuildDirectory;
  78. this->ProgressFileName += "/progress.make";
  79. this->ProgressFileNameFull = this->TargetBuildDirectoryFull;
  80. this->ProgressFileNameFull += "/progress.make";
  81. // reset the progress count
  82. this->NumberOfProgressActions = 0;
  83. // Open the rule file. This should be copy-if-different because the
  84. // rules may depend on this file itself.
  85. this->BuildFileStream =
  86. new cmGeneratedFileStream(this->BuildFileNameFull.c_str());
  87. this->BuildFileStream->SetCopyIfDifferent(true);
  88. if(!this->BuildFileStream)
  89. {
  90. return;
  91. }
  92. this->LocalGenerator->WriteDisclaimer(*this->BuildFileStream);
  93. this->LocalGenerator->WriteSpecialTargetsTop(*this->BuildFileStream);
  94. }
  95. //----------------------------------------------------------------------------
  96. void cmMakefileTargetGenerator::WriteTargetBuildRules()
  97. {
  98. // write the custom commands for this target
  99. // Look for files registered for cleaning in this directory.
  100. if(const char* additional_clean_files =
  101. this->Makefile->GetProperty
  102. ("ADDITIONAL_MAKE_CLEAN_FILES"))
  103. {
  104. cmSystemTools::ExpandListArgument(additional_clean_files,
  105. this->CleanFiles);
  106. }
  107. // add custom commands to the clean rules?
  108. const char* clean_no_custom =
  109. this->Makefile->GetProperty("CLEAN_NO_CUSTOM");
  110. bool clean = cmSystemTools::IsOff(clean_no_custom);
  111. // First generate the object rule files. Save a list of all object
  112. // files for this target.
  113. const std::vector<cmSourceFile*>& sources = this->Target->GetSourceFiles();
  114. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  115. source != sources.end(); ++source)
  116. {
  117. if(cmCustomCommand* cc = (*source)->GetCustomCommand())
  118. {
  119. this->GenerateCustomRuleFile(*cc);
  120. if (clean)
  121. {
  122. const std::vector<std::string>& outputs = cc->GetOutputs();
  123. for(std::vector<std::string>::const_iterator o = outputs.begin();
  124. o != outputs.end(); ++o)
  125. {
  126. this->CleanFiles.push_back
  127. (this->Convert(o->c_str(),
  128. cmLocalGenerator::START_OUTPUT,
  129. cmLocalGenerator::UNCHANGED));
  130. }
  131. }
  132. }
  133. else if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  134. {
  135. if(!this->GlobalGenerator->IgnoreFile
  136. ((*source)->GetSourceExtension().c_str()))
  137. {
  138. // Generate this object file's rule file.
  139. this->WriteObjectRuleFiles(*(*source));
  140. }
  141. else if((*source)->GetPropertyAsBool("EXTERNAL_OBJECT"))
  142. {
  143. // This is an external object file. Just add it.
  144. this->ExternalObjects.push_back((*source)->GetFullPath());
  145. }
  146. else
  147. {
  148. // We only get here if a source file is not an external object
  149. // and has an extension that is listed as an ignored file type
  150. // for this language. No message or diagnosis should be
  151. // given.
  152. }
  153. }
  154. }
  155. }
  156. //----------------------------------------------------------------------------
  157. void cmMakefileTargetGenerator::WriteCommonCodeRules()
  158. {
  159. // Include the dependencies for the target.
  160. std::string dependFileNameFull = this->TargetBuildDirectoryFull;
  161. dependFileNameFull += "/depend.make";
  162. *this->BuildFileStream
  163. << "# Include any dependencies generated for this target.\n"
  164. << this->LocalGenerator->IncludeDirective << " "
  165. << this->Convert(dependFileNameFull.c_str(),
  166. cmLocalGenerator::HOME_OUTPUT,
  167. cmLocalGenerator::MAKEFILE)
  168. << "\n\n";
  169. // Include the progress variables for the target.
  170. *this->BuildFileStream
  171. << "# Include the progress variables for this target.\n"
  172. << this->LocalGenerator->IncludeDirective << " "
  173. << this->Convert(this->ProgressFileNameFull.c_str(),
  174. cmLocalGenerator::HOME_OUTPUT,
  175. cmLocalGenerator::MAKEFILE)
  176. << "\n\n";
  177. // make sure the depend file exists
  178. if (!cmSystemTools::FileExists(dependFileNameFull.c_str()))
  179. {
  180. // Write an empty dependency file.
  181. cmGeneratedFileStream depFileStream(dependFileNameFull.c_str());
  182. depFileStream
  183. << "# Empty dependencies file for " << this->Target->GetName() << ".\n"
  184. << "# This may be replaced when dependencies are built." << std::endl;
  185. }
  186. // Open the flags file. This should be copy-if-different because the
  187. // rules may depend on this file itself.
  188. this->FlagFileNameFull = this->TargetBuildDirectoryFull;
  189. this->FlagFileNameFull += "/flags.make";
  190. this->FlagFileStream =
  191. new cmGeneratedFileStream(this->FlagFileNameFull.c_str());
  192. this->FlagFileStream->SetCopyIfDifferent(true);
  193. if(!this->FlagFileStream)
  194. {
  195. return;
  196. }
  197. this->LocalGenerator->WriteDisclaimer(*this->FlagFileStream);
  198. // Include the flags for the target.
  199. *this->BuildFileStream
  200. << "# Include the compile flags for this target's objects.\n"
  201. << this->LocalGenerator->IncludeDirective << " "
  202. << this->Convert(this->FlagFileNameFull.c_str(),
  203. cmLocalGenerator::HOME_OUTPUT,
  204. cmLocalGenerator::MAKEFILE)
  205. << "\n\n";
  206. }
  207. //----------------------------------------------------------------------------
  208. void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
  209. {
  210. // write language flags for target
  211. std::map<cmStdString,cmLocalUnixMakefileGenerator3::IntegrityCheckSet>&
  212. checkSet =
  213. this->LocalGenerator->GetIntegrityCheckSet()[this->Target->GetName()];
  214. for(std::map<cmStdString,
  215. cmLocalUnixMakefileGenerator3::IntegrityCheckSet>::const_iterator
  216. l = checkSet.begin(); l != checkSet.end(); ++l)
  217. {
  218. const char *lang = l->first.c_str();
  219. std::string flags;
  220. bool shared = ((this->Target->GetType() == cmTarget::SHARED_LIBRARY) ||
  221. (this->Target->GetType() == cmTarget::MODULE_LIBRARY));
  222. // Add the export symbol definition for shared library objects.
  223. if(const char* exportMacro = this->Target->GetExportMacro())
  224. {
  225. flags += "-D";
  226. flags += exportMacro;
  227. }
  228. // Add language-specific flags.
  229. this->LocalGenerator
  230. ->AddLanguageFlags(flags, lang,
  231. this->LocalGenerator->ConfigurationName.c_str());
  232. // Add shared-library flags if needed.
  233. this->LocalGenerator->AddSharedFlags(flags, lang, shared);
  234. // Add include directory flags.
  235. this->LocalGenerator->
  236. AppendFlags(flags, this->LocalGenerator->GetIncludeFlags(lang));
  237. // Add include directory flags.
  238. this->LocalGenerator->
  239. AppendFlags(flags,this->GetFrameworkFlags().c_str());
  240. *this->FlagFileStream << lang << "_FLAGS = " << flags << "\n\n";
  241. }
  242. // Add target-specific flags.
  243. if(this->Target->GetProperty("COMPILE_FLAGS"))
  244. {
  245. std::string flags;
  246. this->LocalGenerator->AppendFlags
  247. (flags, this->Target->GetProperty("COMPILE_FLAGS"));
  248. *this->FlagFileStream << "# TARGET_FLAGS = " << flags << "\n\n";
  249. }
  250. }
  251. //----------------------------------------------------------------------------
  252. void cmMakefileTargetGenerator::WriteObjectRuleFiles(cmSourceFile& source)
  253. {
  254. // Identify the language of the source file.
  255. const char* lang = this->LocalGenerator->GetSourceFileLanguage(source);
  256. if(!lang)
  257. {
  258. // don't know anything about this file so skip it
  259. return;
  260. }
  261. // Get the full path name of the object file.
  262. std::string objNoTargetDir;
  263. std::string obj =
  264. this->LocalGenerator->GetObjectFileName(*this->Target, source,
  265. &objNoTargetDir);
  266. // Avoid generating duplicate rules.
  267. if(this->ObjectFiles.find(obj) == this->ObjectFiles.end())
  268. {
  269. this->ObjectFiles.insert(obj);
  270. }
  271. else
  272. {
  273. cmOStringStream err;
  274. err << "Warning: Source file \""
  275. << source.GetSourceName().c_str() << "."
  276. << source.GetSourceExtension().c_str()
  277. << "\" is listed multiple times for target \""
  278. << this->Target->GetName()
  279. << "\".";
  280. cmSystemTools::Message(err.str().c_str(), "Warning");
  281. return;
  282. }
  283. // Create the directory containing the object file. This may be a
  284. // subdirectory under the target's directory.
  285. std::string dir = cmSystemTools::GetFilenamePath(obj.c_str());
  286. cmSystemTools::MakeDirectory
  287. (this->LocalGenerator->ConvertToFullPath(dir).c_str());
  288. // Save this in the target's list of object files.
  289. if ( source.GetPropertyAsBool("EXTRA_CONTENT") )
  290. {
  291. this->ExtraContent.insert(obj);
  292. }
  293. this->Objects.push_back(obj);
  294. // TODO: Remove
  295. //std::string relativeObj
  296. //= this->LocalGenerator->GetHomeRelativeOutputPath();
  297. //relativeObj += obj;
  298. // we compute some depends when writing the depend.make that we will also
  299. // use in the build.make, same with depMakeFile
  300. std::vector<std::string> depends;
  301. std::string depMakeFile;
  302. // generate the build rule file
  303. this->WriteObjectBuildFile(obj, lang, source, depends);
  304. // The object file should be checked for dependency integrity.
  305. this->LocalGenerator->
  306. CheckDependFiles[this->Target->GetName()][lang].insert(&source);
  307. // add this to the list of objects for this local generator
  308. if(cmSystemTools::FileIsFullPath(objNoTargetDir.c_str()))
  309. {
  310. objNoTargetDir = cmSystemTools::GetFilenameName(objNoTargetDir);
  311. }
  312. this->LocalGenerator->LocalObjectFiles[objNoTargetDir].
  313. push_back(
  314. cmLocalUnixMakefileGenerator3::LocalObjectEntry(this->Target, lang)
  315. );
  316. }
  317. //----------------------------------------------------------------------------
  318. void
  319. cmMakefileTargetGenerator
  320. ::WriteObjectBuildFile(std::string &obj,
  321. const char *lang,
  322. cmSourceFile& source,
  323. std::vector<std::string>& depends)
  324. {
  325. this->LocalGenerator->AppendRuleDepend(depends,
  326. this->FlagFileNameFull.c_str());
  327. // generate the depend scanning rule
  328. this->WriteObjectDependRules(source, depends);
  329. std::string relativeObj = this->LocalGenerator->GetHomeRelativeOutputPath();
  330. if ( source.GetPropertyAsBool("MACOSX_CONTENT") )
  331. {
  332. relativeObj = "";
  333. }
  334. relativeObj += obj;
  335. // Write the build rule.
  336. // Build the set of compiler flags.
  337. std::string flags;
  338. // Add language-specific flags.
  339. std::string langFlags = "$(";
  340. langFlags += lang;
  341. langFlags += "_FLAGS)";
  342. this->LocalGenerator->AppendFlags(flags, langFlags.c_str());
  343. // Add target-specific flags.
  344. if(this->Target->GetProperty("COMPILE_FLAGS"))
  345. {
  346. this->LocalGenerator->AppendFlags
  347. (flags, this->Target->GetProperty("COMPILE_FLAGS"));
  348. }
  349. // Add flags from source file properties.
  350. if (source.GetProperty("COMPILE_FLAGS"))
  351. {
  352. this->LocalGenerator->AppendFlags
  353. (flags, source.GetProperty("COMPILE_FLAGS"));
  354. *this->FlagFileStream << "# Custom flags: "
  355. << relativeObj << "_FLAGS = "
  356. << source.GetProperty("COMPILE_FLAGS")
  357. << "\n"
  358. << "\n";
  359. }
  360. // Get the output paths for source and object files.
  361. std::string sourceFile = source.GetFullPath();
  362. if(this->LocalGenerator->UseRelativePaths)
  363. {
  364. sourceFile = this->Convert(sourceFile.c_str(),
  365. cmLocalGenerator::HOME_OUTPUT);
  366. }
  367. sourceFile = this->Convert(sourceFile.c_str(),
  368. cmLocalGenerator::NONE,
  369. cmLocalGenerator::SHELL);
  370. std::string objectFile = this->Convert(obj.c_str(),
  371. cmLocalGenerator::START_OUTPUT,
  372. cmLocalGenerator::SHELL);
  373. // Construct the build message.
  374. std::vector<std::string> no_commands;
  375. std::vector<std::string> commands;
  376. // add in a progress call if needed
  377. std::string progressDir = this->Makefile->GetHomeOutputDirectory();
  378. progressDir += cmake::GetCMakeFilesDirectory();
  379. cmOStringStream progCmd;
  380. progCmd << "$(CMAKE_COMMAND) -E cmake_progress_report ";
  381. progCmd << this->LocalGenerator->Convert(progressDir.c_str(),
  382. cmLocalGenerator::FULL,
  383. cmLocalGenerator::SHELL);
  384. this->NumberOfProgressActions++;
  385. progCmd << " $(CMAKE_PROGRESS_"
  386. << this->NumberOfProgressActions
  387. << ")";
  388. commands.push_back(progCmd.str());
  389. std::string buildEcho = "Building ";
  390. buildEcho += lang;
  391. buildEcho += " object ";
  392. buildEcho += relativeObj;
  393. this->LocalGenerator->AppendEcho(commands, buildEcho.c_str(),
  394. cmLocalUnixMakefileGenerator3::EchoBuild);
  395. // Construct the compile rules.
  396. std::string compileRuleVar = "CMAKE_";
  397. compileRuleVar += lang;
  398. compileRuleVar += "_COMPILE_OBJECT";
  399. std::string compileRule =
  400. this->Makefile->GetRequiredDefinition(compileRuleVar.c_str());
  401. cmSystemTools::ExpandListArgument(compileRule, commands);
  402. std::string targetOutPathPDB;
  403. {
  404. std::string targetFullPathPDB;
  405. const char* configName = this->LocalGenerator->ConfigurationName.c_str();
  406. if(this->Target->GetType() == cmTarget::EXECUTABLE ||
  407. this->Target->GetType() == cmTarget::STATIC_LIBRARY ||
  408. this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
  409. this->Target->GetType() == cmTarget::MODULE_LIBRARY)
  410. {
  411. targetFullPathPDB = this->Target->GetDirectory();
  412. targetFullPathPDB += "/";
  413. targetFullPathPDB += this->Target->GetPDBName(configName);
  414. }
  415. targetOutPathPDB =
  416. this->Convert(targetFullPathPDB.c_str(),cmLocalGenerator::FULL,
  417. cmLocalGenerator::SHELL);
  418. }
  419. cmLocalGenerator::RuleVariables vars;
  420. vars.Language = lang;
  421. vars.TargetPDB = targetOutPathPDB.c_str();
  422. vars.Source = sourceFile.c_str();
  423. std::string shellrelativeObj =
  424. this->Convert(relativeObj.c_str(),
  425. cmLocalGenerator::NONE,
  426. cmLocalGenerator::SHELL).c_str();
  427. vars.Object = shellrelativeObj.c_str();
  428. std::string objdir = this->LocalGenerator->GetHomeRelativeOutputPath();
  429. objdir = this->Convert(objdir.c_str(),
  430. cmLocalGenerator::START_OUTPUT,
  431. cmLocalGenerator::SHELL);
  432. std::string objectDir = cmSystemTools::GetFilenamePath(obj);
  433. vars.ObjectDir = objectDir.c_str();
  434. vars.Flags = flags.c_str();
  435. // Expand placeholders in the commands.
  436. for(std::vector<std::string>::iterator i = commands.begin();
  437. i != commands.end(); ++i)
  438. {
  439. this->LocalGenerator->ExpandRuleVariables(*i, vars);
  440. }
  441. // Make the target dependency scanning rule include cmake-time-known
  442. // dependencies. The others are handled by the check-build-system
  443. // path.
  444. std::string depMark =
  445. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  446. depMark += "/depend.make.mark";
  447. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  448. depMark.c_str(),
  449. depends, no_commands, false);
  450. // Write the rule.
  451. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  452. relativeObj.c_str(),
  453. depends, commands, false);
  454. bool lang_is_c_or_cxx = ((strcmp(lang, "C") == 0) ||
  455. (strcmp(lang, "CXX") == 0));
  456. bool do_preprocess_rules = lang_is_c_or_cxx &&
  457. this->LocalGenerator->GetCreatePreprocessedSourceRules();
  458. bool do_assembly_rules = lang_is_c_or_cxx &&
  459. this->LocalGenerator->GetCreateAssemblySourceRules();
  460. if(do_preprocess_rules || do_assembly_rules)
  461. {
  462. std::vector<std::string> force_depends;
  463. force_depends.push_back("cmake_force");
  464. std::string::size_type dot_pos = relativeObj.rfind(".");
  465. std::string relativeObjBase = relativeObj.substr(0, dot_pos);
  466. if(do_preprocess_rules)
  467. {
  468. commands.clear();
  469. std::string relativeObjI = relativeObjBase + ".i";
  470. std::string preprocessEcho = "Preprocessing ";
  471. preprocessEcho += lang;
  472. preprocessEcho += " source to ";
  473. preprocessEcho += relativeObjI;
  474. this->LocalGenerator->AppendEcho(
  475. commands, preprocessEcho.c_str(),
  476. cmLocalUnixMakefileGenerator3::EchoBuild
  477. );
  478. std::string preprocessRuleVar = "CMAKE_";
  479. preprocessRuleVar += lang;
  480. preprocessRuleVar += "_CREATE_PREPROCESSED_SOURCE";
  481. if(const char* preprocessRule =
  482. this->Makefile->GetDefinition(preprocessRuleVar.c_str()))
  483. {
  484. cmSystemTools::ExpandListArgument(preprocessRule, commands);
  485. vars.PreprocessedSource = relativeObjI.c_str();
  486. // Expand placeholders in the commands.
  487. for(std::vector<std::string>::iterator i = commands.begin();
  488. i != commands.end(); ++i)
  489. {
  490. this->LocalGenerator->ExpandRuleVariables(*i, vars);
  491. }
  492. }
  493. else
  494. {
  495. std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
  496. cmd += preprocessRuleVar;
  497. commands.push_back(cmd);
  498. }
  499. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  500. relativeObjI.c_str(),
  501. force_depends, commands, false);
  502. }
  503. if(do_assembly_rules)
  504. {
  505. commands.clear();
  506. std::string relativeObjS = relativeObjBase + ".s";
  507. std::string assemblyEcho = "Compiling ";
  508. assemblyEcho += lang;
  509. assemblyEcho += " source to assembly ";
  510. assemblyEcho += relativeObjS;
  511. this->LocalGenerator->AppendEcho(
  512. commands, assemblyEcho.c_str(),
  513. cmLocalUnixMakefileGenerator3::EchoBuild
  514. );
  515. std::string assemblyRuleVar = "CMAKE_";
  516. assemblyRuleVar += lang;
  517. assemblyRuleVar += "_CREATE_ASSEMBLY_SOURCE";
  518. if(const char* assemblyRule =
  519. this->Makefile->GetDefinition(assemblyRuleVar.c_str()))
  520. {
  521. cmSystemTools::ExpandListArgument(assemblyRule, commands);
  522. vars.AssemblySource = relativeObjS.c_str();
  523. // Expand placeholders in the commands.
  524. for(std::vector<std::string>::iterator i = commands.begin();
  525. i != commands.end(); ++i)
  526. {
  527. this->LocalGenerator->ExpandRuleVariables(*i, vars);
  528. }
  529. }
  530. else
  531. {
  532. std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
  533. cmd += assemblyRuleVar;
  534. commands.push_back(cmd);
  535. }
  536. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  537. relativeObjS.c_str(),
  538. force_depends, commands, false);
  539. }
  540. }
  541. // If the language needs provides-requires mode, create the
  542. // corresponding targets.
  543. std::string objectRequires = relativeObj;
  544. objectRequires += ".requires";
  545. std::vector<std::string> p_depends;
  546. // always provide an empty requires target
  547. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  548. objectRequires.c_str(), p_depends,
  549. no_commands, true);
  550. // write a build rule to recursively build what this obj provides
  551. std::string objectProvides = relativeObj;
  552. objectProvides += ".provides";
  553. std::string temp = relativeObj;
  554. temp += ".provides.build";
  555. std::vector<std::string> r_commands;
  556. std::string tgtMakefileName =
  557. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  558. tgtMakefileName += "/build.make";
  559. r_commands.push_back
  560. (this->LocalGenerator->GetRecursiveMakeCall(tgtMakefileName.c_str(),
  561. temp.c_str()));
  562. p_depends.clear();
  563. p_depends.push_back(objectRequires);
  564. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  565. objectProvides.c_str(), p_depends,
  566. r_commands, true);
  567. // write the provides.build rule dependency on the obj file
  568. p_depends.clear();
  569. p_depends.push_back(relativeObj);
  570. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  571. temp.c_str(), p_depends, no_commands,
  572. true);
  573. }
  574. //----------------------------------------------------------------------------
  575. void cmMakefileTargetGenerator::WriteTargetRequiresRules()
  576. {
  577. std::vector<std::string> depends;
  578. std::vector<std::string> no_commands;
  579. // Construct the name of the dependency generation target.
  580. std::string depTarget =
  581. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  582. depTarget += "/requires";
  583. // This target drives dependency generation for all object files.
  584. std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
  585. std::string objTarget;
  586. for(std::vector<std::string>::const_iterator obj = this->Objects.begin();
  587. obj != this->Objects.end(); ++obj)
  588. {
  589. objTarget = relPath;
  590. objTarget += *obj;
  591. objTarget += ".requires";
  592. depends.push_back(objTarget);
  593. }
  594. // Write the rule.
  595. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  596. depTarget.c_str(),
  597. depends, no_commands, true);
  598. }
  599. //----------------------------------------------------------------------------
  600. void cmMakefileTargetGenerator::WriteTargetCleanRules()
  601. {
  602. std::vector<std::string> depends;
  603. std::vector<std::string> commands;
  604. // Construct the clean target name.
  605. std::string cleanTarget =
  606. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  607. cleanTarget += "/clean";
  608. // Construct the clean command.
  609. this->LocalGenerator->AppendCleanCommand(commands, this->CleanFiles,
  610. *this->Target);
  611. this->LocalGenerator->CreateCDCommand
  612. (commands,
  613. this->Makefile->GetStartOutputDirectory(),
  614. this->Makefile->GetHomeOutputDirectory());
  615. // Write the rule.
  616. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  617. cleanTarget.c_str(),
  618. depends, commands, true);
  619. }
  620. //----------------------------------------------------------------------------
  621. void cmMakefileTargetGenerator::WriteTargetDependRules()
  622. {
  623. // must write the targets depend info file
  624. std::string dir = this->LocalGenerator->GetTargetDirectory(*this->Target);
  625. this->InfoFileNameFull = dir;
  626. this->InfoFileNameFull += "/DependInfo.cmake";
  627. this->InfoFileNameFull =
  628. this->LocalGenerator->ConvertToFullPath(this->InfoFileNameFull);
  629. this->InfoFileStream =
  630. new cmGeneratedFileStream(this->InfoFileNameFull.c_str());
  631. this->InfoFileStream->SetCopyIfDifferent(true);
  632. if(!*this->InfoFileStream)
  633. {
  634. return;
  635. }
  636. this->LocalGenerator->
  637. WriteDependLanguageInfo(*this->InfoFileStream,*this->Target);
  638. // and now write the rule to use it
  639. std::vector<std::string> depends;
  640. std::vector<std::string> commands;
  641. // Construct the name of the dependency generation target.
  642. std::string depTarget =
  643. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  644. depTarget += "/depend";
  645. std::string depMark = depTarget;
  646. depMark += ".make.mark";
  647. depends.push_back(depMark);
  648. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  649. depTarget.c_str(),
  650. depends, commands, true);
  651. depends.clear();
  652. // Write the dependency generation rule.
  653. std::string depEcho = "Scanning dependencies of target ";
  654. depEcho += this->Target->GetName();
  655. this->LocalGenerator->AppendEcho(commands, depEcho.c_str(),
  656. cmLocalUnixMakefileGenerator3::EchoDepend);
  657. // Add a command to call CMake to scan dependencies. CMake will
  658. // touch the corresponding depends file after scanning dependencies.
  659. cmOStringStream depCmd;
  660. // TODO: Account for source file properties and directory-level
  661. // definitions when scanning for dependencies.
  662. #if !defined(_WIN32) || defined(__CYGWIN__)
  663. // This platform supports symlinks, so cmSystemTools will translate
  664. // paths. Make sure PWD is set to the original name of the home
  665. // output directory to help cmSystemTools to create the same
  666. // translation table for the dependency scanning process.
  667. depCmd << "cd "
  668. << (this->LocalGenerator->Convert(
  669. this->Makefile->GetHomeOutputDirectory(),
  670. cmLocalGenerator::FULL, cmLocalGenerator::SHELL))
  671. << " && ";
  672. #endif
  673. // Generate a call this signature:
  674. //
  675. // cmake -E cmake_depends <generator>
  676. // <home-src-dir> <start-src-dir>
  677. // <home-out-dir> <start-out-dir>
  678. // <dep-info>
  679. //
  680. // This gives the dependency scanner enough information to recreate
  681. // the state of our local generator sufficiently for its needs.
  682. depCmd << "$(CMAKE_COMMAND) -E cmake_depends \""
  683. << this->GlobalGenerator->GetName() << "\" "
  684. << this->Convert(this->Makefile->GetHomeDirectory(),
  685. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  686. << " "
  687. << this->Convert(this->Makefile->GetStartDirectory(),
  688. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  689. << " "
  690. << this->Convert(this->Makefile->GetHomeOutputDirectory(),
  691. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  692. << " "
  693. << this->Convert(this->Makefile->GetStartOutputDirectory(),
  694. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  695. << " "
  696. << this->Convert(this->InfoFileNameFull.c_str(),
  697. cmLocalGenerator::FULL, cmLocalGenerator::SHELL);
  698. commands.push_back(depCmd.str());
  699. // Make sure all custom command outputs in this target are built.
  700. if(this->CustomCommandDriver == OnDepends)
  701. {
  702. this->DriveCustomCommands(depends);
  703. }
  704. // Write the rule.
  705. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  706. depMark.c_str(),
  707. depends, commands, false);
  708. }
  709. //----------------------------------------------------------------------------
  710. void
  711. cmMakefileTargetGenerator
  712. ::DriveCustomCommands(std::vector<std::string>& depends)
  713. {
  714. // Depend on all custom command outputs.
  715. const std::vector<cmSourceFile*>& sources =
  716. this->Target->GetSourceFiles();
  717. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  718. source != sources.end(); ++source)
  719. {
  720. if(cmCustomCommand* cc = (*source)->GetCustomCommand())
  721. {
  722. const std::vector<std::string>& outputs = cc->GetOutputs();
  723. for(std::vector<std::string>::const_iterator o = outputs.begin();
  724. o != outputs.end(); ++o)
  725. {
  726. depends.push_back(*o);
  727. }
  728. }
  729. }
  730. }
  731. //----------------------------------------------------------------------------
  732. void cmMakefileTargetGenerator
  733. ::WriteObjectDependRules(cmSourceFile& source,
  734. std::vector<std::string>& depends)
  735. {
  736. // Create the list of dependencies known at cmake time. These are
  737. // shared between the object file and dependency scanning rule.
  738. depends.push_back(source.GetFullPath());
  739. if(const char* objectDeps = source.GetProperty("OBJECT_DEPENDS"))
  740. {
  741. std::vector<std::string> deps;
  742. cmSystemTools::ExpandListArgument(objectDeps, deps);
  743. for(std::vector<std::string>::iterator i = deps.begin();
  744. i != deps.end(); ++i)
  745. {
  746. depends.push_back(i->c_str());
  747. }
  748. }
  749. }
  750. //----------------------------------------------------------------------------
  751. void cmMakefileTargetGenerator
  752. ::GenerateCustomRuleFile(const cmCustomCommand& cc)
  753. {
  754. // Collect the commands.
  755. std::vector<std::string> commands;
  756. std::string comment = this->LocalGenerator->ConstructComment(cc);
  757. if(!comment.empty())
  758. {
  759. // add in a progress call if needed
  760. std::string progressDir = this->Makefile->GetHomeOutputDirectory();
  761. progressDir += cmake::GetCMakeFilesDirectory();
  762. cmOStringStream progCmd;
  763. progCmd << "$(CMAKE_COMMAND) -E cmake_progress_report ";
  764. progCmd << this->LocalGenerator->Convert(progressDir.c_str(),
  765. cmLocalGenerator::FULL,
  766. cmLocalGenerator::SHELL);
  767. this->NumberOfProgressActions++;
  768. progCmd << " $(CMAKE_PROGRESS_"
  769. << this->NumberOfProgressActions
  770. << ")";
  771. commands.push_back(progCmd.str());
  772. this->LocalGenerator
  773. ->AppendEcho(commands, comment.c_str(),
  774. cmLocalUnixMakefileGenerator3::EchoGenerate);
  775. }
  776. this->LocalGenerator->AppendCustomCommand(commands, cc);
  777. // Collect the dependencies.
  778. std::vector<std::string> depends;
  779. this->LocalGenerator->AppendCustomDepend(depends, cc);
  780. // Add a dependency on the rule file itself.
  781. this->LocalGenerator->AppendRuleDepend(depends,
  782. this->BuildFileNameFull.c_str());
  783. // Check whether we need to bother checking for a symbolic output.
  784. bool need_symbolic = this->GlobalGenerator->GetNeedSymbolicMark();
  785. // Write the rule.
  786. const std::vector<std::string>& outputs = cc.GetOutputs();
  787. std::vector<std::string>::const_iterator o = outputs.begin();
  788. {
  789. bool symbolic = false;
  790. if(need_symbolic)
  791. {
  792. if(cmSourceFile* sf = this->Makefile->GetSource(o->c_str()))
  793. {
  794. symbolic = sf->GetPropertyAsBool("SYMBOLIC");
  795. }
  796. }
  797. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  798. o->c_str(), depends, commands,
  799. symbolic);
  800. }
  801. // Write rules to drive building any outputs beyond the first.
  802. const char* in = o->c_str();
  803. for(++o; o != outputs.end(); ++o)
  804. {
  805. bool symbolic = false;
  806. if(need_symbolic)
  807. {
  808. if(cmSourceFile* sf = this->Makefile->GetSource(o->c_str()))
  809. {
  810. symbolic = sf->GetPropertyAsBool("SYMBOLIC");
  811. }
  812. }
  813. this->GenerateExtraOutput(o->c_str(), in, symbolic);
  814. }
  815. }
  816. //----------------------------------------------------------------------------
  817. void
  818. cmMakefileTargetGenerator
  819. ::GenerateExtraOutput(const char* out, const char* in, bool symbolic)
  820. {
  821. // Add a rule to build the primary output if the extra output needs
  822. // to be created.
  823. std::vector<std::string> commands;
  824. std::vector<std::string> depends;
  825. std::string emptyCommand = this->GlobalGenerator->GetEmptyRuleHackCommand();
  826. if(!emptyCommand.empty())
  827. {
  828. commands.push_back(emptyCommand);
  829. }
  830. depends.push_back(in);
  831. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  832. out, depends, commands,
  833. symbolic);
  834. // Register the extra output as paired with the first output so that
  835. // the check-build-system step will remove the primary output if any
  836. // extra outputs are missing. This forces the rule to regenerate
  837. // all outputs.
  838. this->GlobalGenerator->AddMultipleOutputPair(out, in);
  839. }
  840. //----------------------------------------------------------------------------
  841. void
  842. cmMakefileTargetGenerator
  843. ::WriteObjectsVariable(std::string& variableName,
  844. std::string& variableNameExternal)
  845. {
  846. // Write a make variable assignment that lists all objects for the
  847. // target.
  848. variableName =
  849. this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
  850. "_OBJECTS");
  851. *this->BuildFileStream
  852. << "# Object files for target " << this->Target->GetName() << "\n"
  853. << variableName.c_str() << " =";
  854. std::string object;
  855. const char* objName =
  856. this->Makefile->GetDefinition("CMAKE_NO_QUOTED_OBJECTS");
  857. const char* lineContinue =
  858. this->Makefile->GetDefinition("CMAKE_MAKE_LINE_CONTINUE");
  859. if(!lineContinue)
  860. {
  861. lineContinue = "\\";
  862. }
  863. for(std::vector<std::string>::const_iterator i = this->Objects.begin();
  864. i != this->Objects.end(); ++i)
  865. {
  866. if ( this->ExtraContent.find(i->c_str()) != this->ExtraContent.end() )
  867. {
  868. continue;
  869. }
  870. *this->BuildFileStream << " " << lineContinue << "\n";
  871. if(objName)
  872. {
  873. *this->BuildFileStream <<
  874. this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
  875. cmLocalGenerator::MAKEFILE);
  876. }
  877. else
  878. {
  879. *this->BuildFileStream <<
  880. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
  881. }
  882. }
  883. *this->BuildFileStream << "\n";
  884. // Write a make variable assignment that lists all external objects
  885. // for the target.
  886. variableNameExternal =
  887. this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
  888. "_EXTERNAL_OBJECTS");
  889. *this->BuildFileStream
  890. << "\n"
  891. << "# External object files for target "
  892. << this->Target->GetName() << "\n"
  893. << variableNameExternal.c_str() << " =";
  894. for(std::vector<std::string>::const_iterator i =
  895. this->ExternalObjects.begin();
  896. i != this->ExternalObjects.end(); ++i)
  897. {
  898. object = this->Convert(i->c_str(),cmLocalGenerator::START_OUTPUT);
  899. *this->BuildFileStream
  900. << " " << lineContinue << "\n"
  901. << this->Makefile->GetSafeDefinition("CMAKE_OBJECT_NAME");
  902. if(objName)
  903. {
  904. *this->BuildFileStream <<
  905. this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
  906. cmLocalGenerator::MAKEFILE);
  907. }
  908. else
  909. {
  910. *this->BuildFileStream <<
  911. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
  912. }
  913. }
  914. *this->BuildFileStream << "\n" << "\n";
  915. }
  916. //----------------------------------------------------------------------------
  917. void
  918. cmMakefileTargetGenerator
  919. ::WriteObjectsString(std::string& buildObjs)
  920. {
  921. std::string object;
  922. const char* no_quoted =
  923. this->Makefile->GetDefinition("CMAKE_NO_QUOTED_OBJECTS");
  924. const char* space = "";
  925. for(std::vector<std::string>::const_iterator i = this->Objects.begin();
  926. i != this->Objects.end(); ++i)
  927. {
  928. if ( this->ExtraContent.find(i->c_str()) != this->ExtraContent.end() )
  929. {
  930. continue;
  931. }
  932. buildObjs += space;
  933. space = " ";
  934. if(no_quoted)
  935. {
  936. buildObjs +=
  937. this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
  938. cmLocalGenerator::SHELL);
  939. }
  940. else
  941. {
  942. buildObjs +=
  943. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
  944. }
  945. }
  946. for(std::vector<std::string>::const_iterator i =
  947. this->ExternalObjects.begin();
  948. i != this->ExternalObjects.end(); ++i)
  949. {
  950. buildObjs += space;
  951. space = " ";
  952. if(no_quoted)
  953. {
  954. buildObjs +=
  955. this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
  956. cmLocalGenerator::SHELL);
  957. }
  958. else
  959. {
  960. buildObjs +=
  961. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
  962. }
  963. }
  964. }
  965. //----------------------------------------------------------------------------
  966. void cmMakefileTargetGenerator::WriteTargetDriverRule(const char* main_output,
  967. bool relink)
  968. {
  969. // Compute the name of the driver target.
  970. std::string dir =
  971. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  972. std::string buildTargetRuleName = dir;
  973. buildTargetRuleName += relink?"/preinstall":"/build";
  974. buildTargetRuleName = this->Convert(buildTargetRuleName.c_str(),
  975. cmLocalGenerator::HOME_OUTPUT,
  976. cmLocalGenerator::UNCHANGED);
  977. // Build the list of target outputs to drive.
  978. std::vector<std::string> depends;
  979. if(main_output)
  980. {
  981. depends.push_back(main_output);
  982. }
  983. const char* comment = 0;
  984. if(relink)
  985. {
  986. // Setup the comment for the preinstall driver.
  987. comment = "Rule to relink during preinstall.";
  988. }
  989. else
  990. {
  991. // Setup the comment for the main build driver.
  992. comment = "Rule to build all files generated by this target.";
  993. // Make sure all custom command outputs in this target are built.
  994. if(this->CustomCommandDriver == OnBuild)
  995. {
  996. this->DriveCustomCommands(depends);
  997. }
  998. }
  999. // Write the driver rule.
  1000. std::vector<std::string> no_commands;
  1001. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, comment,
  1002. buildTargetRuleName.c_str(),
  1003. depends, no_commands, true);
  1004. }
  1005. //----------------------------------------------------------------------------
  1006. std::string cmMakefileTargetGenerator::GetFrameworkFlags()
  1007. {
  1008. #ifndef __APPLE__
  1009. return std::string();
  1010. #else
  1011. std::set<cmStdString> emitted;
  1012. emitted.insert("/System/Library/Frameworks");
  1013. std::vector<std::string> includes;
  1014. this->LocalGenerator->GetIncludeDirectories(includes);
  1015. std::vector<std::string>::iterator i;
  1016. // check all include directories for frameworks as this
  1017. // will already have added a -F for the framework
  1018. for(i = includes.begin(); i != includes.end(); ++i)
  1019. {
  1020. if(cmSystemTools::IsPathToFramework(i->c_str()))
  1021. {
  1022. std::string frameworkDir = *i;
  1023. frameworkDir += "/../";
  1024. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1025. emitted.insert(frameworkDir);
  1026. }
  1027. }
  1028. std::string flags;
  1029. std::vector<std::string>& frameworks = this->Target->GetFrameworks();
  1030. for(i = frameworks.begin();
  1031. i != frameworks.end(); ++i)
  1032. {
  1033. if(emitted.insert(*i).second)
  1034. {
  1035. flags += "-F";
  1036. flags += this->LocalGenerator->ConvertToOutputForExisting(i->c_str());
  1037. flags += " ";
  1038. }
  1039. }
  1040. return flags;
  1041. #endif
  1042. }
  1043. //----------------------------------------------------------------------------
  1044. void cmMakefileTargetGenerator
  1045. ::AppendTargetDepends(std::vector<std::string>& depends)
  1046. {
  1047. // Static libraries never depend on anything for linking.
  1048. if(this->Target->GetType() == cmTarget::STATIC_LIBRARY)
  1049. {
  1050. return;
  1051. }
  1052. // Compute which library configuration to link.
  1053. cmTarget::LinkLibraryType linkType = cmTarget::OPTIMIZED;
  1054. if(cmSystemTools::UpperCase(
  1055. this->LocalGenerator->ConfigurationName.c_str()) == "DEBUG")
  1056. {
  1057. linkType = cmTarget::DEBUG;
  1058. }
  1059. // Keep track of dependencies already listed.
  1060. std::set<cmStdString> emitted;
  1061. // A target should not depend on itself.
  1062. emitted.insert(this->Target->GetName());
  1063. // Loop over all library dependencies.
  1064. const cmTarget::LinkLibraryVectorType& tlibs =
  1065. this->Target->GetLinkLibraries();
  1066. for(cmTarget::LinkLibraryVectorType::const_iterator lib = tlibs.begin();
  1067. lib != tlibs.end(); ++lib)
  1068. {
  1069. // skip the library if it is not general and the link type
  1070. // does not match the current target
  1071. if(lib->second != cmTarget::GENERAL &&
  1072. lib->second != linkType)
  1073. {
  1074. continue;
  1075. }
  1076. // Don't emit the same library twice for this target.
  1077. if(emitted.insert(lib->first).second)
  1078. {
  1079. // Depend on other CMake targets.
  1080. if(cmTarget* tgt =
  1081. this->GlobalGenerator->FindTarget(0, lib->first.c_str(), false))
  1082. {
  1083. if(const char* location =
  1084. tgt->GetLocation(this->LocalGenerator->ConfigurationName.c_str()))
  1085. {
  1086. depends.push_back(location);
  1087. }
  1088. }
  1089. // depend on full path libs as well
  1090. else if(cmSystemTools::FileIsFullPath(lib->first.c_str()))
  1091. {
  1092. depends.push_back(lib->first.c_str());
  1093. }
  1094. }
  1095. }
  1096. }
  1097. //----------------------------------------------------------------------------
  1098. void cmMakefileTargetGenerator
  1099. ::CloseFileStreams()
  1100. {
  1101. delete this->BuildFileStream;
  1102. delete this->InfoFileStream;
  1103. delete this->FlagFileStream;
  1104. }
  1105. void cmMakefileTargetGenerator::RemoveForbiddenFlags(const char* flagVar,
  1106. const char* linkLang,
  1107. std::string& linkFlags)
  1108. {
  1109. // check for language flags that are not allowed at link time, and
  1110. // remove them, -w on darwin for gcc -w -dynamiclib sends -w to libtool
  1111. // which fails, there may be more]
  1112. std::string removeFlags = "CMAKE_";
  1113. removeFlags += linkLang;
  1114. removeFlags += flagVar;
  1115. std::string removeflags =
  1116. this->Makefile->GetSafeDefinition(removeFlags.c_str());
  1117. std::vector<std::string> removeList;
  1118. cmSystemTools::ExpandListArgument(removeflags, removeList);
  1119. for(std::vector<std::string>::iterator i = removeList.begin();
  1120. i != removeList.end(); ++i)
  1121. {
  1122. cmSystemTools::ReplaceString(linkFlags, i->c_str(), "");
  1123. }
  1124. }
  1125. void cmMakefileTargetGenerator::WriteProgressVariables(unsigned long total,
  1126. unsigned long &current)
  1127. {
  1128. cmGeneratedFileStream *progressFileStream =
  1129. new cmGeneratedFileStream(this->ProgressFileNameFull.c_str());
  1130. if(!progressFileStream)
  1131. {
  1132. return;
  1133. }
  1134. unsigned long num;
  1135. unsigned long i;
  1136. for (i = 1; i <= this->NumberOfProgressActions; ++i)
  1137. {
  1138. *progressFileStream
  1139. << "CMAKE_PROGRESS_" << i << " = ";
  1140. if (total <= 100)
  1141. {
  1142. num = i + current;
  1143. *progressFileStream << num;
  1144. this->LocalGenerator->ProgressFiles[this->Target->GetName()]
  1145. .push_back(num);
  1146. }
  1147. else if (((i+current)*100)/total > ((i-1+current)*100)/total)
  1148. {
  1149. num = ((i+current)*100)/total;
  1150. *progressFileStream << num;
  1151. this->LocalGenerator->ProgressFiles[this->Target->GetName()]
  1152. .push_back(num);
  1153. }
  1154. *progressFileStream << "\n";
  1155. }
  1156. *progressFileStream << "\n";
  1157. current += this->NumberOfProgressActions;
  1158. delete progressFileStream;
  1159. }