cmLocalVisualStudio7Generator.cxx 43 KB

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