cmLocalVisualStudio7Generator.cxx 46 KB

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