cmLocalVisualStudio7Generator.cxx 46 KB

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