cmMakefileTargetGenerator.cxx 61 KB

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