cmLocalVisualStudio7Generator.cxx 45 KB

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