cmMakefileTargetGenerator.cxx 42 KB

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