cmMakefileTargetGenerator.cxx 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  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. 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->DriveCustomCommandsOnDepends)
  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. // Check whether we need to bother checking for a symbolic output.
  781. bool need_symbolic = this->GlobalGenerator->GetNeedSymbolicMark();
  782. // Write the rule.
  783. const std::vector<std::string>& outputs = cc.GetOutputs();
  784. std::vector<std::string>::const_iterator o = outputs.begin();
  785. {
  786. bool symbolic = false;
  787. if(need_symbolic)
  788. {
  789. if(cmSourceFile* sf = this->Makefile->GetSource(o->c_str()))
  790. {
  791. symbolic = sf->GetPropertyAsBool("SYMBOLIC");
  792. }
  793. }
  794. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  795. o->c_str(), depends, commands,
  796. symbolic);
  797. }
  798. // Write rules to drive building any outputs beyond the first.
  799. const char* in = o->c_str();
  800. for(++o; o != outputs.end(); ++o)
  801. {
  802. bool symbolic = false;
  803. if(need_symbolic)
  804. {
  805. if(cmSourceFile* sf = this->Makefile->GetSource(o->c_str()))
  806. {
  807. symbolic = sf->GetPropertyAsBool("SYMBOLIC");
  808. }
  809. }
  810. this->GenerateExtraOutput(o->c_str(), in, symbolic);
  811. }
  812. }
  813. //----------------------------------------------------------------------------
  814. void
  815. cmMakefileTargetGenerator
  816. ::GenerateExtraOutput(const char* out, const char* in, bool symbolic)
  817. {
  818. // Add a rule to build the primary output if the extra output needs
  819. // to be created.
  820. std::vector<std::string> commands;
  821. std::vector<std::string> depends;
  822. std::string emptyCommand = this->GlobalGenerator->GetEmptyCommandHack();
  823. if(!emptyCommand.empty())
  824. {
  825. commands.push_back(emptyCommand);
  826. }
  827. depends.push_back(in);
  828. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  829. out, depends, commands,
  830. symbolic);
  831. // Register the extra output as paired with the first output so that
  832. // the check-build-system step will remove the primary output if any
  833. // extra outputs are missing. This forces the rule to regenerate
  834. // all outputs.
  835. this->GlobalGenerator->AddMultipleOutputPair(out, in);
  836. }
  837. //----------------------------------------------------------------------------
  838. void
  839. cmMakefileTargetGenerator
  840. ::WriteObjectsVariable(std::string& variableName,
  841. std::string& variableNameExternal)
  842. {
  843. // Write a make variable assignment that lists all objects for the
  844. // target.
  845. variableName =
  846. this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
  847. "_OBJECTS");
  848. *this->BuildFileStream
  849. << "# Object files for target " << this->Target->GetName() << "\n"
  850. << variableName.c_str() << " =";
  851. std::string object;
  852. const char* objName =
  853. this->Makefile->GetDefinition("CMAKE_NO_QUOTED_OBJECTS");
  854. const char* lineContinue =
  855. this->Makefile->GetDefinition("CMAKE_MAKE_LINE_CONTINUE");
  856. if(!lineContinue)
  857. {
  858. lineContinue = "\\";
  859. }
  860. for(std::vector<std::string>::const_iterator i = this->Objects.begin();
  861. i != this->Objects.end(); ++i)
  862. {
  863. if ( this->ExtraContent.find(i->c_str()) != this->ExtraContent.end() )
  864. {
  865. continue;
  866. }
  867. *this->BuildFileStream << " " << lineContinue << "\n";
  868. if(objName)
  869. {
  870. *this->BuildFileStream <<
  871. this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
  872. cmLocalGenerator::MAKEFILE);
  873. }
  874. else
  875. {
  876. *this->BuildFileStream <<
  877. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
  878. }
  879. }
  880. *this->BuildFileStream << "\n";
  881. // Write a make variable assignment that lists all external objects
  882. // for the target.
  883. variableNameExternal =
  884. this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
  885. "_EXTERNAL_OBJECTS");
  886. *this->BuildFileStream
  887. << "\n"
  888. << "# External object files for target "
  889. << this->Target->GetName() << "\n"
  890. << variableNameExternal.c_str() << " =";
  891. for(std::vector<std::string>::const_iterator i =
  892. this->ExternalObjects.begin();
  893. i != this->ExternalObjects.end(); ++i)
  894. {
  895. object = this->Convert(i->c_str(),cmLocalGenerator::START_OUTPUT);
  896. *this->BuildFileStream
  897. << " " << lineContinue << "\n"
  898. << this->Makefile->GetSafeDefinition("CMAKE_OBJECT_NAME");
  899. if(objName)
  900. {
  901. *this->BuildFileStream <<
  902. this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
  903. cmLocalGenerator::MAKEFILE);
  904. }
  905. else
  906. {
  907. *this->BuildFileStream <<
  908. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
  909. }
  910. }
  911. *this->BuildFileStream << "\n" << "\n";
  912. }
  913. //----------------------------------------------------------------------------
  914. void
  915. cmMakefileTargetGenerator
  916. ::WriteObjectsString(std::string& buildObjs)
  917. {
  918. std::string object;
  919. const char* no_quoted =
  920. this->Makefile->GetDefinition("CMAKE_NO_QUOTED_OBJECTS");
  921. const char* space = "";
  922. for(std::vector<std::string>::const_iterator i = this->Objects.begin();
  923. i != this->Objects.end(); ++i)
  924. {
  925. if ( this->ExtraContent.find(i->c_str()) != this->ExtraContent.end() )
  926. {
  927. continue;
  928. }
  929. buildObjs += space;
  930. space = " ";
  931. if(no_quoted)
  932. {
  933. buildObjs +=
  934. this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
  935. cmLocalGenerator::SHELL);
  936. }
  937. else
  938. {
  939. buildObjs +=
  940. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
  941. }
  942. }
  943. for(std::vector<std::string>::const_iterator i =
  944. this->ExternalObjects.begin();
  945. i != this->ExternalObjects.end(); ++i)
  946. {
  947. buildObjs += space;
  948. space = " ";
  949. if(no_quoted)
  950. {
  951. buildObjs +=
  952. this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
  953. cmLocalGenerator::SHELL);
  954. }
  955. else
  956. {
  957. buildObjs +=
  958. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
  959. }
  960. }
  961. }
  962. //----------------------------------------------------------------------------
  963. void cmMakefileTargetGenerator::WriteTargetDriverRule(const char* main_output,
  964. bool relink)
  965. {
  966. // Compute the name of the driver target.
  967. std::string dir =
  968. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  969. std::string buildTargetRuleName = dir;
  970. buildTargetRuleName += relink?"/preinstall":"/build";
  971. buildTargetRuleName = this->Convert(buildTargetRuleName.c_str(),
  972. cmLocalGenerator::HOME_OUTPUT,
  973. cmLocalGenerator::UNCHANGED);
  974. // Build the list of target outputs to drive.
  975. std::vector<std::string> depends;
  976. if(main_output)
  977. {
  978. depends.push_back(main_output);
  979. }
  980. const char* comment = 0;
  981. if(relink)
  982. {
  983. // Setup the comment for the preinstall driver.
  984. comment = "Rule to relink during preinstall.";
  985. }
  986. else
  987. {
  988. // Setup the comment for the main build driver.
  989. comment = "Rule to build all files generated by this target.";
  990. // Make sure all custom command outputs in this target are built.
  991. if(!this->DriveCustomCommandsOnDepends)
  992. {
  993. this->DriveCustomCommands(depends);
  994. }
  995. }
  996. // Write the driver rule.
  997. std::vector<std::string> no_commands;
  998. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, comment,
  999. buildTargetRuleName.c_str(),
  1000. depends, no_commands, true);
  1001. }
  1002. //----------------------------------------------------------------------------
  1003. std::string cmMakefileTargetGenerator::GetFrameworkFlags()
  1004. {
  1005. #ifndef __APPLE__
  1006. return std::string();
  1007. #else
  1008. std::set<cmStdString> emitted;
  1009. std::vector<std::string> includes;
  1010. this->LocalGenerator->GetIncludeDirectories(includes);
  1011. std::vector<std::string>::iterator i;
  1012. // check all include directories for frameworks as this
  1013. // will already have added a -F for the framework
  1014. for(i = includes.begin(); i != includes.end(); ++i)
  1015. {
  1016. if(cmSystemTools::IsPathToFramework(i->c_str()))
  1017. {
  1018. std::string frameworkDir = *i;
  1019. frameworkDir += "/../";
  1020. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1021. emitted.insert(frameworkDir);
  1022. }
  1023. }
  1024. std::string flags;
  1025. std::vector<std::string>& frameworks = this->Target->GetFrameworks();
  1026. for(i = frameworks.begin();
  1027. i != frameworks.end(); ++i)
  1028. {
  1029. if(emitted.insert(*i).second)
  1030. {
  1031. flags += "-F";
  1032. flags += this->LocalGenerator->ConvertToOutputForExisting(i->c_str());
  1033. flags += " ";
  1034. }
  1035. }
  1036. return flags;
  1037. #endif
  1038. }
  1039. //----------------------------------------------------------------------------
  1040. void cmMakefileTargetGenerator
  1041. ::AppendTargetDepends(std::vector<std::string>& depends)
  1042. {
  1043. // Static libraries never depend on anything for linking.
  1044. if(this->Target->GetType() == cmTarget::STATIC_LIBRARY)
  1045. {
  1046. return;
  1047. }
  1048. // Compute which library configuration to link.
  1049. cmTarget::LinkLibraryType linkType = cmTarget::OPTIMIZED;
  1050. if(cmSystemTools::UpperCase(
  1051. this->LocalGenerator->ConfigurationName.c_str()) == "DEBUG")
  1052. {
  1053. linkType = cmTarget::DEBUG;
  1054. }
  1055. // Keep track of dependencies already listed.
  1056. std::set<cmStdString> emitted;
  1057. // A target should not depend on itself.
  1058. emitted.insert(this->Target->GetName());
  1059. // Loop over all library dependencies.
  1060. const cmTarget::LinkLibraryVectorType& tlibs =
  1061. this->Target->GetLinkLibraries();
  1062. for(cmTarget::LinkLibraryVectorType::const_iterator lib = tlibs.begin();
  1063. lib != tlibs.end(); ++lib)
  1064. {
  1065. // skip the library if it is not general and the link type
  1066. // does not match the current target
  1067. if(lib->second != cmTarget::GENERAL &&
  1068. lib->second != linkType)
  1069. {
  1070. continue;
  1071. }
  1072. // Don't emit the same library twice for this target.
  1073. if(emitted.insert(lib->first).second)
  1074. {
  1075. // Depend on other CMake targets.
  1076. if(cmTarget* tgt =
  1077. this->GlobalGenerator->FindTarget(0, lib->first.c_str()))
  1078. {
  1079. if(const char* location =
  1080. tgt->GetLocation(this->LocalGenerator->ConfigurationName.c_str()))
  1081. {
  1082. depends.push_back(location);
  1083. }
  1084. }
  1085. // depend on full path libs as well
  1086. else if(cmSystemTools::FileIsFullPath(lib->first.c_str()))
  1087. {
  1088. depends.push_back(lib->first.c_str());
  1089. }
  1090. }
  1091. }
  1092. }
  1093. //----------------------------------------------------------------------------
  1094. void cmMakefileTargetGenerator
  1095. ::CloseFileStreams()
  1096. {
  1097. delete this->BuildFileStream;
  1098. delete this->InfoFileStream;
  1099. delete this->FlagFileStream;
  1100. }
  1101. void cmMakefileTargetGenerator::RemoveForbiddenFlags(const char* flagVar,
  1102. const char* linkLang,
  1103. std::string& linkFlags)
  1104. {
  1105. // check for language flags that are not allowed at link time, and
  1106. // remove them, -w on darwin for gcc -w -dynamiclib sends -w to libtool
  1107. // which fails, there may be more]
  1108. std::string removeFlags = "CMAKE_";
  1109. removeFlags += linkLang;
  1110. removeFlags += flagVar;
  1111. std::string removeflags =
  1112. this->Makefile->GetSafeDefinition(removeFlags.c_str());
  1113. std::vector<std::string> removeList;
  1114. cmSystemTools::ExpandListArgument(removeflags, removeList);
  1115. for(std::vector<std::string>::iterator i = removeList.begin();
  1116. i != removeList.end(); ++i)
  1117. {
  1118. cmSystemTools::ReplaceString(linkFlags, i->c_str(), "");
  1119. }
  1120. }
  1121. void cmMakefileTargetGenerator::WriteProgressVariables(unsigned long total,
  1122. unsigned long &current)
  1123. {
  1124. cmGeneratedFileStream *progressFileStream =
  1125. new cmGeneratedFileStream(this->ProgressFileNameFull.c_str());
  1126. if(!progressFileStream)
  1127. {
  1128. return;
  1129. }
  1130. unsigned long num;
  1131. unsigned long i;
  1132. for (i = 1; i <= this->NumberOfProgressActions; ++i)
  1133. {
  1134. *progressFileStream
  1135. << "CMAKE_PROGRESS_" << i << " = ";
  1136. if (total <= 100)
  1137. {
  1138. num = i + current;
  1139. *progressFileStream << num;
  1140. this->LocalGenerator->ProgressFiles[this->Target->GetName()]
  1141. .push_back(num);
  1142. }
  1143. else if (((i+current)*100)/total > ((i-1+current)*100)/total)
  1144. {
  1145. num = ((i+current)*100)/total;
  1146. *progressFileStream << num;
  1147. this->LocalGenerator->ProgressFiles[this->Target->GetName()]
  1148. .push_back(num);
  1149. }
  1150. *progressFileStream << "\n";
  1151. }
  1152. *progressFileStream << "\n";
  1153. current += this->NumberOfProgressActions;
  1154. delete progressFileStream;
  1155. }