1
0

cmLocalVisualStudio7Generator.cxx 44 KB

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