cmLocalVisualStudio7Generator.cxx 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670
  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 "cmGlobalVisualStudio7Generator.h"
  14. #include "cmLocalVisualStudio7Generator.h"
  15. #include "cmMakefile.h"
  16. #include "cmSystemTools.h"
  17. #include "cmSourceFile.h"
  18. #include "cmCacheManager.h"
  19. #include "cmake.h"
  20. #include <ctype.h> // for isspace
  21. cmLocalVisualStudio7Generator::cmLocalVisualStudio7Generator()
  22. {
  23. this->Version = 7;
  24. this->PlatformName = "Win32";
  25. }
  26. cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator()
  27. {
  28. }
  29. void cmLocalVisualStudio7Generator::Generate()
  30. {
  31. std::set<cmStdString> lang;
  32. lang.insert("C");
  33. lang.insert("CXX");
  34. lang.insert("RC");
  35. lang.insert("IDL");
  36. lang.insert("DEF");
  37. this->CreateCustomTargetsAndCommands(lang);
  38. this->FixGlobalTargets();
  39. this->OutputVCProjFile();
  40. }
  41. void cmLocalVisualStudio7Generator::FixGlobalTargets()
  42. {
  43. // Visual Studio .NET 2003 Service Pack 1 will not run post-build
  44. // commands for targets in which no sources are built. Add dummy
  45. // rules to force these targets to build.
  46. cmTargets &tgts = this->Makefile->GetTargets();
  47. for(cmTargets::iterator l = tgts.begin();
  48. l != tgts.end(); l++)
  49. {
  50. cmTarget& tgt = l->second;
  51. if(tgt.GetType() == cmTarget::GLOBAL_TARGET)
  52. {
  53. std::vector<std::string> no_depends;
  54. cmCustomCommandLine force_command;
  55. force_command.push_back(";");
  56. cmCustomCommandLines force_commands;
  57. force_commands.push_back(force_command);
  58. const char* no_main_dependency = 0;
  59. std::string force = this->Makefile->GetStartOutputDirectory();
  60. force += cmake::GetCMakeFilesDirectory();
  61. force += "/";
  62. force += tgt.GetName();
  63. force += "_force";
  64. this->Makefile->AddCustomCommandToOutput(force.c_str(), no_depends,
  65. no_main_dependency,
  66. force_commands, " ", 0, true);
  67. if(cmSourceFile* file =
  68. this->Makefile->GetSourceFileWithOutput(force.c_str()))
  69. {
  70. tgt.GetSourceFiles().push_back(file);
  71. }
  72. }
  73. }
  74. }
  75. // TODO
  76. // for CommandLine= need to repleace quotes with &quot
  77. // write out configurations
  78. void cmLocalVisualStudio7Generator::OutputVCProjFile()
  79. {
  80. // If not an in source build, then create the output directory
  81. if(strcmp(this->Makefile->GetStartOutputDirectory(),
  82. this->Makefile->GetHomeDirectory()) != 0)
  83. {
  84. if(!cmSystemTools::MakeDirectory
  85. (this->Makefile->GetStartOutputDirectory()))
  86. {
  87. cmSystemTools::Error("Error creating directory ",
  88. this->Makefile->GetStartOutputDirectory());
  89. }
  90. }
  91. this->LibraryOutputPath = "";
  92. if (this->Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  93. {
  94. this->LibraryOutputPath =
  95. this->Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
  96. }
  97. if(this->LibraryOutputPath.size())
  98. {
  99. // make sure there is a trailing slash
  100. if(this->LibraryOutputPath[this->LibraryOutputPath.size()-1] != '/')
  101. {
  102. this->LibraryOutputPath += "/";
  103. }
  104. }
  105. this->ExecutableOutputPath = "";
  106. if (this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  107. {
  108. this->ExecutableOutputPath =
  109. this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  110. }
  111. if(this->ExecutableOutputPath.size())
  112. {
  113. // make sure there is a trailing slash
  114. if(this->ExecutableOutputPath[this->ExecutableOutputPath.size()-1] != '/')
  115. {
  116. this->ExecutableOutputPath += "/";
  117. }
  118. }
  119. // Create the VCProj or set of VCProj's for libraries and executables
  120. // clear project names
  121. this->CreatedProjectNames.clear();
  122. // Call TraceVSDependencies on all targets
  123. cmTargets &tgts = this->Makefile->GetTargets();
  124. for(cmTargets::iterator l = tgts.begin();
  125. l != tgts.end(); l++)
  126. {
  127. // Add a rule to regenerate the build system when the target
  128. // specification source changes.
  129. const char* suppRegenRule =
  130. this->Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
  131. if (!cmSystemTools::IsOn(suppRegenRule) &&
  132. (strcmp(l->first.c_str(), CMAKE_CHECK_BUILD_SYSTEM_TARGET) != 0))
  133. {
  134. this->AddVCProjBuildRule(l->second);
  135. }
  136. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  137. // so don't build a projectfile for it
  138. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  139. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)
  140. && (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0))
  141. {
  142. cmTarget& target = l->second;
  143. target.TraceVSDependencies(target.GetName(), this->Makefile);
  144. }
  145. }
  146. for(cmTargets::iterator l = tgts.begin();
  147. l != tgts.end(); l++)
  148. {
  149. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  150. // so don't build a projectfile for it
  151. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  152. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)
  153. && (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0))
  154. {
  155. this->CreateSingleVCProj(l->first.c_str(),l->second);
  156. }
  157. }
  158. }
  159. void cmLocalVisualStudio7Generator
  160. ::CreateSingleVCProj(const char *lname, cmTarget &target)
  161. {
  162. // add to the list of projects
  163. std::string pname = lname;
  164. this->CreatedProjectNames.push_back(pname);
  165. // create the dsp.cmake file
  166. std::string fname;
  167. fname = this->Makefile->GetStartOutputDirectory();
  168. fname += "/";
  169. fname += lname;
  170. fname += ".vcproj";
  171. // save the name of the real dsp file
  172. std::string realVCProj = fname;
  173. fname += ".cmake";
  174. std::ofstream fout(fname.c_str());
  175. if(!fout)
  176. {
  177. cmSystemTools::Error("Error Writing ", fname.c_str());
  178. }
  179. this->WriteVCProjFile(fout,lname,target);
  180. fout.close();
  181. // if the dsp file has changed, then write it.
  182. cmSystemTools::CopyFileIfDifferent(fname.c_str(), realVCProj.c_str());
  183. }
  184. void cmLocalVisualStudio7Generator::AddVCProjBuildRule(cmTarget& tgt)
  185. {
  186. std::string dspname = tgt.GetName();
  187. dspname += ".vcproj.cmake";
  188. const char* dsprule =
  189. this->Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  190. cmCustomCommandLine commandLine;
  191. commandLine.push_back(dsprule);
  192. std::string makefileIn = this->Makefile->GetStartDirectory();
  193. makefileIn += "/";
  194. makefileIn += "CMakeLists.txt";
  195. makefileIn = cmSystemTools::CollapseFullPath(makefileIn.c_str());
  196. std::string comment = "Building Custom Rule ";
  197. comment += makefileIn;
  198. std::string args;
  199. args = "-H";
  200. args += this->Convert(this->Makefile->GetHomeDirectory(),
  201. START_OUTPUT, UNCHANGED, true);
  202. commandLine.push_back(args);
  203. args = "-B";
  204. args +=
  205. this->Convert(this->Makefile->GetHomeOutputDirectory(),
  206. START_OUTPUT, UNCHANGED, true);
  207. commandLine.push_back(args);
  208. std::string configFile =
  209. this->Makefile->GetRequiredDefinition("CMAKE_ROOT");
  210. configFile += "/Templates/CMakeWindowsSystemConfig.cmake";
  211. std::vector<std::string> listFiles = this->Makefile->GetListFiles();
  212. bool found = false;
  213. for(std::vector<std::string>::iterator i = listFiles.begin();
  214. i != listFiles.end(); ++i)
  215. {
  216. if(*i == configFile)
  217. {
  218. found = true;
  219. }
  220. }
  221. if(!found)
  222. {
  223. listFiles.push_back(configFile);
  224. }
  225. cmCustomCommandLines commandLines;
  226. commandLines.push_back(commandLine);
  227. const char* no_working_directory = 0;
  228. this->Makefile->AddCustomCommandToOutput(dspname.c_str(), listFiles,
  229. makefileIn.c_str(), commandLines,
  230. comment.c_str(),
  231. no_working_directory, true);
  232. if(cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str()))
  233. {
  234. tgt.GetSourceFiles().push_back(file);
  235. }
  236. else
  237. {
  238. cmSystemTools::Error("Error adding rule for ", makefileIn.c_str());
  239. }
  240. }
  241. void cmLocalVisualStudio7Generator::WriteConfigurations(std::ostream& fout,
  242. const char *libName,
  243. cmTarget &target)
  244. {
  245. std::vector<std::string> *configs =
  246. static_cast<cmGlobalVisualStudio7Generator *>
  247. (this->GlobalGenerator)->GetConfigurations();
  248. fout << "\t<Configurations>\n";
  249. for( std::vector<std::string>::iterator i = configs->begin();
  250. i != configs->end(); ++i)
  251. {
  252. this->WriteConfiguration(fout, i->c_str(), libName, target);
  253. }
  254. fout << "\t</Configurations>\n";
  255. }
  256. // This is a table mapping XML tag IDE names to command line options
  257. struct cmVS7FlagTable
  258. {
  259. const char* IDEName; // name used in the IDE xml file
  260. const char* commandFlag; // command line flag
  261. const char* comment; // comment
  262. const char* value; // string value
  263. };
  264. // fill the table here currently the comment field is not used for
  265. // anything other than documentation NOTE: Make sure the longer
  266. // commandFlag comes FIRST!
  267. cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[] =
  268. {
  269. // option flags (some flags map to the same option)
  270. {"BasicRuntimeChecks", "GZ", "Stack frame checks", "1"},
  271. {"BasicRuntimeChecks", "RTCsu", "Both stack and uninitialized checks", "3"},
  272. {"BasicRuntimeChecks", "RTCs", "Stack frame checks", "1"},
  273. {"BasicRuntimeChecks", "RTCu", "Uninitialized Variables ", "2"},
  274. {"BasicRuntimeChecks", "RTC1", "Both stack and uninitialized checks ", "3"},
  275. {"DebugInformationFormat", "Z7", "debug format", "1"},
  276. {"DebugInformationFormat", "Zd", "debug format", "2"},
  277. {"DebugInformationFormat", "Zi", "debug format", "3"},
  278. {"DebugInformationFormat", "ZI", "debug format", "4"},
  279. {"EnableEnhancedInstructionSet", "arch:SSE2", "Use sse2 instructions", "2"},
  280. {"EnableEnhancedInstructionSet", "arch:SSE", "Use sse instructions", "1"},
  281. {"FavorSizeOrSpeed", "Ot", "Favor fast code", "1"},
  282. {"FavorSizeOrSpeed", "Os", "Favor small code", "2"},
  283. {"CompileAs", "TC", "Compile as c code", "1"},
  284. {"CompileAs", "TP", "Compile as c++ code", "2"},
  285. {"Optimization", "Od", "Non Debug", "0"},
  286. {"Optimization", "O1", "Min Size", "1"},
  287. {"Optimization", "O2", "Max Speed", "2"},
  288. {"Optimization", "Ox", "Max Optimization", "3"},
  289. {"OptimizeForProcessor", "GB", "Blended processor mode", "0"},
  290. {"OptimizeForProcessor", "G5", "Pentium", "1"},
  291. {"OptimizeForProcessor", "G6", "PPro PII PIII", "2"},
  292. {"OptimizeForProcessor", "G7", "Pentium 4 or Athlon", "3"},
  293. {"InlineFunctionExpansion", "Ob0", "no inlines", "0"},
  294. {"InlineFunctionExpansion", "Ob1", "when inline keyword", "1"},
  295. {"InlineFunctionExpansion", "Ob2", "any time you can inline", "2"},
  296. {"RuntimeLibrary", "MTd", "Multithreded debug", "1"},
  297. {"RuntimeLibrary", "MT", "Multithreded", "0"},
  298. {"RuntimeLibrary", "MDd", "Multithreded dll debug", "3"},
  299. {"RuntimeLibrary", "MD", "Multithreded dll", "2"},
  300. {"RuntimeLibrary", "MLd", "Sinble Thread debug", "5"},
  301. {"RuntimeLibrary", "ML", "Sinble Thread", "4"},
  302. {"StructMemberAlignment", "Zp16", "struct align 16 byte ", "5"},
  303. {"StructMemberAlignment", "Zp1", "struct align 1 byte ", "1"},
  304. {"StructMemberAlignment", "Zp2", "struct align 2 byte ", "2"},
  305. {"StructMemberAlignment", "Zp4", "struct align 4 byte ", "3"},
  306. {"StructMemberAlignment", "Zp8", "struct align 8 byte ", "4"},
  307. {"WarningLevel", "W1", "Warning level", "1"},
  308. {"WarningLevel", "W2", "Warning level", "2"},
  309. {"WarningLevel", "W3", "Warning level", "3"},
  310. {"WarningLevel", "W4", "Warning level", "4"},
  311. // boolean flags
  312. {"BufferSecurityCheck", "GS", "Buffer security check", "TRUE"},
  313. {"EnableFibreSafeOptimization", "GT", "OmitFramePointers", "TRUE"},
  314. {"EnableFunctionLevelLinking", "Gy", "EnableFunctionLevelLinking", "TRUE"},
  315. {"EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "TRUE"},
  316. {"ExceptionHandling", "EHsc", "enable c++ exceptions", "TRUE"},
  317. {"ExceptionHandling", "EHa", "enable c++ exceptions", "2"},
  318. {"ExceptionHandling", "GX", "enable c++ exceptions", "TRUE"},
  319. {"GlobalOptimizations", "Og", "Global Optimize", "TRUE"},
  320. {"ImproveFloatingPointConsistency", "Op",
  321. "ImproveFloatingPointConsistency", "TRUE"},
  322. {"MinimalRebuild", "Gm", "minimal rebuild", "TRUE"},
  323. {"OmitFramePointers", "Oy", "OmitFramePointers", "TRUE"},
  324. {"OptimizeForWindowsApplication", "GA", "Optimize for windows", "TRUE"},
  325. {"RuntimeTypeInfo", "GR",
  326. "Turn on Run time type information for c++", "TRUE"},
  327. {"SmallerTypeCheck", "RTCc", "smaller type check", "TRUE"},
  328. {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "TRUE"},
  329. {"WarnAsError", "WX", "Treat warnings as errors", "TRUE"},
  330. {0,0,0,0 }
  331. };
  332. cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] =
  333. {
  334. // option flags (some flags map to the same option)
  335. {"GenerateManifest", "MANIFEST:NO", "disable manifest generation", "FALSE"},
  336. {"GenerateManifest", "MANIFEST", "enable manifest generation", "TRUE"},
  337. {"LinkIncremental", "INCREMENTAL:NO", "link incremental", "1"},
  338. {"LinkIncremental", "INCREMENTAL:YES", "link incremental", "2"},
  339. {"IgnoreDefaultLibraryNames", "NODEFAULTLIB:", "USER_VALUE", ""},
  340. {0,0,0,0 }
  341. };
  342. void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
  343. const char* configName,
  344. const char *libName,
  345. cmTarget &target)
  346. {
  347. // create a map of xml tags to the values they should have in the output
  348. // for example, "BufferSecurityCheck" = "TRUE"
  349. // first fill this table with the values for the configuration
  350. // Debug, Release, etc,
  351. // Then parse the command line flags specified in CMAKE_CXX_FLAGS
  352. // and CMAKE_C_FLAGS
  353. // and overwrite or add new values to this map
  354. std::map<cmStdString, cmStdString> flagMap;
  355. // since the default is on for this, but if /EHsc is found
  356. // in the flags it will be turned on and we have /EHSC on by
  357. // default in the CXX flags, then this is the only way to turn this off
  358. flagMap["ExceptionHandling"] = "FALSE";
  359. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  360. if(!mfcFlag)
  361. {
  362. mfcFlag = "0";
  363. }
  364. fout << "\t\t<Configuration\n"
  365. << "\t\t\tName=\"" << configName << "|" << this->PlatformName << "\"\n"
  366. << "\t\t\tOutputDirectory=\"" << configName << "\"\n";
  367. // This is an internal type to Visual Studio, it seems that:
  368. // 4 == static library
  369. // 2 == dll
  370. // 1 == executable
  371. // 10 == utility
  372. const char* configType = "10";
  373. switch(target.GetType())
  374. {
  375. case cmTarget::STATIC_LIBRARY:
  376. configType = "4";
  377. break;
  378. case cmTarget::SHARED_LIBRARY:
  379. case cmTarget::MODULE_LIBRARY:
  380. configType = "2";
  381. break;
  382. case cmTarget::EXECUTABLE:
  383. configType = "1";
  384. break;
  385. case cmTarget::UTILITY:
  386. case cmTarget::GLOBAL_TARGET:
  387. configType = "10";
  388. default:
  389. break;
  390. }
  391. std::string flags;
  392. if(strcmp(configType, "10") != 0)
  393. {
  394. const char* linkLanguage =
  395. target.GetLinkerLanguage(this->GetGlobalGenerator());
  396. if(!linkLanguage)
  397. {
  398. cmSystemTools::Error
  399. ("CMake can not determine linker language for target:",
  400. target.GetName());
  401. return;
  402. }
  403. if(strcmp(linkLanguage, "C") == 0 || strcmp(linkLanguage, "CXX") == 0)
  404. {
  405. std::string baseFlagVar = "CMAKE_";
  406. baseFlagVar += linkLanguage;
  407. baseFlagVar += "_FLAGS";
  408. flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  409. std::string flagVar = baseFlagVar + std::string("_") +
  410. cmSystemTools::UpperCase(configName);
  411. flags += " ";
  412. flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
  413. }
  414. // set the correct language
  415. if(strcmp(linkLanguage, "C") == 0)
  416. {
  417. flags += " /TC ";
  418. }
  419. if(strcmp(linkLanguage, "CXX") == 0)
  420. {
  421. flags += " /TP ";
  422. }
  423. }
  424. // Add the target-specific flags.
  425. if(const char* targetFlags = target.GetProperty("COMPILE_FLAGS"))
  426. {
  427. flags += " ";
  428. flags += targetFlags;
  429. }
  430. // The intermediate directory name consists of a directory for the
  431. // target and a subdirectory for the configuration name.
  432. std::string intermediateDir = this->GetTargetDirectory(target);
  433. intermediateDir += "/";
  434. intermediateDir += configName;
  435. fout << "\t\t\tIntermediateDirectory=\""
  436. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  437. << "\"\n"
  438. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  439. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  440. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
  441. // if -D_UNICODE or /D_UNICODE is found in the flags
  442. // change the character set to unicode, if not then
  443. // default to MBCS
  444. std::string defs = this->Makefile->GetDefineFlags();
  445. if(flags.find("D_UNICODE") != flags.npos ||
  446. defs.find("D_UNICODE") != flags.npos)
  447. {
  448. fout << "\t\t\tCharacterSet=\"1\">\n";
  449. }
  450. else
  451. {
  452. fout << "\t\t\tCharacterSet=\"2\">\n";
  453. }
  454. fout << "\t\t\t<Tool\n"
  455. << "\t\t\t\tName=\"VCCLCompilerTool\"\n"
  456. << "\t\t\t\tAdditionalOptions=\"";
  457. // now fill the flagMap from the command line flags, and
  458. // if a flag is used, it will be removed from the flags string by
  459. // this function call
  460. this->FillFlagMapFromCommandFlags
  461. (flagMap, &cmLocalVisualStudio7GeneratorFlagTable[0], flags);
  462. std::string defineFlags = this->Makefile->GetDefineFlags();
  463. // now check the define flags for flags other than -D and
  464. // put them in the map, the -D flags will be left in the defineFlags
  465. // variable as -D is not in the flagMap
  466. this->FillFlagMapFromCommandFlags
  467. (flagMap, &cmLocalVisualStudio7GeneratorFlagTable[0], defineFlags);
  468. // output remaining flags that were not mapped to anything
  469. fout << this->EscapeForXML(flags.c_str()).c_str();
  470. fout << " -DCMAKE_INTDIR=\\&quot;" << configName << "\\&quot;"
  471. << "\"\n";
  472. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  473. std::vector<std::string> includes;
  474. this->GetIncludeDirectories(includes);
  475. std::vector<std::string>::iterator i = includes.begin();
  476. for(;i != includes.end(); ++i)
  477. {
  478. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  479. fout << ipath << ";";
  480. }
  481. fout << "\"\n";
  482. // set a few cmake specific flags
  483. if(this->Makefile->IsOn("CMAKE_CXX_USE_RTTI"))
  484. {
  485. flagMap["RuntimeTypeInfo"] = "TRUE";
  486. }
  487. if ( this->Makefile->GetDefinition("CMAKE_CXX_WARNING_LEVEL") )
  488. {
  489. flagMap["WarningLevel"] =
  490. this->Makefile->GetDefinition("CMAKE_CXX_WARNING_LEVEL");
  491. }
  492. // Now copy the flag map into the xml for the file
  493. for(std::map<cmStdString, cmStdString>::iterator m = flagMap.begin();
  494. m != flagMap.end(); ++m)
  495. {
  496. fout << "\t\t\t\t" << m->first << "=\"" << m->second << "\"\n";
  497. }
  498. fout << "\t\t\t\tPreprocessorDefinitions=\"";
  499. if(target.GetType() == cmTarget::SHARED_LIBRARY
  500. || target.GetType() == cmTarget::MODULE_LIBRARY)
  501. {
  502. std::string exportSymbol;
  503. if (const char* custom_export_name =
  504. target.GetProperty("DEFINE_SYMBOL"))
  505. {
  506. exportSymbol = custom_export_name;
  507. }
  508. else
  509. {
  510. std::string id = libName;
  511. id += "_EXPORTS";
  512. exportSymbol = cmSystemTools::MakeCindentifier(id.c_str());
  513. }
  514. fout << "," << exportSymbol;
  515. }
  516. this->OutputDefineFlags(defineFlags.c_str(), fout);
  517. fout << "\"\n";
  518. fout << "\t\t\t\tAssemblerListingLocation=\"" << configName << "\"\n";
  519. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  520. std::map<cmStdString, cmStdString>::iterator mi =
  521. flagMap.find("DebugInformationFormat");
  522. if(mi != flagMap.end() && mi->second != "1")
  523. {
  524. fout << "\t\t\t\tProgramDataBaseFileName=\""
  525. << this->LibraryOutputPath
  526. << "$(OutDir)/" << libName << ".pdb\"\n";
  527. }
  528. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  529. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n";
  530. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"\n"
  531. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  532. for(i = includes.begin();i != includes.end(); ++i)
  533. {
  534. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  535. fout << ipath << ";";
  536. }
  537. // add the -D flags to the RC tool
  538. fout << "\"\n"
  539. << "\t\t\t\tPreprocessorDefinitions=\"";
  540. this->OutputDefineFlags(defineFlags.c_str(), fout);
  541. fout << "\" />\n";
  542. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"\n";
  543. fout << "\t\t\t\tPreprocessorDefinitions=\"";
  544. this->OutputDefineFlags(defineFlags.c_str(), fout);
  545. fout << "\"\n";
  546. fout << "\t\t\t\tMkTypLibCompatible=\"FALSE\"\n";
  547. if( this->PlatformName == "x64" )
  548. {
  549. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  550. }
  551. else if( this->PlatformName == "ia64" )
  552. {
  553. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  554. }
  555. else
  556. {
  557. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  558. }
  559. fout << "\t\t\t\tGenerateStublessProxies=\"TRUE\"\n";
  560. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  561. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  562. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  563. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  564. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  565. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  566. // end of <Tool Name=VCMIDLTool
  567. // If we are building a version 8 project file, add a flag telling the
  568. // manifest tool to use a workaround for FAT32 file systems, which can cause
  569. // an empty manifest to be embedded into the resulting executable.
  570. // See CMake bug #2617.
  571. if ( this->Version == 8 )
  572. {
  573. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCManifestTool\"\n"
  574. << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
  575. << "\t\t\t/>\n";
  576. }
  577. this->OutputTargetRules(fout, target, libName);
  578. this->OutputBuildTool(fout, configName, libName, target);
  579. fout << "\t\t</Configuration>\n";
  580. }
  581. void cmLocalVisualStudio7Generator::ReplaceFlagSetMap(std::string& flags,
  582. cmVS7FlagTable* flagTable,
  583. std::map<cmStdString,
  584. cmStdString>& flagMap,
  585. std::string& option,
  586. std::string::size_type pos)
  587. {
  588. std::string value = flagTable->value;
  589. if(strcmp(flagTable->comment, "USER_VALUE") == 0)
  590. {
  591. std::string::size_type len = flags.find(" ", pos);
  592. if(len != flags.npos)
  593. {
  594. len -= option.size();
  595. }
  596. value = flags.substr(pos+option.size(), len);
  597. std::string fullflag = option;
  598. fullflag += value;
  599. // remove everything
  600. cmSystemTools::ReplaceString(flags, fullflag.c_str(), "");
  601. }
  602. else
  603. {
  604. cmSystemTools::ReplaceString(flags, option.c_str(), "");
  605. }
  606. // now put value into flag map
  607. flagMap[flagTable->IDEName] = value;
  608. }
  609. void cmLocalVisualStudio7Generator::FillFlagMapFromCommandFlags(
  610. std::map<cmStdString, cmStdString>& flagMap,
  611. cmVS7FlagTable* flagTable,
  612. std::string& flags)
  613. {
  614. std::string replace;
  615. std::string option;
  616. while(flagTable->IDEName)
  617. {
  618. option.reserve(strlen(flagTable->commandFlag)+2);
  619. // first do the - version
  620. option = "-";
  621. option += flagTable->commandFlag;
  622. std::string::size_type pos = flags.find(option);
  623. while(pos != flags.npos)
  624. {
  625. this->ReplaceFlagSetMap(flags, flagTable, flagMap,
  626. option, pos);
  627. pos = flags.find(option);
  628. }
  629. // now do the / version
  630. option[0] = '/';
  631. pos = flags.find(option);
  632. while(pos != flags.npos)
  633. {
  634. this->ReplaceFlagSetMap(flags, flagTable, flagMap,
  635. option, pos);
  636. pos = flags.find(option);
  637. }
  638. // move to next flag
  639. flagTable++;
  640. }
  641. // If verbose makefiles have been requested and the /nologo option
  642. // was not given explicitly in the flags we want to add an attribute
  643. // to the generated project to disable logo suppression. Otherwise
  644. // the GUI default is to enable suppression.
  645. if(this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  646. {
  647. if(flagMap.find("SuppressStartupBanner") == flagMap.end())
  648. {
  649. flagMap["SuppressStartupBanner"] = "FALSE";
  650. }
  651. }
  652. }
  653. //----------------------------------------------------------------------------
  654. std::string
  655. cmLocalVisualStudio7Generator
  656. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags, const char* configName)
  657. {
  658. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  659. std::string extraLinkOptionsBuildTypeDef =
  660. rootLinkerFlags + "_" + configTypeUpper;
  661. std::string extraLinkOptionsBuildType =
  662. this->Makefile->GetRequiredDefinition
  663. (extraLinkOptionsBuildTypeDef.c_str());
  664. return extraLinkOptionsBuildType;
  665. }
  666. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  667. const char* configName,
  668. const char *libName,
  669. cmTarget &target)
  670. {
  671. std::string targetFullName = target.GetFullName(configName);
  672. std::string temp;
  673. std::string extraLinkOptions;
  674. if(target.GetType() == cmTarget::EXECUTABLE)
  675. {
  676. extraLinkOptions =
  677. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
  678. + std::string(" ")
  679. + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  680. }
  681. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  682. {
  683. extraLinkOptions =
  684. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
  685. + std::string(" ")
  686. + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  687. }
  688. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  689. {
  690. extraLinkOptions =
  691. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
  692. + std::string(" ")
  693. + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  694. }
  695. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  696. if(targetLinkFlags)
  697. {
  698. extraLinkOptions += " ";
  699. extraLinkOptions += targetLinkFlags;
  700. }
  701. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  702. std::string linkFlagsConfig = "LINK_FLAGS_";
  703. linkFlagsConfig += configTypeUpper;
  704. targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
  705. if(targetLinkFlags)
  706. {
  707. extraLinkOptions += " ";
  708. extraLinkOptions += targetLinkFlags;
  709. }
  710. std::map<cmStdString, cmStdString> flagMap;
  711. this->FillFlagMapFromCommandFlags
  712. (flagMap, &cmLocalVisualStudio7GeneratorLinkFlagTable[0],
  713. extraLinkOptions);
  714. switch(target.GetType())
  715. {
  716. case cmTarget::STATIC_LIBRARY:
  717. {
  718. std::string libpath = this->LibraryOutputPath +
  719. "$(OutDir)/" + targetFullName;
  720. fout << "\t\t\t<Tool\n"
  721. << "\t\t\t\tName=\"VCLibrarianTool\"\n";
  722. if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
  723. {
  724. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  725. }
  726. fout << "\t\t\t\tOutputFile=\""
  727. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  728. break;
  729. }
  730. case cmTarget::SHARED_LIBRARY:
  731. case cmTarget::MODULE_LIBRARY:
  732. {
  733. // Compute the link library and directory information.
  734. std::vector<cmStdString> linkLibs;
  735. std::vector<cmStdString> linkDirs;
  736. this->ComputeLinkInformation(target, configName, linkLibs, linkDirs);
  737. // Get the language to use for linking.
  738. const char* linkLanguage =
  739. target.GetLinkerLanguage(this->GetGlobalGenerator());
  740. if(!linkLanguage)
  741. {
  742. cmSystemTools::Error
  743. ("CMake can not determine linker language for target:",
  744. target.GetName());
  745. return;
  746. }
  747. // Compute the variable name to lookup standard libraries for this
  748. // language.
  749. std::string standardLibsVar = "CMAKE_";
  750. standardLibsVar += linkLanguage;
  751. standardLibsVar += "_STANDARD_LIBRARIES";
  752. fout << "\t\t\t<Tool\n"
  753. << "\t\t\t\tName=\"VCLinkerTool\"\n"
  754. << "\t\t\t\tAdditionalOptions=\"/MACHINE:I386";
  755. if(extraLinkOptions.size())
  756. {
  757. fout << " " << cmLocalVisualStudio7Generator::EscapeForXML(
  758. extraLinkOptions.c_str()).c_str();
  759. }
  760. // Use the NOINHERIT macro to avoid getting VS project default
  761. // libraries which may be set by the user to something bad.
  762. fout << "\"\n"
  763. << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  764. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  765. << " ";
  766. this->OutputLibraries(fout, linkLibs);
  767. fout << "\"\n";
  768. temp = this->LibraryOutputPath;
  769. temp += configName;
  770. temp += "/";
  771. temp += targetFullName;
  772. fout << "\t\t\t\tOutputFile=\""
  773. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  774. this->WriteTargetVersionAttribute(fout, target);
  775. for(std::map<cmStdString, cmStdString>::iterator i = flagMap.begin();
  776. i != flagMap.end(); ++i)
  777. {
  778. fout << "\t\t\t\t" << i->first << "=\"" << i->second << "\"\n";
  779. }
  780. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  781. this->OutputLibraryDirectories(fout, linkDirs);
  782. fout << "\"\n";
  783. this->OutputModuleDefinitionFile(fout, target);
  784. temp = this->LibraryOutputPath;
  785. temp += "$(OutDir)/";
  786. temp += libName;
  787. temp += ".pdb";
  788. fout << "\t\t\t\tProgramDataBaseFile=\"" <<
  789. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  790. if(strcmp(configName, "Debug") == 0
  791. || strcmp(configName, "RelWithDebInfo") == 0)
  792. {
  793. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  794. }
  795. std::string stackVar = "CMAKE_";
  796. stackVar += linkLanguage;
  797. stackVar += "_STACK_SIZE";
  798. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  799. if(stackVal)
  800. {
  801. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  802. }
  803. temp = this->LibraryOutputPath;
  804. temp += configName;
  805. temp += "/";
  806. temp +=
  807. cmSystemTools::GetFilenameWithoutLastExtension(targetFullName.c_str());
  808. temp += ".lib";
  809. fout << "\t\t\t\tImportLibrary=\""
  810. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  811. }
  812. break;
  813. case cmTarget::EXECUTABLE:
  814. {
  815. // Compute the link library and directory information.
  816. std::vector<cmStdString> linkLibs;
  817. std::vector<cmStdString> linkDirs;
  818. this->ComputeLinkInformation(target, configName, linkLibs, linkDirs);
  819. // Get the language to use for linking.
  820. const char* linkLanguage =
  821. target.GetLinkerLanguage(this->GetGlobalGenerator());
  822. if(!linkLanguage)
  823. {
  824. cmSystemTools::Error
  825. ("CMake can not determine linker language for target:",
  826. target.GetName());
  827. return;
  828. }
  829. // Compute the variable name to lookup standard libraries for this
  830. // language.
  831. std::string standardLibsVar = "CMAKE_";
  832. standardLibsVar += linkLanguage;
  833. standardLibsVar += "_STANDARD_LIBRARIES";
  834. fout << "\t\t\t<Tool\n"
  835. << "\t\t\t\tName=\"VCLinkerTool\"\n"
  836. << "\t\t\t\tAdditionalOptions=\"";
  837. if(extraLinkOptions.size())
  838. {
  839. fout << " " << cmLocalVisualStudio7Generator::EscapeForXML(
  840. extraLinkOptions.c_str()).c_str();
  841. }
  842. // Use the NOINHERIT macro to avoid getting VS project default
  843. // libraries which may be set by the user to something bad.
  844. fout << "\"\n"
  845. << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  846. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  847. << " ";
  848. this->OutputLibraries(fout, linkLibs);
  849. fout << "\"\n";
  850. temp = this->ExecutableOutputPath;
  851. temp += configName;
  852. temp += "/";
  853. temp += targetFullName;
  854. fout << "\t\t\t\tOutputFile=\""
  855. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  856. this->WriteTargetVersionAttribute(fout, target);
  857. for(std::map<cmStdString, cmStdString>::iterator i = flagMap.begin();
  858. i != flagMap.end(); ++i)
  859. {
  860. fout << "\t\t\t\t" << i->first << "=\"" << i->second << "\"\n";
  861. }
  862. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  863. this->OutputLibraryDirectories(fout, linkDirs);
  864. fout << "\"\n";
  865. fout << "\t\t\t\tProgramDataBaseFile=\"" << this->LibraryOutputPath
  866. << "$(OutDir)\\" << libName << ".pdb\"\n";
  867. if(strcmp(configName, "Debug") == 0
  868. || strcmp(configName, "RelWithDebInfo") == 0)
  869. {
  870. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  871. }
  872. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  873. {
  874. fout << "\t\t\t\tSubSystem=\"2\"\n";
  875. }
  876. else
  877. {
  878. fout << "\t\t\t\tSubSystem=\"1\"\n";
  879. }
  880. std::string stackVar = "CMAKE_";
  881. stackVar += linkLanguage;
  882. stackVar += "_STACK_SIZE";
  883. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  884. if(stackVal)
  885. {
  886. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  887. }
  888. fout << "/>\n";
  889. break;
  890. }
  891. case cmTarget::UTILITY:
  892. case cmTarget::GLOBAL_TARGET:
  893. break;
  894. }
  895. }
  896. //----------------------------------------------------------------------------
  897. void
  898. cmLocalVisualStudio7Generator
  899. ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
  900. {
  901. int major;
  902. int minor;
  903. target.GetTargetVersion(major, minor);
  904. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  905. }
  906. void cmLocalVisualStudio7Generator
  907. ::OutputModuleDefinitionFile(std::ostream& fout,
  908. cmTarget &target)
  909. {
  910. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  911. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  912. i != classes.end(); i++)
  913. {
  914. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  915. {
  916. fout << "\t\t\t\tModuleDefinitionFile=\""
  917. << this->ConvertToXMLOutputPath((*i)->GetFullPath().c_str())
  918. << "\"\n";
  919. return;
  920. }
  921. }
  922. }
  923. //----------------------------------------------------------------------------
  924. void
  925. cmLocalVisualStudio7Generator
  926. ::OutputLibraries(std::ostream& fout,
  927. std::vector<cmStdString> const& libs)
  928. {
  929. for(std::vector<cmStdString>::const_iterator l = libs.begin();
  930. l != libs.end(); ++l)
  931. {
  932. fout << this->ConvertToXMLOutputPath(l->c_str()) << " ";
  933. }
  934. }
  935. //----------------------------------------------------------------------------
  936. void
  937. cmLocalVisualStudio7Generator
  938. ::OutputLibraryDirectories(std::ostream& fout,
  939. std::vector<cmStdString> const& dirs)
  940. {
  941. const char* comma = "";
  942. for(std::vector<cmStdString>::const_iterator d = dirs.begin();
  943. d != dirs.end(); ++d)
  944. {
  945. // Remove any trailing slash and skip empty paths.
  946. std::string dir = *d;
  947. if(dir[dir.size()-1] == '/')
  948. {
  949. dir = dir.substr(0, dir.size()-1);
  950. }
  951. if(dir.empty())
  952. {
  953. continue;
  954. }
  955. // Switch to a relative path specification if it is shorter.
  956. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  957. {
  958. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  959. if(rel.size() < dir.size())
  960. {
  961. dir = rel;
  962. }
  963. }
  964. // First search a configuration-specific subdirectory and then the
  965. // original directory.
  966. fout << comma << this->ConvertToXMLOutputPath((dir+"/$(OutDir)").c_str())
  967. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  968. comma = ",";
  969. }
  970. }
  971. //----------------------------------------------------------------------------
  972. void cmLocalVisualStudio7Generator::OutputDefineFlags(const char* flags,
  973. std::ostream& fout)
  974. {
  975. std::string defs = flags;
  976. cmSystemTools::ReplaceString(defs, "/D","-D");
  977. std::string::size_type pos = defs.find("-D");
  978. bool done = pos == std::string::npos;
  979. if(!done)
  980. {
  981. fout << ",";
  982. }
  983. while(!done)
  984. {
  985. std::string::size_type nextpos = defs.find("-D", pos+2);
  986. std::string define;
  987. if(nextpos != std::string::npos)
  988. {
  989. define = defs.substr(pos+2, nextpos - pos -3);
  990. }
  991. else
  992. {
  993. define = defs.substr(pos+2);
  994. done = true;
  995. }
  996. // Remove trailing whitespace from the definition.
  997. while(!define.empty() && isspace(define[define.size()-1]))
  998. {
  999. define = define.substr(0, define.size()-1);
  1000. }
  1001. // Double-quotes in the value of the definition must be escaped
  1002. // with a backslash. The entire definition should be quoted in
  1003. // the generated xml attribute to avoid confusing the VS parser.
  1004. define = this->EscapeForXML(define.c_str());
  1005. // if the define has something in it that is not a letter or a number
  1006. // then quote it
  1007. if(define.
  1008. find_first_not_of(
  1009. "-_abcdefghigklmnopqrstuvwxyz1234567890ABCDEFGHIGKLMNOPQRSTUVWXYZ")
  1010. != define.npos)
  1011. {
  1012. fout << "&quot;" << define << "&quot;,";
  1013. }
  1014. else
  1015. {
  1016. fout << define << ",";
  1017. }
  1018. if(!done)
  1019. {
  1020. pos = defs.find("-D", nextpos);
  1021. }
  1022. }
  1023. }
  1024. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1025. const char *libName,
  1026. cmTarget &target)
  1027. {
  1028. // get the configurations
  1029. std::vector<std::string> *configs =
  1030. static_cast<cmGlobalVisualStudio7Generator *>
  1031. (this->GlobalGenerator)->GetConfigurations();
  1032. // trace the visual studio dependencies
  1033. std::string name = libName;
  1034. name += ".vcproj.cmake";
  1035. // We may be modifying the source groups temporarily, so make a copy.
  1036. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1037. // get the classes from the source lists then add them to the groups
  1038. std::vector<cmSourceFile*> & classes = target.GetSourceFiles();
  1039. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1040. i != classes.end(); i++)
  1041. {
  1042. // Add the file to the list of sources.
  1043. std::string source = (*i)->GetFullPath();
  1044. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  1045. {
  1046. this->ModuleDefinitionFile = (*i)->GetFullPath();
  1047. }
  1048. cmSourceGroup& sourceGroup =
  1049. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1050. sourceGroup.AssignSource(*i);
  1051. }
  1052. // Compute which sources need unique object computation.
  1053. this->ComputeObjectNameRequirements(sourceGroups);
  1054. // open the project
  1055. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1056. // write the configuration information
  1057. this->WriteConfigurations(fout, libName, target);
  1058. fout << "\t<Files>\n";
  1059. // Loop through every source group.
  1060. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  1061. {
  1062. cmSourceGroup sg = sourceGroups[i];
  1063. this->WriteGroup(&sg, target, fout, libName, configs);
  1064. }
  1065. //}
  1066. fout << "\t</Files>\n";
  1067. // Write the VCProj file's footer.
  1068. this->WriteVCProjFooter(fout);
  1069. }
  1070. void cmLocalVisualStudio7Generator
  1071. ::WriteGroup(const cmSourceGroup *sg, cmTarget target,
  1072. std::ostream &fout, const char *libName,
  1073. std::vector<std::string> *configs)
  1074. {
  1075. const std::vector<const cmSourceFile *> &sourceFiles =
  1076. sg->GetSourceFiles();
  1077. // If the group is empty, don't write it at all.
  1078. if(sourceFiles.empty() && sg->GetGroupChildren().empty())
  1079. {
  1080. return;
  1081. }
  1082. // If the group has a name, write the header.
  1083. std::string name = sg->GetName();
  1084. if(name != "")
  1085. {
  1086. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1087. }
  1088. // Loop through each source in the source group.
  1089. std::string objectName;
  1090. for(std::vector<const cmSourceFile *>::const_iterator sf =
  1091. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  1092. {
  1093. std::string source = (*sf)->GetFullPath();
  1094. const cmCustomCommand *command = (*sf)->GetCustomCommand();
  1095. std::string compileFlags;
  1096. std::string additionalDeps;
  1097. if(this->NeedObjectName.find(*sf) != this->NeedObjectName.end())
  1098. {
  1099. objectName = this->GetObjectFileNameWithoutTarget(*(*sf));
  1100. }
  1101. else
  1102. {
  1103. objectName = "";
  1104. }
  1105. // Add per-source flags.
  1106. const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS");
  1107. if(cflags)
  1108. {
  1109. compileFlags += " ";
  1110. compileFlags += cflags;
  1111. }
  1112. const char* lang = this->GlobalGenerator->GetLanguageFromExtension
  1113. ((*sf)->GetSourceExtension().c_str());
  1114. const char* linkLanguage = target.GetLinkerLanguage
  1115. (this->GetGlobalGenerator());
  1116. // If lang is set, the compiler will generate code automatically.
  1117. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1118. // the project file
  1119. bool excludedFromBuild =
  1120. (lang && (*sf)->GetPropertyAsBool("HEADER_FILE_ONLY"));
  1121. // if the source file does not match the linker language
  1122. // then force c or c++
  1123. if(linkLanguage && lang && strcmp(lang, linkLanguage) != 0)
  1124. {
  1125. if(strcmp(lang, "CXX") == 0)
  1126. {
  1127. // force a C++ file type
  1128. compileFlags += " /TP ";
  1129. }
  1130. else if(strcmp(lang, "C") == 0)
  1131. {
  1132. // force to c
  1133. compileFlags += " /TC ";
  1134. }
  1135. }
  1136. // Check for extra object-file dependencies.
  1137. const char* deps = (*sf)->GetProperty("OBJECT_DEPENDS");
  1138. if(deps)
  1139. {
  1140. std::vector<std::string> depends;
  1141. cmSystemTools::ExpandListArgument(deps, depends);
  1142. if(!depends.empty())
  1143. {
  1144. std::vector<std::string>::iterator i = depends.begin();
  1145. additionalDeps = this->ConvertToXMLOutputPath(i->c_str());
  1146. for(++i;i != depends.end(); ++i)
  1147. {
  1148. additionalDeps += ";";
  1149. additionalDeps += this->ConvertToXMLOutputPath(i->c_str());
  1150. }
  1151. }
  1152. }
  1153. if (source != libName || target.GetType() == cmTarget::UTILITY ||
  1154. target.GetType() == cmTarget::GLOBAL_TARGET )
  1155. {
  1156. fout << "\t\t\t<File\n";
  1157. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1158. // Tell MS-Dev what the source is. If the compiler knows how to
  1159. // build it, then it will.
  1160. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1161. if (command)
  1162. {
  1163. // Construct the entire set of commands in one string.
  1164. std::string script =
  1165. this->ConstructScript(command->GetCommandLines(),
  1166. command->GetWorkingDirectory(),
  1167. command->GetEscapeOldStyle(),
  1168. command->GetEscapeAllowMakeVars());
  1169. std::string comment = this->ConstructComment(*command);
  1170. const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
  1171. this->WriteCustomRule(fout, source.c_str(), script.c_str(),
  1172. comment.c_str(), command->GetDepends(),
  1173. command->GetOutputs(), flags);
  1174. }
  1175. else if(compileFlags.size() || additionalDeps.length()
  1176. || objectName.size() || excludedFromBuild)
  1177. {
  1178. const char* aCompilerTool = "VCCLCompilerTool";
  1179. std::string ext = (*sf)->GetSourceExtension();
  1180. ext = cmSystemTools::LowerCase(ext);
  1181. if(ext == "idl")
  1182. {
  1183. aCompilerTool = "VCMIDLTool";
  1184. }
  1185. if(ext == "rc")
  1186. {
  1187. aCompilerTool = "VCResourceCompilerTool";
  1188. }
  1189. if(ext == "def")
  1190. {
  1191. aCompilerTool = "VCCustomBuildTool";
  1192. }
  1193. for(std::vector<std::string>::iterator i = configs->begin();
  1194. i != configs->end(); ++i)
  1195. {
  1196. fout << "\t\t\t\t<FileConfiguration\n"
  1197. << "\t\t\t\t\tName=\"" << *i
  1198. << "|" << this->PlatformName << "\"";
  1199. if(excludedFromBuild)
  1200. {
  1201. fout << " ExcludedFromBuild=\"true\"";
  1202. }
  1203. fout << ">\n";
  1204. fout << "\t\t\t\t\t<Tool\n"
  1205. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1206. if(compileFlags.size())
  1207. {
  1208. std::string compileFlagsCopy = compileFlags;
  1209. std::map<cmStdString, cmStdString> fileFlagMap;
  1210. this->FillFlagMapFromCommandFlags
  1211. (fileFlagMap,
  1212. &cmLocalVisualStudio7GeneratorFlagTable[0],
  1213. compileFlagsCopy);
  1214. if(compileFlagsCopy.size() &&
  1215. compileFlagsCopy.find_first_not_of(" ")
  1216. != compileFlagsCopy.npos)
  1217. {
  1218. fout << "\t\t\t\t\tAdditionalOptions=\""
  1219. << this->EscapeForXML(compileFlagsCopy.c_str()) << "\"\n";
  1220. }
  1221. for(std::map<cmStdString,
  1222. cmStdString>::iterator m = fileFlagMap.begin();
  1223. m != fileFlagMap.end(); ++m)
  1224. {
  1225. fout << "\t\t\t\t\t" << m->first << "=\""
  1226. << m->second << "\"\n";
  1227. }
  1228. }
  1229. if(additionalDeps.length())
  1230. {
  1231. fout << "\t\t\t\t\tAdditionalDependencies=\""
  1232. << additionalDeps.c_str() << "\"\n";
  1233. }
  1234. if(objectName.size())
  1235. {
  1236. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/"
  1237. << objectName.c_str() << "\"\n";
  1238. }
  1239. fout << "\t\t\t\t\t/>\n"
  1240. << "\t\t\t\t</FileConfiguration>\n";
  1241. }
  1242. }
  1243. fout << "\t\t\t</File>\n";
  1244. }
  1245. }
  1246. std::vector<cmSourceGroup> children = sg->GetGroupChildren();
  1247. for(unsigned int i=0;i<children.size();++i)
  1248. {
  1249. this->WriteGroup(&children[i], target, fout, libName, configs);
  1250. }
  1251. // If the group has a name, write the footer.
  1252. if(name != "")
  1253. {
  1254. this->WriteVCProjEndGroup(fout);
  1255. }
  1256. }
  1257. void cmLocalVisualStudio7Generator::
  1258. WriteCustomRule(std::ostream& fout,
  1259. const char* source,
  1260. const char* command,
  1261. const char* comment,
  1262. const std::vector<std::string>& depends,
  1263. const std::vector<std::string>& outputs,
  1264. const char* compileFlags)
  1265. {
  1266. // Write the rule for each configuration.
  1267. std::vector<std::string>::iterator i;
  1268. std::vector<std::string> *configs =
  1269. static_cast<cmGlobalVisualStudio7Generator *>
  1270. (this->GlobalGenerator)->GetConfigurations();
  1271. for(i = configs->begin(); i != configs->end(); ++i)
  1272. {
  1273. fout << "\t\t\t\t<FileConfiguration\n";
  1274. fout << "\t\t\t\t\tName=\"" << *i << "|" << this->PlatformName << "\">\n";
  1275. if(compileFlags)
  1276. {
  1277. fout << "\t\t\t\t\t<Tool\n"
  1278. << "\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
  1279. << "\t\t\t\t\tAdditionalOptions=\""
  1280. << this->EscapeForXML(compileFlags) << "\"/>\n";
  1281. }
  1282. fout << "\t\t\t\t\t<Tool\n"
  1283. << "\t\t\t\t\tName=\"VCCustomBuildTool\"\n"
  1284. << "\t\t\t\t\tDescription=\""
  1285. << this->EscapeForXML(comment) << "\"\n"
  1286. << "\t\t\t\t\tCommandLine=\""
  1287. << this->EscapeForXML(command) << "\"\n"
  1288. << "\t\t\t\t\tAdditionalDependencies=\"";
  1289. if(depends.empty())
  1290. {
  1291. // There are no real dependencies. Produce an artificial one to
  1292. // make sure the rule runs reliably.
  1293. if(!cmSystemTools::FileExists(source))
  1294. {
  1295. std::ofstream depout(source);
  1296. depout << "Artificial dependency for a custom command.\n";
  1297. }
  1298. fout << this->ConvertToXMLOutputPath(source);
  1299. }
  1300. else
  1301. {
  1302. // Write out the dependencies for the rule.
  1303. std::string temp;
  1304. for(std::vector<std::string>::const_iterator d = depends.begin();
  1305. d != depends.end(); ++d)
  1306. {
  1307. // Get the real name of the dependency in case it is a CMake target.
  1308. std::string dep = this->GetRealDependency(d->c_str(), i->c_str());
  1309. fout << this->ConvertToXMLOutputPath(dep.c_str())
  1310. << ";";
  1311. }
  1312. }
  1313. fout << "\"\n";
  1314. fout << "\t\t\t\t\tOutputs=\"";
  1315. if(outputs.empty())
  1316. {
  1317. fout << source << "_force";
  1318. }
  1319. else
  1320. {
  1321. // Write a rule for the output generated by this command.
  1322. const char* sep = "";
  1323. for(std::vector<std::string>::const_iterator o = outputs.begin();
  1324. o != outputs.end(); ++o)
  1325. {
  1326. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1327. sep = ";";
  1328. }
  1329. }
  1330. fout << "\"/>\n";
  1331. fout << "\t\t\t\t</FileConfiguration>\n";
  1332. }
  1333. }
  1334. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1335. const char* group,
  1336. const char* )
  1337. {
  1338. fout << "\t\t<Filter\n"
  1339. << "\t\t\tName=\"" << group << "\"\n"
  1340. << "\t\t\tFilter=\"\">\n";
  1341. }
  1342. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1343. {
  1344. fout << "\t\t</Filter>\n";
  1345. }
  1346. // look for custom rules on a target and collect them together
  1347. void cmLocalVisualStudio7Generator
  1348. ::OutputTargetRules(std::ostream& fout,
  1349. cmTarget &target,
  1350. const char * /*libName*/)
  1351. {
  1352. if (target.GetType() > cmTarget::GLOBAL_TARGET)
  1353. {
  1354. return;
  1355. }
  1356. // add the pre build rules
  1357. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"";
  1358. bool init = false;
  1359. for (std::vector<cmCustomCommand>::const_iterator cr =
  1360. target.GetPreBuildCommands().begin();
  1361. cr != target.GetPreBuildCommands().end(); ++cr)
  1362. {
  1363. if(!init)
  1364. {
  1365. fout << "\nCommandLine=\"";
  1366. init = true;
  1367. }
  1368. else
  1369. {
  1370. fout << this->EscapeForXML("\n");
  1371. }
  1372. std::string script =
  1373. this->ConstructScript(cr->GetCommandLines(),
  1374. cr->GetWorkingDirectory(),
  1375. cr->GetEscapeOldStyle(),
  1376. cr->GetEscapeAllowMakeVars());
  1377. fout << this->EscapeForXML(script.c_str()).c_str();
  1378. }
  1379. if (init)
  1380. {
  1381. fout << "\"";
  1382. }
  1383. fout << "/>\n";
  1384. // add the pre Link rules
  1385. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"";
  1386. init = false;
  1387. for (std::vector<cmCustomCommand>::const_iterator cr =
  1388. target.GetPreLinkCommands().begin();
  1389. cr != target.GetPreLinkCommands().end(); ++cr)
  1390. {
  1391. if(!init)
  1392. {
  1393. fout << "\nCommandLine=\"";
  1394. init = true;
  1395. }
  1396. else
  1397. {
  1398. fout << this->EscapeForXML("\n");
  1399. }
  1400. std::string script =
  1401. this->ConstructScript(cr->GetCommandLines(),
  1402. cr->GetWorkingDirectory(),
  1403. cr->GetEscapeOldStyle(),
  1404. cr->GetEscapeAllowMakeVars());
  1405. fout << this->EscapeForXML(script.c_str()).c_str();
  1406. }
  1407. if (init)
  1408. {
  1409. fout << "\"";
  1410. }
  1411. fout << "/>\n";
  1412. // add the PostBuild rules
  1413. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"";
  1414. init = false;
  1415. for (std::vector<cmCustomCommand>::const_iterator cr =
  1416. target.GetPostBuildCommands().begin();
  1417. cr != target.GetPostBuildCommands().end(); ++cr)
  1418. {
  1419. if(!init)
  1420. {
  1421. fout << "\nCommandLine=\"";
  1422. init = true;
  1423. }
  1424. else
  1425. {
  1426. fout << this->EscapeForXML("\n");
  1427. }
  1428. std::string script =
  1429. this->ConstructScript(cr->GetCommandLines(),
  1430. cr->GetWorkingDirectory(),
  1431. cr->GetEscapeOldStyle(),
  1432. cr->GetEscapeAllowMakeVars());
  1433. fout << this->EscapeForXML(script.c_str()).c_str();
  1434. }
  1435. if (init)
  1436. {
  1437. fout << "\"";
  1438. }
  1439. fout << "/>\n";
  1440. }
  1441. void
  1442. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  1443. const char *libName,
  1444. cmTarget & target,
  1445. std::vector<cmSourceGroup> &)
  1446. {
  1447. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1448. << "<VisualStudioProject\n"
  1449. << "\tProjectType=\"Visual C++\"\n";
  1450. if(this->Version == 71)
  1451. {
  1452. fout << "\tVersion=\"7.10\"\n";
  1453. }
  1454. else
  1455. {
  1456. if (this->Version == 8)
  1457. {
  1458. fout << "\tVersion=\"8.00\"\n";
  1459. }
  1460. else
  1461. {
  1462. fout << "\tVersion=\"7.00\"\n";
  1463. }
  1464. }
  1465. const char* projLabel = target.GetProperty("PROJECT_LABEL");
  1466. if(!projLabel)
  1467. {
  1468. projLabel = libName;
  1469. }
  1470. const char* keyword = target.GetProperty("VS_KEYWORD");
  1471. if(!keyword)
  1472. {
  1473. keyword = "Win32Proj";
  1474. }
  1475. cmGlobalVisualStudio7Generator* gg =
  1476. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1477. fout << "\tName=\"" << projLabel << "\"\n";
  1478. if(this->Version == 8)
  1479. {
  1480. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\"\n";
  1481. }
  1482. fout << "\tSccProjectName=\"\"\n"
  1483. << "\tSccLocalPath=\"\"\n"
  1484. << "\tKeyword=\"" << keyword << "\">\n"
  1485. << "\t<Platforms>\n"
  1486. << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName << "\"/>\n"
  1487. << "\t</Platforms>\n";
  1488. }
  1489. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout)
  1490. {
  1491. fout << "\t<Globals>\n"
  1492. << "\t</Globals>\n"
  1493. << "</VisualStudioProject>\n";
  1494. }
  1495. std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s)
  1496. {
  1497. std::string ret = s;
  1498. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1499. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1500. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1501. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1502. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  1503. return ret;
  1504. }
  1505. std::string cmLocalVisualStudio7Generator
  1506. ::ConvertToXMLOutputPath(const char* path)
  1507. {
  1508. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  1509. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1510. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1511. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1512. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1513. return ret;
  1514. }
  1515. std::string cmLocalVisualStudio7Generator
  1516. ::ConvertToXMLOutputPathSingle(const char* path)
  1517. {
  1518. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  1519. cmSystemTools::ReplaceString(ret, "\"", "");
  1520. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1521. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1522. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1523. return ret;
  1524. }
  1525. void cmLocalVisualStudio7Generator::ConfigureFinalPass()
  1526. {
  1527. cmLocalGenerator::ConfigureFinalPass();
  1528. cmTargets &tgts = this->Makefile->GetTargets();
  1529. cmGlobalVisualStudio7Generator* gg =
  1530. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1531. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  1532. {
  1533. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  1534. {
  1535. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  1536. const cmCustomCommandLines& cmds = cc.GetCommandLines();
  1537. std::string project_name = cmds[0][0];
  1538. gg->CreateGUID(project_name.c_str());
  1539. }
  1540. else
  1541. {
  1542. gg->CreateGUID(l->first.c_str());
  1543. }
  1544. }
  1545. }
  1546. //----------------------------------------------------------------------------
  1547. std::string cmLocalVisualStudio7Generator
  1548. ::GetTargetDirectory(cmTarget& target)
  1549. {
  1550. std::string dir;
  1551. dir += target.GetName();
  1552. dir += ".dir";
  1553. return dir;
  1554. }