cmMakefileTargetGenerator.cxx 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmMakefileTargetGenerator.h"
  11. #include "cmGeneratedFileStream.h"
  12. #include "cmGlobalGenerator.h"
  13. #include "cmGlobalUnixMakefileGenerator3.h"
  14. #include "cmLocalUnixMakefileGenerator3.h"
  15. #include "cmMakefile.h"
  16. #include "cmSourceFile.h"
  17. #include "cmTarget.h"
  18. #include "cmake.h"
  19. #include "cmComputeLinkInformation.h"
  20. #include "cmMakefileExecutableTargetGenerator.h"
  21. #include "cmMakefileLibraryTargetGenerator.h"
  22. #include "cmMakefileUtilityTargetGenerator.h"
  23. cmMakefileTargetGenerator::cmMakefileTargetGenerator(cmTarget* target)
  24. {
  25. this->BuildFileStream = 0;
  26. this->InfoFileStream = 0;
  27. this->FlagFileStream = 0;
  28. this->CustomCommandDriver = OnBuild;
  29. this->FortranModuleDirectoryComputed = false;
  30. this->Target = target;
  31. this->Makefile = this->Target->GetMakefile();
  32. this->LocalGenerator =
  33. static_cast<cmLocalUnixMakefileGenerator3*>(
  34. this->Makefile->GetLocalGenerator());
  35. this->ConfigName = this->LocalGenerator->ConfigurationName.c_str();
  36. this->GlobalGenerator =
  37. static_cast<cmGlobalUnixMakefileGenerator3*>(
  38. this->LocalGenerator->GetGlobalGenerator());
  39. cmake* cm = this->GlobalGenerator->GetCMakeInstance();
  40. this->NoRuleMessages = false;
  41. if(const char* ruleStatus = cm->GetProperty("RULE_MESSAGES"))
  42. {
  43. this->NoRuleMessages = cmSystemTools::IsOff(ruleStatus);
  44. }
  45. }
  46. cmMakefileTargetGenerator *
  47. cmMakefileTargetGenerator::New(cmTarget *tgt)
  48. {
  49. cmMakefileTargetGenerator *result = 0;
  50. switch (tgt->GetType())
  51. {
  52. case cmTarget::EXECUTABLE:
  53. result = new cmMakefileExecutableTargetGenerator(tgt);
  54. break;
  55. case cmTarget::STATIC_LIBRARY:
  56. case cmTarget::SHARED_LIBRARY:
  57. case cmTarget::MODULE_LIBRARY:
  58. result = new cmMakefileLibraryTargetGenerator(tgt);
  59. break;
  60. case cmTarget::UTILITY:
  61. result = new cmMakefileUtilityTargetGenerator(tgt);
  62. break;
  63. default:
  64. return result;
  65. // break; /* unreachable */
  66. }
  67. return result;
  68. }
  69. //----------------------------------------------------------------------------
  70. void cmMakefileTargetGenerator::CreateRuleFile()
  71. {
  72. // Create a directory for this target.
  73. this->TargetBuildDirectory =
  74. this->LocalGenerator->GetTargetDirectory(*this->Target);
  75. this->TargetBuildDirectoryFull =
  76. this->LocalGenerator->ConvertToFullPath(this->TargetBuildDirectory);
  77. cmSystemTools::MakeDirectory(this->TargetBuildDirectoryFull.c_str());
  78. // Construct the rule file name.
  79. this->BuildFileName = this->TargetBuildDirectory;
  80. this->BuildFileName += "/build.make";
  81. this->BuildFileNameFull = this->TargetBuildDirectoryFull;
  82. this->BuildFileNameFull += "/build.make";
  83. // Construct the rule file name.
  84. this->ProgressFileNameFull = this->TargetBuildDirectoryFull;
  85. this->ProgressFileNameFull += "/progress.make";
  86. // reset the progress count
  87. this->NumberOfProgressActions = 0;
  88. // Open the rule file. This should be copy-if-different because the
  89. // rules may depend on this file itself.
  90. this->BuildFileStream =
  91. new cmGeneratedFileStream(this->BuildFileNameFull.c_str());
  92. this->BuildFileStream->SetCopyIfDifferent(true);
  93. if(!this->BuildFileStream)
  94. {
  95. return;
  96. }
  97. this->LocalGenerator->WriteDisclaimer(*this->BuildFileStream);
  98. this->LocalGenerator->WriteSpecialTargetsTop(*this->BuildFileStream);
  99. }
  100. //----------------------------------------------------------------------------
  101. void cmMakefileTargetGenerator::WriteTargetBuildRules()
  102. {
  103. // write the custom commands for this target
  104. // Look for files registered for cleaning in this directory.
  105. if(const char* additional_clean_files =
  106. this->Makefile->GetProperty
  107. ("ADDITIONAL_MAKE_CLEAN_FILES"))
  108. {
  109. cmSystemTools::ExpandListArgument(additional_clean_files,
  110. this->CleanFiles);
  111. }
  112. // add custom commands to the clean rules?
  113. const char* clean_no_custom =
  114. this->Makefile->GetProperty("CLEAN_NO_CUSTOM");
  115. bool clean = cmSystemTools::IsOff(clean_no_custom);
  116. // First generate the object rule files. Save a list of all object
  117. // files for this target.
  118. const std::vector<cmSourceFile*>& sources = this->Target->GetSourceFiles();
  119. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  120. source != sources.end(); ++source)
  121. {
  122. cmTarget::SourceFileFlags tsFlags =
  123. this->Target->GetTargetSourceFileFlags(*source);
  124. if(cmCustomCommand* cc = (*source)->GetCustomCommand())
  125. {
  126. this->GenerateCustomRuleFile(*cc);
  127. if (clean)
  128. {
  129. const std::vector<std::string>& outputs = cc->GetOutputs();
  130. for(std::vector<std::string>::const_iterator o = outputs.begin();
  131. o != outputs.end(); ++o)
  132. {
  133. this->CleanFiles.push_back
  134. (this->Convert(o->c_str(),
  135. cmLocalGenerator::START_OUTPUT,
  136. cmLocalGenerator::UNCHANGED));
  137. }
  138. }
  139. }
  140. else if(tsFlags.Type != cmTarget::SourceFileTypeNormal)
  141. {
  142. this->WriteMacOSXContentRules(*(*source), tsFlags.MacFolder);
  143. }
  144. else if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  145. {
  146. if(!this->GlobalGenerator->IgnoreFile
  147. ((*source)->GetExtension().c_str()))
  148. {
  149. // Generate this object file's rule file.
  150. this->WriteObjectRuleFiles(*(*source));
  151. }
  152. else if((*source)->GetPropertyAsBool("EXTERNAL_OBJECT"))
  153. {
  154. // This is an external object file. Just add it.
  155. this->ExternalObjects.push_back((*source)->GetFullPath());
  156. }
  157. else if(cmSystemTools::UpperCase((*source)->GetExtension()) == "DEF")
  158. {
  159. this->ModuleDefinitionFile = (*source)->GetFullPath();
  160. }
  161. else
  162. {
  163. // We only get here if a source file is not an external object
  164. // and has an extension that is listed as an ignored file type
  165. // for this language. No message or diagnosis should be
  166. // given.
  167. }
  168. }
  169. }
  170. }
  171. //----------------------------------------------------------------------------
  172. void cmMakefileTargetGenerator::WriteCommonCodeRules()
  173. {
  174. // Include the dependencies for the target.
  175. std::string dependFileNameFull = this->TargetBuildDirectoryFull;
  176. dependFileNameFull += "/depend.make";
  177. *this->BuildFileStream
  178. << "# Include any dependencies generated for this target.\n"
  179. << this->LocalGenerator->IncludeDirective << " "
  180. << this->Convert(dependFileNameFull.c_str(),
  181. cmLocalGenerator::HOME_OUTPUT,
  182. cmLocalGenerator::MAKEFILE)
  183. << "\n\n";
  184. if(!this->NoRuleMessages)
  185. {
  186. // Include the progress variables for the target.
  187. *this->BuildFileStream
  188. << "# Include the progress variables for this target.\n"
  189. << this->LocalGenerator->IncludeDirective << " "
  190. << this->Convert(this->ProgressFileNameFull.c_str(),
  191. cmLocalGenerator::HOME_OUTPUT,
  192. cmLocalGenerator::MAKEFILE)
  193. << "\n\n";
  194. }
  195. // make sure the depend file exists
  196. if (!cmSystemTools::FileExists(dependFileNameFull.c_str()))
  197. {
  198. // Write an empty dependency file.
  199. cmGeneratedFileStream depFileStream(dependFileNameFull.c_str());
  200. depFileStream
  201. << "# Empty dependencies file for " << this->Target->GetName() << ".\n"
  202. << "# This may be replaced when dependencies are built." << std::endl;
  203. }
  204. // Open the flags file. This should be copy-if-different because the
  205. // rules may depend on this file itself.
  206. this->FlagFileNameFull = this->TargetBuildDirectoryFull;
  207. this->FlagFileNameFull += "/flags.make";
  208. this->FlagFileStream =
  209. new cmGeneratedFileStream(this->FlagFileNameFull.c_str());
  210. this->FlagFileStream->SetCopyIfDifferent(true);
  211. if(!this->FlagFileStream)
  212. {
  213. return;
  214. }
  215. this->LocalGenerator->WriteDisclaimer(*this->FlagFileStream);
  216. // Include the flags for the target.
  217. *this->BuildFileStream
  218. << "# Include the compile flags for this target's objects.\n"
  219. << this->LocalGenerator->IncludeDirective << " "
  220. << this->Convert(this->FlagFileNameFull.c_str(),
  221. cmLocalGenerator::HOME_OUTPUT,
  222. cmLocalGenerator::MAKEFILE)
  223. << "\n\n";
  224. }
  225. //----------------------------------------------------------------------------
  226. void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
  227. {
  228. // write language flags for target
  229. std::set<cmStdString> languages;
  230. this->Target->GetLanguages(languages);
  231. // put the compiler in the rules.make file so that if it changes
  232. // things rebuild
  233. for(std::set<cmStdString>::const_iterator l = languages.begin();
  234. l != languages.end(); ++l)
  235. {
  236. cmStdString compiler = "CMAKE_";
  237. compiler += *l;
  238. compiler += "_COMPILER";
  239. *this->FlagFileStream << "# compile " << l->c_str() << " with " <<
  240. this->Makefile->GetSafeDefinition(compiler.c_str()) << "\n";
  241. }
  242. for(std::set<cmStdString>::const_iterator l = languages.begin();
  243. l != languages.end(); ++l)
  244. {
  245. const char *lang = l->c_str();
  246. std::string flags;
  247. std::string defines;
  248. bool shared = ((this->Target->GetType() == cmTarget::SHARED_LIBRARY) ||
  249. (this->Target->GetType() == cmTarget::MODULE_LIBRARY));
  250. // Add the export symbol definition for shared library objects.
  251. if(const char* exportMacro = this->Target->GetExportMacro())
  252. {
  253. this->LocalGenerator->AppendDefines(defines, exportMacro, lang);
  254. }
  255. // Add preprocessor definitions for this target and configuration.
  256. this->LocalGenerator->AppendDefines
  257. (defines, this->Makefile->GetProperty("COMPILE_DEFINITIONS"), lang);
  258. this->LocalGenerator->AppendDefines
  259. (defines, this->Target->GetProperty("COMPILE_DEFINITIONS"), lang);
  260. std::string defPropName = "COMPILE_DEFINITIONS_";
  261. defPropName +=
  262. cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName);
  263. this->LocalGenerator->AppendDefines
  264. (defines, this->Makefile->GetProperty(defPropName.c_str()), lang);
  265. this->LocalGenerator->AppendDefines
  266. (defines, this->Target->GetProperty(defPropName.c_str()), lang);
  267. // Add language feature flags.
  268. this->AddFeatureFlags(flags, lang);
  269. #ifdef __APPLE__
  270. this->LocalGenerator->AddArchitectureFlags(flags, this->Target,
  271. lang, this->ConfigName);
  272. #endif /* __APPLE__ */
  273. // Fortran-specific flags computed for this target.
  274. if(*l == "Fortran")
  275. {
  276. this->AddFortranFlags(flags);
  277. }
  278. // Add shared-library flags if needed.
  279. this->LocalGenerator->AddSharedFlags(flags, lang, shared);
  280. // Add include directory flags.
  281. this->LocalGenerator->
  282. AppendFlags(flags, this->LocalGenerator->GetIncludeFlags(lang));
  283. // Add include directory flags.
  284. this->LocalGenerator->
  285. AppendFlags(flags,this->GetFrameworkFlags().c_str());
  286. *this->FlagFileStream << lang << "_FLAGS = " << flags << "\n\n";
  287. *this->FlagFileStream << lang << "_DEFINES = " << defines << "\n\n";
  288. }
  289. // Add target-specific flags.
  290. if(this->Target->GetProperty("COMPILE_FLAGS"))
  291. {
  292. std::string flags;
  293. this->LocalGenerator->AppendFlags
  294. (flags, this->Target->GetProperty("COMPILE_FLAGS"));
  295. *this->FlagFileStream << "# TARGET_FLAGS = " << flags << "\n\n";
  296. }
  297. }
  298. //----------------------------------------------------------------------------
  299. void cmMakefileTargetGenerator::WriteMacOSXContentRules(cmSourceFile& source,
  300. const char* pkgloc)
  301. {
  302. // Skip OS X content when not building a Framework or Bundle.
  303. if(this->MacContentDirectory.empty())
  304. {
  305. return;
  306. }
  307. // Construct the full path to the content subdirectory.
  308. std::string macdir = this->MacContentDirectory;
  309. macdir += pkgloc;
  310. cmSystemTools::MakeDirectory(macdir.c_str());
  311. // Record use of this content location. Only the first level
  312. // directory is needed.
  313. {
  314. std::string loc = pkgloc;
  315. loc = loc.substr(0, loc.find('/'));
  316. this->MacContentFolders.insert(loc);
  317. }
  318. // Get the input file location.
  319. std::string input = source.GetFullPath();
  320. // Get the output file location.
  321. std::string output = macdir;
  322. output += "/";
  323. output += cmSystemTools::GetFilenameName(input);
  324. this->CleanFiles.push_back(this->Convert(output.c_str(),
  325. cmLocalGenerator::START_OUTPUT));
  326. output = this->Convert(output.c_str(), cmLocalGenerator::HOME_OUTPUT);
  327. // Create a rule to copy the content into the bundle.
  328. std::vector<std::string> depends;
  329. std::vector<std::string> commands;
  330. depends.push_back(input);
  331. std::string copyEcho = "Copying OS X content ";
  332. copyEcho += output;
  333. this->LocalGenerator->AppendEcho(commands, copyEcho.c_str(),
  334. cmLocalUnixMakefileGenerator3::EchoBuild);
  335. std::string copyCommand = "$(CMAKE_COMMAND) -E copy ";
  336. copyCommand += this->Convert(input.c_str(),
  337. cmLocalGenerator::NONE,
  338. cmLocalGenerator::SHELL);
  339. copyCommand += " ";
  340. copyCommand += this->Convert(output.c_str(),
  341. cmLocalGenerator::NONE,
  342. cmLocalGenerator::SHELL);
  343. commands.push_back(copyCommand);
  344. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  345. output.c_str(),
  346. depends, commands, false);
  347. this->ExtraFiles.insert(output);
  348. }
  349. //----------------------------------------------------------------------------
  350. void cmMakefileTargetGenerator::WriteObjectRuleFiles(cmSourceFile& source)
  351. {
  352. // Identify the language of the source file.
  353. const char* lang = this->LocalGenerator->GetSourceFileLanguage(source);
  354. if(!lang)
  355. {
  356. // don't know anything about this file so skip it
  357. return;
  358. }
  359. // Get the full path name of the object file.
  360. bool hasSourceExtension;
  361. std::string objNoTargetDir;
  362. std::string obj =
  363. this->LocalGenerator->GetObjectFileName(*this->Target, source,
  364. &objNoTargetDir,
  365. &hasSourceExtension);
  366. // Avoid generating duplicate rules.
  367. if(this->ObjectFiles.find(obj) == this->ObjectFiles.end())
  368. {
  369. this->ObjectFiles.insert(obj);
  370. }
  371. else
  372. {
  373. cmOStringStream err;
  374. err << "Warning: Source file \""
  375. << source.GetFullPath()
  376. << "\" is listed multiple times for target \""
  377. << this->Target->GetName()
  378. << "\".";
  379. cmSystemTools::Message(err.str().c_str(), "Warning");
  380. return;
  381. }
  382. // Create the directory containing the object file. This may be a
  383. // subdirectory under the target's directory.
  384. std::string dir = cmSystemTools::GetFilenamePath(obj.c_str());
  385. cmSystemTools::MakeDirectory
  386. (this->LocalGenerator->ConvertToFullPath(dir).c_str());
  387. // Save this in the target's list of object files.
  388. this->Objects.push_back(obj);
  389. this->CleanFiles.push_back(obj);
  390. // TODO: Remove
  391. //std::string relativeObj
  392. //= this->LocalGenerator->GetHomeRelativeOutputPath();
  393. //relativeObj += obj;
  394. // we compute some depends when writing the depend.make that we will also
  395. // use in the build.make, same with depMakeFile
  396. std::vector<std::string> depends;
  397. std::string depMakeFile;
  398. // generate the build rule file
  399. this->WriteObjectBuildFile(obj, lang, source, depends);
  400. // The object file should be checked for dependency integrity.
  401. std::string objFullPath = this->Makefile->GetCurrentOutputDirectory();
  402. objFullPath += "/";
  403. objFullPath += obj;
  404. objFullPath =
  405. this->Convert(objFullPath.c_str(), cmLocalGenerator::FULL);
  406. std::string srcFullPath =
  407. this->Convert(source.GetFullPath().c_str(), cmLocalGenerator::FULL);
  408. this->LocalGenerator->
  409. AddImplicitDepends(*this->Target, lang,
  410. objFullPath.c_str(),
  411. srcFullPath.c_str());
  412. // add this to the list of objects for this local generator
  413. if(cmSystemTools::FileIsFullPath(objNoTargetDir.c_str()))
  414. {
  415. objNoTargetDir = cmSystemTools::GetFilenameName(objNoTargetDir);
  416. }
  417. cmLocalUnixMakefileGenerator3::LocalObjectInfo& info =
  418. this->LocalGenerator->LocalObjectFiles[objNoTargetDir];
  419. info.HasSourceExtension = hasSourceExtension;
  420. info.push_back(
  421. cmLocalUnixMakefileGenerator3::LocalObjectEntry(this->Target, lang)
  422. );
  423. }
  424. //----------------------------------------------------------------------------
  425. void
  426. cmMakefileTargetGenerator
  427. ::WriteObjectBuildFile(std::string &obj,
  428. const char *lang,
  429. cmSourceFile& source,
  430. std::vector<std::string>& depends)
  431. {
  432. this->LocalGenerator->AppendRuleDepend(depends,
  433. this->FlagFileNameFull.c_str());
  434. // generate the depend scanning rule
  435. this->WriteObjectDependRules(source, depends);
  436. std::string relativeObj = this->LocalGenerator->GetHomeRelativeOutputPath();
  437. relativeObj += obj;
  438. // Write the build rule.
  439. // Build the set of compiler flags.
  440. std::string flags;
  441. // Add language-specific flags.
  442. std::string langFlags = "$(";
  443. langFlags += lang;
  444. langFlags += "_FLAGS)";
  445. this->LocalGenerator->AppendFlags(flags, langFlags.c_str());
  446. // Add target-specific flags.
  447. if(this->Target->GetProperty("COMPILE_FLAGS"))
  448. {
  449. std::string langIncludeExpr = "CMAKE_";
  450. langIncludeExpr += lang;
  451. langIncludeExpr += "_FLAG_REGEX";
  452. const char* regex = this->Makefile->
  453. GetDefinition(langIncludeExpr.c_str());
  454. if(regex)
  455. {
  456. cmsys::RegularExpression r(regex);
  457. std::vector<std::string> args;
  458. cmSystemTools::ParseWindowsCommandLine(
  459. this->Target->GetProperty("COMPILE_FLAGS"),
  460. args);
  461. for(std::vector<std::string>::iterator i = args.begin();
  462. i != args.end(); ++i)
  463. {
  464. if(r.find(i->c_str()))
  465. {
  466. this->LocalGenerator->AppendFlags
  467. (flags, i->c_str());
  468. }
  469. }
  470. }
  471. else
  472. {
  473. this->LocalGenerator->AppendFlags
  474. (flags, this->Target->GetProperty("COMPILE_FLAGS"));
  475. }
  476. }
  477. // Add flags from source file properties.
  478. if (source.GetProperty("COMPILE_FLAGS"))
  479. {
  480. this->LocalGenerator->AppendFlags
  481. (flags, source.GetProperty("COMPILE_FLAGS"));
  482. *this->FlagFileStream << "# Custom flags: "
  483. << relativeObj << "_FLAGS = "
  484. << source.GetProperty("COMPILE_FLAGS")
  485. << "\n"
  486. << "\n";
  487. }
  488. // Add language-specific defines.
  489. std::string defines = "$(";
  490. defines += lang;
  491. defines += "_DEFINES)";
  492. // Add source-sepcific preprocessor definitions.
  493. if(const char* compile_defs = source.GetProperty("COMPILE_DEFINITIONS"))
  494. {
  495. this->LocalGenerator->AppendDefines(defines, compile_defs, lang);
  496. *this->FlagFileStream << "# Custom defines: "
  497. << relativeObj << "_DEFINES = "
  498. << compile_defs << "\n"
  499. << "\n";
  500. }
  501. std::string configUpper =
  502. cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName);
  503. std::string defPropName = "COMPILE_DEFINITIONS_";
  504. defPropName += configUpper;
  505. if(const char* config_compile_defs =
  506. source.GetProperty(defPropName.c_str()))
  507. {
  508. this->LocalGenerator->AppendDefines(defines, config_compile_defs, lang);
  509. *this->FlagFileStream
  510. << "# Custom defines: "
  511. << relativeObj << "_DEFINES_" << configUpper
  512. << " = " << config_compile_defs << "\n"
  513. << "\n";
  514. }
  515. // Get the output paths for source and object files.
  516. std::string sourceFile = source.GetFullPath();
  517. if(this->LocalGenerator->UseRelativePaths)
  518. {
  519. sourceFile = this->Convert(sourceFile.c_str(),
  520. cmLocalGenerator::START_OUTPUT);
  521. }
  522. sourceFile = this->Convert(sourceFile.c_str(),
  523. cmLocalGenerator::NONE,
  524. cmLocalGenerator::SHELL);
  525. // Construct the build message.
  526. std::vector<std::string> no_commands;
  527. std::vector<std::string> commands;
  528. // add in a progress call if needed
  529. this->AppendProgress(commands);
  530. if(!this->NoRuleMessages)
  531. {
  532. std::string buildEcho = "Building ";
  533. buildEcho += lang;
  534. buildEcho += " object ";
  535. buildEcho += relativeObj;
  536. this->LocalGenerator->AppendEcho
  537. (commands, buildEcho.c_str(), cmLocalUnixMakefileGenerator3::EchoBuild);
  538. }
  539. std::string targetOutPathPDB;
  540. {
  541. std::string targetFullPathPDB;
  542. if(this->Target->GetType() == cmTarget::EXECUTABLE ||
  543. this->Target->GetType() == cmTarget::STATIC_LIBRARY ||
  544. this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
  545. this->Target->GetType() == cmTarget::MODULE_LIBRARY)
  546. {
  547. targetFullPathPDB = this->Target->GetDirectory(this->ConfigName);
  548. targetFullPathPDB += "/";
  549. targetFullPathPDB += this->Target->GetPDBName(this->ConfigName);
  550. }
  551. targetOutPathPDB =
  552. this->Convert(targetFullPathPDB.c_str(),cmLocalGenerator::NONE,
  553. cmLocalGenerator::SHELL);
  554. }
  555. cmLocalGenerator::RuleVariables vars;
  556. vars.RuleLauncher = "RULE_LAUNCH_COMPILE";
  557. vars.CMTarget = this->Target;
  558. vars.Language = lang;
  559. vars.TargetPDB = targetOutPathPDB.c_str();
  560. vars.Source = sourceFile.c_str();
  561. std::string shellObj =
  562. this->Convert(obj.c_str(),
  563. cmLocalGenerator::NONE,
  564. cmLocalGenerator::SHELL).c_str();
  565. vars.Object = shellObj.c_str();
  566. std::string objectDir = cmSystemTools::GetFilenamePath(obj);
  567. objectDir = this->Convert(objectDir.c_str(),
  568. cmLocalGenerator::START_OUTPUT,
  569. cmLocalGenerator::SHELL);
  570. vars.ObjectDir = objectDir.c_str();
  571. vars.Flags = flags.c_str();
  572. vars.Defines = defines.c_str();
  573. // Construct the compile rules.
  574. {
  575. std::string compileRuleVar = "CMAKE_";
  576. compileRuleVar += lang;
  577. compileRuleVar += "_COMPILE_OBJECT";
  578. std::string compileRule =
  579. this->Makefile->GetRequiredDefinition(compileRuleVar.c_str());
  580. std::vector<std::string> compileCommands;
  581. cmSystemTools::ExpandListArgument(compileRule, compileCommands);
  582. // Expand placeholders in the commands.
  583. for(std::vector<std::string>::iterator i = compileCommands.begin();
  584. i != compileCommands.end(); ++i)
  585. {
  586. this->LocalGenerator->ExpandRuleVariables(*i, vars);
  587. }
  588. // Change the command working directory to the local build tree.
  589. this->LocalGenerator->CreateCDCommand
  590. (compileCommands,
  591. this->Makefile->GetStartOutputDirectory(),
  592. cmLocalGenerator::HOME_OUTPUT);
  593. commands.insert(commands.end(),
  594. compileCommands.begin(), compileCommands.end());
  595. }
  596. // Write the rule.
  597. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  598. relativeObj.c_str(),
  599. depends, commands, false);
  600. // Check for extra outputs created by the compilation.
  601. if(const char* extra_outputs_str =
  602. source.GetProperty("OBJECT_OUTPUTS"))
  603. {
  604. std::vector<std::string> extra_outputs;
  605. cmSystemTools::ExpandListArgument(extra_outputs_str, extra_outputs);
  606. for(std::vector<std::string>::const_iterator eoi = extra_outputs.begin();
  607. eoi != extra_outputs.end(); ++eoi)
  608. {
  609. // Register this as an extra output for the object file rule.
  610. // This will cause the object file to be rebuilt if the extra
  611. // output is missing.
  612. this->GenerateExtraOutput(eoi->c_str(), relativeObj.c_str(), false);
  613. // Register this as an extra file to clean.
  614. this->CleanFiles.push_back(eoi->c_str());
  615. }
  616. }
  617. bool lang_is_c_or_cxx = ((strcmp(lang, "C") == 0) ||
  618. (strcmp(lang, "CXX") == 0));
  619. bool do_preprocess_rules = lang_is_c_or_cxx &&
  620. this->LocalGenerator->GetCreatePreprocessedSourceRules();
  621. bool do_assembly_rules = lang_is_c_or_cxx &&
  622. this->LocalGenerator->GetCreateAssemblySourceRules();
  623. if(do_preprocess_rules || do_assembly_rules)
  624. {
  625. std::vector<std::string> force_depends;
  626. force_depends.push_back("cmake_force");
  627. std::string::size_type dot_pos = relativeObj.rfind(".");
  628. std::string relativeObjBase = relativeObj.substr(0, dot_pos);
  629. dot_pos = obj.rfind(".");
  630. std::string objBase = obj.substr(0, dot_pos);
  631. if(do_preprocess_rules)
  632. {
  633. commands.clear();
  634. std::string relativeObjI = relativeObjBase + ".i";
  635. std::string objI = objBase + ".i";
  636. std::string preprocessEcho = "Preprocessing ";
  637. preprocessEcho += lang;
  638. preprocessEcho += " source to ";
  639. preprocessEcho += objI;
  640. this->LocalGenerator->AppendEcho(
  641. commands, preprocessEcho.c_str(),
  642. cmLocalUnixMakefileGenerator3::EchoBuild
  643. );
  644. std::string preprocessRuleVar = "CMAKE_";
  645. preprocessRuleVar += lang;
  646. preprocessRuleVar += "_CREATE_PREPROCESSED_SOURCE";
  647. if(const char* preprocessRule =
  648. this->Makefile->GetDefinition(preprocessRuleVar.c_str()))
  649. {
  650. std::vector<std::string> preprocessCommands;
  651. cmSystemTools::ExpandListArgument(preprocessRule, preprocessCommands);
  652. std::string shellObjI =
  653. this->Convert(objI.c_str(),
  654. cmLocalGenerator::NONE,
  655. cmLocalGenerator::SHELL).c_str();
  656. vars.PreprocessedSource = shellObjI.c_str();
  657. // Expand placeholders in the commands.
  658. for(std::vector<std::string>::iterator i = preprocessCommands.begin();
  659. i != preprocessCommands.end(); ++i)
  660. {
  661. this->LocalGenerator->ExpandRuleVariables(*i, vars);
  662. }
  663. this->LocalGenerator->CreateCDCommand
  664. (preprocessCommands,
  665. this->Makefile->GetStartOutputDirectory(),
  666. cmLocalGenerator::HOME_OUTPUT);
  667. commands.insert(commands.end(),
  668. preprocessCommands.begin(),
  669. preprocessCommands.end());
  670. }
  671. else
  672. {
  673. std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
  674. cmd += preprocessRuleVar;
  675. commands.push_back(cmd);
  676. }
  677. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  678. relativeObjI.c_str(),
  679. force_depends, commands, false);
  680. }
  681. if(do_assembly_rules)
  682. {
  683. commands.clear();
  684. std::string relativeObjS = relativeObjBase + ".s";
  685. std::string objS = objBase + ".s";
  686. std::string assemblyEcho = "Compiling ";
  687. assemblyEcho += lang;
  688. assemblyEcho += " source to assembly ";
  689. assemblyEcho += objS;
  690. this->LocalGenerator->AppendEcho(
  691. commands, assemblyEcho.c_str(),
  692. cmLocalUnixMakefileGenerator3::EchoBuild
  693. );
  694. std::string assemblyRuleVar = "CMAKE_";
  695. assemblyRuleVar += lang;
  696. assemblyRuleVar += "_CREATE_ASSEMBLY_SOURCE";
  697. if(const char* assemblyRule =
  698. this->Makefile->GetDefinition(assemblyRuleVar.c_str()))
  699. {
  700. std::vector<std::string> assemblyCommands;
  701. cmSystemTools::ExpandListArgument(assemblyRule, assemblyCommands);
  702. std::string shellObjS =
  703. this->Convert(objS.c_str(),
  704. cmLocalGenerator::NONE,
  705. cmLocalGenerator::SHELL).c_str();
  706. vars.AssemblySource = shellObjS.c_str();
  707. // Expand placeholders in the commands.
  708. for(std::vector<std::string>::iterator i = assemblyCommands.begin();
  709. i != assemblyCommands.end(); ++i)
  710. {
  711. this->LocalGenerator->ExpandRuleVariables(*i, vars);
  712. }
  713. this->LocalGenerator->CreateCDCommand
  714. (assemblyCommands,
  715. this->Makefile->GetStartOutputDirectory(),
  716. cmLocalGenerator::HOME_OUTPUT);
  717. commands.insert(commands.end(),
  718. assemblyCommands.begin(),
  719. assemblyCommands.end());
  720. }
  721. else
  722. {
  723. std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
  724. cmd += assemblyRuleVar;
  725. commands.push_back(cmd);
  726. }
  727. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  728. relativeObjS.c_str(),
  729. force_depends, commands, false);
  730. }
  731. }
  732. // If the language needs provides-requires mode, create the
  733. // corresponding targets.
  734. std::string objectRequires = relativeObj;
  735. objectRequires += ".requires";
  736. std::vector<std::string> p_depends;
  737. // always provide an empty requires target
  738. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  739. objectRequires.c_str(), p_depends,
  740. no_commands, true);
  741. // write a build rule to recursively build what this obj provides
  742. std::string objectProvides = relativeObj;
  743. objectProvides += ".provides";
  744. std::string temp = relativeObj;
  745. temp += ".provides.build";
  746. std::vector<std::string> r_commands;
  747. std::string tgtMakefileName =
  748. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  749. tgtMakefileName += "/build.make";
  750. r_commands.push_back
  751. (this->LocalGenerator->GetRecursiveMakeCall(tgtMakefileName.c_str(),
  752. temp.c_str()));
  753. p_depends.clear();
  754. p_depends.push_back(objectRequires);
  755. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  756. objectProvides.c_str(), p_depends,
  757. r_commands, true);
  758. // write the provides.build rule dependency on the obj file
  759. p_depends.clear();
  760. p_depends.push_back(relativeObj);
  761. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  762. temp.c_str(), p_depends, no_commands,
  763. true);
  764. }
  765. //----------------------------------------------------------------------------
  766. void cmMakefileTargetGenerator::WriteTargetRequiresRules()
  767. {
  768. std::vector<std::string> depends;
  769. std::vector<std::string> no_commands;
  770. // Construct the name of the dependency generation target.
  771. std::string depTarget =
  772. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  773. depTarget += "/requires";
  774. // This target drives dependency generation for all object files.
  775. std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
  776. std::string objTarget;
  777. for(std::vector<std::string>::const_iterator obj = this->Objects.begin();
  778. obj != this->Objects.end(); ++obj)
  779. {
  780. objTarget = relPath;
  781. objTarget += *obj;
  782. objTarget += ".requires";
  783. depends.push_back(objTarget);
  784. }
  785. // Write the rule.
  786. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  787. depTarget.c_str(),
  788. depends, no_commands, true);
  789. }
  790. //----------------------------------------------------------------------------
  791. void cmMakefileTargetGenerator::WriteTargetCleanRules()
  792. {
  793. std::vector<std::string> depends;
  794. std::vector<std::string> commands;
  795. // Construct the clean target name.
  796. std::string cleanTarget =
  797. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  798. cleanTarget += "/clean";
  799. // Construct the clean command.
  800. this->LocalGenerator->AppendCleanCommand(commands, this->CleanFiles,
  801. *this->Target);
  802. this->LocalGenerator->CreateCDCommand
  803. (commands,
  804. this->Makefile->GetStartOutputDirectory(),
  805. cmLocalGenerator::HOME_OUTPUT);
  806. // Write the rule.
  807. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  808. cleanTarget.c_str(),
  809. depends, commands, true);
  810. }
  811. //----------------------------------------------------------------------------
  812. void cmMakefileTargetGenerator::WriteTargetDependRules()
  813. {
  814. // must write the targets depend info file
  815. std::string dir = this->LocalGenerator->GetTargetDirectory(*this->Target);
  816. this->InfoFileNameFull = dir;
  817. this->InfoFileNameFull += "/DependInfo.cmake";
  818. this->InfoFileNameFull =
  819. this->LocalGenerator->ConvertToFullPath(this->InfoFileNameFull);
  820. this->InfoFileStream =
  821. new cmGeneratedFileStream(this->InfoFileNameFull.c_str());
  822. this->InfoFileStream->SetCopyIfDifferent(true);
  823. if(!*this->InfoFileStream)
  824. {
  825. return;
  826. }
  827. this->LocalGenerator->
  828. WriteDependLanguageInfo(*this->InfoFileStream,*this->Target);
  829. // Store multiple output pairs in the depend info file.
  830. if(!this->MultipleOutputPairs.empty())
  831. {
  832. *this->InfoFileStream
  833. << "\n"
  834. << "# Pairs of files generated by the same build rule.\n"
  835. << "SET(CMAKE_MULTIPLE_OUTPUT_PAIRS\n";
  836. for(MultipleOutputPairsType::const_iterator pi =
  837. this->MultipleOutputPairs.begin();
  838. pi != this->MultipleOutputPairs.end(); ++pi)
  839. {
  840. *this->InfoFileStream
  841. << " " << this->LocalGenerator->EscapeForCMake(pi->first.c_str())
  842. << " " << this->LocalGenerator->EscapeForCMake(pi->second.c_str())
  843. << "\n";
  844. }
  845. *this->InfoFileStream << " )\n\n";
  846. }
  847. // Store list of targets linked directly or transitively.
  848. {
  849. *this->InfoFileStream
  850. << "\n"
  851. << "# Targets to which this target links.\n"
  852. << "SET(CMAKE_TARGET_LINKED_INFO_FILES\n";
  853. std::set<cmTarget const*> emitted;
  854. const char* cfg = this->LocalGenerator->ConfigurationName.c_str();
  855. if(cmComputeLinkInformation* cli = this->Target->GetLinkInformation(cfg))
  856. {
  857. cmComputeLinkInformation::ItemVector const& items = cli->GetItems();
  858. for(cmComputeLinkInformation::ItemVector::const_iterator
  859. i = items.begin(); i != items.end(); ++i)
  860. {
  861. cmTarget const* linkee = i->Target;
  862. if(linkee && !linkee->IsImported() && emitted.insert(linkee).second)
  863. {
  864. cmMakefile* mf = linkee->GetMakefile();
  865. cmLocalGenerator* lg = mf->GetLocalGenerator();
  866. std::string di = mf->GetStartOutputDirectory();
  867. di += "/";
  868. di += lg->GetTargetDirectory(*linkee);
  869. di += "/DependInfo.cmake";
  870. *this->InfoFileStream << " \"" << di << "\"\n";
  871. }
  872. }
  873. }
  874. *this->InfoFileStream
  875. << " )\n";
  876. }
  877. // Check for a target-specific module output directory.
  878. if(const char* mdir = this->GetFortranModuleDirectory())
  879. {
  880. *this->InfoFileStream
  881. << "\n"
  882. << "# Fortran module output directory.\n"
  883. << "SET(CMAKE_Fortran_TARGET_MODULE_DIR \"" << mdir << "\")\n";
  884. }
  885. // and now write the rule to use it
  886. std::vector<std::string> depends;
  887. std::vector<std::string> commands;
  888. // Construct the name of the dependency generation target.
  889. std::string depTarget =
  890. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  891. depTarget += "/depend";
  892. // Add a command to call CMake to scan dependencies. CMake will
  893. // touch the corresponding depends file after scanning dependencies.
  894. cmOStringStream depCmd;
  895. // TODO: Account for source file properties and directory-level
  896. // definitions when scanning for dependencies.
  897. #if !defined(_WIN32) || defined(__CYGWIN__)
  898. // This platform supports symlinks, so cmSystemTools will translate
  899. // paths. Make sure PWD is set to the original name of the home
  900. // output directory to help cmSystemTools to create the same
  901. // translation table for the dependency scanning process.
  902. depCmd << "cd "
  903. << (this->LocalGenerator->Convert(
  904. this->Makefile->GetHomeOutputDirectory(),
  905. cmLocalGenerator::FULL, cmLocalGenerator::SHELL))
  906. << " && ";
  907. #endif
  908. // Generate a call this signature:
  909. //
  910. // cmake -E cmake_depends <generator>
  911. // <home-src-dir> <start-src-dir>
  912. // <home-out-dir> <start-out-dir>
  913. // <dep-info> --color=$(COLOR)
  914. //
  915. // This gives the dependency scanner enough information to recreate
  916. // the state of our local generator sufficiently for its needs.
  917. depCmd << "$(CMAKE_COMMAND) -E cmake_depends \""
  918. << this->GlobalGenerator->GetName() << "\" "
  919. << this->Convert(this->Makefile->GetHomeDirectory(),
  920. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  921. << " "
  922. << this->Convert(this->Makefile->GetStartDirectory(),
  923. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  924. << " "
  925. << this->Convert(this->Makefile->GetHomeOutputDirectory(),
  926. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  927. << " "
  928. << this->Convert(this->Makefile->GetStartOutputDirectory(),
  929. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  930. << " "
  931. << this->Convert(this->InfoFileNameFull.c_str(),
  932. cmLocalGenerator::FULL, cmLocalGenerator::SHELL);
  933. if(this->LocalGenerator->GetColorMakefile())
  934. {
  935. depCmd << " --color=$(COLOR)";
  936. }
  937. commands.push_back(depCmd.str());
  938. // Make sure all custom command outputs in this target are built.
  939. if(this->CustomCommandDriver == OnDepends)
  940. {
  941. this->DriveCustomCommands(depends);
  942. }
  943. // Write the rule.
  944. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  945. depTarget.c_str(),
  946. depends, commands, true);
  947. }
  948. //----------------------------------------------------------------------------
  949. void
  950. cmMakefileTargetGenerator
  951. ::DriveCustomCommands(std::vector<std::string>& depends)
  952. {
  953. // Depend on all custom command outputs.
  954. const std::vector<cmSourceFile*>& sources =
  955. this->Target->GetSourceFiles();
  956. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  957. source != sources.end(); ++source)
  958. {
  959. if(cmCustomCommand* cc = (*source)->GetCustomCommand())
  960. {
  961. const std::vector<std::string>& outputs = cc->GetOutputs();
  962. for(std::vector<std::string>::const_iterator o = outputs.begin();
  963. o != outputs.end(); ++o)
  964. {
  965. depends.push_back(*o);
  966. }
  967. }
  968. }
  969. }
  970. //----------------------------------------------------------------------------
  971. void cmMakefileTargetGenerator
  972. ::WriteObjectDependRules(cmSourceFile& source,
  973. std::vector<std::string>& depends)
  974. {
  975. // Create the list of dependencies known at cmake time. These are
  976. // shared between the object file and dependency scanning rule.
  977. depends.push_back(source.GetFullPath());
  978. if(const char* objectDeps = source.GetProperty("OBJECT_DEPENDS"))
  979. {
  980. std::vector<std::string> deps;
  981. cmSystemTools::ExpandListArgument(objectDeps, deps);
  982. for(std::vector<std::string>::iterator i = deps.begin();
  983. i != deps.end(); ++i)
  984. {
  985. depends.push_back(i->c_str());
  986. }
  987. }
  988. }
  989. //----------------------------------------------------------------------------
  990. void cmMakefileTargetGenerator
  991. ::GenerateCustomRuleFile(const cmCustomCommand& cc)
  992. {
  993. // Collect the commands.
  994. std::vector<std::string> commands;
  995. std::string comment = this->LocalGenerator->ConstructComment(cc);
  996. if(!comment.empty())
  997. {
  998. // add in a progress call if needed
  999. this->AppendProgress(commands);
  1000. if(!this->NoRuleMessages)
  1001. {
  1002. this->LocalGenerator
  1003. ->AppendEcho(commands, comment.c_str(),
  1004. cmLocalUnixMakefileGenerator3::EchoGenerate);
  1005. }
  1006. }
  1007. // Now append the actual user-specified commands.
  1008. cmOStringStream content;
  1009. this->LocalGenerator->AppendCustomCommand(commands, cc, this->Target, false,
  1010. cmLocalGenerator::HOME_OUTPUT,
  1011. &content);
  1012. // Collect the dependencies.
  1013. std::vector<std::string> depends;
  1014. this->LocalGenerator->AppendCustomDepend(depends, cc);
  1015. // Check whether we need to bother checking for a symbolic output.
  1016. bool need_symbolic = this->GlobalGenerator->GetNeedSymbolicMark();
  1017. // Write the rule.
  1018. const std::vector<std::string>& outputs = cc.GetOutputs();
  1019. std::vector<std::string>::const_iterator o = outputs.begin();
  1020. {
  1021. bool symbolic = false;
  1022. if(need_symbolic)
  1023. {
  1024. if(cmSourceFile* sf = this->Makefile->GetSource(o->c_str()))
  1025. {
  1026. symbolic = sf->GetPropertyAsBool("SYMBOLIC");
  1027. }
  1028. }
  1029. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  1030. o->c_str(), depends, commands,
  1031. symbolic);
  1032. // If the rule has changed make sure the output is rebuilt.
  1033. if(!symbolic)
  1034. {
  1035. this->GlobalGenerator->AddRuleHash(cc.GetOutputs(), content.str());
  1036. }
  1037. }
  1038. // Write rules to drive building any outputs beyond the first.
  1039. const char* in = o->c_str();
  1040. for(++o; o != outputs.end(); ++o)
  1041. {
  1042. bool symbolic = false;
  1043. if(need_symbolic)
  1044. {
  1045. if(cmSourceFile* sf = this->Makefile->GetSource(o->c_str()))
  1046. {
  1047. symbolic = sf->GetPropertyAsBool("SYMBOLIC");
  1048. }
  1049. }
  1050. this->GenerateExtraOutput(o->c_str(), in, symbolic);
  1051. }
  1052. // Setup implicit dependency scanning.
  1053. for(cmCustomCommand::ImplicitDependsList::const_iterator
  1054. idi = cc.GetImplicitDepends().begin();
  1055. idi != cc.GetImplicitDepends().end(); ++idi)
  1056. {
  1057. std::string objFullPath =
  1058. this->Convert(outputs[0].c_str(), cmLocalGenerator::FULL);
  1059. std::string srcFullPath =
  1060. this->Convert(idi->second.c_str(), cmLocalGenerator::FULL);
  1061. this->LocalGenerator->
  1062. AddImplicitDepends(*this->Target, idi->first.c_str(),
  1063. objFullPath.c_str(),
  1064. srcFullPath.c_str());
  1065. }
  1066. }
  1067. //----------------------------------------------------------------------------
  1068. void
  1069. cmMakefileTargetGenerator
  1070. ::GenerateExtraOutput(const char* out, const char* in, bool symbolic)
  1071. {
  1072. // Add a rule to build the primary output if the extra output needs
  1073. // to be created.
  1074. std::vector<std::string> commands;
  1075. std::vector<std::string> depends;
  1076. std::string emptyCommand = this->GlobalGenerator->GetEmptyRuleHackCommand();
  1077. if(!emptyCommand.empty())
  1078. {
  1079. commands.push_back(emptyCommand);
  1080. }
  1081. depends.push_back(in);
  1082. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  1083. out, depends, commands,
  1084. symbolic);
  1085. // Register the extra output as paired with the first output so that
  1086. // the check-build-system step will remove the primary output if any
  1087. // extra outputs are missing. This forces the rule to regenerate
  1088. // all outputs.
  1089. this->AddMultipleOutputPair(out, in);
  1090. }
  1091. //----------------------------------------------------------------------------
  1092. void
  1093. cmMakefileTargetGenerator::AppendProgress(std::vector<std::string>& commands)
  1094. {
  1095. this->NumberOfProgressActions++;
  1096. if(this->NoRuleMessages)
  1097. {
  1098. return;
  1099. }
  1100. std::string progressDir = this->Makefile->GetHomeOutputDirectory();
  1101. progressDir += cmake::GetCMakeFilesDirectory();
  1102. cmOStringStream progCmd;
  1103. progCmd << "$(CMAKE_COMMAND) -E cmake_progress_report ";
  1104. progCmd << this->LocalGenerator->Convert(progressDir.c_str(),
  1105. cmLocalGenerator::FULL,
  1106. cmLocalGenerator::SHELL);
  1107. progCmd << " $(CMAKE_PROGRESS_" << this->NumberOfProgressActions << ")";
  1108. commands.push_back(progCmd.str());
  1109. }
  1110. //----------------------------------------------------------------------------
  1111. void
  1112. cmMakefileTargetGenerator
  1113. ::WriteObjectsVariable(std::string& variableName,
  1114. std::string& variableNameExternal)
  1115. {
  1116. // Write a make variable assignment that lists all objects for the
  1117. // target.
  1118. variableName =
  1119. this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
  1120. "_OBJECTS");
  1121. *this->BuildFileStream
  1122. << "# Object files for target " << this->Target->GetName() << "\n"
  1123. << variableName.c_str() << " =";
  1124. std::string object;
  1125. const char* objName =
  1126. this->Makefile->GetDefinition("CMAKE_NO_QUOTED_OBJECTS");
  1127. const char* lineContinue =
  1128. this->Makefile->GetDefinition("CMAKE_MAKE_LINE_CONTINUE");
  1129. if(!lineContinue)
  1130. {
  1131. lineContinue = "\\";
  1132. }
  1133. for(std::vector<std::string>::const_iterator i = this->Objects.begin();
  1134. i != this->Objects.end(); ++i)
  1135. {
  1136. *this->BuildFileStream << " " << lineContinue << "\n";
  1137. if(objName)
  1138. {
  1139. *this->BuildFileStream <<
  1140. this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
  1141. cmLocalGenerator::MAKEFILE);
  1142. }
  1143. else
  1144. {
  1145. *this->BuildFileStream <<
  1146. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
  1147. }
  1148. }
  1149. *this->BuildFileStream << "\n";
  1150. // Write a make variable assignment that lists all external objects
  1151. // for the target.
  1152. variableNameExternal =
  1153. this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
  1154. "_EXTERNAL_OBJECTS");
  1155. *this->BuildFileStream
  1156. << "\n"
  1157. << "# External object files for target "
  1158. << this->Target->GetName() << "\n"
  1159. << variableNameExternal.c_str() << " =";
  1160. for(std::vector<std::string>::const_iterator i =
  1161. this->ExternalObjects.begin();
  1162. i != this->ExternalObjects.end(); ++i)
  1163. {
  1164. object = this->Convert(i->c_str(),cmLocalGenerator::START_OUTPUT);
  1165. *this->BuildFileStream
  1166. << " " << lineContinue << "\n"
  1167. << this->Makefile->GetSafeDefinition("CMAKE_OBJECT_NAME");
  1168. if(objName)
  1169. {
  1170. *this->BuildFileStream <<
  1171. this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
  1172. cmLocalGenerator::MAKEFILE);
  1173. }
  1174. else
  1175. {
  1176. *this->BuildFileStream <<
  1177. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
  1178. }
  1179. }
  1180. *this->BuildFileStream << "\n" << "\n";
  1181. }
  1182. //----------------------------------------------------------------------------
  1183. void
  1184. cmMakefileTargetGenerator
  1185. ::WriteObjectsString(std::string& buildObjs)
  1186. {
  1187. std::vector<std::string> objStrings;
  1188. this->WriteObjectsStrings(objStrings);
  1189. buildObjs = objStrings[0];
  1190. }
  1191. //----------------------------------------------------------------------------
  1192. class cmMakefileTargetGeneratorObjectStrings
  1193. {
  1194. public:
  1195. cmMakefileTargetGeneratorObjectStrings(std::vector<std::string>& strings,
  1196. cmMakefile* mf,
  1197. cmLocalUnixMakefileGenerator3* lg,
  1198. std::string::size_type limit):
  1199. Strings(strings), Makefile(mf), LocalGenerator(lg), LengthLimit(limit)
  1200. {
  1201. this->Space = "";
  1202. }
  1203. void Feed(std::string const& obj)
  1204. {
  1205. // Construct the name of the next object.
  1206. this->NextObject =
  1207. this->LocalGenerator->Convert(obj.c_str(),
  1208. cmLocalGenerator::START_OUTPUT,
  1209. cmLocalGenerator::RESPONSE);
  1210. // Roll over to next string if the limit will be exceeded.
  1211. if(this->LengthLimit != std::string::npos &&
  1212. (this->CurrentString.length() + 1 + this->NextObject.length()
  1213. > this->LengthLimit))
  1214. {
  1215. this->Strings.push_back(this->CurrentString);
  1216. this->CurrentString = "";
  1217. this->Space = "";
  1218. }
  1219. // Separate from previous object.
  1220. this->CurrentString += this->Space;
  1221. this->Space = " ";
  1222. // Append this object.
  1223. this->CurrentString += this->NextObject;
  1224. }
  1225. void Done()
  1226. {
  1227. this->Strings.push_back(this->CurrentString);
  1228. }
  1229. private:
  1230. std::vector<std::string>& Strings;
  1231. cmMakefile* Makefile;
  1232. cmLocalUnixMakefileGenerator3* LocalGenerator;
  1233. std::string::size_type LengthLimit;
  1234. std::string CurrentString;
  1235. std::string NextObject;
  1236. const char* Space;
  1237. };
  1238. //----------------------------------------------------------------------------
  1239. void
  1240. cmMakefileTargetGenerator
  1241. ::WriteObjectsStrings(std::vector<std::string>& objStrings,
  1242. std::string::size_type limit)
  1243. {
  1244. cmMakefileTargetGeneratorObjectStrings
  1245. helper(objStrings, this->Makefile, this->LocalGenerator, limit);
  1246. for(std::vector<std::string>::const_iterator i = this->Objects.begin();
  1247. i != this->Objects.end(); ++i)
  1248. {
  1249. helper.Feed(*i);
  1250. }
  1251. for(std::vector<std::string>::const_iterator i =
  1252. this->ExternalObjects.begin();
  1253. i != this->ExternalObjects.end(); ++i)
  1254. {
  1255. helper.Feed(*i);
  1256. }
  1257. helper.Done();
  1258. }
  1259. //----------------------------------------------------------------------------
  1260. void cmMakefileTargetGenerator::WriteTargetDriverRule(const char* main_output,
  1261. bool relink)
  1262. {
  1263. // Compute the name of the driver target.
  1264. std::string dir =
  1265. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  1266. std::string buildTargetRuleName = dir;
  1267. buildTargetRuleName += relink?"/preinstall":"/build";
  1268. buildTargetRuleName = this->Convert(buildTargetRuleName.c_str(),
  1269. cmLocalGenerator::HOME_OUTPUT,
  1270. cmLocalGenerator::UNCHANGED);
  1271. // Build the list of target outputs to drive.
  1272. std::vector<std::string> depends;
  1273. if(main_output)
  1274. {
  1275. depends.push_back(main_output);
  1276. }
  1277. const char* comment = 0;
  1278. if(relink)
  1279. {
  1280. // Setup the comment for the preinstall driver.
  1281. comment = "Rule to relink during preinstall.";
  1282. }
  1283. else
  1284. {
  1285. // Setup the comment for the main build driver.
  1286. comment = "Rule to build all files generated by this target.";
  1287. // Make sure all custom command outputs in this target are built.
  1288. if(this->CustomCommandDriver == OnBuild)
  1289. {
  1290. this->DriveCustomCommands(depends);
  1291. }
  1292. // Make sure the extra files are built.
  1293. for(std::set<cmStdString>::const_iterator i = this->ExtraFiles.begin();
  1294. i != this->ExtraFiles.end(); ++i)
  1295. {
  1296. depends.push_back(*i);
  1297. }
  1298. }
  1299. // Write the driver rule.
  1300. std::vector<std::string> no_commands;
  1301. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, comment,
  1302. buildTargetRuleName.c_str(),
  1303. depends, no_commands, true);
  1304. }
  1305. //----------------------------------------------------------------------------
  1306. std::string cmMakefileTargetGenerator::GetFrameworkFlags()
  1307. {
  1308. #ifndef __APPLE__
  1309. return std::string();
  1310. #else
  1311. std::set<cmStdString> emitted;
  1312. emitted.insert("/System/Library/Frameworks");
  1313. std::vector<std::string> includes;
  1314. this->LocalGenerator->GetIncludeDirectories(includes);
  1315. std::vector<std::string>::iterator i;
  1316. // check all include directories for frameworks as this
  1317. // will already have added a -F for the framework
  1318. for(i = includes.begin(); i != includes.end(); ++i)
  1319. {
  1320. if(this->Target->NameResolvesToFramework(i->c_str()))
  1321. {
  1322. std::string frameworkDir = *i;
  1323. frameworkDir += "/../";
  1324. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1325. emitted.insert(frameworkDir);
  1326. }
  1327. }
  1328. std::string flags;
  1329. std::vector<std::string>& frameworks = this->Target->GetFrameworks();
  1330. for(i = frameworks.begin();
  1331. i != frameworks.end(); ++i)
  1332. {
  1333. if(emitted.insert(*i).second)
  1334. {
  1335. flags += "-F";
  1336. flags += this->Convert(i->c_str(),
  1337. cmLocalGenerator::START_OUTPUT,
  1338. cmLocalGenerator::SHELL, true);
  1339. flags += " ";
  1340. }
  1341. }
  1342. return flags;
  1343. #endif
  1344. }
  1345. //----------------------------------------------------------------------------
  1346. void cmMakefileTargetGenerator
  1347. ::AppendTargetDepends(std::vector<std::string>& depends)
  1348. {
  1349. // Static libraries never depend on anything for linking.
  1350. if(this->Target->GetType() == cmTarget::STATIC_LIBRARY)
  1351. {
  1352. return;
  1353. }
  1354. // Loop over all library dependencies.
  1355. const char* cfg = this->LocalGenerator->ConfigurationName.c_str();
  1356. if(cmComputeLinkInformation* cli = this->Target->GetLinkInformation(cfg))
  1357. {
  1358. std::vector<std::string> const& libDeps = cli->GetDepends();
  1359. for(std::vector<std::string>::const_iterator j = libDeps.begin();
  1360. j != libDeps.end(); ++j)
  1361. {
  1362. depends.push_back(*j);
  1363. }
  1364. }
  1365. }
  1366. //----------------------------------------------------------------------------
  1367. void cmMakefileTargetGenerator
  1368. ::CloseFileStreams()
  1369. {
  1370. delete this->BuildFileStream;
  1371. delete this->InfoFileStream;
  1372. delete this->FlagFileStream;
  1373. }
  1374. void cmMakefileTargetGenerator::RemoveForbiddenFlags(const char* flagVar,
  1375. const char* linkLang,
  1376. std::string& linkFlags)
  1377. {
  1378. // check for language flags that are not allowed at link time, and
  1379. // remove them, -w on darwin for gcc -w -dynamiclib sends -w to libtool
  1380. // which fails, there may be more]
  1381. std::string removeFlags = "CMAKE_";
  1382. removeFlags += linkLang;
  1383. removeFlags += flagVar;
  1384. std::string removeflags =
  1385. this->Makefile->GetSafeDefinition(removeFlags.c_str());
  1386. std::vector<std::string> removeList;
  1387. cmSystemTools::ExpandListArgument(removeflags, removeList);
  1388. for(std::vector<std::string>::iterator i = removeList.begin();
  1389. i != removeList.end(); ++i)
  1390. {
  1391. cmSystemTools::ReplaceString(linkFlags, i->c_str(), "");
  1392. }
  1393. }
  1394. //----------------------------------------------------------------------------
  1395. void
  1396. cmMakefileTargetGenerator
  1397. ::AddMultipleOutputPair(const char* depender, const char* dependee)
  1398. {
  1399. MultipleOutputPairsType::value_type p(depender, dependee);
  1400. this->MultipleOutputPairs.insert(p);
  1401. }
  1402. //----------------------------------------------------------------------------
  1403. void
  1404. cmMakefileTargetGenerator
  1405. ::CreateLinkScript(const char* name,
  1406. std::vector<std::string> const& link_commands,
  1407. std::vector<std::string>& makefile_commands,
  1408. std::vector<std::string>& makefile_depends)
  1409. {
  1410. // Create the link script file.
  1411. std::string linkScriptName = this->TargetBuildDirectoryFull;
  1412. linkScriptName += "/";
  1413. linkScriptName += name;
  1414. cmGeneratedFileStream linkScriptStream(linkScriptName.c_str());
  1415. linkScriptStream.SetCopyIfDifferent(true);
  1416. for(std::vector<std::string>::const_iterator cmd = link_commands.begin();
  1417. cmd != link_commands.end(); ++cmd)
  1418. {
  1419. // Do not write out empty commands or commands beginning in the
  1420. // shell no-op ":".
  1421. if(!cmd->empty() && (*cmd)[0] != ':')
  1422. {
  1423. linkScriptStream << *cmd << "\n";
  1424. }
  1425. }
  1426. // Create the makefile command to invoke the link script.
  1427. std::string link_command = "$(CMAKE_COMMAND) -E cmake_link_script ";
  1428. link_command += this->Convert(linkScriptName.c_str(),
  1429. cmLocalGenerator::START_OUTPUT,
  1430. cmLocalGenerator::SHELL);
  1431. link_command += " --verbose=$(VERBOSE)";
  1432. makefile_commands.push_back(link_command);
  1433. makefile_depends.push_back(linkScriptName);
  1434. }
  1435. //----------------------------------------------------------------------------
  1436. std::string
  1437. cmMakefileTargetGenerator
  1438. ::CreateResponseFile(const char* name, std::string const& options,
  1439. std::vector<std::string>& makefile_depends)
  1440. {
  1441. // Create the response file.
  1442. std::string responseFileNameFull = this->TargetBuildDirectoryFull;
  1443. responseFileNameFull += "/";
  1444. responseFileNameFull += name;
  1445. cmGeneratedFileStream responseStream(responseFileNameFull.c_str());
  1446. responseStream.SetCopyIfDifferent(true);
  1447. responseStream << options << "\n";
  1448. // Add a dependency so the target will rebuild when the set of
  1449. // objects changes.
  1450. makefile_depends.push_back(responseFileNameFull);
  1451. // Construct the name to be used on the command line.
  1452. std::string responseFileName = this->TargetBuildDirectory;
  1453. responseFileName += "/";
  1454. responseFileName += name;
  1455. return responseFileName;
  1456. }
  1457. //----------------------------------------------------------------------------
  1458. void
  1459. cmMakefileTargetGenerator
  1460. ::CreateObjectLists(bool useLinkScript, bool useArchiveRules,
  1461. bool useResponseFile, std::string& buildObjs,
  1462. std::vector<std::string>& makefile_depends)
  1463. {
  1464. std::string variableName;
  1465. std::string variableNameExternal;
  1466. this->WriteObjectsVariable(variableName, variableNameExternal);
  1467. if(useResponseFile)
  1468. {
  1469. // MSVC response files cannot exceed 128K.
  1470. std::string::size_type const responseFileLimit = 131000;
  1471. // Construct the individual object list strings.
  1472. std::vector<std::string> object_strings;
  1473. this->WriteObjectsStrings(object_strings, responseFileLimit);
  1474. // Lookup the response file reference flag.
  1475. std::string responseFlagVar = "CMAKE_";
  1476. responseFlagVar += this->Target->GetLinkerLanguage(this->ConfigName);
  1477. responseFlagVar += "_RESPONSE_FILE_LINK_FLAG";
  1478. const char* responseFlag =
  1479. this->Makefile->GetDefinition(responseFlagVar.c_str());
  1480. if(!responseFlag)
  1481. {
  1482. responseFlag = "@";
  1483. }
  1484. // Write a response file for each string.
  1485. const char* sep = "";
  1486. for(unsigned int i = 0; i < object_strings.size(); ++i)
  1487. {
  1488. // Number the response files.
  1489. char rsp[32];
  1490. sprintf(rsp, "objects%u.rsp", i+1);
  1491. // Create this response file.
  1492. std::string objects_rsp =
  1493. this->CreateResponseFile(rsp, object_strings[i], makefile_depends);
  1494. // Separate from previous response file references.
  1495. buildObjs += sep;
  1496. sep = " ";
  1497. // Reference the response file.
  1498. buildObjs += responseFlag;
  1499. buildObjs += this->Convert(objects_rsp.c_str(),
  1500. cmLocalGenerator::NONE,
  1501. cmLocalGenerator::SHELL);
  1502. }
  1503. }
  1504. else if(useLinkScript)
  1505. {
  1506. if(!useArchiveRules)
  1507. {
  1508. this->WriteObjectsString(buildObjs);
  1509. }
  1510. }
  1511. else
  1512. {
  1513. buildObjs = "$(";
  1514. buildObjs += variableName;
  1515. buildObjs += ") $(";
  1516. buildObjs += variableNameExternal;
  1517. buildObjs += ")";
  1518. }
  1519. }
  1520. //----------------------------------------------------------------------------
  1521. const char* cmMakefileTargetGenerator::GetFortranModuleDirectory()
  1522. {
  1523. // Compute the module directory.
  1524. if(!this->FortranModuleDirectoryComputed)
  1525. {
  1526. const char* target_mod_dir =
  1527. this->Target->GetProperty("Fortran_MODULE_DIRECTORY");
  1528. const char* moddir_flag =
  1529. this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG");
  1530. if(target_mod_dir && moddir_flag)
  1531. {
  1532. // Compute the full path to the module directory.
  1533. if(cmSystemTools::FileIsFullPath(target_mod_dir))
  1534. {
  1535. // Already a full path.
  1536. this->FortranModuleDirectory = target_mod_dir;
  1537. }
  1538. else
  1539. {
  1540. // Interpret relative to the current output directory.
  1541. this->FortranModuleDirectory =
  1542. this->Makefile->GetCurrentOutputDirectory();
  1543. this->FortranModuleDirectory += "/";
  1544. this->FortranModuleDirectory += target_mod_dir;
  1545. }
  1546. // Make sure the module output directory exists.
  1547. cmSystemTools::MakeDirectory(this->FortranModuleDirectory.c_str());
  1548. }
  1549. this->FortranModuleDirectoryComputed = true;
  1550. }
  1551. // Return the computed directory.
  1552. if(this->FortranModuleDirectory.empty())
  1553. {
  1554. return 0;
  1555. }
  1556. else
  1557. {
  1558. return this->FortranModuleDirectory.c_str();
  1559. }
  1560. }
  1561. //----------------------------------------------------------------------------
  1562. void cmMakefileTargetGenerator::AddFortranFlags(std::string& flags)
  1563. {
  1564. // Add a module output directory flag if necessary.
  1565. if(const char* mod_dir = this->GetFortranModuleDirectory())
  1566. {
  1567. const char* moddir_flag =
  1568. this->Makefile->GetRequiredDefinition("CMAKE_Fortran_MODDIR_FLAG");
  1569. std::string modflag = moddir_flag;
  1570. modflag += this->Convert(mod_dir,
  1571. cmLocalGenerator::START_OUTPUT,
  1572. cmLocalGenerator::SHELL);
  1573. this->LocalGenerator->AppendFlags(flags, modflag.c_str());
  1574. }
  1575. // If there is a separate module path flag then duplicate the
  1576. // include path with it. This compiler does not search the include
  1577. // path for modules.
  1578. if(const char* modpath_flag =
  1579. this->Makefile->GetDefinition("CMAKE_Fortran_MODPATH_FLAG"))
  1580. {
  1581. std::vector<std::string> includes;
  1582. this->LocalGenerator->GetIncludeDirectories(includes);
  1583. for(std::vector<std::string>::const_iterator idi = includes.begin();
  1584. idi != includes.end(); ++idi)
  1585. {
  1586. std::string flg = modpath_flag;
  1587. flg += this->Convert(idi->c_str(),
  1588. cmLocalGenerator::NONE,
  1589. cmLocalGenerator::SHELL);
  1590. this->LocalGenerator->AppendFlags(flags, flg.c_str());
  1591. }
  1592. }
  1593. }
  1594. //----------------------------------------------------------------------------
  1595. void cmMakefileTargetGenerator::AddModuleDefinitionFlag(std::string& flags)
  1596. {
  1597. if(this->ModuleDefinitionFile.empty())
  1598. {
  1599. return;
  1600. }
  1601. // TODO: Create a per-language flag variable.
  1602. const char* defFileFlag =
  1603. this->Makefile->GetDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  1604. if(!defFileFlag)
  1605. {
  1606. return;
  1607. }
  1608. // Append the flag and value. Use ConvertToLinkReference to help
  1609. // vs6's "cl -link" pass it to the linker.
  1610. std::string flag = defFileFlag;
  1611. flag += (this->LocalGenerator->ConvertToLinkReference(
  1612. this->ModuleDefinitionFile.c_str()));
  1613. this->LocalGenerator->AppendFlags(flags, flag.c_str());
  1614. }
  1615. //----------------------------------------------------------------------------
  1616. const char* cmMakefileTargetGenerator::GetFeature(const char* feature)
  1617. {
  1618. return this->Target->GetFeature(feature, this->ConfigName);
  1619. }
  1620. //----------------------------------------------------------------------------
  1621. bool cmMakefileTargetGenerator::GetFeatureAsBool(const char* feature)
  1622. {
  1623. return cmSystemTools::IsOn(this->GetFeature(feature));
  1624. }
  1625. //----------------------------------------------------------------------------
  1626. void cmMakefileTargetGenerator::AddFeatureFlags(
  1627. std::string& flags, const char* lang
  1628. )
  1629. {
  1630. // Add language-specific flags.
  1631. this->LocalGenerator->AddLanguageFlags(flags, lang, this->ConfigName);
  1632. if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION"))
  1633. {
  1634. this->LocalGenerator->AppendFeatureOptions(flags, lang, "IPO");
  1635. }
  1636. }