cmLocalVisualStudio7Generator.cxx 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  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. // 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(target.HasCxx())
  293. {
  294. flags = m_Makefile->GetDefinition("CMAKE_CXX_FLAGS");
  295. flagsRelease += m_Makefile->GetDefinition("CMAKE_CXX_FLAGS_RELEASE");
  296. flagsMinSize += m_Makefile->GetDefinition("CMAKE_CXX_FLAGS_MINSIZEREL");
  297. flagsDebug += m_Makefile->GetDefinition("CMAKE_CXX_FLAGS_DEBUG");
  298. flagsDebugRel += m_Makefile->GetDefinition("CMAKE_CXX_FLAGS_RELWITHDEBINFO");
  299. }
  300. else
  301. {
  302. flags = m_Makefile->GetDefinition("CMAKE_C_FLAGS");
  303. flagsRelease += m_Makefile->GetDefinition("CMAKE_C_FLAGS_RELEASE");
  304. flagsMinSize += m_Makefile->GetDefinition("CMAKE_C_FLAGS_MINSIZEREL");
  305. flagsDebug += m_Makefile->GetDefinition("CMAKE_C_FLAGS_DEBUG");
  306. flagsDebugRel += m_Makefile->GetDefinition("CMAKE_C_FLAGS_RELWITHDEBINFO");
  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->GetDefinition("CMAKE_EXE_LINKER_FLAGS");
  499. }
  500. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  501. {
  502. extraLinkOptions = m_Makefile->GetDefinition("CMAKE_SHARED_LINKER_FLAGS");
  503. }
  504. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  505. {
  506. extraLinkOptions = m_Makefile->GetDefinition("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. fout << "\t\t\t<Tool\n"
  533. << "\t\t\t\tName=\"VCLinkerTool\"\n"
  534. << "\t\t\t\tAdditionalOptions=\"/MACHINE:I386";
  535. if(extraLinkOptions.size())
  536. {
  537. fout << " " << cmLocalVisualStudio7Generator::EscapeForXML(
  538. extraLinkOptions.c_str()).c_str();
  539. }
  540. fout << "\"\n"
  541. << "\t\t\t\tAdditionalDependencies=\" odbc32.lib odbccp32.lib ";
  542. this->OutputLibraries(fout, configName, libName, target);
  543. fout << "\"\n";
  544. temp = m_LibraryOutputPath;
  545. temp += configName;
  546. temp += "/";
  547. temp += libName;
  548. temp += debugPostfix;
  549. temp += ".dll";
  550. fout << "\t\t\t\tOutputFile=\""
  551. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  552. fout << "\t\t\t\tLinkIncremental=\"1\"\n";
  553. if(m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  554. {
  555. fout << "\t\t\t\tSuppressStartupBanner=\"FALSE\"\n";
  556. }
  557. else
  558. {
  559. fout << "\t\t\t\tSuppressStartupBanner=\"TRUE\"\n";
  560. }
  561. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  562. this->OutputLibraryDirectories(fout, configName, libName, target);
  563. fout << "\"\n";
  564. this->OutputModuleDefinitionFile(fout, target);
  565. temp = m_LibraryOutputPath;
  566. temp += "$(OutDir)/";
  567. temp += libName;
  568. temp += debugPostfix;
  569. temp += ".pdb";
  570. fout << "\t\t\t\tProgramDatabaseFile=\"" <<
  571. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  572. if(strcmp(configName, "Debug") == 0
  573. || strcmp(configName, "RelWithDebInfo") == 0)
  574. {
  575. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  576. }
  577. fout << "\t\t\t\tStackReserveSize=\""
  578. << m_Makefile->GetDefinition("CMAKE_CXX_STACK_SIZE") << "\"\n";
  579. temp = m_LibraryOutputPath;
  580. temp += configName;
  581. temp += "/";
  582. temp += libName;
  583. temp += debugPostfix;
  584. temp += ".lib";
  585. fout << "\t\t\t\tImportLibrary=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  586. break;
  587. case cmTarget::EXECUTABLE:
  588. fout << "\t\t\t<Tool\n"
  589. << "\t\t\t\tName=\"VCLinkerTool\"\n"
  590. << "\t\t\t\tAdditionalOptions=\"/MACHINE:I386";
  591. if(extraLinkOptions.size())
  592. {
  593. fout << " " << cmLocalVisualStudio7Generator::EscapeForXML(
  594. extraLinkOptions.c_str()).c_str();
  595. }
  596. fout << "\"\n"
  597. << "\t\t\t\tAdditionalDependencies=\""
  598. << m_Makefile->GetDefinition("CMAKE_STANDARD_LIBRARIES")
  599. << " ";
  600. this->OutputLibraries(fout, configName, libName, target);
  601. fout << "\"\n";
  602. temp = m_ExecutableOutputPath;
  603. temp += configName;
  604. temp += "/";
  605. temp += libName;
  606. temp += ".exe";
  607. fout << "\t\t\t\tOutputFile=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  608. fout << "\t\t\t\tLinkIncremental=\"1\"\n";
  609. if(m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  610. {
  611. fout << "\t\t\t\tSuppressStartupBanner=\"FALSE\"\n";
  612. }
  613. else
  614. {
  615. fout << "\t\t\t\tSuppressStartupBanner=\"TRUE\"\n";
  616. }
  617. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  618. this->OutputLibraryDirectories(fout, configName, libName, target);
  619. fout << "\"\n";
  620. fout << "\t\t\t\tProgramDatabaseFile=\"" << m_LibraryOutputPath
  621. << "$(OutDir)\\" << libName << ".pdb\"\n";
  622. if(strcmp(configName, "Debug") == 0
  623. || strcmp(configName, "RelWithDebInfo") == 0)
  624. {
  625. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  626. }
  627. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  628. {
  629. fout << "\t\t\t\tSubSystem=\"2\"\n";
  630. }
  631. else
  632. {
  633. fout << "\t\t\t\tSubSystem=\"1\"\n";
  634. }
  635. fout << "\t\t\t\tStackReserveSize=\""
  636. << m_Makefile->GetDefinition("CMAKE_CXX_STACK_SIZE") << "\"/>\n";
  637. break;
  638. case cmTarget::UTILITY:
  639. break;
  640. }
  641. }
  642. void cmLocalVisualStudio7Generator::OutputModuleDefinitionFile(std::ostream& fout,
  643. const cmTarget &target)
  644. {
  645. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  646. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  647. i != classes.end(); i++)
  648. {
  649. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  650. {
  651. fout << "\t\t\t\tModuleDefinitionFile=\""
  652. << this->ConvertToXMLOutputPath((*i)->GetFullPath().c_str())
  653. << "\"\n";
  654. return;
  655. }
  656. }
  657. }
  658. void cmLocalVisualStudio7Generator::OutputLibraryDirectories(std::ostream& fout,
  659. const char*,
  660. const char*,
  661. const cmTarget &tgt)
  662. {
  663. bool hasone = false;
  664. if(m_LibraryOutputPath.size())
  665. {
  666. hasone = true;
  667. std::string temp = m_LibraryOutputPath;
  668. temp += "$(INTDIR)";
  669. fout << this->ConvertToXMLOutputPath(temp.c_str()) << "," <<
  670. this->ConvertToXMLOutputPath(m_LibraryOutputPath.c_str());
  671. }
  672. if(m_ExecutableOutputPath.size() &&
  673. (m_LibraryOutputPath != m_ExecutableOutputPath))
  674. {
  675. if (hasone)
  676. {
  677. fout << ",";
  678. }
  679. hasone = true;
  680. std::string temp = m_ExecutableOutputPath;
  681. temp += "$(INTDIR)";
  682. fout << this->ConvertToXMLOutputPath(temp.c_str()) << "," <<
  683. this->ConvertToXMLOutputPath(m_ExecutableOutputPath.c_str());
  684. }
  685. std::set<std::string> pathEmitted;
  686. std::vector<std::string>::const_iterator i;
  687. const std::vector<std::string>& libdirs = tgt.GetLinkDirectories();
  688. for(i = libdirs.begin(); i != libdirs.end(); ++i)
  689. {
  690. std::string lpath = *i;
  691. if(lpath[lpath.size()-1] != '/')
  692. {
  693. lpath += "/";
  694. }
  695. if(pathEmitted.insert(lpath).second)
  696. {
  697. if(hasone)
  698. {
  699. fout << ",";
  700. }
  701. std::string lpathi = lpath + "$(INTDIR)";
  702. fout << this->ConvertToXMLOutputPath(lpathi.c_str()) << "," <<
  703. this->ConvertToXMLOutputPath(lpath.c_str());
  704. hasone = true;
  705. }
  706. }
  707. }
  708. void cmLocalVisualStudio7Generator::OutputLibraries(std::ostream& fout,
  709. const char* configName,
  710. const char* libName,
  711. const cmTarget &target)
  712. {
  713. const cmTarget::LinkLibraries& libs = target.GetLinkLibraries();
  714. cmTarget::LinkLibraries::const_iterator j;
  715. for(j = libs.begin(); j != libs.end(); ++j)
  716. {
  717. if(j->first != libName)
  718. {
  719. std::string lib = j->first;
  720. std::string debugPostfix = "";
  721. // if this is a library we are building then watch for a debugPostfix
  722. if (!strcmp(configName,"Debug"))
  723. {
  724. std::string libPath = j->first + "_CMAKE_PATH";
  725. const char* cacheValue
  726. = m_GlobalGenerator->GetCMakeInstance()->GetCacheDefinition(libPath.c_str());
  727. if(cacheValue && *cacheValue && m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX"))
  728. {
  729. debugPostfix = m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  730. }
  731. }
  732. if(j->first.find(".lib") == std::string::npos)
  733. {
  734. lib += debugPostfix + ".lib";
  735. }
  736. lib = this->ConvertToXMLOutputPath(lib.c_str());
  737. if (j->second == cmTarget::GENERAL
  738. || (j->second == cmTarget::DEBUG && strcmp(configName, "Debug") == 0)
  739. || (j->second == cmTarget::OPTIMIZED && strcmp(configName, "Debug") != 0))
  740. {
  741. fout << lib << " ";
  742. }
  743. }
  744. }
  745. }
  746. void cmLocalVisualStudio7Generator::OutputDefineFlags(std::ostream& fout)
  747. {
  748. std::string defs = m_Makefile->GetDefineFlags();
  749. cmSystemTools::ReplaceString(defs, "/D","-D");
  750. std::string::size_type pos = defs.find("-D");
  751. bool done = pos == std::string::npos;
  752. if(!done)
  753. {
  754. fout << ",";
  755. }
  756. while(!done)
  757. {
  758. std::string::size_type nextpos = defs.find("-D", pos+2);
  759. std::string define;
  760. if(nextpos != std::string::npos)
  761. {
  762. define = defs.substr(pos+2, nextpos - pos -3);
  763. }
  764. else
  765. {
  766. define = defs.substr(pos+2);
  767. done = true;
  768. }
  769. cmSystemTools::ReplaceString(define, "\"", "&quot;");
  770. fout << define << ",";
  771. if(!done)
  772. {
  773. pos = defs.find("-D", nextpos);
  774. }
  775. }
  776. }
  777. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  778. const char *libName,
  779. cmTarget &target)
  780. {
  781. // get the configurations
  782. std::vector<std::string> *configs =
  783. static_cast<cmGlobalVisualStudio7Generator *>
  784. (m_GlobalGenerator)->GetConfigurations();
  785. // if we should add regen rule then...
  786. const char *suppRegenRule =
  787. m_Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
  788. if (!cmSystemTools::IsOn(suppRegenRule))
  789. {
  790. this->AddVCProjBuildRule();
  791. }
  792. // trace the visual studio dependencies
  793. std::string name = libName;
  794. name += ".vcproj.cmake";
  795. target.TraceVSDependencies(name, m_Makefile);
  796. // We may be modifying the source groups temporarily, so make a copy.
  797. std::vector<cmSourceGroup> sourceGroups = m_Makefile->GetSourceGroups();
  798. // get the classes from the source lists then add them to the groups
  799. std::vector<cmSourceFile*> & classes = target.GetSourceFiles();
  800. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  801. i != classes.end(); i++)
  802. {
  803. // Add the file to the list of sources.
  804. std::string source = (*i)->GetFullPath();
  805. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  806. {
  807. m_ModuleDefinitionFile = (*i)->GetFullPath();
  808. }
  809. cmSourceGroup& sourceGroup =
  810. m_Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  811. sourceGroup.AssignSource(*i);
  812. }
  813. // open the project
  814. this->WriteProjectStart(fout, libName, target, sourceGroups);
  815. // write the configuration information
  816. this->WriteConfigurations(fout, libName, target);
  817. fout << "\t<Files>\n";
  818. // Loop through every source group.
  819. for(std::vector<cmSourceGroup>::const_iterator sg = sourceGroups.begin();
  820. sg != sourceGroups.end(); ++sg)
  821. {
  822. const std::vector<const cmSourceFile *> &sourceFiles =
  823. sg->GetSourceFiles();
  824. // If the group is empty, don't write it at all.
  825. if(sourceFiles.empty())
  826. {
  827. continue;
  828. }
  829. // If the group has a name, write the header.
  830. std::string name = sg->GetName();
  831. if(name != "")
  832. {
  833. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  834. }
  835. // Loop through each source in the source group.
  836. for(std::vector<const cmSourceFile *>::const_iterator sf =
  837. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  838. {
  839. std::string source = (*sf)->GetFullPath();
  840. const cmCustomCommand *command = (*sf)->GetCustomCommand();
  841. std::string compileFlags;
  842. std::string additionalDeps;
  843. // Check for extra compiler flags.
  844. const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS");
  845. if(cflags)
  846. {
  847. compileFlags = cflags;
  848. }
  849. if(cmSystemTools::GetFileFormat((*sf)->GetSourceExtension().c_str())
  850. == cmSystemTools::CXX_FILE_FORMAT)
  851. {
  852. // force a C++ file type
  853. compileFlags += " /TP ";
  854. }
  855. // Check for extra object-file dependencies.
  856. const char* deps = (*sf)->GetProperty("OBJECT_DEPENDS");
  857. if(deps)
  858. {
  859. std::vector<std::string> depends;
  860. cmSystemTools::ExpandListArgument(deps, depends);
  861. if(!depends.empty())
  862. {
  863. std::vector<std::string>::iterator i = depends.begin();
  864. additionalDeps = this->ConvertToXMLOutputPath(i->c_str());
  865. for(++i;i != depends.end(); ++i)
  866. {
  867. additionalDeps += ";";
  868. additionalDeps += this->ConvertToXMLOutputPath(i->c_str());
  869. }
  870. }
  871. }
  872. if (source != libName || target.GetType() == cmTarget::UTILITY)
  873. {
  874. fout << "\t\t\t<File\n";
  875. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  876. // Tell MS-Dev what the source is. If the compiler knows how to
  877. // build it, then it will.
  878. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  879. if (command)
  880. {
  881. std::string totalCommandStr;
  882. totalCommandStr =
  883. this->ConvertToRelativeOutputPath(command->GetCommand().c_str());
  884. totalCommandStr += " ";
  885. totalCommandStr += command->GetArguments();
  886. totalCommandStr += "\n";
  887. const char* comment = command->GetComment().c_str();
  888. const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
  889. this->WriteCustomRule(fout, source.c_str(), totalCommandStr.c_str(),
  890. (*comment?comment:"Custom Rule"),
  891. command->GetDepends(),
  892. command->GetOutput().c_str(), flags);
  893. }
  894. else if(compileFlags.size() || additionalDeps.length())
  895. {
  896. const char* aCompilerTool = "VCCLCompilerTool";
  897. if((*sf)->GetSourceExtension() == "idl")
  898. {
  899. aCompilerTool = "VCMIDLTool";
  900. }
  901. for(std::vector<std::string>::iterator i = configs->begin();
  902. i != configs->end(); ++i)
  903. {
  904. fout << "\t\t\t\t<FileConfiguration\n"
  905. << "\t\t\t\t\tName=\"" << *i << "|Win32\">\n"
  906. << "\t\t\t\t\t<Tool\n"
  907. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  908. if(compileFlags.size())
  909. {
  910. fout << "\t\t\t\t\tAdditionalOptions=\""
  911. << this->EscapeForXML(compileFlags.c_str()) << "\"\n";
  912. }
  913. if(additionalDeps.length())
  914. {
  915. fout << "\t\t\t\t\tAdditionalDependencies=\""
  916. << additionalDeps.c_str() << "\"\n";
  917. }
  918. fout << "\t\t\t\t\t/>\n"
  919. << "\t\t\t\t</FileConfiguration>\n";
  920. }
  921. }
  922. fout << "\t\t\t</File>\n";
  923. }
  924. }
  925. // If the group has a name, write the footer.
  926. if(name != "")
  927. {
  928. this->WriteVCProjEndGroup(fout);
  929. }
  930. }
  931. fout << "\t</Files>\n";
  932. // Write the VCProj file's footer.
  933. this->WriteVCProjFooter(fout);
  934. }
  935. void cmLocalVisualStudio7Generator::
  936. WriteCustomRule(std::ostream& fout,
  937. const char* source,
  938. const char* command,
  939. const char* comment,
  940. const std::vector<std::string>& depends,
  941. const char *output,
  942. const char* compileFlags)
  943. {
  944. std::string cmd = command;
  945. cmSystemTools::ReplaceString(cmd, "\"", "&quot;");
  946. std::vector<std::string>::iterator i;
  947. std::vector<std::string> *configs =
  948. static_cast<cmGlobalVisualStudio7Generator *>(m_GlobalGenerator)->GetConfigurations();
  949. for(i = configs->begin(); i != configs->end(); ++i)
  950. {
  951. fout << "\t\t\t\t<FileConfiguration\n";
  952. fout << "\t\t\t\t\tName=\"" << *i << "|Win32\">\n";
  953. if(compileFlags)
  954. {
  955. fout << "\t\t\t\t\t<Tool\n"
  956. << "\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
  957. << "\t\t\t\t\tAdditionalOptions=\""
  958. << this->EscapeForXML(compileFlags) << "\"/>\n";
  959. }
  960. fout << "\t\t\t\t\t<Tool\n"
  961. << "\t\t\t\t\tName=\"VCCustomBuildTool\"\n"
  962. << "\t\t\t\t\tDescription=\"Building " << comment;
  963. fout << " " << output;
  964. fout << "\"\n"
  965. << "\t\t\t\t\tCommandLine=\"" << cmd << "\n\"\n"
  966. << "\t\t\t\t\tAdditionalDependencies=\"";
  967. // Write out the dependencies for the rule.
  968. std::string temp;
  969. for(std::vector<std::string>::const_iterator d = depends.begin();
  970. d != depends.end(); ++d)
  971. {
  972. std::string dep = cmSystemTools::GetFilenameName(*d);
  973. if (cmSystemTools::GetFilenameLastExtension(dep) == ".exe")
  974. {
  975. dep = cmSystemTools::GetFilenameWithoutLastExtension(dep);
  976. }
  977. // check to see if the dependency is another target built by cmake
  978. std::string libPath = dep + "_CMAKE_PATH";
  979. const char* cacheValue = m_Makefile->GetDefinition(libPath.c_str());
  980. if (cacheValue && *cacheValue)
  981. {
  982. std::string exePath = "";
  983. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  984. {
  985. exePath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  986. }
  987. if(exePath.size())
  988. {
  989. libPath = exePath;
  990. }
  991. else
  992. {
  993. libPath = cacheValue;
  994. }
  995. libPath += "/";
  996. libPath += "$(INTDIR)/";
  997. libPath += dep;
  998. libPath += ".exe";
  999. fout << this->ConvertToXMLOutputPath(libPath.c_str())
  1000. << ";";
  1001. }
  1002. else
  1003. {
  1004. fout << this->ConvertToXMLOutputPath(d->c_str())
  1005. << ";";
  1006. }
  1007. }
  1008. fout << "\"\n";
  1009. fout << "\t\t\t\t\tOutputs=\"";
  1010. if(output == 0)
  1011. {
  1012. fout << source << "_force";
  1013. }
  1014. // Write a rule for the output generated by this command.
  1015. fout << this->ConvertToXMLOutputPathSingle(output);
  1016. fout << "\"/>\n";
  1017. fout << "\t\t\t\t</FileConfiguration>\n";
  1018. }
  1019. }
  1020. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1021. const char* group,
  1022. const char* )
  1023. {
  1024. fout << "\t\t<Filter\n"
  1025. << "\t\t\tName=\"" << group << "\"\n"
  1026. << "\t\t\tFilter=\"\">\n";
  1027. }
  1028. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1029. {
  1030. fout << "\t\t</Filter>\n";
  1031. }
  1032. // look for custom rules on a target and collect them together
  1033. void cmLocalVisualStudio7Generator::OutputTargetRules(std::ostream& fout,
  1034. const cmTarget &target,
  1035. const char * /* libName */)
  1036. {
  1037. if (target.GetType() > cmTarget::UTILITY)
  1038. {
  1039. return;
  1040. }
  1041. // add the pre build rules
  1042. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"";
  1043. bool init = false;
  1044. for (std::vector<cmCustomCommand>::const_iterator cr =
  1045. target.GetPreBuildCommands().begin();
  1046. cr != target.GetPreBuildCommands().end(); ++cr)
  1047. {
  1048. cmCustomCommand cc(*cr);
  1049. cc.ExpandVariables(*m_Makefile);
  1050. if(!init)
  1051. {
  1052. fout << "\nCommandLine=\"";
  1053. init = true;
  1054. }
  1055. std::string args = cc.GetArguments();
  1056. cmSystemTools::ReplaceString(args, "\"", "&quot;");
  1057. fout << this->ConvertToXMLOutputPath(cc.GetCommand().c_str()) << " " <<
  1058. args << "\n";
  1059. }
  1060. if (init)
  1061. {
  1062. fout << "\"";
  1063. }
  1064. fout << "/>\n";
  1065. // add the pre Link rules
  1066. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"";
  1067. init = false;
  1068. for (std::vector<cmCustomCommand>::const_iterator cr =
  1069. target.GetPreLinkCommands().begin();
  1070. cr != target.GetPreLinkCommands().end(); ++cr)
  1071. {
  1072. cmCustomCommand cc(*cr);
  1073. cc.ExpandVariables(*m_Makefile);
  1074. if(!init)
  1075. {
  1076. fout << "\nCommandLine=\"";
  1077. init = true;
  1078. }
  1079. std::string args = cc.GetArguments();
  1080. cmSystemTools::ReplaceString(args, "\"", "&quot;");
  1081. fout << this->ConvertToXMLOutputPath(cc.GetCommand().c_str()) << " " <<
  1082. args << "\n";
  1083. }
  1084. if (init)
  1085. {
  1086. fout << "\"";
  1087. }
  1088. fout << "/>\n";
  1089. // add the PostBuild rules
  1090. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"";
  1091. init = false;
  1092. for (std::vector<cmCustomCommand>::const_iterator cr =
  1093. target.GetPostBuildCommands().begin();
  1094. cr != target.GetPostBuildCommands().end(); ++cr)
  1095. {
  1096. cmCustomCommand cc(*cr);
  1097. cc.ExpandVariables(*m_Makefile);
  1098. if(!init)
  1099. {
  1100. fout << "\nCommandLine=\"";
  1101. init = true;
  1102. }
  1103. std::string args = cc.GetArguments();
  1104. cmSystemTools::ReplaceString(args, "\"", "&quot;");
  1105. fout << this->ConvertToXMLOutputPath(cc.GetCommand().c_str()) << " " <<
  1106. args << "\n";
  1107. }
  1108. if (init)
  1109. {
  1110. fout << "\"";
  1111. }
  1112. fout << "/>\n";
  1113. }
  1114. void
  1115. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  1116. const char *libName,
  1117. const cmTarget &,
  1118. std::vector<cmSourceGroup> &)
  1119. {
  1120. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1121. << "<VisualStudioProject\n"
  1122. << "\tProjectType=\"Visual C++\"\n";
  1123. if(m_Version == 71)
  1124. {
  1125. fout << "\tVersion=\"7.10\"\n";
  1126. }
  1127. else
  1128. {
  1129. if (m_Version == 8)
  1130. {
  1131. fout << "\tVersion=\"8.0\"\n";
  1132. }
  1133. else
  1134. {
  1135. fout << "\tVersion=\"7.00\"\n";
  1136. }
  1137. }
  1138. fout << "\tName=\"" << libName << "\"\n"
  1139. << "\tSccProjectName=\"\"\n"
  1140. << "\tSccLocalPath=\"\"\n"
  1141. << "\tKeyword=\"Win32Proj\">\n"
  1142. << "\t<Platforms>\n"
  1143. << "\t\t<Platform\n\t\t\tName=\"Win32\"/>\n"
  1144. << "\t</Platforms>\n";
  1145. }
  1146. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout)
  1147. {
  1148. fout << "\t<Globals>\n"
  1149. << "\t</Globals>\n"
  1150. << "</VisualStudioProject>\n";
  1151. }
  1152. std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s)
  1153. {
  1154. std::string ret = s;
  1155. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1156. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1157. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1158. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1159. return ret;
  1160. }
  1161. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPath(const char* path)
  1162. {
  1163. std::string ret = this->ConvertToRelativeOutputPath(path);
  1164. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1165. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1166. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1167. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1168. return ret;
  1169. }
  1170. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPathSingle(const char* path)
  1171. {
  1172. std::string ret = this->ConvertToRelativeOutputPath(path);
  1173. cmSystemTools::ReplaceString(ret, "\"", "");
  1174. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1175. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1176. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1177. return ret;
  1178. }
  1179. void cmLocalVisualStudio7Generator::ConfigureFinalPass()
  1180. {
  1181. cmLocalGenerator::ConfigureFinalPass();
  1182. cmTargets &tgts = m_Makefile->GetTargets();
  1183. cmGlobalVisualStudio7Generator* gg =
  1184. static_cast<cmGlobalVisualStudio7Generator *>(m_GlobalGenerator);
  1185. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  1186. {
  1187. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  1188. {
  1189. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  1190. std::vector<std::string> stuff = cc.GetDepends();
  1191. gg->CreateGUID(stuff[0].c_str());
  1192. }
  1193. else
  1194. {
  1195. gg->CreateGUID(l->first.c_str());
  1196. }
  1197. }
  1198. }