cmLocalVisualStudio7Generator.cxx 45 KB

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