1
0

cmLocalVisualStudio7Generator.cxx 43 KB

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