cmLocalVisualStudio7Generator.cxx 46 KB

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