cmMakefileTargetGenerator.cxx 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  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. std::string shellrelativeObj =
  441. this->Convert(relativeObj.c_str(),
  442. cmLocalGenerator::NONE,
  443. cmLocalGenerator::SHELL).c_str();
  444. vars.Object = shellrelativeObj.c_str();
  445. std::string objdir = this->LocalGenerator->GetHomeRelativeOutputPath();
  446. objdir = this->Convert(objdir.c_str(),
  447. cmLocalGenerator::START_OUTPUT,
  448. cmLocalGenerator::SHELL);
  449. std::string objectDir = cmSystemTools::GetFilenamePath(obj);
  450. vars.ObjectDir = objectDir.c_str();
  451. vars.Flags = flags.c_str();
  452. // Expand placeholders in the commands.
  453. for(std::vector<std::string>::iterator i = commands.begin();
  454. i != commands.end(); ++i)
  455. {
  456. this->LocalGenerator->ExpandRuleVariables(*i, vars);
  457. }
  458. // Make the target dependency scanning rule include cmake-time-known
  459. // dependencies. The others are handled by the check-build-system
  460. // path.
  461. std::string depMark =
  462. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  463. depMark += "/depend.make.mark";
  464. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  465. depMark.c_str(),
  466. depends, no_commands, false);
  467. // Write the rule.
  468. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  469. relativeObj.c_str(),
  470. depends, commands, false);
  471. bool lang_is_c_or_cxx = ((strcmp(lang, "C") == 0) ||
  472. (strcmp(lang, "CXX") == 0));
  473. bool do_preprocess_rules = lang_is_c_or_cxx &&
  474. this->LocalGenerator->GetCreatePreprocessedSourceRules();
  475. bool do_assembly_rules = lang_is_c_or_cxx &&
  476. this->LocalGenerator->GetCreateAssemblySourceRules();
  477. if(do_preprocess_rules || do_assembly_rules)
  478. {
  479. std::vector<std::string> force_depends;
  480. force_depends.push_back("cmake_force");
  481. std::string::size_type dot_pos = relativeObj.rfind(".");
  482. std::string relativeObjBase = relativeObj.substr(0, dot_pos);
  483. if(do_preprocess_rules)
  484. {
  485. commands.clear();
  486. std::string relativeObjI = relativeObjBase + ".i";
  487. std::string preprocessEcho = "Preprocessing ";
  488. preprocessEcho += lang;
  489. preprocessEcho += " source to ";
  490. preprocessEcho += relativeObjI;
  491. this->LocalGenerator->AppendEcho(
  492. commands, preprocessEcho.c_str(),
  493. cmLocalUnixMakefileGenerator3::EchoBuild
  494. );
  495. std::string preprocessRuleVar = "CMAKE_";
  496. preprocessRuleVar += lang;
  497. preprocessRuleVar += "_CREATE_PREPROCESSED_SOURCE";
  498. if(const char* preprocessRule =
  499. this->Makefile->GetDefinition(preprocessRuleVar.c_str()))
  500. {
  501. cmSystemTools::ExpandListArgument(preprocessRule, commands);
  502. vars.PreprocessedSource = relativeObjI.c_str();
  503. // Expand placeholders in the commands.
  504. for(std::vector<std::string>::iterator i = commands.begin();
  505. i != commands.end(); ++i)
  506. {
  507. this->LocalGenerator->ExpandRuleVariables(*i, vars);
  508. }
  509. }
  510. else
  511. {
  512. std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
  513. cmd += preprocessRuleVar;
  514. commands.push_back(cmd);
  515. }
  516. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  517. relativeObjI.c_str(),
  518. force_depends, commands, false);
  519. }
  520. if(do_assembly_rules)
  521. {
  522. commands.clear();
  523. std::string relativeObjS = relativeObjBase + ".s";
  524. std::string assemblyEcho = "Compiling ";
  525. assemblyEcho += lang;
  526. assemblyEcho += " source to assembly ";
  527. assemblyEcho += relativeObjS;
  528. this->LocalGenerator->AppendEcho(
  529. commands, assemblyEcho.c_str(),
  530. cmLocalUnixMakefileGenerator3::EchoBuild
  531. );
  532. std::string assemblyRuleVar = "CMAKE_";
  533. assemblyRuleVar += lang;
  534. assemblyRuleVar += "_CREATE_ASSEMBLY_SOURCE";
  535. if(const char* assemblyRule =
  536. this->Makefile->GetDefinition(assemblyRuleVar.c_str()))
  537. {
  538. cmSystemTools::ExpandListArgument(assemblyRule, commands);
  539. vars.AssemblySource = relativeObjS.c_str();
  540. // Expand placeholders in the commands.
  541. for(std::vector<std::string>::iterator i = commands.begin();
  542. i != commands.end(); ++i)
  543. {
  544. this->LocalGenerator->ExpandRuleVariables(*i, vars);
  545. }
  546. }
  547. else
  548. {
  549. std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
  550. cmd += assemblyRuleVar;
  551. commands.push_back(cmd);
  552. }
  553. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  554. relativeObjS.c_str(),
  555. force_depends, commands, false);
  556. }
  557. }
  558. // If the language needs provides-requires mode, create the
  559. // corresponding targets.
  560. std::string objectRequires = relativeObj;
  561. objectRequires += ".requires";
  562. std::vector<std::string> p_depends;
  563. // always provide an empty requires target
  564. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  565. objectRequires.c_str(), p_depends,
  566. no_commands, true);
  567. // write a build rule to recursively build what this obj provides
  568. std::string objectProvides = relativeObj;
  569. objectProvides += ".provides";
  570. std::string temp = relativeObj;
  571. temp += ".provides.build";
  572. std::vector<std::string> r_commands;
  573. std::string tgtMakefileName =
  574. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  575. tgtMakefileName += "/build.make";
  576. r_commands.push_back
  577. (this->LocalGenerator->GetRecursiveMakeCall(tgtMakefileName.c_str(),
  578. temp.c_str()));
  579. p_depends.clear();
  580. p_depends.push_back(objectRequires);
  581. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  582. objectProvides.c_str(), p_depends,
  583. r_commands, true);
  584. // write the provides.build rule dependency on the obj file
  585. p_depends.clear();
  586. p_depends.push_back(relativeObj);
  587. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  588. temp.c_str(), p_depends, no_commands,
  589. true);
  590. }
  591. //----------------------------------------------------------------------------
  592. void cmMakefileTargetGenerator::WriteTargetRequiresRules()
  593. {
  594. std::vector<std::string> depends;
  595. std::vector<std::string> no_commands;
  596. // Construct the name of the dependency generation target.
  597. std::string depTarget =
  598. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  599. depTarget += "/requires";
  600. // This target drives dependency generation for all object files.
  601. std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
  602. std::string objTarget;
  603. for(std::vector<std::string>::const_iterator obj = this->Objects.begin();
  604. obj != this->Objects.end(); ++obj)
  605. {
  606. objTarget = relPath;
  607. objTarget += *obj;
  608. objTarget += ".requires";
  609. depends.push_back(objTarget);
  610. }
  611. // Write the rule.
  612. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  613. depTarget.c_str(),
  614. depends, no_commands, true);
  615. }
  616. //----------------------------------------------------------------------------
  617. void cmMakefileTargetGenerator::WriteTargetCleanRules()
  618. {
  619. std::vector<std::string> depends;
  620. std::vector<std::string> commands;
  621. // Construct the clean target name.
  622. std::string cleanTarget =
  623. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  624. cleanTarget += "/clean";
  625. // Construct the clean command.
  626. this->LocalGenerator->AppendCleanCommand(commands, this->CleanFiles,
  627. *this->Target);
  628. this->LocalGenerator->CreateCDCommand
  629. (commands,
  630. this->Makefile->GetStartOutputDirectory(),
  631. this->Makefile->GetHomeOutputDirectory());
  632. // Write the rule.
  633. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  634. cleanTarget.c_str(),
  635. depends, commands, true);
  636. }
  637. //----------------------------------------------------------------------------
  638. void cmMakefileTargetGenerator::WriteTargetDependRules()
  639. {
  640. // must write the targets depend info file
  641. std::string dir = this->LocalGenerator->GetTargetDirectory(*this->Target);
  642. this->InfoFileNameFull = dir;
  643. this->InfoFileNameFull += "/DependInfo.cmake";
  644. this->InfoFileNameFull =
  645. this->LocalGenerator->ConvertToFullPath(this->InfoFileNameFull);
  646. this->InfoFileStream =
  647. new cmGeneratedFileStream(this->InfoFileNameFull.c_str());
  648. this->InfoFileStream->SetCopyIfDifferent(true);
  649. if(!*this->InfoFileStream)
  650. {
  651. return;
  652. }
  653. this->LocalGenerator->
  654. WriteDependLanguageInfo(*this->InfoFileStream,*this->Target);
  655. // and now write the rule to use it
  656. std::vector<std::string> depends;
  657. std::vector<std::string> commands;
  658. // Construct the name of the dependency generation target.
  659. std::string depTarget =
  660. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  661. depTarget += "/depend";
  662. std::string depMark = depTarget;
  663. depMark += ".make.mark";
  664. depends.push_back(depMark);
  665. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  666. depTarget.c_str(),
  667. depends, commands, true);
  668. depends.clear();
  669. // Write the dependency generation rule.
  670. std::string depEcho = "Scanning dependencies of target ";
  671. depEcho += this->Target->GetName();
  672. this->LocalGenerator->AppendEcho(commands, depEcho.c_str(),
  673. cmLocalUnixMakefileGenerator3::EchoDepend);
  674. // Add a command to call CMake to scan dependencies. CMake will
  675. // touch the corresponding depends file after scanning dependencies.
  676. cmOStringStream depCmd;
  677. // TODO: Account for source file properties and directory-level
  678. // definitions when scanning for dependencies.
  679. #if !defined(_WIN32) || defined(__CYGWIN__)
  680. // This platform supports symlinks, so cmSystemTools will translate
  681. // paths. Make sure PWD is set to the original name of the home
  682. // output directory to help cmSystemTools to create the same
  683. // translation table for the dependency scanning process.
  684. depCmd << "cd "
  685. << (this->LocalGenerator->Convert(
  686. this->Makefile->GetHomeOutputDirectory(),
  687. cmLocalGenerator::FULL, cmLocalGenerator::SHELL))
  688. << " && ";
  689. #endif
  690. // Generate a call this signature:
  691. //
  692. // cmake -E cmake_depends <generator>
  693. // <home-src-dir> <start-src-dir>
  694. // <home-out-dir> <start-out-dir>
  695. // <dep-info>
  696. //
  697. // This gives the dependency scanner enough information to recreate
  698. // the state of our local generator sufficiently for its needs.
  699. depCmd << "$(CMAKE_COMMAND) -E cmake_depends \""
  700. << this->GlobalGenerator->GetName() << "\" "
  701. << this->Convert(this->Makefile->GetHomeDirectory(),
  702. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  703. << " "
  704. << this->Convert(this->Makefile->GetStartDirectory(),
  705. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  706. << " "
  707. << this->Convert(this->Makefile->GetHomeOutputDirectory(),
  708. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  709. << " "
  710. << this->Convert(this->Makefile->GetStartOutputDirectory(),
  711. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  712. << " "
  713. << this->Convert(this->InfoFileNameFull.c_str(),
  714. cmLocalGenerator::FULL, cmLocalGenerator::SHELL);
  715. commands.push_back(depCmd.str());
  716. // Make sure all custom command outputs in this target are built.
  717. if(this->DriveCustomCommandsOnDepends)
  718. {
  719. this->DriveCustomCommands(depends);
  720. }
  721. // Write the rule.
  722. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  723. depMark.c_str(),
  724. depends, commands, false);
  725. }
  726. //----------------------------------------------------------------------------
  727. void
  728. cmMakefileTargetGenerator
  729. ::DriveCustomCommands(std::vector<std::string>& depends)
  730. {
  731. // Depend on all custom command outputs.
  732. const std::vector<cmSourceFile*>& sources =
  733. this->Target->GetSourceFiles();
  734. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  735. source != sources.end(); ++source)
  736. {
  737. if(cmCustomCommand* cc = (*source)->GetCustomCommand())
  738. {
  739. const std::vector<std::string>& outputs = cc->GetOutputs();
  740. for(std::vector<std::string>::const_iterator o = outputs.begin();
  741. o != outputs.end(); ++o)
  742. {
  743. depends.push_back(*o);
  744. }
  745. }
  746. }
  747. }
  748. //----------------------------------------------------------------------------
  749. void cmMakefileTargetGenerator
  750. ::WriteObjectDependRules(cmSourceFile& source,
  751. std::vector<std::string>& depends)
  752. {
  753. // Create the list of dependencies known at cmake time. These are
  754. // shared between the object file and dependency scanning rule.
  755. depends.push_back(source.GetFullPath());
  756. if(const char* objectDeps = source.GetProperty("OBJECT_DEPENDS"))
  757. {
  758. std::vector<std::string> deps;
  759. cmSystemTools::ExpandListArgument(objectDeps, deps);
  760. for(std::vector<std::string>::iterator i = deps.begin();
  761. i != deps.end(); ++i)
  762. {
  763. depends.push_back(i->c_str());
  764. }
  765. }
  766. }
  767. //----------------------------------------------------------------------------
  768. void cmMakefileTargetGenerator
  769. ::GenerateCustomRuleFile(const cmCustomCommand& cc)
  770. {
  771. // Collect the commands.
  772. std::vector<std::string> commands;
  773. std::string comment = this->LocalGenerator->ConstructComment(cc);
  774. if(!comment.empty())
  775. {
  776. // add in a progress call if needed
  777. std::string progressDir = this->Makefile->GetHomeOutputDirectory();
  778. progressDir += cmake::GetCMakeFilesDirectory();
  779. cmOStringStream progCmd;
  780. progCmd << "$(CMAKE_COMMAND) -E cmake_progress_report ";
  781. progCmd << this->LocalGenerator->Convert(progressDir.c_str(),
  782. cmLocalGenerator::FULL,
  783. cmLocalGenerator::SHELL);
  784. this->NumberOfProgressActions++;
  785. progCmd << " $(CMAKE_PROGRESS_"
  786. << this->NumberOfProgressActions
  787. << ")";
  788. commands.push_back(progCmd.str());
  789. this->LocalGenerator
  790. ->AppendEcho(commands, comment.c_str(),
  791. cmLocalUnixMakefileGenerator3::EchoGenerate);
  792. }
  793. this->LocalGenerator->AppendCustomCommand(commands, cc);
  794. // Collect the dependencies.
  795. std::vector<std::string> depends;
  796. this->LocalGenerator->AppendCustomDepend(depends, cc);
  797. // Check whether we need to bother checking for a symbolic output.
  798. bool need_symbolic = this->GlobalGenerator->GetNeedSymbolicMark();
  799. // Write the rule.
  800. const std::vector<std::string>& outputs = cc.GetOutputs();
  801. std::vector<std::string>::const_iterator o = outputs.begin();
  802. {
  803. bool symbolic = false;
  804. if(need_symbolic)
  805. {
  806. if(cmSourceFile* sf = this->Makefile->GetSource(o->c_str()))
  807. {
  808. symbolic = sf->GetPropertyAsBool("SYMBOLIC");
  809. }
  810. }
  811. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  812. o->c_str(), depends, commands,
  813. symbolic);
  814. }
  815. // If the rule has multiple outputs, add a rule for the extra
  816. // outputs to just depend on the first output with no command. Also
  817. // register the extra outputs as paired with the first output so
  818. // that the check-build-system step will remove the primary output
  819. // if any extra outputs are missing, forcing the rule to regenerate
  820. // all outputs.
  821. depends.clear();
  822. depends.push_back(*o);
  823. commands.clear();
  824. std::string emptyCommand = this->GlobalGenerator->GetEmptyCommandHack();
  825. if(!emptyCommand.empty())
  826. {
  827. commands.push_back(emptyCommand);
  828. }
  829. for(++o; o != outputs.end(); ++o)
  830. {
  831. bool symbolic = false;
  832. if(need_symbolic)
  833. {
  834. if(cmSourceFile* sf = this->Makefile->GetSource(o->c_str()))
  835. {
  836. symbolic = sf->GetPropertyAsBool("SYMBOLIC");
  837. }
  838. }
  839. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  840. o->c_str(), depends, commands,
  841. symbolic);
  842. this->GlobalGenerator->AddMultipleOutputPair(o->c_str(),
  843. depends[0].c_str());
  844. }
  845. }
  846. //----------------------------------------------------------------------------
  847. void
  848. cmMakefileTargetGenerator
  849. ::WriteObjectsVariable(std::string& variableName,
  850. std::string& variableNameExternal)
  851. {
  852. // Write a make variable assignment that lists all objects for the
  853. // target.
  854. variableName =
  855. this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
  856. "_OBJECTS");
  857. *this->BuildFileStream
  858. << "# Object files for target " << this->Target->GetName() << "\n"
  859. << variableName.c_str() << " =";
  860. std::string object;
  861. const char* objName =
  862. this->Makefile->GetDefinition("CMAKE_NO_QUOTED_OBJECTS");
  863. const char* lineContinue =
  864. this->Makefile->GetDefinition("CMAKE_MAKE_LINE_CONTINUE");
  865. if(!lineContinue)
  866. {
  867. lineContinue = "\\";
  868. }
  869. for(std::vector<std::string>::const_iterator i = this->Objects.begin();
  870. i != this->Objects.end(); ++i)
  871. {
  872. if ( this->ExtraContent.find(i->c_str()) != this->ExtraContent.end() )
  873. {
  874. continue;
  875. }
  876. *this->BuildFileStream << " " << lineContinue << "\n";
  877. if(objName)
  878. {
  879. *this->BuildFileStream <<
  880. this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
  881. cmLocalGenerator::MAKEFILE);
  882. }
  883. else
  884. {
  885. *this->BuildFileStream <<
  886. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
  887. }
  888. }
  889. *this->BuildFileStream << "\n";
  890. // Write a make variable assignment that lists all external objects
  891. // for the target.
  892. variableNameExternal =
  893. this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
  894. "_EXTERNAL_OBJECTS");
  895. *this->BuildFileStream
  896. << "\n"
  897. << "# External object files for target "
  898. << this->Target->GetName() << "\n"
  899. << variableNameExternal.c_str() << " =";
  900. for(std::vector<std::string>::const_iterator i =
  901. this->ExternalObjects.begin();
  902. i != this->ExternalObjects.end(); ++i)
  903. {
  904. object = this->Convert(i->c_str(),cmLocalGenerator::START_OUTPUT);
  905. *this->BuildFileStream
  906. << " " << lineContinue << "\n"
  907. << this->Makefile->GetSafeDefinition("CMAKE_OBJECT_NAME");
  908. if(objName)
  909. {
  910. *this->BuildFileStream <<
  911. this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
  912. cmLocalGenerator::MAKEFILE);
  913. }
  914. else
  915. {
  916. *this->BuildFileStream <<
  917. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
  918. }
  919. }
  920. *this->BuildFileStream << "\n" << "\n";
  921. }
  922. //----------------------------------------------------------------------------
  923. void
  924. cmMakefileTargetGenerator
  925. ::WriteObjectsString(std::string& buildObjs)
  926. {
  927. std::string object;
  928. const char* no_quoted =
  929. this->Makefile->GetDefinition("CMAKE_NO_QUOTED_OBJECTS");
  930. const char* space = "";
  931. for(std::vector<std::string>::const_iterator i = this->Objects.begin();
  932. i != this->Objects.end(); ++i)
  933. {
  934. if ( this->ExtraContent.find(i->c_str()) != this->ExtraContent.end() )
  935. {
  936. continue;
  937. }
  938. buildObjs += space;
  939. space = " ";
  940. if(no_quoted)
  941. {
  942. buildObjs +=
  943. this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
  944. cmLocalGenerator::SHELL);
  945. }
  946. else
  947. {
  948. buildObjs +=
  949. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
  950. }
  951. }
  952. for(std::vector<std::string>::const_iterator i =
  953. this->ExternalObjects.begin();
  954. i != this->ExternalObjects.end(); ++i)
  955. {
  956. buildObjs += space;
  957. space = " ";
  958. if(no_quoted)
  959. {
  960. buildObjs +=
  961. this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
  962. cmLocalGenerator::SHELL);
  963. }
  964. else
  965. {
  966. buildObjs +=
  967. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
  968. }
  969. }
  970. }
  971. //----------------------------------------------------------------------------
  972. void cmMakefileTargetGenerator::WriteTargetDriverRule(const char* main_output,
  973. bool relink)
  974. {
  975. // Compute the name of the driver target.
  976. std::string dir =
  977. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  978. std::string buildTargetRuleName = dir;
  979. buildTargetRuleName += relink?"/preinstall":"/build";
  980. buildTargetRuleName = this->Convert(buildTargetRuleName.c_str(),
  981. cmLocalGenerator::HOME_OUTPUT,
  982. cmLocalGenerator::UNCHANGED);
  983. // Build the list of target outputs to drive.
  984. std::vector<std::string> depends;
  985. if(main_output)
  986. {
  987. depends.push_back(main_output);
  988. }
  989. const char* comment = 0;
  990. if(relink)
  991. {
  992. // Setup the comment for the preinstall driver.
  993. comment = "Rule to relink during preinstall.";
  994. }
  995. else
  996. {
  997. // Setup the comment for the main build driver.
  998. comment = "Rule to build all files generated by this target.";
  999. // Make sure all custom command outputs in this target are built.
  1000. if(!this->DriveCustomCommandsOnDepends)
  1001. {
  1002. this->DriveCustomCommands(depends);
  1003. }
  1004. }
  1005. // Write the driver rule.
  1006. std::vector<std::string> no_commands;
  1007. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, comment,
  1008. buildTargetRuleName.c_str(),
  1009. depends, no_commands, true);
  1010. }
  1011. //----------------------------------------------------------------------------
  1012. std::string cmMakefileTargetGenerator::GetFrameworkFlags()
  1013. {
  1014. #ifndef __APPLE__
  1015. return std::string();
  1016. #else
  1017. std::set<cmStdString> emitted;
  1018. std::vector<std::string> includes;
  1019. this->LocalGenerator->GetIncludeDirectories(includes);
  1020. std::vector<std::string>::iterator i;
  1021. // check all include directories for frameworks as this
  1022. // will already have added a -F for the framework
  1023. for(i = includes.begin(); i != includes.end(); ++i)
  1024. {
  1025. if(cmSystemTools::IsPathToFramework(i->c_str()))
  1026. {
  1027. std::string frameworkDir = *i;
  1028. frameworkDir += "/../";
  1029. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1030. emitted.insert(frameworkDir);
  1031. }
  1032. }
  1033. std::string flags;
  1034. std::vector<std::string>& frameworks = this->Target->GetFrameworks();
  1035. for(i = frameworks.begin();
  1036. i != frameworks.end(); ++i)
  1037. {
  1038. if(emitted.insert(*i).second)
  1039. {
  1040. flags += "-F";
  1041. flags += this->LocalGenerator->ConvertToOutputForExisting(i->c_str());
  1042. flags += " ";
  1043. }
  1044. }
  1045. return flags;
  1046. #endif
  1047. }
  1048. //----------------------------------------------------------------------------
  1049. void cmMakefileTargetGenerator
  1050. ::AppendTargetDepends(std::vector<std::string>& depends)
  1051. {
  1052. // Static libraries never depend on anything for linking.
  1053. if(this->Target->GetType() == cmTarget::STATIC_LIBRARY)
  1054. {
  1055. return;
  1056. }
  1057. // Compute which library configuration to link.
  1058. cmTarget::LinkLibraryType linkType = cmTarget::OPTIMIZED;
  1059. if(cmSystemTools::UpperCase(
  1060. this->LocalGenerator->ConfigurationName.c_str()) == "DEBUG")
  1061. {
  1062. linkType = cmTarget::DEBUG;
  1063. }
  1064. // Keep track of dependencies already listed.
  1065. std::set<cmStdString> emitted;
  1066. // A target should not depend on itself.
  1067. emitted.insert(this->Target->GetName());
  1068. // Loop over all library dependencies.
  1069. const cmTarget::LinkLibraryVectorType& tlibs =
  1070. this->Target->GetLinkLibraries();
  1071. for(cmTarget::LinkLibraryVectorType::const_iterator lib = tlibs.begin();
  1072. lib != tlibs.end(); ++lib)
  1073. {
  1074. // skip the library if it is not general and the link type
  1075. // does not match the current target
  1076. if(lib->second != cmTarget::GENERAL &&
  1077. lib->second != linkType)
  1078. {
  1079. continue;
  1080. }
  1081. // Don't emit the same library twice for this target.
  1082. if(emitted.insert(lib->first).second)
  1083. {
  1084. // Depend on other CMake targets.
  1085. if(cmTarget* tgt =
  1086. this->GlobalGenerator->FindTarget(0, lib->first.c_str()))
  1087. {
  1088. if(const char* location =
  1089. tgt->GetLocation(this->LocalGenerator->ConfigurationName.c_str()))
  1090. {
  1091. depends.push_back(location);
  1092. }
  1093. }
  1094. // depend on full path libs as well
  1095. else if(cmSystemTools::FileIsFullPath(lib->first.c_str()))
  1096. {
  1097. depends.push_back(lib->first.c_str());
  1098. }
  1099. }
  1100. }
  1101. }
  1102. //----------------------------------------------------------------------------
  1103. void cmMakefileTargetGenerator
  1104. ::CloseFileStreams()
  1105. {
  1106. delete this->BuildFileStream;
  1107. delete this->InfoFileStream;
  1108. delete this->FlagFileStream;
  1109. }
  1110. void cmMakefileTargetGenerator::RemoveForbiddenFlags(const char* flagVar,
  1111. const char* linkLang,
  1112. std::string& linkFlags)
  1113. {
  1114. // check for language flags that are not allowed at link time, and
  1115. // remove them, -w on darwin for gcc -w -dynamiclib sends -w to libtool
  1116. // which fails, there may be more]
  1117. std::string removeFlags = "CMAKE_";
  1118. removeFlags += linkLang;
  1119. removeFlags += flagVar;
  1120. std::string removeflags =
  1121. this->Makefile->GetSafeDefinition(removeFlags.c_str());
  1122. std::vector<std::string> removeList;
  1123. cmSystemTools::ExpandListArgument(removeflags, removeList);
  1124. for(std::vector<std::string>::iterator i = removeList.begin();
  1125. i != removeList.end(); ++i)
  1126. {
  1127. cmSystemTools::ReplaceString(linkFlags, i->c_str(), "");
  1128. }
  1129. }
  1130. void cmMakefileTargetGenerator::WriteProgressVariables(unsigned long total,
  1131. unsigned long &current)
  1132. {
  1133. cmGeneratedFileStream *progressFileStream =
  1134. new cmGeneratedFileStream(this->ProgressFileNameFull.c_str());
  1135. if(!progressFileStream)
  1136. {
  1137. return;
  1138. }
  1139. unsigned long num;
  1140. unsigned long i;
  1141. for (i = 1; i <= this->NumberOfProgressActions; ++i)
  1142. {
  1143. *progressFileStream
  1144. << "CMAKE_PROGRESS_" << i << " = ";
  1145. if (total <= 100)
  1146. {
  1147. num = i + current;
  1148. *progressFileStream << num;
  1149. this->LocalGenerator->ProgressFiles[this->Target->GetName()]
  1150. .push_back(num);
  1151. }
  1152. else if (((i+current)*100)/total > ((i-1+current)*100)/total)
  1153. {
  1154. num = ((i+current)*100)/total;
  1155. *progressFileStream << num;
  1156. this->LocalGenerator->ProgressFiles[this->Target->GetName()]
  1157. .push_back(num);
  1158. }
  1159. *progressFileStream << "\n";
  1160. }
  1161. *progressFileStream << "\n";
  1162. current += this->NumberOfProgressActions;
  1163. delete progressFileStream;
  1164. }