cmMakefileTargetGenerator.cxx 66 KB

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