1
0

cmLocalVisualStudio7Generator.cxx 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  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_Version71 = false;
  23. }
  24. cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator()
  25. {
  26. }
  27. void cmLocalVisualStudio7Generator::Generate(bool /* fromTheTop */)
  28. {
  29. this->OutputVCProjFile();
  30. }
  31. // TODO
  32. // for CommandLine= need to repleace quotes with &quot
  33. // write out configurations
  34. void cmLocalVisualStudio7Generator::OutputVCProjFile()
  35. {
  36. // If not an in source build, then create the output directory
  37. if(strcmp(m_Makefile->GetStartOutputDirectory(),
  38. m_Makefile->GetHomeDirectory()) != 0)
  39. {
  40. if(!cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory()))
  41. {
  42. cmSystemTools::Error("Error creating directory ",
  43. m_Makefile->GetStartOutputDirectory());
  44. }
  45. }
  46. m_LibraryOutputPath = "";
  47. if (m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  48. {
  49. m_LibraryOutputPath = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
  50. }
  51. if(m_LibraryOutputPath.size())
  52. {
  53. // make sure there is a trailing slash
  54. if(m_LibraryOutputPath[m_LibraryOutputPath.size()-1] != '/')
  55. {
  56. m_LibraryOutputPath += "/";
  57. }
  58. }
  59. m_ExecutableOutputPath = "";
  60. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  61. {
  62. m_ExecutableOutputPath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  63. }
  64. if(m_ExecutableOutputPath.size())
  65. {
  66. // make sure there is a trailing slash
  67. if(m_ExecutableOutputPath[m_ExecutableOutputPath.size()-1] != '/')
  68. {
  69. m_ExecutableOutputPath += "/";
  70. }
  71. }
  72. // Create the VCProj or set of VCProj's for libraries and executables
  73. // clear project names
  74. m_CreatedProjectNames.clear();
  75. // expand vars for custom commands
  76. m_Makefile->ExpandVariablesInCustomCommands();
  77. // build any targets
  78. cmTargets &tgts = m_Makefile->GetTargets();
  79. for(cmTargets::iterator l = tgts.begin();
  80. l != tgts.end(); l++)
  81. {
  82. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  83. // so don't build a projectfile for it
  84. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  85. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)
  86. && (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0))
  87. {
  88. this->CreateSingleVCProj(l->first.c_str(),l->second);
  89. }
  90. }
  91. }
  92. void cmLocalVisualStudio7Generator::CreateSingleVCProj(const char *lname, cmTarget &target)
  93. {
  94. // add to the list of projects
  95. std::string pname = lname;
  96. m_CreatedProjectNames.push_back(pname);
  97. // create the dsp.cmake file
  98. std::string fname;
  99. fname = m_Makefile->GetStartOutputDirectory();
  100. fname += "/";
  101. fname += lname;
  102. fname += ".vcproj";
  103. // save the name of the real dsp file
  104. std::string realVCProj = fname;
  105. fname += ".cmake";
  106. std::ofstream fout(fname.c_str());
  107. if(!fout)
  108. {
  109. cmSystemTools::Error("Error Writing ", fname.c_str());
  110. }
  111. this->WriteVCProjFile(fout,lname,target);
  112. fout.close();
  113. // if the dsp file has changed, then write it.
  114. cmSystemTools::CopyFileIfDifferent(fname.c_str(), realVCProj.c_str());
  115. }
  116. void cmLocalVisualStudio7Generator::AddVCProjBuildRule()
  117. {
  118. std::string dspname = *(m_CreatedProjectNames.end()-1);
  119. if(dspname == "ALL_BUILD")
  120. {
  121. return;
  122. }
  123. dspname += ".vcproj.cmake";
  124. std::string makefileIn = m_Makefile->GetStartDirectory();
  125. makefileIn += "/";
  126. makefileIn += "CMakeLists.txt";
  127. makefileIn = this->ConvertToRelativeOutputPath(makefileIn.c_str());
  128. std::string dsprule = "${CMAKE_COMMAND}";
  129. m_Makefile->ExpandVariablesInString(dsprule);
  130. dsprule = this->ConvertToRelativeOutputPath(dsprule.c_str());
  131. std::vector<std::string> argv;
  132. argv.push_back(makefileIn);
  133. makefileIn = m_Makefile->GetStartDirectory();
  134. makefileIn += "/";
  135. makefileIn += "CMakeLists.txt";
  136. std::string args;
  137. args = "-H";
  138. args +=
  139. this->ConvertToRelativeOutputPath(m_Makefile->GetHomeDirectory());
  140. argv.push_back(args);
  141. args = "-S";
  142. args +=
  143. this->ConvertToRelativeOutputPath(m_Makefile->GetStartDirectory());
  144. argv.push_back(args);
  145. args = "-O";
  146. args +=
  147. this->ConvertToRelativeOutputPath(m_Makefile->GetStartOutputDirectory());
  148. argv.push_back(args);
  149. args = "-B";
  150. args +=
  151. this->ConvertToRelativeOutputPath(m_Makefile->GetHomeOutputDirectory());
  152. argv.push_back(args);
  153. std::string configFile =
  154. m_Makefile->GetDefinition("CMAKE_ROOT");
  155. configFile += "/Templates/CMakeWindowsSystemConfig.cmake";
  156. std::vector<std::string> listFiles = m_Makefile->GetListFiles();
  157. bool found = false;
  158. for(std::vector<std::string>::iterator i = listFiles.begin();
  159. i != listFiles.end(); ++i)
  160. {
  161. if(*i == configFile)
  162. {
  163. found = true;
  164. }
  165. }
  166. if(!found)
  167. {
  168. listFiles.push_back(configFile);
  169. }
  170. m_Makefile->AddCustomCommandToOutput(dspname.c_str(), dsprule.c_str(),
  171. argv, makefileIn.c_str(), listFiles,
  172. NULL, true);
  173. }
  174. void cmLocalVisualStudio7Generator::WriteConfigurations(std::ostream& fout,
  175. const char *libName,
  176. const cmTarget &target)
  177. {
  178. std::vector<std::string> *configs =
  179. static_cast<cmGlobalVisualStudio7Generator *>(m_GlobalGenerator)->GetConfigurations();
  180. fout << "\t<Configurations>\n";
  181. for( std::vector<std::string>::iterator i = configs->begin();
  182. i != configs->end(); ++i)
  183. {
  184. this->WriteConfiguration(fout, i->c_str(), libName, target);
  185. }
  186. fout << "\t</Configurations>\n";
  187. }
  188. void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
  189. const char* configName,
  190. const char *libName,
  191. const cmTarget &target)
  192. {
  193. const char* mfcFlag = m_Makefile->GetDefinition("CMAKE_MFC_FLAG");
  194. if(!mfcFlag)
  195. {
  196. mfcFlag = "0";
  197. }
  198. fout << "\t\t<Configuration\n"
  199. << "\t\t\tName=\"" << configName << "|Win32\"\n"
  200. << "\t\t\tOutputDirectory=\"" << configName << "\"\n";
  201. // This is an internal type to Visual Studio, it seems that:
  202. // 4 == static library
  203. // 2 == dll
  204. // 1 == executable
  205. // 10 == utility
  206. const char* configType = "10";
  207. switch(target.GetType())
  208. {
  209. case cmTarget::STATIC_LIBRARY:
  210. configType = "4";
  211. break;
  212. case cmTarget::SHARED_LIBRARY:
  213. case cmTarget::MODULE_LIBRARY:
  214. configType = "2";
  215. break;
  216. case cmTarget::EXECUTABLE:
  217. case cmTarget::WIN32_EXECUTABLE:
  218. configType = "1";
  219. break;
  220. case cmTarget::UTILITY:
  221. configType = "10";
  222. default:
  223. break;
  224. }
  225. std::string flags;
  226. std::string flagsRelease = " ";
  227. std::string flagsMinSize = " ";
  228. std::string flagsDebug = " ";
  229. std::string flagsDebugRel = " ";
  230. if(target.HasCxx())
  231. {
  232. flags = m_Makefile->GetDefinition("CMAKE_CXX_FLAGS");
  233. flagsRelease += m_Makefile->GetDefinition("CMAKE_CXX_FLAGS_RELEASE");
  234. flagsMinSize += m_Makefile->GetDefinition("CMAKE_CXX_FLAGS_MINSIZEREL");
  235. flagsDebug += m_Makefile->GetDefinition("CMAKE_CXX_FLAGS_DEBUG");
  236. flagsDebugRel += m_Makefile->GetDefinition("CMAKE_CXX_FLAGS_RELWITHDEBINFO");
  237. }
  238. else
  239. {
  240. flags = m_Makefile->GetDefinition("CMAKE_C_FLAGS");
  241. flagsRelease += m_Makefile->GetDefinition("CMAKE_C_FLAGS_RELEASE");
  242. flagsMinSize += m_Makefile->GetDefinition("CMAKE_C_FLAGS_MINSIZEREL");
  243. flagsDebug += m_Makefile->GetDefinition("CMAKE_C_FLAGS_DEBUG");
  244. flagsDebugRel += m_Makefile->GetDefinition("CMAKE_C_FLAGS_RELWITHDEBINFO");
  245. }
  246. // Optimization = 0 None Debug /O0
  247. // Optimization = 1 MinSize /O1
  248. // Optimization = 2 MaxSpeed /O2
  249. // Optimization = 3 Max Optimization /O3
  250. // RuntimeLibrary = 0 /MT multithread
  251. // RuntimeLibrary = 1 /MTd multithread debug
  252. // RuntimeLibrary = 2 /MD multithread dll
  253. // RuntimeLibrary = 3 /MDd multithread dll debug
  254. // RuntimeLibrary = 4 /ML single thread
  255. // RuntimeLibrary = 5 /MLd single thread debug
  256. // InlineFunctionExpansion = 0 none
  257. // InlineFunctionExpansion = 1 when inline keyword
  258. // InlineFunctionExpansion = 2 any time you can
  259. int runtime = 0;
  260. int optimized = 0;
  261. int inlineFunctions = 0;
  262. const char* pre = "WIN32,_DEBUG,_WINDOWS";
  263. // set the flags and defaults for
  264. // runtime, optimized, and inlineFunctions , and
  265. // default pre processor flags
  266. if(strcmp(configName, "Debug") == 0)
  267. {
  268. inlineFunctions = 0;
  269. flags += flagsDebug;
  270. optimized = 0;
  271. runtime = 3;
  272. pre = "WIN32,_DEBUG,_WINDOWS";
  273. }
  274. else if (strcmp(configName, "Release") == 0)
  275. {
  276. inlineFunctions = 1;
  277. optimized =2;
  278. pre = "WIN32,NDEBUG,_WINDOWS";
  279. flags += flagsRelease;
  280. runtime = 2;
  281. }
  282. else if(strcmp(configName, "MinSizeRel") == 0)
  283. {
  284. inlineFunctions = 1;
  285. runtime = 2;
  286. optimized = 1;
  287. pre = "WIN32,NDEBUG,_WINDOWS";
  288. flags += flagsMinSize;
  289. }
  290. else if(strcmp(configName, "RelWithDebInfo") == 0)
  291. {
  292. inlineFunctions = 1;
  293. optimized = 2;
  294. runtime = 2;
  295. pre = "WIN32,NDEBUG,_WINDOWS";
  296. flags += flagsDebugRel;
  297. }
  298. fout << "\t\t\tIntermediateDirectory=\".\\" << configName << "\"\n"
  299. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  300. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  301. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
  302. // if -D_UNICODE or /D_UNICODE is found in the flags
  303. // change the character set to unicode, if not then
  304. // default to MBCS
  305. std::string defs = m_Makefile->GetDefineFlags();
  306. if(flags.find("D_UNICODE") != flags.npos ||
  307. defs.find("D_UNICODE") != flags.npos)
  308. {
  309. fout << "\t\t\tCharacterSet=\"1\">\n";
  310. }
  311. else
  312. {
  313. fout << "\t\t\tCharacterSet=\"2\">\n";
  314. }
  315. fout << "\t\t\t<Tool\n"
  316. << "\t\t\t\tName=\"VCCLCompilerTool\"\n"
  317. << "\t\t\t\tAdditionalOptions=\"";
  318. // check the flags for the run time library flag options
  319. // if there is a match set the run time flag
  320. if(flags.find("MTd") != flags.npos)
  321. {
  322. cmSystemTools::ReplaceString(flags, "-MTd", "");
  323. cmSystemTools::ReplaceString(flags, "/MTd", "");
  324. runtime = 1;
  325. }
  326. else if (flags.find("MDd") != flags.npos)
  327. {
  328. cmSystemTools::ReplaceString(flags, "-MDd", "");
  329. cmSystemTools::ReplaceString(flags, "/MDd", "");
  330. runtime = 3;
  331. }
  332. else if (flags.find("MLd") != flags.npos)
  333. {
  334. cmSystemTools::ReplaceString(flags, "-MLd", "");
  335. cmSystemTools::ReplaceString(flags, "/MLd", "");
  336. runtime = 5;
  337. }
  338. else if (flags.find("MT") != flags.npos)
  339. {
  340. cmSystemTools::ReplaceString(flags, "-MT", "");
  341. cmSystemTools::ReplaceString(flags, "/MT", "");
  342. runtime = 0;
  343. }
  344. else if (flags.find("MD") != flags.npos)
  345. {
  346. cmSystemTools::ReplaceString(flags, "-MD", "");
  347. cmSystemTools::ReplaceString(flags, "/MD", "");
  348. runtime = 2;
  349. }
  350. else if (flags.find("ML") != flags.npos)
  351. {
  352. cmSystemTools::ReplaceString(flags, "-ML", "");
  353. cmSystemTools::ReplaceString(flags, "/ML", "");
  354. runtime = 4;
  355. }
  356. int debugFormat = 0;
  357. // check the flags for the debug information format flag options
  358. if(flags.find("Z7") != flags.npos)
  359. {
  360. cmSystemTools::ReplaceString(flags, "-Z7", "");
  361. cmSystemTools::ReplaceString(flags, "/Z7", "");
  362. debugFormat = 1;
  363. }
  364. else if (flags.find("Zd") != flags.npos)
  365. {
  366. cmSystemTools::ReplaceString(flags, "-Zd", "");
  367. cmSystemTools::ReplaceString(flags, "/Zd", "");
  368. debugFormat = 2;
  369. }
  370. else if (flags.find("Zi") != flags.npos)
  371. {
  372. cmSystemTools::ReplaceString(flags, "-Zi", "");
  373. cmSystemTools::ReplaceString(flags, "/Zi", "");
  374. debugFormat = 3;
  375. }
  376. else if (flags.find("ZI") != flags.npos)
  377. {
  378. cmSystemTools::ReplaceString(flags, "-ZI", "");
  379. cmSystemTools::ReplaceString(flags, "/ZI", "");
  380. debugFormat = 4;
  381. }
  382. fout << this->EscapeForXML(flags.c_str()).c_str();
  383. fout << " -DCMAKE_INTDIR=\\&quot;" << configName << "\\&quot;"
  384. << "\"\n";
  385. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  386. std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
  387. std::vector<std::string>::iterator i = includes.begin();
  388. for(;i != includes.end(); ++i)
  389. {
  390. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  391. fout << ipath << ";";
  392. }
  393. fout << "\"\n";
  394. fout << "\t\t\t\tOptimization=\"" << optimized << "\"\n"
  395. << "\t\t\t\tRuntimeLibrary=\"" << runtime << "\"\n"
  396. << "\t\t\t\tInlineFunctionExpansion=\"" << inlineFunctions << "\"\n"
  397. << "\t\t\t\tPreprocessorDefinitions=\"" << pre;
  398. if(target.GetType() == cmTarget::SHARED_LIBRARY
  399. || target.GetType() == cmTarget::MODULE_LIBRARY)
  400. {
  401. std::string exportSymbol;
  402. if (const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
  403. {
  404. exportSymbol = custom_export_name;
  405. }
  406. else
  407. {
  408. std::string id = libName;
  409. id += "_EXPORTS";
  410. exportSymbol = cmSystemTools::MakeCindentifier(id.c_str());
  411. }
  412. fout << "," << exportSymbol;
  413. }
  414. this->OutputDefineFlags(fout);
  415. fout << "\"\n";
  416. if(m_Makefile->IsOn("CMAKE_CXX_USE_RTTI"))
  417. {
  418. fout << "\t\t\t\tRuntimeTypeInfo=\"TRUE\"\n";
  419. }
  420. fout << "\t\t\t\tAssemblerListingLocation=\"" << configName << "\"\n";
  421. fout << "\t\t\t\tObjectFile=\"" << configName << "\\\"\n";
  422. if ( m_Makefile->GetDefinition("CMAKE_CXX_WARNING_LEVEL") )
  423. {
  424. fout << "\t\t\t\tWarningLevel=\"" << m_Makefile->GetDefinition("CMAKE_CXX_WARNING_LEVEL") << "\"\n";
  425. }
  426. fout << "\t\t\t\tDebugInformationFormat=\"" << debugFormat << "\"";
  427. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  428. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n";
  429. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"\n"
  430. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  431. for(i = includes.begin();i != includes.end(); ++i)
  432. {
  433. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  434. fout << ipath << ";";
  435. }
  436. fout << "\"\n"
  437. << "\t\t\t\tPreprocessorDefinitions=\"" << pre;
  438. this->OutputDefineFlags(fout);
  439. fout << "\" />\n";
  440. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n";
  441. this->OutputTargetRules(fout, target, libName);
  442. this->OutputBuildTool(fout, configName, libName, target);
  443. fout << "\t\t</Configuration>\n";
  444. }
  445. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  446. const char* configName,
  447. const char *libName,
  448. const cmTarget &target)
  449. {
  450. std::string temp;
  451. std::string debugPostfix = "";
  452. bool debug = !strcmp(configName,"Debug");
  453. if (debug && m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX"))
  454. {
  455. debugPostfix = m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  456. }
  457. std::string extraLinkOptions;
  458. if((target.GetType() == cmTarget::EXECUTABLE) ||
  459. (target.GetType() == cmTarget::WIN32_EXECUTABLE))
  460. {
  461. extraLinkOptions = m_Makefile->GetDefinition("CMAKE_EXE_LINKER_FLAGS");
  462. }
  463. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  464. {
  465. extraLinkOptions = m_Makefile->GetDefinition("CMAKE_SHARED_LINKER_FLAGS");
  466. }
  467. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  468. {
  469. extraLinkOptions = m_Makefile->GetDefinition("CMAKE_MODULE_LINKER_FLAGS");
  470. }
  471. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  472. if(targetLinkFlags)
  473. {
  474. extraLinkOptions += " ";
  475. extraLinkOptions += targetLinkFlags;
  476. }
  477. switch(target.GetType())
  478. {
  479. case cmTarget::STATIC_LIBRARY:
  480. {
  481. std::string libpath = m_LibraryOutputPath +
  482. "$(OutDir)/" + libName + debugPostfix + ".lib";
  483. fout << "\t\t\t<Tool\n"
  484. << "\t\t\t\tName=\"VCLibrarianTool\"\n"
  485. << "\t\t\t\t\tOutputFile=\""
  486. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << ".\"/>\n";
  487. break;
  488. }
  489. case cmTarget::SHARED_LIBRARY:
  490. case cmTarget::MODULE_LIBRARY:
  491. fout << "\t\t\t<Tool\n"
  492. << "\t\t\t\tName=\"VCLinkerTool\"\n"
  493. << "\t\t\t\tAdditionalOptions=\"/MACHINE:I386";
  494. if(extraLinkOptions.size())
  495. {
  496. fout << " " << cmLocalVisualStudio7Generator::EscapeForXML(
  497. extraLinkOptions.c_str()).c_str();
  498. }
  499. fout << "\"\n"
  500. << "\t\t\t\tAdditionalDependencies=\" odbc32.lib odbccp32.lib ";
  501. this->OutputLibraries(fout, configName, libName, target);
  502. fout << "\"\n";
  503. temp = m_LibraryOutputPath;
  504. temp += configName;
  505. temp += "/";
  506. temp += libName;
  507. temp += debugPostfix;
  508. temp += ".dll";
  509. fout << "\t\t\t\tOutputFile=\""
  510. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  511. fout << "\t\t\t\tLinkIncremental=\"1\"\n";
  512. fout << "\t\t\t\tSuppressStartupBanner=\"TRUE\"\n";
  513. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  514. this->OutputLibraryDirectories(fout, configName, libName, target);
  515. fout << "\"\n";
  516. this->OutputModuleDefinitionFile(fout, target);
  517. temp = m_LibraryOutputPath;
  518. temp += "$(OutDir)/";
  519. temp += libName;
  520. temp += debugPostfix;
  521. temp += ".pdb";
  522. fout << "\t\t\t\tProgramDatabaseFile=\"" <<
  523. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  524. if(strcmp(configName, "Debug") == 0
  525. || strcmp(configName, "RelWithDebInfo") == 0)
  526. {
  527. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  528. }
  529. fout << "\t\t\t\tStackReserveSize=\""
  530. << m_Makefile->GetDefinition("CMAKE_CXX_STACK_SIZE") << "\"\n";
  531. temp = m_LibraryOutputPath;
  532. temp += configName;
  533. temp += "/";
  534. temp += libName;
  535. temp += debugPostfix;
  536. temp += ".lib";
  537. fout << "\t\t\t\tImportLibrary=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  538. break;
  539. case cmTarget::EXECUTABLE:
  540. case cmTarget::WIN32_EXECUTABLE:
  541. fout << "\t\t\t<Tool\n"
  542. << "\t\t\t\tName=\"VCLinkerTool\"\n"
  543. << "\t\t\t\tAdditionalOptions=\"/MACHINE:I386";
  544. if(extraLinkOptions.size())
  545. {
  546. fout << " " << cmLocalVisualStudio7Generator::EscapeForXML(
  547. extraLinkOptions.c_str()).c_str();
  548. }
  549. fout << "\"\n"
  550. << "\t\t\t\tAdditionalDependencies=\" odbc32.lib odbccp32.lib ";
  551. this->OutputLibraries(fout, configName, libName, target);
  552. fout << "\"\n";
  553. temp = m_ExecutableOutputPath;
  554. temp += configName;
  555. temp += "/";
  556. temp += libName;
  557. temp += ".exe";
  558. fout << "\t\t\t\tOutputFile=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  559. fout << "\t\t\t\tLinkIncremental=\"1\"\n";
  560. fout << "\t\t\t\tSuppressStartupBanner=\"TRUE\"\n";
  561. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  562. this->OutputLibraryDirectories(fout, configName, libName, target);
  563. fout << "\"\n";
  564. fout << "\t\t\t\tProgramDatabaseFile=\"" << m_LibraryOutputPath
  565. << "$(OutDir)\\" << libName << ".pdb\"\n";
  566. if(strcmp(configName, "Debug") == 0
  567. || strcmp(configName, "RelWithDebInfo") == 0)
  568. {
  569. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  570. }
  571. if( target.GetType() == cmTarget::EXECUTABLE)
  572. {
  573. fout << "\t\t\t\tSubSystem=\"1\"\n";
  574. }
  575. else
  576. {
  577. fout << "\t\t\t\tSubSystem=\"2\"\n";
  578. }
  579. fout << "\t\t\t\tStackReserveSize=\""
  580. << m_Makefile->GetDefinition("CMAKE_CXX_STACK_SIZE") << "\"/>\n";
  581. break;
  582. case cmTarget::UTILITY:
  583. break;
  584. }
  585. }
  586. void cmLocalVisualStudio7Generator::OutputModuleDefinitionFile(std::ostream& fout,
  587. const cmTarget &target)
  588. {
  589. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  590. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  591. i != classes.end(); i++)
  592. {
  593. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  594. {
  595. fout << "\t\t\t\tModuleDefinitionFile=\""
  596. << this->ConvertToXMLOutputPath((*i)->GetFullPath().c_str())
  597. << "\"\n";
  598. return;
  599. }
  600. }
  601. }
  602. void cmLocalVisualStudio7Generator::OutputLibraryDirectories(std::ostream& fout,
  603. const char*,
  604. const char*,
  605. const cmTarget &tgt)
  606. {
  607. bool hasone = false;
  608. if(m_LibraryOutputPath.size())
  609. {
  610. hasone = true;
  611. std::string temp = m_LibraryOutputPath;
  612. temp += "$(INTDIR)";
  613. fout << this->ConvertToXMLOutputPath(temp.c_str()) << "," <<
  614. this->ConvertToXMLOutputPath(m_LibraryOutputPath.c_str());
  615. }
  616. if(m_ExecutableOutputPath.size() &&
  617. (m_LibraryOutputPath != m_ExecutableOutputPath))
  618. {
  619. if (hasone)
  620. {
  621. fout << ",";
  622. }
  623. hasone = true;
  624. std::string temp = m_ExecutableOutputPath;
  625. temp += "$(INTDIR)";
  626. fout << this->ConvertToXMLOutputPath(temp.c_str()) << "," <<
  627. this->ConvertToXMLOutputPath(m_ExecutableOutputPath.c_str());
  628. }
  629. std::set<std::string> pathEmitted;
  630. std::vector<std::string>::const_iterator i;
  631. const std::vector<std::string>& libdirs = tgt.GetLinkDirectories();
  632. for(i = libdirs.begin(); i != libdirs.end(); ++i)
  633. {
  634. std::string lpath = *i;
  635. if(lpath[lpath.size()-1] != '/')
  636. {
  637. lpath += "/";
  638. }
  639. if(pathEmitted.insert(lpath).second)
  640. {
  641. if(hasone)
  642. {
  643. fout << ",";
  644. }
  645. std::string lpathi = lpath + "$(INTDIR)";
  646. fout << this->ConvertToXMLOutputPath(lpathi.c_str()) << "," <<
  647. this->ConvertToXMLOutputPath(lpath.c_str());
  648. hasone = true;
  649. }
  650. }
  651. }
  652. void cmLocalVisualStudio7Generator::OutputLibraries(std::ostream& fout,
  653. const char* configName,
  654. const char* libName,
  655. const cmTarget &target)
  656. {
  657. const cmTarget::LinkLibraries& libs = target.GetLinkLibraries();
  658. cmTarget::LinkLibraries::const_iterator j;
  659. for(j = libs.begin(); j != libs.end(); ++j)
  660. {
  661. if(j->first != libName)
  662. {
  663. std::string lib = j->first;
  664. std::string debugPostfix = "";
  665. // if this is a library we are building then watch for a debugPostfix
  666. if (!strcmp(configName,"Debug"))
  667. {
  668. std::string libPath = j->first + "_CMAKE_PATH";
  669. const char* cacheValue
  670. = m_GlobalGenerator->GetCMakeInstance()->GetCacheDefinition(libPath.c_str());
  671. if(cacheValue && *cacheValue && m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX"))
  672. {
  673. debugPostfix = m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  674. }
  675. }
  676. if(j->first.find(".lib") == std::string::npos)
  677. {
  678. lib += debugPostfix + ".lib";
  679. }
  680. lib = this->ConvertToXMLOutputPath(lib.c_str());
  681. if (j->second == cmTarget::GENERAL
  682. || (j->second == cmTarget::DEBUG && strcmp(configName, "Debug") == 0)
  683. || (j->second == cmTarget::OPTIMIZED && strcmp(configName, "Debug") != 0))
  684. {
  685. fout << lib << " ";
  686. }
  687. }
  688. }
  689. }
  690. void cmLocalVisualStudio7Generator::OutputDefineFlags(std::ostream& fout)
  691. {
  692. std::string defs = m_Makefile->GetDefineFlags();
  693. cmSystemTools::ReplaceString(defs, "/D","-D");
  694. std::string::size_type pos = defs.find("-D");
  695. bool done = pos == std::string::npos;
  696. if(!done)
  697. {
  698. fout << ",";
  699. }
  700. while(!done)
  701. {
  702. std::string::size_type nextpos = defs.find("-D", pos+2);
  703. std::string define;
  704. if(nextpos != std::string::npos)
  705. {
  706. define = defs.substr(pos+2, nextpos - pos -3);
  707. }
  708. else
  709. {
  710. define = defs.substr(pos+2);
  711. done = true;
  712. }
  713. cmSystemTools::ReplaceString(define, "\"", "&quot;");
  714. fout << define << ",";
  715. if(!done)
  716. {
  717. pos = defs.find("-D", nextpos);
  718. }
  719. }
  720. }
  721. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  722. const char *libName,
  723. cmTarget &target)
  724. {
  725. // get the configurations
  726. std::vector<std::string> *configs =
  727. static_cast<cmGlobalVisualStudio7Generator *>
  728. (m_GlobalGenerator)->GetConfigurations();
  729. // if we should add regen rule then...
  730. const char *suppRegenRule =
  731. m_Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
  732. if (!cmSystemTools::IsOn(suppRegenRule))
  733. {
  734. this->AddVCProjBuildRule();
  735. }
  736. // trace the visual studio dependencies
  737. std::string name = libName;
  738. name += ".vcproj.cmake";
  739. target.TraceVSDependencies(name, m_Makefile);
  740. // We may be modifying the source groups temporarily, so make a copy.
  741. std::vector<cmSourceGroup> sourceGroups = m_Makefile->GetSourceGroups();
  742. // get the classes from the source lists then add them to the groups
  743. std::vector<cmSourceFile*> & classes = target.GetSourceFiles();
  744. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  745. i != classes.end(); i++)
  746. {
  747. // Add the file to the list of sources.
  748. std::string source = (*i)->GetFullPath();
  749. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  750. {
  751. m_ModuleDefinitionFile = (*i)->GetFullPath();
  752. }
  753. cmSourceGroup& sourceGroup =
  754. m_Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  755. sourceGroup.AssignSource(*i);
  756. }
  757. // open the project
  758. this->WriteProjectStart(fout, libName, target, sourceGroups);
  759. // write the configuration information
  760. this->WriteConfigurations(fout, libName, target);
  761. fout << "\t<Files>\n";
  762. // Loop through every source group.
  763. for(std::vector<cmSourceGroup>::const_iterator sg = sourceGroups.begin();
  764. sg != sourceGroups.end(); ++sg)
  765. {
  766. const std::vector<const cmSourceFile *> &sourceFiles =
  767. sg->GetSourceFiles();
  768. // If the group is empty, don't write it at all.
  769. if(sourceFiles.empty())
  770. {
  771. continue;
  772. }
  773. // If the group has a name, write the header.
  774. std::string name = sg->GetName();
  775. if(name != "")
  776. {
  777. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  778. }
  779. // Loop through each source in the source group.
  780. for(std::vector<const cmSourceFile *>::const_iterator sf =
  781. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  782. {
  783. std::string source = (*sf)->GetFullPath();
  784. const cmCustomCommand *command = (*sf)->GetCustomCommand();
  785. std::string compileFlags;
  786. std::string additionalDeps;
  787. // Check for extra compiler flags.
  788. const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS");
  789. if(cflags)
  790. {
  791. compileFlags = cflags;
  792. }
  793. if(cmSystemTools::GetFileFormat((*sf)->GetSourceExtension().c_str())
  794. == cmSystemTools::CXX_FILE_FORMAT)
  795. {
  796. // force a C++ file type
  797. compileFlags += " /TP ";
  798. }
  799. // Check for extra object-file dependencies.
  800. const char* deps = (*sf)->GetProperty("OBJECT_DEPENDS");
  801. if(deps)
  802. {
  803. std::vector<std::string> depends;
  804. cmSystemTools::ExpandListArgument(deps, depends);
  805. if(!depends.empty())
  806. {
  807. std::vector<std::string>::iterator i = depends.begin();
  808. additionalDeps = this->ConvertToXMLOutputPath(i->c_str());
  809. for(++i;i != depends.end(); ++i)
  810. {
  811. additionalDeps += ";";
  812. additionalDeps += this->ConvertToXMLOutputPath(i->c_str());
  813. }
  814. }
  815. }
  816. if (source != libName || target.GetType() == cmTarget::UTILITY)
  817. {
  818. fout << "\t\t\t<File\n";
  819. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  820. // Tell MS-Dev what the source is. If the compiler knows how to
  821. // build it, then it will.
  822. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  823. if (command)
  824. {
  825. std::string totalCommandStr;
  826. totalCommandStr =
  827. this->ConvertToRelativeOutputPath(command->GetCommand().c_str());
  828. totalCommandStr += " ";
  829. totalCommandStr += command->GetArguments();
  830. totalCommandStr += "\n";
  831. const char* comment = command->GetComment().c_str();
  832. const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
  833. this->WriteCustomRule(fout, source.c_str(), totalCommandStr.c_str(),
  834. (*comment?comment:"Custom Rule"),
  835. command->GetDepends(),
  836. command->GetOutput().c_str(), flags);
  837. }
  838. else if(compileFlags.size() || additionalDeps.length())
  839. {
  840. const char* aCompilerTool = "VCCLCompilerTool";
  841. if((*sf)->GetSourceExtension() == "idl")
  842. {
  843. aCompilerTool = "VCMIDLTool";
  844. }
  845. for(std::vector<std::string>::iterator i = configs->begin();
  846. i != configs->end(); ++i)
  847. {
  848. fout << "\t\t\t\t<FileConfiguration\n"
  849. << "\t\t\t\t\tName=\"" << *i << "|Win32\">\n"
  850. << "\t\t\t\t\t<Tool\n"
  851. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  852. if(compileFlags.size())
  853. {
  854. fout << "\t\t\t\t\tAdditionalOptions=\""
  855. << this->EscapeForXML(compileFlags.c_str()) << "\"\n";
  856. }
  857. if(additionalDeps.length())
  858. {
  859. fout << "\t\t\t\t\tAdditionalDependencies=\""
  860. << additionalDeps.c_str() << "\"\n";
  861. }
  862. fout << "\t\t\t\t\t/>\n"
  863. << "\t\t\t\t</FileConfiguration>\n";
  864. }
  865. }
  866. fout << "\t\t\t</File>\n";
  867. }
  868. }
  869. // If the group has a name, write the footer.
  870. if(name != "")
  871. {
  872. this->WriteVCProjEndGroup(fout);
  873. }
  874. }
  875. fout << "\t</Files>\n";
  876. // Write the VCProj file's footer.
  877. this->WriteVCProjFooter(fout);
  878. }
  879. void cmLocalVisualStudio7Generator::
  880. WriteCustomRule(std::ostream& fout,
  881. const char* source,
  882. const char* command,
  883. const char* comment,
  884. const std::vector<std::string>& depends,
  885. const char *output,
  886. const char* compileFlags)
  887. {
  888. std::string cmd = command;
  889. cmSystemTools::ReplaceString(cmd, "\"", "&quot;");
  890. std::vector<std::string>::iterator i;
  891. std::vector<std::string> *configs =
  892. static_cast<cmGlobalVisualStudio7Generator *>(m_GlobalGenerator)->GetConfigurations();
  893. for(i = configs->begin(); i != configs->end(); ++i)
  894. {
  895. fout << "\t\t\t\t<FileConfiguration\n";
  896. fout << "\t\t\t\t\tName=\"" << *i << "|Win32\">\n";
  897. if(compileFlags)
  898. {
  899. fout << "\t\t\t\t\t<Tool\n"
  900. << "\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
  901. << "\t\t\t\t\tAdditionalOptions=\""
  902. << this->EscapeForXML(compileFlags) << "\"/>\n";
  903. }
  904. fout << "\t\t\t\t\t<Tool\n"
  905. << "\t\t\t\t\tName=\"VCCustomBuildTool\"\n"
  906. << "\t\t\t\t\tDescription=\"Building " << comment;
  907. fout << " " << output;
  908. fout << "\"\n"
  909. << "\t\t\t\t\tCommandLine=\"" << cmd << "\n\"\n"
  910. << "\t\t\t\t\tAdditionalDependencies=\"";
  911. // Write out the dependencies for the rule.
  912. std::string temp;
  913. for(std::vector<std::string>::const_iterator d = depends.begin();
  914. d != depends.end(); ++d)
  915. {
  916. std::string dep = cmSystemTools::GetFilenameName(*d);
  917. if (cmSystemTools::GetFilenameLastExtension(dep) == ".exe")
  918. {
  919. dep = cmSystemTools::GetFilenameWithoutLastExtension(dep);
  920. }
  921. std::string libPath = dep + "_CMAKE_PATH";
  922. const char* cacheValue = m_Makefile->GetDefinition(libPath.c_str());
  923. if (cacheValue && *cacheValue)
  924. {
  925. std::string exePath = "";
  926. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  927. {
  928. exePath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  929. }
  930. if(exePath.size())
  931. {
  932. libPath = exePath;
  933. }
  934. else
  935. {
  936. libPath = cacheValue;
  937. }
  938. libPath += "/";
  939. libPath += "$(INTDIR)";
  940. libPath += dep;
  941. libPath += ".exe";
  942. fout << this->ConvertToXMLOutputPath(libPath.c_str())
  943. << ";";
  944. }
  945. else
  946. {
  947. fout << this->ConvertToXMLOutputPath(d->c_str())
  948. << ";";
  949. }
  950. }
  951. fout << "\"\n";
  952. fout << "\t\t\t\t\tOutputs=\"";
  953. if(output == 0)
  954. {
  955. fout << source << "_force";
  956. }
  957. // Write a rule for the output generated by this command.
  958. fout << this->ConvertToXMLOutputPathSingle(output);
  959. fout << "\"/>\n";
  960. fout << "\t\t\t\t</FileConfiguration>\n";
  961. }
  962. }
  963. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  964. const char* group,
  965. const char* )
  966. {
  967. fout << "\t\t<Filter\n"
  968. << "\t\t\tName=\"" << group << "\"\n"
  969. << "\t\t\tFilter=\"\">\n";
  970. }
  971. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  972. {
  973. fout << "\t\t</Filter>\n";
  974. }
  975. // look for custom rules on a target and collect them together
  976. void cmLocalVisualStudio7Generator::OutputTargetRules(std::ostream& fout,
  977. const cmTarget &target,
  978. const char * /* libName */)
  979. {
  980. if (target.GetType() > cmTarget::UTILITY)
  981. {
  982. return;
  983. }
  984. // add the pre build rules
  985. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"";
  986. bool init = false;
  987. for (std::vector<cmCustomCommand>::const_iterator cr =
  988. target.GetPreBuildCommands().begin();
  989. cr != target.GetPreBuildCommands().end(); ++cr)
  990. {
  991. cmCustomCommand cc(*cr);
  992. cc.ExpandVariables(*m_Makefile);
  993. if(!init)
  994. {
  995. fout << "\nCommandLine=\"";
  996. init = true;
  997. }
  998. std::string args = cc.GetArguments();
  999. cmSystemTools::ReplaceString(args, "\"", "&quot;");
  1000. fout << this->ConvertToXMLOutputPath(cc.GetCommand().c_str()) << " " <<
  1001. args << "\n";
  1002. }
  1003. if (init)
  1004. {
  1005. fout << "\"";
  1006. }
  1007. fout << "/>\n";
  1008. // add the pre Link rules
  1009. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"";
  1010. init = false;
  1011. for (std::vector<cmCustomCommand>::const_iterator cr =
  1012. target.GetPreLinkCommands().begin();
  1013. cr != target.GetPreLinkCommands().end(); ++cr)
  1014. {
  1015. cmCustomCommand cc(*cr);
  1016. cc.ExpandVariables(*m_Makefile);
  1017. if(!init)
  1018. {
  1019. fout << "\nCommandLine=\"";
  1020. init = true;
  1021. }
  1022. std::string args = cc.GetArguments();
  1023. cmSystemTools::ReplaceString(args, "\"", "&quot;");
  1024. fout << this->ConvertToXMLOutputPath(cc.GetCommand().c_str()) << " " <<
  1025. args << "\n";
  1026. }
  1027. if (init)
  1028. {
  1029. fout << "\"";
  1030. }
  1031. fout << "/>\n";
  1032. // add the PostBuild rules
  1033. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"";
  1034. init = false;
  1035. for (std::vector<cmCustomCommand>::const_iterator cr =
  1036. target.GetPostBuildCommands().begin();
  1037. cr != target.GetPostBuildCommands().end(); ++cr)
  1038. {
  1039. cmCustomCommand cc(*cr);
  1040. cc.ExpandVariables(*m_Makefile);
  1041. if(!init)
  1042. {
  1043. fout << "\nCommandLine=\"";
  1044. init = true;
  1045. }
  1046. std::string args = cc.GetArguments();
  1047. cmSystemTools::ReplaceString(args, "\"", "&quot;");
  1048. fout << this->ConvertToXMLOutputPath(cc.GetCommand().c_str()) << " " <<
  1049. args << "\n";
  1050. }
  1051. if (init)
  1052. {
  1053. fout << "\"";
  1054. }
  1055. fout << "/>\n";
  1056. }
  1057. void
  1058. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  1059. const char *libName,
  1060. const cmTarget &,
  1061. std::vector<cmSourceGroup> &)
  1062. {
  1063. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1064. << "<VisualStudioProject\n"
  1065. << "\tProjectType=\"Visual C++\"\n";
  1066. if(m_Version71)
  1067. {
  1068. fout << "\tVersion=\"7.10\"\n";
  1069. }
  1070. else
  1071. {
  1072. fout << "\tVersion=\"7.00\"\n";
  1073. }
  1074. fout << "\tName=\"" << libName << "\"\n"
  1075. << "\tSccProjectName=\"\"\n"
  1076. << "\tSccLocalPath=\"\"\n"
  1077. << "\tKeyword=\"Win32Proj\">\n"
  1078. << "\t<Platforms>\n"
  1079. << "\t\t<Platform\n\t\t\tName=\"Win32\"/>\n"
  1080. << "\t</Platforms>\n";
  1081. }
  1082. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout)
  1083. {
  1084. fout << "\t<Globals>\n"
  1085. << "\t</Globals>\n"
  1086. << "</VisualStudioProject>\n";
  1087. }
  1088. std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s)
  1089. {
  1090. std::string ret = s;
  1091. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1092. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1093. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1094. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1095. return ret;
  1096. }
  1097. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPath(const char* path)
  1098. {
  1099. std::string ret = this->ConvertToRelativeOutputPath(path);
  1100. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1101. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1102. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1103. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1104. return ret;
  1105. }
  1106. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPathSingle(const char* path)
  1107. {
  1108. std::string ret = this->ConvertToRelativeOutputPath(path);
  1109. cmSystemTools::ReplaceString(ret, "\"", "");
  1110. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1111. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1112. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1113. return ret;
  1114. }