cmLocalVisualStudio7Generator.cxx 45 KB

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