cmLocalVisualStudio7Generator.cxx 45 KB

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