cmLocalVisualStudio7Generator.cxx 42 KB

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