cmLocalVisualStudio7Generator.cxx 40 KB

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