cmMakefileTargetGenerator.cxx 46 KB

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