cmLocalVisualStudio7Generator.cxx 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  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. cmLocalVisualStudio7Generator::cmLocalVisualStudio7Generator()
  21. {
  22. m_Version = 7;
  23. }
  24. cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator()
  25. {
  26. }
  27. void cmLocalVisualStudio7Generator::Generate()
  28. {
  29. std::set<cmStdString> lang;
  30. lang.insert("C");
  31. lang.insert("CXX");
  32. lang.insert("RC");
  33. lang.insert("IDL");
  34. lang.insert("DEF");
  35. this->CreateCustomTargetsAndCommands(lang);
  36. this->OutputVCProjFile();
  37. }
  38. // TODO
  39. // for CommandLine= need to repleace quotes with &quot
  40. // write out configurations
  41. void cmLocalVisualStudio7Generator::OutputVCProjFile()
  42. {
  43. // If not an in source build, then create the output directory
  44. if(strcmp(m_Makefile->GetStartOutputDirectory(),
  45. m_Makefile->GetHomeDirectory()) != 0)
  46. {
  47. if(!cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory()))
  48. {
  49. cmSystemTools::Error("Error creating directory ",
  50. m_Makefile->GetStartOutputDirectory());
  51. }
  52. }
  53. m_LibraryOutputPath = "";
  54. if (m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  55. {
  56. m_LibraryOutputPath = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
  57. }
  58. if(m_LibraryOutputPath.size())
  59. {
  60. // make sure there is a trailing slash
  61. if(m_LibraryOutputPath[m_LibraryOutputPath.size()-1] != '/')
  62. {
  63. m_LibraryOutputPath += "/";
  64. }
  65. }
  66. m_ExecutableOutputPath = "";
  67. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  68. {
  69. m_ExecutableOutputPath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  70. }
  71. if(m_ExecutableOutputPath.size())
  72. {
  73. // make sure there is a trailing slash
  74. if(m_ExecutableOutputPath[m_ExecutableOutputPath.size()-1] != '/')
  75. {
  76. m_ExecutableOutputPath += "/";
  77. }
  78. }
  79. // Create the VCProj or set of VCProj's for libraries and executables
  80. // clear project names
  81. m_CreatedProjectNames.clear();
  82. // build any targets
  83. cmTargets &tgts = m_Makefile->GetTargets();
  84. for(cmTargets::iterator l = tgts.begin();
  85. l != tgts.end(); l++)
  86. {
  87. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  88. // so don't build a projectfile for it
  89. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  90. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)
  91. && (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0))
  92. {
  93. this->CreateSingleVCProj(l->first.c_str(),l->second);
  94. }
  95. }
  96. }
  97. void cmLocalVisualStudio7Generator::CreateSingleVCProj(const char *lname, cmTarget &target)
  98. {
  99. // add to the list of projects
  100. std::string pname = lname;
  101. m_CreatedProjectNames.push_back(pname);
  102. // create the dsp.cmake file
  103. std::string fname;
  104. fname = m_Makefile->GetStartOutputDirectory();
  105. fname += "/";
  106. fname += lname;
  107. fname += ".vcproj";
  108. // save the name of the real dsp file
  109. std::string realVCProj = fname;
  110. fname += ".cmake";
  111. std::ofstream fout(fname.c_str());
  112. if(!fout)
  113. {
  114. cmSystemTools::Error("Error Writing ", fname.c_str());
  115. }
  116. this->WriteVCProjFile(fout,lname,target);
  117. fout.close();
  118. // if the dsp file has changed, then write it.
  119. cmSystemTools::CopyFileIfDifferent(fname.c_str(), realVCProj.c_str());
  120. }
  121. void cmLocalVisualStudio7Generator::AddVCProjBuildRule()
  122. {
  123. std::string dspname = *(m_CreatedProjectNames.end()-1);
  124. dspname += ".vcproj.cmake";
  125. const char* dsprule = m_Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  126. cmCustomCommandLine commandLine;
  127. commandLine.push_back(dsprule);
  128. std::string makefileIn = m_Makefile->GetStartDirectory();
  129. makefileIn += "/";
  130. makefileIn += "CMakeLists.txt";
  131. std::string args;
  132. args = "-H";
  133. args +=
  134. this->ConvertToRelativeOutputPath(m_Makefile->GetHomeDirectory());
  135. commandLine.push_back(args);
  136. args = "-B";
  137. args +=
  138. this->ConvertToRelativeOutputPath(m_Makefile->GetHomeOutputDirectory());
  139. commandLine.push_back(args);
  140. std::string configFile =
  141. m_Makefile->GetRequiredDefinition("CMAKE_ROOT");
  142. configFile += "/Templates/CMakeWindowsSystemConfig.cmake";
  143. std::vector<std::string> listFiles = m_Makefile->GetListFiles();
  144. bool found = false;
  145. for(std::vector<std::string>::iterator i = listFiles.begin();
  146. i != listFiles.end(); ++i)
  147. {
  148. if(*i == configFile)
  149. {
  150. found = true;
  151. }
  152. }
  153. if(!found)
  154. {
  155. listFiles.push_back(configFile);
  156. }
  157. cmCustomCommandLines commandLines;
  158. commandLines.push_back(commandLine);
  159. const char* no_comment = 0;
  160. m_Makefile->AddCustomCommandToOutput(dspname.c_str(), listFiles, makefileIn.c_str(),
  161. commandLines, no_comment, true);
  162. }
  163. void cmLocalVisualStudio7Generator::WriteConfigurations(std::ostream& fout,
  164. const char *libName,
  165. const cmTarget &target)
  166. {
  167. std::vector<std::string> *configs =
  168. static_cast<cmGlobalVisualStudio7Generator *>(m_GlobalGenerator)->GetConfigurations();
  169. fout << "\t<Configurations>\n";
  170. for( std::vector<std::string>::iterator i = configs->begin();
  171. i != configs->end(); ++i)
  172. {
  173. this->WriteConfiguration(fout, i->c_str(), libName, target);
  174. }
  175. fout << "\t</Configurations>\n";
  176. }
  177. // This is a table mapping XML tag IDE names to command line options
  178. struct cmVS7FlagTable
  179. {
  180. const char* IDEName; // name used in the IDE xml file
  181. const char* commandFlag; // command line flag
  182. const char* comment; // comment
  183. const char* value; // string value
  184. };
  185. // fill the table here
  186. // currently the comment field is not used for anything other than documentation
  187. // NOTE: Make sure the longer commandFlag comes FIRST!
  188. cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[] =
  189. {
  190. // option flags (some flags map to the same option)
  191. {"BasicRuntimeChecks", "GZ", "Stack frame checks", "1"},
  192. {"BasicRuntimeChecks", "RTCsu", "Both stack and uninitialized checks ", "3"},
  193. {"BasicRuntimeChecks", "RTCs", "Stack frame checks", "1"},
  194. {"BasicRuntimeChecks", "RTCu", "Uninitialized Variables ", "2"},
  195. {"BasicRuntimeChecks", "RTC1", "Both stack and uninitialized checks ", "3"},
  196. {"DebugInformationFormat", "Z7", "debug format", "1"},
  197. {"DebugInformationFormat", "Zd", "debug format", "2"},
  198. {"DebugInformationFormat", "Zi", "debug format", "3"},
  199. {"DebugInformationFormat", "ZI", "debug format", "4"},
  200. {"EnableEnhancedInstructionSet", "arch:SSE2", "Use sse2 instructions", "2"},
  201. {"EnableEnhancedInstructionSet", "arch:SSE", "Use sse instructions", "1"},
  202. {"FavorSizeOrSpeed", "Ot", "Favor fast code", "1"},
  203. {"FavorSizeOrSpeed", "Os", "Favor small code", "2"},
  204. {"Optimization", "Od", "Non Debug", "0"},
  205. {"Optimization", "O1", "Min Size", "1"},
  206. {"Optimization", "O2", "Max Speed", "2"},
  207. {"Optimization", "Ox", "Max Optimization", "3"},
  208. {"OptimizeForProcessor", "GB", "Blended processor mode", "0"},
  209. {"OptimizeForProcessor", "G5", "Pentium", "1"},
  210. {"OptimizeForProcessor", "G6", "PPro PII PIII", "2"},
  211. {"OptimizeForProcessor", "G7", "Pentium 4 or Athlon", "3"},
  212. {"InlineFunctionExpansion", "Ob0", "no inlines", "0"},
  213. {"InlineFunctionExpansion", "Ob1", "when inline keyword", "1"},
  214. {"InlineFunctionExpansion", "Ob2", "any time you can inline", "2"},
  215. {"RuntimeLibrary", "MTd", "Multithreded debug", "1"},
  216. {"RuntimeLibrary", "MT", "Multithreded", "0"},
  217. {"RuntimeLibrary", "MDd", "Multithreded dll debug", "3"},
  218. {"RuntimeLibrary", "MD", "Multithreded dll", "2"},
  219. {"RuntimeLibrary", "MLd", "Sinble Thread debug", "5"},
  220. {"RuntimeLibrary", "ML", "Sinble Thread", "4"},
  221. {"StructMemberAlignment", "Zp16", "struct align 16 byte ", "5"},
  222. {"StructMemberAlignment", "Zp1", "struct align 1 byte ", "1"},
  223. {"StructMemberAlignment", "Zp2", "struct align 2 byte ", "2"},
  224. {"StructMemberAlignment", "Zp4", "struct align 4 byte ", "3"},
  225. {"StructMemberAlignment", "Zp8", "struct align 8 byte ", "4"},
  226. {"WarningLevel", "W1", "Warning level", "1"},
  227. {"WarningLevel", "W2", "Warning level", "2"},
  228. {"WarningLevel", "W3", "Warning level", "3"},
  229. {"WarningLevel", "W4", "Warning level", "4"},
  230. // boolean flags
  231. {"BufferSecurityCheck", "GS", "Buffer security check", "TRUE"},
  232. {"EnableFibreSafeOptimization", "GT", "OmitFramePointers", "TRUE"},
  233. {"EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "TRUE"},
  234. {"ExceptionHandling", "EHsc", "enable c++ exceptions", "TRUE"},
  235. {"ExceptionHandling", "GX", "enable c++ exceptions", "TRUE"},
  236. {"GlobalOptimizations", "Og", "Global Optimize", "TRUE"},
  237. {"ImproveFloatingPointConsistency", "Op", "ImproveFloatingPointConsistency", "TRUE"},
  238. {"MinimalRebuild", "Gm", "minimal rebuild", "TRUE"},
  239. {"OmitFramePointers", "Oy", "OmitFramePointers", "TRUE"},
  240. {"OptimizeForWindowsApplication", "GA", "Optimize for windows", "TRUE"},
  241. {"RuntimeTypeInfo", "GR", "Turn on Run time type information for c++", "TRUE"},
  242. {"SmallerTypeCheck", "RTCc", "smaller type check", "TRUE"},
  243. {"WarnAsError", "WX", "Treat warnings as errors", "TRUE"},
  244. {0,0,0,0 }
  245. };
  246. cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] =
  247. {
  248. // option flags (some flags map to the same option)
  249. {"LinkIncremental", "INCREMENTAL:NO", "link incremental", "1"},
  250. {"LinkIncremental", "INCREMENTAL:YES", "link incremental", "2"},
  251. {0,0,0,0 }
  252. };
  253. void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
  254. const char* configName,
  255. const char *libName,
  256. const cmTarget &target)
  257. {
  258. // create a map of xml tags to the values they should have in the output
  259. // for example, "BufferSecurityCheck" = "TRUE"
  260. // first fill this table with the values for the configuration
  261. // Debug, Release, etc,
  262. // Then parse the command line flags specified in CMAKE_CXX_FLAGS
  263. // and CMAKE_C_FLAGS
  264. // and overwrite or add new values to this map
  265. std::map<cmStdString, cmStdString> flagMap;
  266. // since the default is on for this, but if /EHsc is found
  267. // in the flags it will be turned on and we have /EHSC on by
  268. // default in the CXX flags, then this is the only way to turn this off
  269. flagMap["ExceptionHandling"] = "FALSE";
  270. const char* mfcFlag = m_Makefile->GetDefinition("CMAKE_MFC_FLAG");
  271. if(!mfcFlag)
  272. {
  273. mfcFlag = "0";
  274. }
  275. fout << "\t\t<Configuration\n"
  276. << "\t\t\tName=\"" << configName << "|Win32\"\n"
  277. << "\t\t\tOutputDirectory=\"" << configName << "\"\n";
  278. // This is an internal type to Visual Studio, it seems that:
  279. // 4 == static library
  280. // 2 == dll
  281. // 1 == executable
  282. // 10 == utility
  283. const char* configType = "10";
  284. switch(target.GetType())
  285. {
  286. case cmTarget::STATIC_LIBRARY:
  287. configType = "4";
  288. break;
  289. case cmTarget::SHARED_LIBRARY:
  290. case cmTarget::MODULE_LIBRARY:
  291. configType = "2";
  292. break;
  293. case cmTarget::EXECUTABLE:
  294. configType = "1";
  295. break;
  296. case cmTarget::UTILITY:
  297. configType = "10";
  298. default:
  299. break;
  300. }
  301. std::string flags;
  302. std::string flagsRelease = " ";
  303. std::string flagsMinSize = " ";
  304. std::string flagsDebug = " ";
  305. std::string flagsDebugRel = " ";
  306. if(strcmp(configType, "10") != 0)
  307. {
  308. const char* linkLanguage = target.GetLinkerLanguage(this->GetGlobalGenerator());
  309. if(!linkLanguage)
  310. {
  311. cmSystemTools::Error("CMake can not determine linker language for target:",
  312. target.GetName());
  313. return;
  314. }
  315. if(!(strcmp(linkLanguage, "RC") == 0 || strcmp(linkLanguage, "DEF") == 0))
  316. {
  317. std::string baseFlagVar = "CMAKE_";
  318. baseFlagVar += linkLanguage;
  319. baseFlagVar += "_FLAGS";
  320. flags = m_Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  321. std::string flagVar = baseFlagVar + "_RELEASE";
  322. flagsRelease += m_Makefile->GetRequiredDefinition(flagVar.c_str());
  323. flagVar = baseFlagVar + "_MINSIZEREL";
  324. flagsMinSize += m_Makefile->GetRequiredDefinition(flagVar.c_str());
  325. flagVar = baseFlagVar + "_DEBUG";
  326. flagsDebug += m_Makefile->GetRequiredDefinition(flagVar.c_str());
  327. flagVar = baseFlagVar + "_RELWITHDEBINFO";
  328. flagsDebugRel += m_Makefile->GetRequiredDefinition(flagVar.c_str());
  329. }
  330. }
  331. std::string programDatabase;
  332. const char* pre = "WIN32,_DEBUG,_WINDOWS";
  333. std::string debugPostfix = "";
  334. bool debug = !strcmp(configName,"Debug");
  335. if (debug && m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX"))
  336. {
  337. debugPostfix = m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  338. }
  339. // fill the flagMap for Debug, Release, MinSizeRel, and RelWithDebInfo
  340. // also set the flags, and pre-defined macros
  341. if(strcmp(configName, "Debug") == 0)
  342. {
  343. flagMap["InlineFunctionExpansion"] = "0";
  344. flagMap["Optimization"] = "0";
  345. flagMap["RuntimeLibrary"] = "3";
  346. flags += flagsDebug;
  347. pre = "WIN32,_DEBUG,_WINDOWS";
  348. std::string libpath = m_LibraryOutputPath +
  349. "$(OutDir)/" + libName + debugPostfix + ".pdb";
  350. programDatabase = "\t\t\t\tProgramDatabaseFileName=\"";
  351. programDatabase += libpath;
  352. programDatabase += "\"";
  353. }
  354. else if (strcmp(configName, "Release") == 0)
  355. {
  356. flagMap["InlineFunctionExpansion"] = "1";
  357. flagMap["Optimization"] = "2";
  358. flagMap["RuntimeLibrary"] = "2";
  359. flags += flagsRelease;
  360. pre = "WIN32,_WINDOWS";
  361. flags += flagsRelease;
  362. }
  363. else if(strcmp(configName, "MinSizeRel") == 0)
  364. {
  365. flagMap["InlineFunctionExpansion"] = "1";
  366. flagMap["Optimization"] = "1";
  367. flagMap["RuntimeLibrary"] = "2";
  368. pre = "WIN32,_WINDOWS";
  369. flags += flagsMinSize;
  370. }
  371. else if(strcmp(configName, "RelWithDebInfo") == 0)
  372. {
  373. flagMap["InlineFunctionExpansion"] = "1";
  374. flagMap["Optimization"] = "2";
  375. flagMap["RuntimeLibrary"] = "2";
  376. pre = "WIN32,_WINDOWS";
  377. flags += flagsDebugRel;
  378. std::string libpath = m_LibraryOutputPath +
  379. "$(OutDir)/" + libName + debugPostfix + ".pdb";
  380. programDatabase = "\t\t\t\tProgramDatabaseFileName=\"";
  381. programDatabase += libpath;
  382. programDatabase += "\"";
  383. }
  384. fout << "\t\t\tIntermediateDirectory=\".\\" << configName << "\"\n"
  385. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  386. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  387. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
  388. // if -D_UNICODE or /D_UNICODE is found in the flags
  389. // change the character set to unicode, if not then
  390. // default to MBCS
  391. std::string defs = m_Makefile->GetDefineFlags();
  392. if(flags.find("D_UNICODE") != flags.npos ||
  393. defs.find("D_UNICODE") != flags.npos)
  394. {
  395. fout << "\t\t\tCharacterSet=\"1\">\n";
  396. }
  397. else
  398. {
  399. fout << "\t\t\tCharacterSet=\"2\">\n";
  400. }
  401. fout << "\t\t\t<Tool\n"
  402. << "\t\t\t\tName=\"VCCLCompilerTool\"\n"
  403. << "\t\t\t\tAdditionalOptions=\"";
  404. // now fill the flagMap from the command line flags, and
  405. // if a flag is used, it will be removed from the flags string by
  406. // this function call
  407. this->FillFlagMapFromCommandFlags(flagMap,
  408. &cmLocalVisualStudio7GeneratorFlagTable[0],
  409. flags);
  410. std::string defineFlags = m_Makefile->GetDefineFlags();
  411. // now check the define flags for flags other than -D and
  412. // put them in the map, the -D flags will be left in the defineFlags
  413. // variable as -D is not in the flagMap
  414. this->FillFlagMapFromCommandFlags(flagMap,
  415. &cmLocalVisualStudio7GeneratorFlagTable[0],
  416. defineFlags);
  417. // output remaining flags that were not mapped to anything
  418. fout << this->EscapeForXML(flags.c_str()).c_str();
  419. fout << " -DCMAKE_INTDIR=\\&quot;" << configName << "\\&quot;"
  420. << "\"\n";
  421. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  422. std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
  423. std::vector<std::string>::iterator i = includes.begin();
  424. for(;i != includes.end(); ++i)
  425. {
  426. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  427. fout << ipath << ";";
  428. }
  429. fout << "\"\n";
  430. // set a few cmake specific flags
  431. if(m_Makefile->IsOn("CMAKE_CXX_USE_RTTI"))
  432. {
  433. flagMap["RuntimeTypeInfo"] = "TRUE";
  434. }
  435. if ( m_Makefile->GetDefinition("CMAKE_CXX_WARNING_LEVEL") )
  436. {
  437. flagMap["WarningLevel"] = m_Makefile->GetDefinition("CMAKE_CXX_WARNING_LEVEL");
  438. }
  439. // Now copy the flag map into the xml for the file
  440. for(std::map<cmStdString, cmStdString>::iterator m = flagMap.begin();
  441. m != flagMap.end(); ++m)
  442. {
  443. fout << "\t\t\t\t" << m->first << "=\"" << m->second << "\"\n";
  444. }
  445. fout << "\t\t\t\tPreprocessorDefinitions=\"" << pre;
  446. if(target.GetType() == cmTarget::SHARED_LIBRARY
  447. || target.GetType() == cmTarget::MODULE_LIBRARY)
  448. {
  449. std::string exportSymbol;
  450. if (const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
  451. {
  452. exportSymbol = custom_export_name;
  453. }
  454. else
  455. {
  456. std::string id = libName;
  457. id += "_EXPORTS";
  458. exportSymbol = cmSystemTools::MakeCindentifier(id.c_str());
  459. }
  460. fout << "," << exportSymbol;
  461. }
  462. this->OutputDefineFlags(defineFlags.c_str(), fout);
  463. fout << "\"\n";
  464. fout << "\t\t\t\tAssemblerListingLocation=\"" << configName << "\"\n";
  465. fout << "\t\t\t\tObjectFile=\"" << configName << "\\\"\n";
  466. if(m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  467. {
  468. fout << "\t\t\t\tSuppressStartupBanner=\"FALSE\"\n";
  469. }
  470. if(programDatabase.size())
  471. {
  472. fout << programDatabase << "\n";
  473. }
  474. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  475. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n";
  476. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"\n"
  477. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  478. for(i = includes.begin();i != includes.end(); ++i)
  479. {
  480. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  481. fout << ipath << ";";
  482. }
  483. // add the -D flags to the RC tool
  484. fout << "\"\n"
  485. << "\t\t\t\tPreprocessorDefinitions=\"" << pre;
  486. this->OutputDefineFlags(defineFlags.c_str(), fout);
  487. fout << "\" />\n";
  488. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n";
  489. this->OutputTargetRules(fout, target, libName);
  490. this->OutputBuildTool(fout, configName, libName, target);
  491. fout << "\t\t</Configuration>\n";
  492. }
  493. void cmLocalVisualStudio7Generator::FillFlagMapFromCommandFlags(
  494. std::map<cmStdString, cmStdString>& flagMap,
  495. cmVS7FlagTable* flagTable,
  496. std::string& flags)
  497. {
  498. std::string replace;
  499. std::string option;
  500. while(flagTable->IDEName)
  501. {
  502. option.reserve(strlen(flagTable->commandFlag+2));
  503. // first do the - version
  504. option.insert(static_cast<unsigned int>(0),
  505. static_cast<unsigned int>(1),
  506. '-');
  507. option.append(flagTable->commandFlag);
  508. while(flags.find(option) != flags.npos)
  509. {
  510. // replace the flag
  511. cmSystemTools::ReplaceString(flags, option.c_str(), "");
  512. // now put value into flag map
  513. flagMap[flagTable->IDEName] = flagTable->value;
  514. }
  515. // now do the / version
  516. option[0] = '/';
  517. while(flags.find(option) != flags.npos)
  518. {
  519. // replace the flag
  520. cmSystemTools::ReplaceString(flags, option.c_str(), "");
  521. // now put value into flag map
  522. flagMap[flagTable->IDEName] = flagTable->value;
  523. }
  524. // move to next flag
  525. flagTable++;
  526. }
  527. }
  528. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  529. const char* configName,
  530. const char *libName,
  531. const cmTarget &target)
  532. {
  533. std::string temp;
  534. std::string debugPostfix = "";
  535. bool debug = !strcmp(configName,"Debug");
  536. if (debug && m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX"))
  537. {
  538. debugPostfix = m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  539. }
  540. std::string extraLinkOptions;
  541. if(target.GetType() == cmTarget::EXECUTABLE)
  542. {
  543. extraLinkOptions = m_Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS");
  544. }
  545. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  546. {
  547. extraLinkOptions = m_Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS");
  548. }
  549. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  550. {
  551. extraLinkOptions = m_Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS");
  552. }
  553. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  554. if(targetLinkFlags)
  555. {
  556. extraLinkOptions += " ";
  557. extraLinkOptions += targetLinkFlags;
  558. }
  559. std::map<cmStdString, cmStdString> flagMap;
  560. this->
  561. FillFlagMapFromCommandFlags(flagMap,
  562. &cmLocalVisualStudio7GeneratorLinkFlagTable[0],
  563. extraLinkOptions);
  564. switch(target.GetType())
  565. {
  566. case cmTarget::STATIC_LIBRARY:
  567. {
  568. std::string libpath = m_LibraryOutputPath +
  569. "$(OutDir)/" + libName + debugPostfix + ".lib";
  570. fout << "\t\t\t<Tool\n"
  571. << "\t\t\t\tName=\"VCLibrarianTool\"\n";
  572. if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
  573. {
  574. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  575. }
  576. fout << "\t\t\t\tOutputFile=\""
  577. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << ".\"/>\n";
  578. break;
  579. }
  580. case cmTarget::SHARED_LIBRARY:
  581. case cmTarget::MODULE_LIBRARY:
  582. {
  583. fout << "\t\t\t<Tool\n"
  584. << "\t\t\t\tName=\"VCLinkerTool\"\n"
  585. << "\t\t\t\tAdditionalOptions=\"/MACHINE:I386";
  586. if(extraLinkOptions.size())
  587. {
  588. fout << " " << cmLocalVisualStudio7Generator::EscapeForXML(
  589. extraLinkOptions.c_str()).c_str();
  590. }
  591. fout << "\"\n"
  592. << "\t\t\t\tAdditionalDependencies=\" odbc32.lib odbccp32.lib ";
  593. this->OutputLibraries(fout, configName, libName, target);
  594. fout << "\"\n";
  595. temp = m_LibraryOutputPath;
  596. temp += configName;
  597. temp += "/";
  598. temp += libName;
  599. temp += debugPostfix;
  600. temp += ".dll";
  601. fout << "\t\t\t\tOutputFile=\""
  602. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  603. for(std::map<cmStdString, cmStdString>::iterator i = flagMap.begin();
  604. i != flagMap.end(); ++i)
  605. {
  606. fout << "\t\t\t\t" << i->first << "=\"" << i->second << "\"\n";
  607. }
  608. if(m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  609. {
  610. fout << "\t\t\t\tSuppressStartupBanner=\"FALSE\"\n";
  611. }
  612. else
  613. {
  614. fout << "\t\t\t\tSuppressStartupBanner=\"TRUE\"\n";
  615. }
  616. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  617. this->OutputLibraryDirectories(fout, configName, libName, target);
  618. fout << "\"\n";
  619. this->OutputModuleDefinitionFile(fout, target);
  620. temp = m_LibraryOutputPath;
  621. temp += "$(OutDir)/";
  622. temp += libName;
  623. temp += debugPostfix;
  624. temp += ".pdb";
  625. fout << "\t\t\t\tProgramDatabaseFile=\"" <<
  626. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  627. if(strcmp(configName, "Debug") == 0
  628. || strcmp(configName, "RelWithDebInfo") == 0)
  629. {
  630. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  631. }
  632. const char* linkLanguage = target.GetLinkerLanguage(this->GetGlobalGenerator());
  633. if(!linkLanguage)
  634. {
  635. cmSystemTools::Error("CMake can not determine linker language for target:",
  636. target.GetName());
  637. return;
  638. }
  639. std::string stackVar = "CMAKE_";
  640. stackVar += linkLanguage;
  641. stackVar += "_STACK_SIZE";
  642. const char* stackVal = m_Makefile->GetDefinition(stackVar.c_str());
  643. if(stackVal)
  644. {
  645. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  646. }
  647. temp = m_LibraryOutputPath;
  648. temp += configName;
  649. temp += "/";
  650. temp += libName;
  651. temp += debugPostfix;
  652. temp += ".lib";
  653. fout << "\t\t\t\tImportLibrary=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  654. }
  655. break;
  656. case cmTarget::EXECUTABLE:
  657. {
  658. fout << "\t\t\t<Tool\n"
  659. << "\t\t\t\tName=\"VCLinkerTool\"\n"
  660. << "\t\t\t\tAdditionalOptions=\"/MACHINE:I386";
  661. if(extraLinkOptions.size())
  662. {
  663. fout << " " << cmLocalVisualStudio7Generator::EscapeForXML(
  664. extraLinkOptions.c_str()).c_str();
  665. }
  666. fout << "\"\n"
  667. << "\t\t\t\tAdditionalDependencies=\""
  668. << m_Makefile->GetRequiredDefinition("CMAKE_STANDARD_LIBRARIES")
  669. << " ";
  670. this->OutputLibraries(fout, configName, libName, target);
  671. fout << "\"\n";
  672. temp = m_ExecutableOutputPath;
  673. temp += configName;
  674. temp += "/";
  675. temp += libName;
  676. temp += ".exe";
  677. fout << "\t\t\t\tOutputFile=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  678. for(std::map<cmStdString, cmStdString>::iterator i = flagMap.begin();
  679. i != flagMap.end(); ++i)
  680. {
  681. fout << "\t\t\t\t" << i->first << "=\"" << i->second << "\"\n";
  682. }
  683. if(m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  684. {
  685. fout << "\t\t\t\tSuppressStartupBanner=\"FALSE\"\n";
  686. }
  687. else
  688. {
  689. fout << "\t\t\t\tSuppressStartupBanner=\"TRUE\"\n";
  690. }
  691. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  692. this->OutputLibraryDirectories(fout, configName, libName, target);
  693. fout << "\"\n";
  694. fout << "\t\t\t\tProgramDatabaseFile=\"" << m_LibraryOutputPath
  695. << "$(OutDir)\\" << libName << ".pdb\"\n";
  696. if(strcmp(configName, "Debug") == 0
  697. || strcmp(configName, "RelWithDebInfo") == 0)
  698. {
  699. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  700. }
  701. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  702. {
  703. fout << "\t\t\t\tSubSystem=\"2\"\n";
  704. }
  705. else
  706. {
  707. fout << "\t\t\t\tSubSystem=\"1\"\n";
  708. }
  709. const char* linkLanguage = target.GetLinkerLanguage(this->GetGlobalGenerator());
  710. if(!linkLanguage)
  711. {
  712. cmSystemTools::Error("CMake can not determine linker language for target:",
  713. target.GetName());
  714. return;
  715. }
  716. std::string stackVar = "CMAKE_";
  717. stackVar += linkLanguage;
  718. stackVar += "_STACK_SIZE";
  719. const char* stackVal = m_Makefile->GetDefinition(stackVar.c_str());
  720. if(stackVal)
  721. {
  722. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  723. }
  724. fout << "/>\n";
  725. break;
  726. }
  727. case cmTarget::UTILITY:
  728. break;
  729. }
  730. }
  731. void cmLocalVisualStudio7Generator::OutputModuleDefinitionFile(std::ostream& fout,
  732. const cmTarget &target)
  733. {
  734. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  735. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  736. i != classes.end(); i++)
  737. {
  738. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  739. {
  740. fout << "\t\t\t\tModuleDefinitionFile=\""
  741. << this->ConvertToXMLOutputPath((*i)->GetFullPath().c_str())
  742. << "\"\n";
  743. return;
  744. }
  745. }
  746. }
  747. void cmLocalVisualStudio7Generator::OutputLibraryDirectories(std::ostream& fout,
  748. const char*,
  749. const char*,
  750. const cmTarget &tgt)
  751. {
  752. bool hasone = false;
  753. if(m_LibraryOutputPath.size())
  754. {
  755. hasone = true;
  756. std::string temp = m_LibraryOutputPath;
  757. temp += "$(INTDIR)";
  758. fout << this->ConvertToXMLOutputPath(temp.c_str()) << "," <<
  759. this->ConvertToXMLOutputPath(m_LibraryOutputPath.c_str());
  760. }
  761. if(m_ExecutableOutputPath.size() &&
  762. (m_LibraryOutputPath != m_ExecutableOutputPath))
  763. {
  764. if (hasone)
  765. {
  766. fout << ",";
  767. }
  768. hasone = true;
  769. std::string temp = m_ExecutableOutputPath;
  770. temp += "$(INTDIR)";
  771. fout << this->ConvertToXMLOutputPath(temp.c_str()) << "," <<
  772. this->ConvertToXMLOutputPath(m_ExecutableOutputPath.c_str());
  773. }
  774. std::set<std::string> pathEmitted;
  775. std::vector<std::string>::const_iterator i;
  776. const std::vector<std::string>& libdirs = tgt.GetLinkDirectories();
  777. for(i = libdirs.begin(); i != libdirs.end(); ++i)
  778. {
  779. std::string lpath = *i;
  780. if(lpath[lpath.size()-1] != '/')
  781. {
  782. lpath += "/";
  783. }
  784. if(pathEmitted.insert(lpath).second)
  785. {
  786. if(hasone)
  787. {
  788. fout << ",";
  789. }
  790. std::string lpathi = lpath + "$(INTDIR)";
  791. fout << this->ConvertToXMLOutputPath(lpathi.c_str()) << "," <<
  792. this->ConvertToXMLOutputPath(lpath.c_str());
  793. hasone = true;
  794. }
  795. }
  796. }
  797. void cmLocalVisualStudio7Generator::OutputLibraries(std::ostream& fout,
  798. const char* configName,
  799. const char* libName,
  800. const cmTarget &target)
  801. {
  802. const cmTarget::LinkLibraries& libs = target.GetLinkLibraries();
  803. cmTarget::LinkLibraries::const_iterator j;
  804. for(j = libs.begin(); j != libs.end(); ++j)
  805. {
  806. if(j->first != libName)
  807. {
  808. std::string lib = j->first;
  809. std::string debugPostfix = "";
  810. // if this is a library we are building then watch for a debugPostfix
  811. if (!strcmp(configName,"Debug"))
  812. {
  813. std::string libPath = j->first + "_CMAKE_PATH";
  814. const char* cacheValue
  815. = m_GlobalGenerator->GetCMakeInstance()->GetCacheDefinition(libPath.c_str());
  816. if(cacheValue && *cacheValue && m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX"))
  817. {
  818. debugPostfix = m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  819. }
  820. }
  821. if(j->first.find(".lib") == std::string::npos)
  822. {
  823. lib += debugPostfix + ".lib";
  824. }
  825. lib = this->ConvertToXMLOutputPath(lib.c_str());
  826. if (j->second == cmTarget::GENERAL
  827. || (j->second == cmTarget::DEBUG && strcmp(configName, "Debug") == 0)
  828. || (j->second == cmTarget::OPTIMIZED && strcmp(configName, "Debug") != 0))
  829. {
  830. fout << lib << " ";
  831. }
  832. }
  833. }
  834. }
  835. void cmLocalVisualStudio7Generator::OutputDefineFlags(const char* flags,
  836. std::ostream& fout)
  837. {
  838. std::string defs = flags;
  839. cmSystemTools::ReplaceString(defs, "/D","-D");
  840. std::string::size_type pos = defs.find("-D");
  841. bool done = pos == std::string::npos;
  842. if(!done)
  843. {
  844. fout << ",";
  845. }
  846. while(!done)
  847. {
  848. std::string::size_type nextpos = defs.find("-D", pos+2);
  849. std::string define;
  850. if(nextpos != std::string::npos)
  851. {
  852. define = defs.substr(pos+2, nextpos - pos -3);
  853. }
  854. else
  855. {
  856. define = defs.substr(pos+2);
  857. done = true;
  858. }
  859. cmSystemTools::ReplaceString(define, "\"", "&quot;");
  860. fout << define << ",";
  861. if(!done)
  862. {
  863. pos = defs.find("-D", nextpos);
  864. }
  865. }
  866. }
  867. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  868. const char *libName,
  869. cmTarget &target)
  870. {
  871. // get the configurations
  872. std::vector<std::string> *configs =
  873. static_cast<cmGlobalVisualStudio7Generator *>
  874. (m_GlobalGenerator)->GetConfigurations();
  875. // if we should add regen rule then...
  876. const char *suppRegenRule =
  877. m_Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
  878. if (!cmSystemTools::IsOn(suppRegenRule))
  879. {
  880. this->AddVCProjBuildRule();
  881. }
  882. // trace the visual studio dependencies
  883. std::string name = libName;
  884. name += ".vcproj.cmake";
  885. target.TraceVSDependencies(name, m_Makefile);
  886. // We may be modifying the source groups temporarily, so make a copy.
  887. std::vector<cmSourceGroup> sourceGroups = m_Makefile->GetSourceGroups();
  888. // get the classes from the source lists then add them to the groups
  889. std::vector<cmSourceFile*> & classes = target.GetSourceFiles();
  890. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  891. i != classes.end(); i++)
  892. {
  893. // Add the file to the list of sources.
  894. std::string source = (*i)->GetFullPath();
  895. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  896. {
  897. m_ModuleDefinitionFile = (*i)->GetFullPath();
  898. }
  899. cmSourceGroup& sourceGroup =
  900. m_Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  901. sourceGroup.AssignSource(*i);
  902. }
  903. // open the project
  904. this->WriteProjectStart(fout, libName, target, sourceGroups);
  905. // write the configuration information
  906. this->WriteConfigurations(fout, libName, target);
  907. fout << "\t<Files>\n";
  908. // Loop through every source group.
  909. for(std::vector<cmSourceGroup>::const_iterator sg = sourceGroups.begin();
  910. sg != sourceGroups.end(); ++sg)
  911. {
  912. const std::vector<const cmSourceFile *> &sourceFiles =
  913. sg->GetSourceFiles();
  914. // If the group is empty, don't write it at all.
  915. if(sourceFiles.empty())
  916. {
  917. continue;
  918. }
  919. // If the group has a name, write the header.
  920. std::string name = sg->GetName();
  921. if(name != "")
  922. {
  923. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  924. }
  925. // Loop through each source in the source group.
  926. for(std::vector<const cmSourceFile *>::const_iterator sf =
  927. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  928. {
  929. std::string source = (*sf)->GetFullPath();
  930. const cmCustomCommand *command = (*sf)->GetCustomCommand();
  931. std::string compileFlags;
  932. std::string additionalDeps;
  933. // Check for extra compiler flags.
  934. const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS");
  935. if(cflags)
  936. {
  937. compileFlags = cflags;
  938. }
  939. const char* lang =
  940. m_GlobalGenerator->GetLanguageFromExtension((*sf)->GetSourceExtension().c_str());
  941. if(lang && strcmp(lang, "CXX") == 0)
  942. {
  943. // force a C++ file type
  944. compileFlags += " /TP ";
  945. }
  946. // Check for extra object-file dependencies.
  947. const char* deps = (*sf)->GetProperty("OBJECT_DEPENDS");
  948. if(deps)
  949. {
  950. std::vector<std::string> depends;
  951. cmSystemTools::ExpandListArgument(deps, depends);
  952. if(!depends.empty())
  953. {
  954. std::vector<std::string>::iterator i = depends.begin();
  955. additionalDeps = this->ConvertToXMLOutputPath(i->c_str());
  956. for(++i;i != depends.end(); ++i)
  957. {
  958. additionalDeps += ";";
  959. additionalDeps += this->ConvertToXMLOutputPath(i->c_str());
  960. }
  961. }
  962. }
  963. if (source != libName || target.GetType() == cmTarget::UTILITY)
  964. {
  965. fout << "\t\t\t<File\n";
  966. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  967. // Tell MS-Dev what the source is. If the compiler knows how to
  968. // build it, then it will.
  969. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  970. if (command)
  971. {
  972. // Construct the entire set of commands in one string.
  973. std::string script = this->ConstructScript(command->GetCommandLines());
  974. const char* comment = command->GetComment();
  975. const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
  976. this->WriteCustomRule(fout, source.c_str(), script.c_str(),
  977. (*comment?comment:"Custom Rule"),
  978. command->GetDepends(),
  979. command->GetOutput(), flags);
  980. }
  981. else if(compileFlags.size() || additionalDeps.length())
  982. {
  983. const char* aCompilerTool = "VCCLCompilerTool";
  984. std::string ext = (*sf)->GetSourceExtension();
  985. ext = cmSystemTools::LowerCase(ext);
  986. if(ext == "idl")
  987. {
  988. aCompilerTool = "VCMIDLTool";
  989. }
  990. if(ext == "rc")
  991. {
  992. aCompilerTool = "VCResourceCompilerTool";
  993. }
  994. if(ext == "def")
  995. {
  996. aCompilerTool = "VCCustomBuildTool";
  997. }
  998. for(std::vector<std::string>::iterator i = configs->begin();
  999. i != configs->end(); ++i)
  1000. {
  1001. fout << "\t\t\t\t<FileConfiguration\n"
  1002. << "\t\t\t\t\tName=\"" << *i << "|Win32\">\n"
  1003. << "\t\t\t\t\t<Tool\n"
  1004. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1005. if(compileFlags.size())
  1006. {
  1007. fout << "\t\t\t\t\tAdditionalOptions=\""
  1008. << this->EscapeForXML(compileFlags.c_str()) << "\"\n";
  1009. }
  1010. if(additionalDeps.length())
  1011. {
  1012. fout << "\t\t\t\t\tAdditionalDependencies=\""
  1013. << additionalDeps.c_str() << "\"\n";
  1014. }
  1015. fout << "\t\t\t\t\t/>\n"
  1016. << "\t\t\t\t</FileConfiguration>\n";
  1017. }
  1018. }
  1019. fout << "\t\t\t</File>\n";
  1020. }
  1021. }
  1022. // If the group has a name, write the footer.
  1023. if(name != "")
  1024. {
  1025. this->WriteVCProjEndGroup(fout);
  1026. }
  1027. }
  1028. fout << "\t</Files>\n";
  1029. // Write the VCProj file's footer.
  1030. this->WriteVCProjFooter(fout);
  1031. }
  1032. void cmLocalVisualStudio7Generator::
  1033. WriteCustomRule(std::ostream& fout,
  1034. const char* source,
  1035. const char* command,
  1036. const char* comment,
  1037. const std::vector<std::string>& depends,
  1038. const char *output,
  1039. const char* compileFlags)
  1040. {
  1041. std::string cmd = command;
  1042. cmSystemTools::ReplaceString(cmd, "\"", "&quot;");
  1043. std::vector<std::string>::iterator i;
  1044. std::vector<std::string> *configs =
  1045. static_cast<cmGlobalVisualStudio7Generator *>(m_GlobalGenerator)->GetConfigurations();
  1046. for(i = configs->begin(); i != configs->end(); ++i)
  1047. {
  1048. fout << "\t\t\t\t<FileConfiguration\n";
  1049. fout << "\t\t\t\t\tName=\"" << *i << "|Win32\">\n";
  1050. if(compileFlags)
  1051. {
  1052. fout << "\t\t\t\t\t<Tool\n"
  1053. << "\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
  1054. << "\t\t\t\t\tAdditionalOptions=\""
  1055. << this->EscapeForXML(compileFlags) << "\"/>\n";
  1056. }
  1057. fout << "\t\t\t\t\t<Tool\n"
  1058. << "\t\t\t\t\tName=\"VCCustomBuildTool\"\n"
  1059. << "\t\t\t\t\tDescription=\"Building " << comment;
  1060. fout << " " << output;
  1061. fout << "\"\n"
  1062. << "\t\t\t\t\tCommandLine=\"" << cmd << "\n\"\n"
  1063. << "\t\t\t\t\tAdditionalDependencies=\"";
  1064. // Write out the dependencies for the rule.
  1065. std::string temp;
  1066. for(std::vector<std::string>::const_iterator d = depends.begin();
  1067. d != depends.end(); ++d)
  1068. {
  1069. std::string dep = cmSystemTools::GetFilenameName(*d);
  1070. if (cmSystemTools::GetFilenameLastExtension(dep) == ".exe")
  1071. {
  1072. dep = cmSystemTools::GetFilenameWithoutLastExtension(dep);
  1073. }
  1074. // check to see if the dependency is another target built by cmake
  1075. std::string libPath = dep + "_CMAKE_PATH";
  1076. const char* cacheValue = m_Makefile->GetDefinition(libPath.c_str());
  1077. if (cacheValue && *cacheValue)
  1078. {
  1079. std::string exePath = "";
  1080. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  1081. {
  1082. exePath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  1083. }
  1084. if(exePath.size())
  1085. {
  1086. libPath = exePath;
  1087. }
  1088. else
  1089. {
  1090. libPath = cacheValue;
  1091. }
  1092. libPath += "/";
  1093. libPath += "$(INTDIR)/";
  1094. libPath += dep;
  1095. libPath += ".exe";
  1096. fout << this->ConvertToXMLOutputPath(libPath.c_str())
  1097. << ";";
  1098. }
  1099. else
  1100. {
  1101. fout << this->ConvertToXMLOutputPath(d->c_str())
  1102. << ";";
  1103. }
  1104. }
  1105. fout << "\"\n";
  1106. fout << "\t\t\t\t\tOutputs=\"";
  1107. if(output == 0)
  1108. {
  1109. fout << source << "_force";
  1110. }
  1111. // Write a rule for the output generated by this command.
  1112. fout << this->ConvertToXMLOutputPathSingle(output);
  1113. fout << "\"/>\n";
  1114. fout << "\t\t\t\t</FileConfiguration>\n";
  1115. }
  1116. }
  1117. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1118. const char* group,
  1119. const char* )
  1120. {
  1121. fout << "\t\t<Filter\n"
  1122. << "\t\t\tName=\"" << group << "\"\n"
  1123. << "\t\t\tFilter=\"\">\n";
  1124. }
  1125. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1126. {
  1127. fout << "\t\t</Filter>\n";
  1128. }
  1129. // look for custom rules on a target and collect them together
  1130. void cmLocalVisualStudio7Generator::OutputTargetRules(std::ostream& fout,
  1131. const cmTarget &target,
  1132. const char * /* libName */)
  1133. {
  1134. if (target.GetType() > cmTarget::UTILITY)
  1135. {
  1136. return;
  1137. }
  1138. // add the pre build rules
  1139. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"";
  1140. bool init = false;
  1141. for (std::vector<cmCustomCommand>::const_iterator cr =
  1142. target.GetPreBuildCommands().begin();
  1143. cr != target.GetPreBuildCommands().end(); ++cr)
  1144. {
  1145. if(!init)
  1146. {
  1147. fout << "\nCommandLine=\"";
  1148. init = true;
  1149. }
  1150. std::string script = this->ConstructScript(cr->GetCommandLines());
  1151. fout << this->EscapeForXML(script.c_str()).c_str();
  1152. }
  1153. if (init)
  1154. {
  1155. fout << "\"";
  1156. }
  1157. fout << "/>\n";
  1158. // add the pre Link rules
  1159. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"";
  1160. init = false;
  1161. for (std::vector<cmCustomCommand>::const_iterator cr =
  1162. target.GetPreLinkCommands().begin();
  1163. cr != target.GetPreLinkCommands().end(); ++cr)
  1164. {
  1165. if(!init)
  1166. {
  1167. fout << "\nCommandLine=\"";
  1168. init = true;
  1169. }
  1170. std::string script = this->ConstructScript(cr->GetCommandLines());
  1171. fout << this->EscapeForXML(script.c_str()).c_str();
  1172. }
  1173. if (init)
  1174. {
  1175. fout << "\"";
  1176. }
  1177. fout << "/>\n";
  1178. // add the PostBuild rules
  1179. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"";
  1180. init = false;
  1181. for (std::vector<cmCustomCommand>::const_iterator cr =
  1182. target.GetPostBuildCommands().begin();
  1183. cr != target.GetPostBuildCommands().end(); ++cr)
  1184. {
  1185. if(!init)
  1186. {
  1187. fout << "\nCommandLine=\"";
  1188. init = true;
  1189. }
  1190. std::string script = this->ConstructScript(cr->GetCommandLines());
  1191. fout << this->EscapeForXML(script.c_str()).c_str();
  1192. }
  1193. if (init)
  1194. {
  1195. fout << "\"";
  1196. }
  1197. fout << "/>\n";
  1198. }
  1199. void
  1200. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  1201. const char *libName,
  1202. const cmTarget &,
  1203. std::vector<cmSourceGroup> &)
  1204. {
  1205. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1206. << "<VisualStudioProject\n"
  1207. << "\tProjectType=\"Visual C++\"\n";
  1208. if(m_Version == 71)
  1209. {
  1210. fout << "\tVersion=\"7.10\"\n";
  1211. }
  1212. else
  1213. {
  1214. if (m_Version == 8)
  1215. {
  1216. fout << "\tVersion=\"8.00\"\n";
  1217. }
  1218. else
  1219. {
  1220. fout << "\tVersion=\"7.00\"\n";
  1221. }
  1222. }
  1223. fout << "\tName=\"" << libName << "\"\n"
  1224. << "\tSccProjectName=\"\"\n"
  1225. << "\tSccLocalPath=\"\"\n"
  1226. << "\tKeyword=\"Win32Proj\">\n"
  1227. << "\t<Platforms>\n"
  1228. << "\t\t<Platform\n\t\t\tName=\"Win32\"/>\n"
  1229. << "\t</Platforms>\n";
  1230. }
  1231. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout)
  1232. {
  1233. fout << "\t<Globals>\n"
  1234. << "\t</Globals>\n"
  1235. << "</VisualStudioProject>\n";
  1236. }
  1237. std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s)
  1238. {
  1239. std::string ret = s;
  1240. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1241. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1242. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1243. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1244. return ret;
  1245. }
  1246. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPath(const char* path)
  1247. {
  1248. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  1249. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1250. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1251. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1252. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1253. return ret;
  1254. }
  1255. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPathSingle(const char* path)
  1256. {
  1257. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  1258. cmSystemTools::ReplaceString(ret, "\"", "");
  1259. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1260. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1261. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1262. return ret;
  1263. }
  1264. void cmLocalVisualStudio7Generator::ConfigureFinalPass()
  1265. {
  1266. cmLocalGenerator::ConfigureFinalPass();
  1267. cmTargets &tgts = m_Makefile->GetTargets();
  1268. cmGlobalVisualStudio7Generator* gg =
  1269. static_cast<cmGlobalVisualStudio7Generator *>(m_GlobalGenerator);
  1270. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  1271. {
  1272. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  1273. {
  1274. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  1275. const cmCustomCommandLines& cmds = cc.GetCommandLines();
  1276. std::string project_name = cmds[0][0];
  1277. gg->CreateGUID(project_name.c_str());
  1278. }
  1279. else
  1280. {
  1281. gg->CreateGUID(l->first.c_str());
  1282. }
  1283. }
  1284. }