1
0

cmLocalVisualStudio7Generator.cxx 39 KB

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