cmMakefileTargetGenerator.cxx 61 KB

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