cmLocalVisualStudio7Generator.cxx 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  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
  257. // Debug, Release, etc,
  258. // Then parse the command line flags specified in CMAKE_CXX_FLAGS
  259. // and CMAKE_C_FLAGS
  260. // and overwrite or add new values to this map
  261. std::map<cmStdString, cmStdString> flagMap;
  262. // since the default is on for this, but if /EHsc is found
  263. // in the flags it will be turned on and we have /EHSC on by
  264. // default in the CXX flags, then this is the only way to turn this off
  265. flagMap["ExceptionHandling"] = "FALSE";
  266. const char* mfcFlag = m_Makefile->GetDefinition("CMAKE_MFC_FLAG");
  267. if(!mfcFlag)
  268. {
  269. mfcFlag = "0";
  270. }
  271. fout << "\t\t<Configuration\n"
  272. << "\t\t\tName=\"" << configName << "|Win32\"\n"
  273. << "\t\t\tOutputDirectory=\"" << configName << "\"\n";
  274. // This is an internal type to Visual Studio, it seems that:
  275. // 4 == static library
  276. // 2 == dll
  277. // 1 == executable
  278. // 10 == utility
  279. const char* configType = "10";
  280. switch(target.GetType())
  281. {
  282. case cmTarget::STATIC_LIBRARY:
  283. configType = "4";
  284. break;
  285. case cmTarget::SHARED_LIBRARY:
  286. case cmTarget::MODULE_LIBRARY:
  287. configType = "2";
  288. break;
  289. case cmTarget::EXECUTABLE:
  290. configType = "1";
  291. break;
  292. case cmTarget::UTILITY:
  293. configType = "10";
  294. default:
  295. break;
  296. }
  297. std::string flags;
  298. std::string flagsRelease = " ";
  299. std::string flagsMinSize = " ";
  300. std::string flagsDebug = " ";
  301. std::string flagsDebugRel = " ";
  302. if(strcmp(configType, "10") != 0)
  303. {
  304. const char* linkLanguage = target.GetLinkerLanguage(this->GetGlobalGenerator());
  305. if(!linkLanguage)
  306. {
  307. cmSystemTools::Error("CMake can not determine linker language for target:",
  308. target.GetName());
  309. return;
  310. }
  311. std::string baseFlagVar = "CMAKE_";
  312. baseFlagVar += linkLanguage;
  313. baseFlagVar += "_FLAGS";
  314. flags = m_Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  315. std::string flagVar = baseFlagVar + "_RELEASE";
  316. flagsRelease += m_Makefile->GetRequiredDefinition(flagVar.c_str());
  317. flagVar = baseFlagVar + "_MINSIZEREL";
  318. flagsMinSize += m_Makefile->GetRequiredDefinition(flagVar.c_str());
  319. flagVar = baseFlagVar + "_DEBUG";
  320. flagsDebug += m_Makefile->GetRequiredDefinition(flagVar.c_str());
  321. flagVar = baseFlagVar + "_RELWITHDEBINFO";
  322. flagsDebugRel += m_Makefile->GetRequiredDefinition(flagVar.c_str());
  323. }
  324. std::string programDatabase;
  325. const char* pre = "WIN32,_DEBUG,_WINDOWS";
  326. std::string debugPostfix = "";
  327. bool debug = !strcmp(configName,"Debug");
  328. if (debug && m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX"))
  329. {
  330. debugPostfix = m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  331. }
  332. // fill the flagMap for Debug, Release, MinSizeRel, and RelWithDebInfo
  333. // also set the flags, and pre-defined macros
  334. if(strcmp(configName, "Debug") == 0)
  335. {
  336. flagMap["InlineFunctionExpansion"] = "0";
  337. flagMap["Optimization"] = "0";
  338. flagMap["RuntimeLibrary"] = "3";
  339. flags += flagsDebug;
  340. pre = "WIN32,_DEBUG,_WINDOWS";
  341. std::string libpath = m_LibraryOutputPath +
  342. "$(OutDir)/" + libName + debugPostfix + ".pdb";
  343. programDatabase = "\t\t\t\tProgramDatabaseFileName=\"";
  344. programDatabase += libpath;
  345. programDatabase += "\"";
  346. }
  347. else if (strcmp(configName, "Release") == 0)
  348. {
  349. flagMap["InlineFunctionExpansion"] = "1";
  350. flagMap["Optimization"] = "2";
  351. flagMap["RuntimeLibrary"] = "2";
  352. flags += flagsRelease;
  353. pre = "WIN32,_WINDOWS";
  354. flags += flagsRelease;
  355. }
  356. else if(strcmp(configName, "MinSizeRel") == 0)
  357. {
  358. flagMap["InlineFunctionExpansion"] = "1";
  359. flagMap["Optimization"] = "1";
  360. flagMap["RuntimeLibrary"] = "2";
  361. pre = "WIN32,_WINDOWS";
  362. flags += flagsMinSize;
  363. }
  364. else if(strcmp(configName, "RelWithDebInfo") == 0)
  365. {
  366. flagMap["InlineFunctionExpansion"] = "1";
  367. flagMap["Optimization"] = "2";
  368. flagMap["RuntimeLibrary"] = "2";
  369. pre = "WIN32,_WINDOWS";
  370. flags += flagsDebugRel;
  371. std::string libpath = m_LibraryOutputPath +
  372. "$(OutDir)/" + libName + debugPostfix + ".pdb";
  373. programDatabase = "\t\t\t\tProgramDatabaseFileName=\"";
  374. programDatabase += libpath;
  375. programDatabase += "\"";
  376. }
  377. fout << "\t\t\tIntermediateDirectory=\".\\" << configName << "\"\n"
  378. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  379. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  380. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
  381. // if -D_UNICODE or /D_UNICODE is found in the flags
  382. // change the character set to unicode, if not then
  383. // default to MBCS
  384. std::string defs = m_Makefile->GetDefineFlags();
  385. if(flags.find("D_UNICODE") != flags.npos ||
  386. defs.find("D_UNICODE") != flags.npos)
  387. {
  388. fout << "\t\t\tCharacterSet=\"1\">\n";
  389. }
  390. else
  391. {
  392. fout << "\t\t\tCharacterSet=\"2\">\n";
  393. }
  394. fout << "\t\t\t<Tool\n"
  395. << "\t\t\t\tName=\"VCCLCompilerTool\"\n"
  396. << "\t\t\t\tAdditionalOptions=\"";
  397. // now fill the flagMap from the command line flags, and
  398. // if a flag is used, it will be removed from the flags string by
  399. // this function call
  400. this->FillFlagMapFromCommandFlags(flagMap,
  401. &cmLocalVisualStudio7GeneratorFlagTable[0],
  402. flags);
  403. std::string defineFlags = m_Makefile->GetDefineFlags();
  404. // now check the define flags for flags other than -D and
  405. // put them in the map, the -D flags will be left in the defineFlags
  406. // variable as -D is not in the flagMap
  407. this->FillFlagMapFromCommandFlags(flagMap,
  408. &cmLocalVisualStudio7GeneratorFlagTable[0],
  409. defineFlags);
  410. // output remaining flags that were not mapped to anything
  411. fout << this->EscapeForXML(flags.c_str()).c_str();
  412. fout << " -DCMAKE_INTDIR=\\&quot;" << configName << "\\&quot;"
  413. << "\"\n";
  414. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  415. std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
  416. std::vector<std::string>::iterator i = includes.begin();
  417. for(;i != includes.end(); ++i)
  418. {
  419. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  420. fout << ipath << ";";
  421. }
  422. fout << "\"\n";
  423. // set a few cmake specific flags
  424. if(m_Makefile->IsOn("CMAKE_CXX_USE_RTTI"))
  425. {
  426. flagMap["RuntimeTypeInfo"] = "TRUE";
  427. }
  428. if ( m_Makefile->GetDefinition("CMAKE_CXX_WARNING_LEVEL") )
  429. {
  430. flagMap["WarningLevel"] = m_Makefile->GetDefinition("CMAKE_CXX_WARNING_LEVEL");
  431. }
  432. // Now copy the flag map into the xml for the file
  433. for(std::map<cmStdString, cmStdString>::iterator m = flagMap.begin();
  434. m != flagMap.end(); ++m)
  435. {
  436. fout << "\t\t\t\t" << m->first << "=\"" << m->second << "\"\n";
  437. }
  438. fout << "\t\t\t\tPreprocessorDefinitions=\"" << pre;
  439. if(target.GetType() == cmTarget::SHARED_LIBRARY
  440. || target.GetType() == cmTarget::MODULE_LIBRARY)
  441. {
  442. std::string exportSymbol;
  443. if (const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
  444. {
  445. exportSymbol = custom_export_name;
  446. }
  447. else
  448. {
  449. std::string id = libName;
  450. id += "_EXPORTS";
  451. exportSymbol = cmSystemTools::MakeCindentifier(id.c_str());
  452. }
  453. fout << "," << exportSymbol;
  454. }
  455. this->OutputDefineFlags(defineFlags.c_str(), fout);
  456. fout << "\"\n";
  457. fout << "\t\t\t\tAssemblerListingLocation=\"" << configName << "\"\n";
  458. fout << "\t\t\t\tObjectFile=\"" << configName << "\\\"\n";
  459. if(m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  460. {
  461. fout << "\t\t\t\tSuppressStartupBanner=\"FALSE\"\n";
  462. }
  463. if(programDatabase.size())
  464. {
  465. fout << programDatabase << "\n";
  466. }
  467. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  468. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n";
  469. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"\n"
  470. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  471. for(i = includes.begin();i != includes.end(); ++i)
  472. {
  473. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  474. fout << ipath << ";";
  475. }
  476. // add the -D flags to the RC tool
  477. fout << "\"\n"
  478. << "\t\t\t\tPreprocessorDefinitions=\"" << pre;
  479. this->OutputDefineFlags(defineFlags.c_str(), fout);
  480. fout << "\" />\n";
  481. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n";
  482. this->OutputTargetRules(fout, target, libName);
  483. this->OutputBuildTool(fout, configName, libName, target);
  484. fout << "\t\t</Configuration>\n";
  485. }
  486. void cmLocalVisualStudio7Generator::FillFlagMapFromCommandFlags(
  487. std::map<cmStdString, cmStdString>& flagMap,
  488. cmVS7FlagTable* flagTable,
  489. std::string& flags)
  490. {
  491. std::string replace;
  492. while(flagTable->IDEName)
  493. {
  494. if(flags.find(flagTable->commandFlag) != flags.npos)
  495. {
  496. // replace -flag
  497. replace = "-";
  498. replace += flagTable->commandFlag;
  499. cmSystemTools::ReplaceString(flags, replace.c_str(), "");
  500. // now replace /flag
  501. replace[0] = '/';
  502. cmSystemTools::ReplaceString(flags, replace.c_str(), "");
  503. // now put value into flag map
  504. flagMap[flagTable->IDEName] = flagTable->value;
  505. }
  506. flagTable++;
  507. }
  508. }
  509. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  510. const char* configName,
  511. const char *libName,
  512. const cmTarget &target)
  513. {
  514. std::string temp;
  515. std::string debugPostfix = "";
  516. bool debug = !strcmp(configName,"Debug");
  517. if (debug && m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX"))
  518. {
  519. debugPostfix = m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  520. }
  521. std::string extraLinkOptions;
  522. if(target.GetType() == cmTarget::EXECUTABLE)
  523. {
  524. extraLinkOptions = m_Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS");
  525. }
  526. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  527. {
  528. extraLinkOptions = m_Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS");
  529. }
  530. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  531. {
  532. extraLinkOptions = m_Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS");
  533. }
  534. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  535. if(targetLinkFlags)
  536. {
  537. extraLinkOptions += " ";
  538. extraLinkOptions += targetLinkFlags;
  539. }
  540. switch(target.GetType())
  541. {
  542. case cmTarget::STATIC_LIBRARY:
  543. {
  544. std::string libpath = m_LibraryOutputPath +
  545. "$(OutDir)/" + libName + debugPostfix + ".lib";
  546. fout << "\t\t\t<Tool\n"
  547. << "\t\t\t\tName=\"VCLibrarianTool\"\n";
  548. if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
  549. {
  550. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  551. }
  552. fout << "\t\t\t\tOutputFile=\""
  553. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << ".\"/>\n";
  554. break;
  555. }
  556. case cmTarget::SHARED_LIBRARY:
  557. case cmTarget::MODULE_LIBRARY:
  558. {
  559. fout << "\t\t\t<Tool\n"
  560. << "\t\t\t\tName=\"VCLinkerTool\"\n"
  561. << "\t\t\t\tAdditionalOptions=\"/MACHINE:I386";
  562. if(extraLinkOptions.size())
  563. {
  564. fout << " " << cmLocalVisualStudio7Generator::EscapeForXML(
  565. extraLinkOptions.c_str()).c_str();
  566. }
  567. fout << "\"\n"
  568. << "\t\t\t\tAdditionalDependencies=\" odbc32.lib odbccp32.lib ";
  569. this->OutputLibraries(fout, configName, libName, target);
  570. fout << "\"\n";
  571. temp = m_LibraryOutputPath;
  572. temp += configName;
  573. temp += "/";
  574. temp += libName;
  575. temp += debugPostfix;
  576. temp += ".dll";
  577. fout << "\t\t\t\tOutputFile=\""
  578. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  579. fout << "\t\t\t\tLinkIncremental=\"1\"\n";
  580. if(m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  581. {
  582. fout << "\t\t\t\tSuppressStartupBanner=\"FALSE\"\n";
  583. }
  584. else
  585. {
  586. fout << "\t\t\t\tSuppressStartupBanner=\"TRUE\"\n";
  587. }
  588. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  589. this->OutputLibraryDirectories(fout, configName, libName, target);
  590. fout << "\"\n";
  591. this->OutputModuleDefinitionFile(fout, target);
  592. temp = m_LibraryOutputPath;
  593. temp += "$(OutDir)/";
  594. temp += libName;
  595. temp += debugPostfix;
  596. temp += ".pdb";
  597. fout << "\t\t\t\tProgramDatabaseFile=\"" <<
  598. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  599. if(strcmp(configName, "Debug") == 0
  600. || strcmp(configName, "RelWithDebInfo") == 0)
  601. {
  602. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  603. }
  604. const char* linkLanguage = target.GetLinkerLanguage(this->GetGlobalGenerator());
  605. if(!linkLanguage)
  606. {
  607. cmSystemTools::Error("CMake can not determine linker language for target:",
  608. target.GetName());
  609. return;
  610. }
  611. std::string stackVar = "CMAKE_";
  612. stackVar += linkLanguage;
  613. stackVar += "_STACK_SIZE";
  614. const char* stackVal = m_Makefile->GetDefinition(stackVar.c_str());
  615. if(stackVal)
  616. {
  617. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  618. }
  619. temp = m_LibraryOutputPath;
  620. temp += configName;
  621. temp += "/";
  622. temp += libName;
  623. temp += debugPostfix;
  624. temp += ".lib";
  625. fout << "\t\t\t\tImportLibrary=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  626. }
  627. break;
  628. case cmTarget::EXECUTABLE:
  629. {
  630. fout << "\t\t\t<Tool\n"
  631. << "\t\t\t\tName=\"VCLinkerTool\"\n"
  632. << "\t\t\t\tAdditionalOptions=\"/MACHINE:I386";
  633. if(extraLinkOptions.size())
  634. {
  635. fout << " " << cmLocalVisualStudio7Generator::EscapeForXML(
  636. extraLinkOptions.c_str()).c_str();
  637. }
  638. fout << "\"\n"
  639. << "\t\t\t\tAdditionalDependencies=\""
  640. << m_Makefile->GetRequiredDefinition("CMAKE_STANDARD_LIBRARIES")
  641. << " ";
  642. this->OutputLibraries(fout, configName, libName, target);
  643. fout << "\"\n";
  644. temp = m_ExecutableOutputPath;
  645. temp += configName;
  646. temp += "/";
  647. temp += libName;
  648. temp += ".exe";
  649. fout << "\t\t\t\tOutputFile=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  650. fout << "\t\t\t\tLinkIncremental=\"1\"\n";
  651. if(m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  652. {
  653. fout << "\t\t\t\tSuppressStartupBanner=\"FALSE\"\n";
  654. }
  655. else
  656. {
  657. fout << "\t\t\t\tSuppressStartupBanner=\"TRUE\"\n";
  658. }
  659. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  660. this->OutputLibraryDirectories(fout, configName, libName, target);
  661. fout << "\"\n";
  662. fout << "\t\t\t\tProgramDatabaseFile=\"" << m_LibraryOutputPath
  663. << "$(OutDir)\\" << libName << ".pdb\"\n";
  664. if(strcmp(configName, "Debug") == 0
  665. || strcmp(configName, "RelWithDebInfo") == 0)
  666. {
  667. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  668. }
  669. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  670. {
  671. fout << "\t\t\t\tSubSystem=\"2\"\n";
  672. }
  673. else
  674. {
  675. fout << "\t\t\t\tSubSystem=\"1\"\n";
  676. }
  677. const char* linkLanguage = target.GetLinkerLanguage(this->GetGlobalGenerator());
  678. if(!linkLanguage)
  679. {
  680. cmSystemTools::Error("CMake can not determine linker language for target:",
  681. target.GetName());
  682. return;
  683. }
  684. std::string stackVar = "CMAKE_";
  685. stackVar += linkLanguage;
  686. stackVar += "_STACK_SIZE";
  687. const char* stackVal = m_Makefile->GetDefinition(stackVar.c_str());
  688. if(stackVal)
  689. {
  690. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  691. }
  692. fout << "/>\n";
  693. break;
  694. }
  695. case cmTarget::UTILITY:
  696. break;
  697. }
  698. }
  699. void cmLocalVisualStudio7Generator::OutputModuleDefinitionFile(std::ostream& fout,
  700. const cmTarget &target)
  701. {
  702. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  703. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  704. i != classes.end(); i++)
  705. {
  706. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  707. {
  708. fout << "\t\t\t\tModuleDefinitionFile=\""
  709. << this->ConvertToXMLOutputPath((*i)->GetFullPath().c_str())
  710. << "\"\n";
  711. return;
  712. }
  713. }
  714. }
  715. void cmLocalVisualStudio7Generator::OutputLibraryDirectories(std::ostream& fout,
  716. const char*,
  717. const char*,
  718. const cmTarget &tgt)
  719. {
  720. bool hasone = false;
  721. if(m_LibraryOutputPath.size())
  722. {
  723. hasone = true;
  724. std::string temp = m_LibraryOutputPath;
  725. temp += "$(INTDIR)";
  726. fout << this->ConvertToXMLOutputPath(temp.c_str()) << "," <<
  727. this->ConvertToXMLOutputPath(m_LibraryOutputPath.c_str());
  728. }
  729. if(m_ExecutableOutputPath.size() &&
  730. (m_LibraryOutputPath != m_ExecutableOutputPath))
  731. {
  732. if (hasone)
  733. {
  734. fout << ",";
  735. }
  736. hasone = true;
  737. std::string temp = m_ExecutableOutputPath;
  738. temp += "$(INTDIR)";
  739. fout << this->ConvertToXMLOutputPath(temp.c_str()) << "," <<
  740. this->ConvertToXMLOutputPath(m_ExecutableOutputPath.c_str());
  741. }
  742. std::set<std::string> pathEmitted;
  743. std::vector<std::string>::const_iterator i;
  744. const std::vector<std::string>& libdirs = tgt.GetLinkDirectories();
  745. for(i = libdirs.begin(); i != libdirs.end(); ++i)
  746. {
  747. std::string lpath = *i;
  748. if(lpath[lpath.size()-1] != '/')
  749. {
  750. lpath += "/";
  751. }
  752. if(pathEmitted.insert(lpath).second)
  753. {
  754. if(hasone)
  755. {
  756. fout << ",";
  757. }
  758. std::string lpathi = lpath + "$(INTDIR)";
  759. fout << this->ConvertToXMLOutputPath(lpathi.c_str()) << "," <<
  760. this->ConvertToXMLOutputPath(lpath.c_str());
  761. hasone = true;
  762. }
  763. }
  764. }
  765. void cmLocalVisualStudio7Generator::OutputLibraries(std::ostream& fout,
  766. const char* configName,
  767. const char* libName,
  768. const cmTarget &target)
  769. {
  770. const cmTarget::LinkLibraries& libs = target.GetLinkLibraries();
  771. cmTarget::LinkLibraries::const_iterator j;
  772. for(j = libs.begin(); j != libs.end(); ++j)
  773. {
  774. if(j->first != libName)
  775. {
  776. std::string lib = j->first;
  777. std::string debugPostfix = "";
  778. // if this is a library we are building then watch for a debugPostfix
  779. if (!strcmp(configName,"Debug"))
  780. {
  781. std::string libPath = j->first + "_CMAKE_PATH";
  782. const char* cacheValue
  783. = m_GlobalGenerator->GetCMakeInstance()->GetCacheDefinition(libPath.c_str());
  784. if(cacheValue && *cacheValue && m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX"))
  785. {
  786. debugPostfix = m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  787. }
  788. }
  789. if(j->first.find(".lib") == std::string::npos)
  790. {
  791. lib += debugPostfix + ".lib";
  792. }
  793. lib = this->ConvertToXMLOutputPath(lib.c_str());
  794. if (j->second == cmTarget::GENERAL
  795. || (j->second == cmTarget::DEBUG && strcmp(configName, "Debug") == 0)
  796. || (j->second == cmTarget::OPTIMIZED && strcmp(configName, "Debug") != 0))
  797. {
  798. fout << lib << " ";
  799. }
  800. }
  801. }
  802. }
  803. void cmLocalVisualStudio7Generator::OutputDefineFlags(const char* flags,
  804. std::ostream& fout)
  805. {
  806. std::string defs = flags;
  807. cmSystemTools::ReplaceString(defs, "/D","-D");
  808. std::string::size_type pos = defs.find("-D");
  809. bool done = pos == std::string::npos;
  810. if(!done)
  811. {
  812. fout << ",";
  813. }
  814. while(!done)
  815. {
  816. std::string::size_type nextpos = defs.find("-D", pos+2);
  817. std::string define;
  818. if(nextpos != std::string::npos)
  819. {
  820. define = defs.substr(pos+2, nextpos - pos -3);
  821. }
  822. else
  823. {
  824. define = defs.substr(pos+2);
  825. done = true;
  826. }
  827. cmSystemTools::ReplaceString(define, "\"", "&quot;");
  828. fout << define << ",";
  829. if(!done)
  830. {
  831. pos = defs.find("-D", nextpos);
  832. }
  833. }
  834. }
  835. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  836. const char *libName,
  837. cmTarget &target)
  838. {
  839. // get the configurations
  840. std::vector<std::string> *configs =
  841. static_cast<cmGlobalVisualStudio7Generator *>
  842. (m_GlobalGenerator)->GetConfigurations();
  843. // if we should add regen rule then...
  844. const char *suppRegenRule =
  845. m_Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
  846. if (!cmSystemTools::IsOn(suppRegenRule))
  847. {
  848. this->AddVCProjBuildRule();
  849. }
  850. // trace the visual studio dependencies
  851. std::string name = libName;
  852. name += ".vcproj.cmake";
  853. target.TraceVSDependencies(name, m_Makefile);
  854. // We may be modifying the source groups temporarily, so make a copy.
  855. std::vector<cmSourceGroup> sourceGroups = m_Makefile->GetSourceGroups();
  856. // get the classes from the source lists then add them to the groups
  857. std::vector<cmSourceFile*> & classes = target.GetSourceFiles();
  858. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  859. i != classes.end(); i++)
  860. {
  861. // Add the file to the list of sources.
  862. std::string source = (*i)->GetFullPath();
  863. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  864. {
  865. m_ModuleDefinitionFile = (*i)->GetFullPath();
  866. }
  867. cmSourceGroup& sourceGroup =
  868. m_Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  869. sourceGroup.AssignSource(*i);
  870. }
  871. // open the project
  872. this->WriteProjectStart(fout, libName, target, sourceGroups);
  873. // write the configuration information
  874. this->WriteConfigurations(fout, libName, target);
  875. fout << "\t<Files>\n";
  876. // Loop through every source group.
  877. for(std::vector<cmSourceGroup>::const_iterator sg = sourceGroups.begin();
  878. sg != sourceGroups.end(); ++sg)
  879. {
  880. const std::vector<const cmSourceFile *> &sourceFiles =
  881. sg->GetSourceFiles();
  882. // If the group is empty, don't write it at all.
  883. if(sourceFiles.empty())
  884. {
  885. continue;
  886. }
  887. // If the group has a name, write the header.
  888. std::string name = sg->GetName();
  889. if(name != "")
  890. {
  891. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  892. }
  893. // Loop through each source in the source group.
  894. for(std::vector<const cmSourceFile *>::const_iterator sf =
  895. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  896. {
  897. std::string source = (*sf)->GetFullPath();
  898. const cmCustomCommand *command = (*sf)->GetCustomCommand();
  899. std::string compileFlags;
  900. std::string additionalDeps;
  901. // Check for extra compiler flags.
  902. const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS");
  903. if(cflags)
  904. {
  905. compileFlags = cflags;
  906. }
  907. const char* lang =
  908. m_GlobalGenerator->GetLanguageFromExtension((*sf)->GetSourceExtension().c_str());
  909. if(lang && strcmp(lang, "CXX") == 0)
  910. {
  911. // force a C++ file type
  912. compileFlags += " /TP ";
  913. }
  914. // Check for extra object-file dependencies.
  915. const char* deps = (*sf)->GetProperty("OBJECT_DEPENDS");
  916. if(deps)
  917. {
  918. std::vector<std::string> depends;
  919. cmSystemTools::ExpandListArgument(deps, depends);
  920. if(!depends.empty())
  921. {
  922. std::vector<std::string>::iterator i = depends.begin();
  923. additionalDeps = this->ConvertToXMLOutputPath(i->c_str());
  924. for(++i;i != depends.end(); ++i)
  925. {
  926. additionalDeps += ";";
  927. additionalDeps += this->ConvertToXMLOutputPath(i->c_str());
  928. }
  929. }
  930. }
  931. if (source != libName || target.GetType() == cmTarget::UTILITY)
  932. {
  933. fout << "\t\t\t<File\n";
  934. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  935. // Tell MS-Dev what the source is. If the compiler knows how to
  936. // build it, then it will.
  937. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  938. if (command)
  939. {
  940. std::string totalCommandStr;
  941. totalCommandStr =
  942. this->ConvertToRelativeOutputPath(command->GetCommand().c_str());
  943. totalCommandStr += " ";
  944. totalCommandStr += command->GetArguments();
  945. totalCommandStr += "\n";
  946. const char* comment = command->GetComment().c_str();
  947. const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
  948. this->WriteCustomRule(fout, source.c_str(), totalCommandStr.c_str(),
  949. (*comment?comment:"Custom Rule"),
  950. command->GetDepends(),
  951. command->GetOutput().c_str(), flags);
  952. }
  953. else if(compileFlags.size() || additionalDeps.length())
  954. {
  955. const char* aCompilerTool = "VCCLCompilerTool";
  956. if((*sf)->GetSourceExtension() == "idl")
  957. {
  958. aCompilerTool = "VCMIDLTool";
  959. }
  960. for(std::vector<std::string>::iterator i = configs->begin();
  961. i != configs->end(); ++i)
  962. {
  963. fout << "\t\t\t\t<FileConfiguration\n"
  964. << "\t\t\t\t\tName=\"" << *i << "|Win32\">\n"
  965. << "\t\t\t\t\t<Tool\n"
  966. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  967. if(compileFlags.size())
  968. {
  969. fout << "\t\t\t\t\tAdditionalOptions=\""
  970. << this->EscapeForXML(compileFlags.c_str()) << "\"\n";
  971. }
  972. if(additionalDeps.length())
  973. {
  974. fout << "\t\t\t\t\tAdditionalDependencies=\""
  975. << additionalDeps.c_str() << "\"\n";
  976. }
  977. fout << "\t\t\t\t\t/>\n"
  978. << "\t\t\t\t</FileConfiguration>\n";
  979. }
  980. }
  981. fout << "\t\t\t</File>\n";
  982. }
  983. }
  984. // If the group has a name, write the footer.
  985. if(name != "")
  986. {
  987. this->WriteVCProjEndGroup(fout);
  988. }
  989. }
  990. fout << "\t</Files>\n";
  991. // Write the VCProj file's footer.
  992. this->WriteVCProjFooter(fout);
  993. }
  994. void cmLocalVisualStudio7Generator::
  995. WriteCustomRule(std::ostream& fout,
  996. const char* source,
  997. const char* command,
  998. const char* comment,
  999. const std::vector<std::string>& depends,
  1000. const char *output,
  1001. const char* compileFlags)
  1002. {
  1003. std::string cmd = command;
  1004. cmSystemTools::ReplaceString(cmd, "\"", "&quot;");
  1005. std::vector<std::string>::iterator i;
  1006. std::vector<std::string> *configs =
  1007. static_cast<cmGlobalVisualStudio7Generator *>(m_GlobalGenerator)->GetConfigurations();
  1008. for(i = configs->begin(); i != configs->end(); ++i)
  1009. {
  1010. fout << "\t\t\t\t<FileConfiguration\n";
  1011. fout << "\t\t\t\t\tName=\"" << *i << "|Win32\">\n";
  1012. if(compileFlags)
  1013. {
  1014. fout << "\t\t\t\t\t<Tool\n"
  1015. << "\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
  1016. << "\t\t\t\t\tAdditionalOptions=\""
  1017. << this->EscapeForXML(compileFlags) << "\"/>\n";
  1018. }
  1019. fout << "\t\t\t\t\t<Tool\n"
  1020. << "\t\t\t\t\tName=\"VCCustomBuildTool\"\n"
  1021. << "\t\t\t\t\tDescription=\"Building " << comment;
  1022. fout << " " << output;
  1023. fout << "\"\n"
  1024. << "\t\t\t\t\tCommandLine=\"" << cmd << "\n\"\n"
  1025. << "\t\t\t\t\tAdditionalDependencies=\"";
  1026. // Write out the dependencies for the rule.
  1027. std::string temp;
  1028. for(std::vector<std::string>::const_iterator d = depends.begin();
  1029. d != depends.end(); ++d)
  1030. {
  1031. std::string dep = cmSystemTools::GetFilenameName(*d);
  1032. if (cmSystemTools::GetFilenameLastExtension(dep) == ".exe")
  1033. {
  1034. dep = cmSystemTools::GetFilenameWithoutLastExtension(dep);
  1035. }
  1036. // check to see if the dependency is another target built by cmake
  1037. std::string libPath = dep + "_CMAKE_PATH";
  1038. const char* cacheValue = m_Makefile->GetDefinition(libPath.c_str());
  1039. if (cacheValue && *cacheValue)
  1040. {
  1041. std::string exePath = "";
  1042. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  1043. {
  1044. exePath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  1045. }
  1046. if(exePath.size())
  1047. {
  1048. libPath = exePath;
  1049. }
  1050. else
  1051. {
  1052. libPath = cacheValue;
  1053. }
  1054. libPath += "/";
  1055. libPath += "$(INTDIR)/";
  1056. libPath += dep;
  1057. libPath += ".exe";
  1058. fout << this->ConvertToXMLOutputPath(libPath.c_str())
  1059. << ";";
  1060. }
  1061. else
  1062. {
  1063. fout << this->ConvertToXMLOutputPath(d->c_str())
  1064. << ";";
  1065. }
  1066. }
  1067. fout << "\"\n";
  1068. fout << "\t\t\t\t\tOutputs=\"";
  1069. if(output == 0)
  1070. {
  1071. fout << source << "_force";
  1072. }
  1073. // Write a rule for the output generated by this command.
  1074. fout << this->ConvertToXMLOutputPathSingle(output);
  1075. fout << "\"/>\n";
  1076. fout << "\t\t\t\t</FileConfiguration>\n";
  1077. }
  1078. }
  1079. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1080. const char* group,
  1081. const char* )
  1082. {
  1083. fout << "\t\t<Filter\n"
  1084. << "\t\t\tName=\"" << group << "\"\n"
  1085. << "\t\t\tFilter=\"\">\n";
  1086. }
  1087. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1088. {
  1089. fout << "\t\t</Filter>\n";
  1090. }
  1091. // look for custom rules on a target and collect them together
  1092. void cmLocalVisualStudio7Generator::OutputTargetRules(std::ostream& fout,
  1093. const cmTarget &target,
  1094. const char * /* libName */)
  1095. {
  1096. if (target.GetType() > cmTarget::UTILITY)
  1097. {
  1098. return;
  1099. }
  1100. // add the pre build rules
  1101. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"";
  1102. bool init = false;
  1103. for (std::vector<cmCustomCommand>::const_iterator cr =
  1104. target.GetPreBuildCommands().begin();
  1105. cr != target.GetPreBuildCommands().end(); ++cr)
  1106. {
  1107. cmCustomCommand cc(*cr);
  1108. cc.ExpandVariables(*m_Makefile);
  1109. if(!init)
  1110. {
  1111. fout << "\nCommandLine=\"";
  1112. init = true;
  1113. }
  1114. std::string args = cc.GetArguments();
  1115. cmSystemTools::ReplaceString(args, "\"", "&quot;");
  1116. fout << this->ConvertToXMLOutputPath(cc.GetCommand().c_str()) << " " <<
  1117. args << "\n";
  1118. }
  1119. if (init)
  1120. {
  1121. fout << "\"";
  1122. }
  1123. fout << "/>\n";
  1124. // add the pre Link rules
  1125. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"";
  1126. init = false;
  1127. for (std::vector<cmCustomCommand>::const_iterator cr =
  1128. target.GetPreLinkCommands().begin();
  1129. cr != target.GetPreLinkCommands().end(); ++cr)
  1130. {
  1131. cmCustomCommand cc(*cr);
  1132. cc.ExpandVariables(*m_Makefile);
  1133. if(!init)
  1134. {
  1135. fout << "\nCommandLine=\"";
  1136. init = true;
  1137. }
  1138. std::string args = cc.GetArguments();
  1139. cmSystemTools::ReplaceString(args, "\"", "&quot;");
  1140. fout << this->ConvertToXMLOutputPath(cc.GetCommand().c_str()) << " " <<
  1141. args << "\n";
  1142. }
  1143. if (init)
  1144. {
  1145. fout << "\"";
  1146. }
  1147. fout << "/>\n";
  1148. // add the PostBuild rules
  1149. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"";
  1150. init = false;
  1151. for (std::vector<cmCustomCommand>::const_iterator cr =
  1152. target.GetPostBuildCommands().begin();
  1153. cr != target.GetPostBuildCommands().end(); ++cr)
  1154. {
  1155. cmCustomCommand cc(*cr);
  1156. cc.ExpandVariables(*m_Makefile);
  1157. if(!init)
  1158. {
  1159. fout << "\nCommandLine=\"";
  1160. init = true;
  1161. }
  1162. std::string args = cc.GetArguments();
  1163. cmSystemTools::ReplaceString(args, "\"", "&quot;");
  1164. fout << this->ConvertToXMLOutputPath(cc.GetCommand().c_str()) << " " <<
  1165. args << "\n";
  1166. }
  1167. if (init)
  1168. {
  1169. fout << "\"";
  1170. }
  1171. fout << "/>\n";
  1172. }
  1173. void
  1174. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  1175. const char *libName,
  1176. const cmTarget &,
  1177. std::vector<cmSourceGroup> &)
  1178. {
  1179. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1180. << "<VisualStudioProject\n"
  1181. << "\tProjectType=\"Visual C++\"\n";
  1182. if(m_Version == 71)
  1183. {
  1184. fout << "\tVersion=\"7.10\"\n";
  1185. }
  1186. else
  1187. {
  1188. if (m_Version == 8)
  1189. {
  1190. fout << "\tVersion=\"8.00\"\n";
  1191. }
  1192. else
  1193. {
  1194. fout << "\tVersion=\"7.00\"\n";
  1195. }
  1196. }
  1197. fout << "\tName=\"" << libName << "\"\n"
  1198. << "\tSccProjectName=\"\"\n"
  1199. << "\tSccLocalPath=\"\"\n"
  1200. << "\tKeyword=\"Win32Proj\">\n"
  1201. << "\t<Platforms>\n"
  1202. << "\t\t<Platform\n\t\t\tName=\"Win32\"/>\n"
  1203. << "\t</Platforms>\n";
  1204. }
  1205. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout)
  1206. {
  1207. fout << "\t<Globals>\n"
  1208. << "\t</Globals>\n"
  1209. << "</VisualStudioProject>\n";
  1210. }
  1211. std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s)
  1212. {
  1213. std::string ret = s;
  1214. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1215. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1216. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1217. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1218. return ret;
  1219. }
  1220. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPath(const char* path)
  1221. {
  1222. std::string ret = this->ConvertToRelativeOutputPath(path);
  1223. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1224. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1225. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1226. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1227. return ret;
  1228. }
  1229. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPathSingle(const char* path)
  1230. {
  1231. std::string ret = this->ConvertToRelativeOutputPath(path);
  1232. cmSystemTools::ReplaceString(ret, "\"", "");
  1233. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1234. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1235. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1236. return ret;
  1237. }
  1238. void cmLocalVisualStudio7Generator::ConfigureFinalPass()
  1239. {
  1240. cmLocalGenerator::ConfigureFinalPass();
  1241. cmTargets &tgts = m_Makefile->GetTargets();
  1242. cmGlobalVisualStudio7Generator* gg =
  1243. static_cast<cmGlobalVisualStudio7Generator *>(m_GlobalGenerator);
  1244. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  1245. {
  1246. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  1247. {
  1248. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  1249. std::string project_name = cc.GetCommand();
  1250. gg->CreateGUID(project_name.c_str());
  1251. }
  1252. else
  1253. {
  1254. gg->CreateGUID(l->first.c_str());
  1255. }
  1256. }
  1257. }