cmLocalVisualStudio7Generator.cxx 46 KB

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