cmMakefileTargetGenerator.cxx 44 KB

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