cmMakefileTargetGenerator.cxx 61 KB

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