cmLocalVisualStudio7Generator.cxx 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmGlobalVisualStudio7Generator.h"
  11. #include "cmLocalVisualStudio7Generator.h"
  12. #include "cmXMLParser.h"
  13. #include <cm_expat.h>
  14. #include "cmMakefile.h"
  15. #include "cmSystemTools.h"
  16. #include "cmSourceFile.h"
  17. #include "cmGeneratorTarget.h"
  18. #include "cmCustomCommandGenerator.h"
  19. #include "cmake.h"
  20. #include "cmComputeLinkInformation.h"
  21. #include "cmGeneratedFileStream.h"
  22. #include <cmsys/System.h>
  23. #include <ctype.h> // for isspace
  24. static bool cmLVS6G_IsFAT(const char* dir);
  25. class cmLocalVisualStudio7GeneratorInternals
  26. {
  27. public:
  28. cmLocalVisualStudio7GeneratorInternals(cmLocalVisualStudio7Generator* e):
  29. LocalGenerator(e) {}
  30. typedef cmComputeLinkInformation::ItemVector ItemVector;
  31. void OutputLibraries(std::ostream& fout, ItemVector const& libs);
  32. void OutputObjects(std::ostream& fout, cmTarget* t, const char* isep = 0);
  33. private:
  34. cmLocalVisualStudio7Generator* LocalGenerator;
  35. };
  36. extern cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[];
  37. static void cmConvertToWindowsSlash(std::string& s)
  38. {
  39. std::string::size_type pos = 0;
  40. while((pos = s.find('/', pos)) != std::string::npos)
  41. {
  42. s[pos] = '\\';
  43. pos++;
  44. }
  45. }
  46. //----------------------------------------------------------------------------
  47. cmLocalVisualStudio7Generator
  48. ::cmLocalVisualStudio7Generator(cmGlobalGenerator* gg,
  49. cmLocalGenerator* parent,
  50. cmState::Snapshot snapshot):
  51. cmLocalVisualStudioGenerator(gg, parent, snapshot)
  52. {
  53. this->Internal = new cmLocalVisualStudio7GeneratorInternals(this);
  54. }
  55. cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator()
  56. {
  57. delete this->Internal;
  58. }
  59. void cmLocalVisualStudio7Generator::AddHelperCommands()
  60. {
  61. std::set<std::string> lang;
  62. lang.insert("C");
  63. lang.insert("CXX");
  64. lang.insert("RC");
  65. lang.insert("IDL");
  66. lang.insert("DEF");
  67. lang.insert("Fortran");
  68. this->CreateCustomTargetsAndCommands(lang);
  69. // Now create GUIDs for targets
  70. cmTargets &tgts = this->Makefile->GetTargets();
  71. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  72. {
  73. if(l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  74. {
  75. continue;
  76. }
  77. const char* path = l->second.GetProperty("EXTERNAL_MSPROJECT");
  78. if(path)
  79. {
  80. this->ReadAndStoreExternalGUID(
  81. l->second.GetName().c_str(), path);
  82. }
  83. }
  84. this->FixGlobalTargets();
  85. }
  86. void cmLocalVisualStudio7Generator::Generate()
  87. {
  88. this->WriteProjectFiles();
  89. this->WriteStampFiles();
  90. }
  91. void cmLocalVisualStudio7Generator::AddCMakeListsRules()
  92. {
  93. cmTargets &tgts = this->Makefile->GetTargets();
  94. // Create the regeneration custom rule.
  95. if(!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION"))
  96. {
  97. // Create a rule to regenerate the build system when the target
  98. // specification source changes.
  99. if(cmSourceFile* sf = this->CreateVCProjBuildRule())
  100. {
  101. // Add the rule to targets that need it.
  102. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  103. {
  104. if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
  105. {
  106. l->second.AddSource(sf->GetFullPath());
  107. }
  108. }
  109. }
  110. }
  111. }
  112. void cmLocalVisualStudio7Generator::FixGlobalTargets()
  113. {
  114. // Visual Studio .NET 2003 Service Pack 1 will not run post-build
  115. // commands for targets in which no sources are built. Add dummy
  116. // rules to force these targets to build.
  117. cmTargets &tgts = this->Makefile->GetTargets();
  118. for(cmTargets::iterator l = tgts.begin();
  119. l != tgts.end(); l++)
  120. {
  121. cmTarget& tgt = l->second;
  122. if(tgt.GetType() == cmTarget::GLOBAL_TARGET)
  123. {
  124. std::vector<std::string> no_depends;
  125. cmCustomCommandLine force_command;
  126. force_command.push_back("cd");
  127. force_command.push_back(".");
  128. cmCustomCommandLines force_commands;
  129. force_commands.push_back(force_command);
  130. std::string no_main_dependency = "";
  131. std::string force = this->Makefile->GetCurrentBinaryDirectory();
  132. force += cmake::GetCMakeFilesDirectory();
  133. force += "/";
  134. force += tgt.GetName();
  135. force += "_force";
  136. if(cmSourceFile* file =
  137. this->Makefile->AddCustomCommandToOutput(
  138. force.c_str(), no_depends, no_main_dependency,
  139. force_commands, " ", 0, true))
  140. {
  141. tgt.AddSource(file->GetFullPath());
  142. }
  143. }
  144. }
  145. }
  146. // TODO
  147. // for CommandLine= need to repleace quotes with &quot
  148. // write out configurations
  149. void cmLocalVisualStudio7Generator::WriteProjectFiles()
  150. {
  151. // If not an in source build, then create the output directory
  152. if(strcmp(this->Makefile->GetCurrentBinaryDirectory(),
  153. this->Makefile->GetHomeDirectory()) != 0)
  154. {
  155. if(!cmSystemTools::MakeDirectory
  156. (this->Makefile->GetCurrentBinaryDirectory()))
  157. {
  158. cmSystemTools::Error("Error creating directory ",
  159. this->Makefile->GetCurrentBinaryDirectory());
  160. }
  161. }
  162. // Get the set of targets in this directory.
  163. cmTargets &tgts = this->Makefile->GetTargets();
  164. // Create the project file for each target.
  165. for(cmTargets::iterator l = tgts.begin();
  166. l != tgts.end(); l++)
  167. {
  168. if(l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  169. {
  170. continue;
  171. }
  172. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  173. // so don't build a projectfile for it
  174. if(!l->second.GetProperty("EXTERNAL_MSPROJECT"))
  175. {
  176. this->CreateSingleVCProj(l->first.c_str(),l->second);
  177. }
  178. }
  179. }
  180. //----------------------------------------------------------------------------
  181. void cmLocalVisualStudio7Generator::WriteStampFiles()
  182. {
  183. // Touch a timestamp file used to determine when the project file is
  184. // out of date.
  185. std::string stampName = this->Makefile->GetCurrentBinaryDirectory();
  186. stampName += cmake::GetCMakeFilesDirectory();
  187. cmSystemTools::MakeDirectory(stampName.c_str());
  188. stampName += "/";
  189. stampName += "generate.stamp";
  190. cmsys::ofstream stamp(stampName.c_str());
  191. stamp << "# CMake generation timestamp file for this directory.\n";
  192. // Create a helper file so CMake can determine when it is run
  193. // through the rule created by CreateVCProjBuildRule whether it
  194. // really needs to regenerate the project. This file lists its own
  195. // dependencies. If any file listed in it is newer than itself then
  196. // CMake must rerun. Otherwise the project files are up to date and
  197. // the stamp file can just be touched.
  198. std::string depName = stampName;
  199. depName += ".depend";
  200. cmsys::ofstream depFile(depName.c_str());
  201. depFile << "# CMake generation dependency list for this directory.\n";
  202. std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
  203. for(std::vector<std::string>::const_iterator lf = listFiles.begin();
  204. lf != listFiles.end(); ++lf)
  205. {
  206. depFile << *lf << std::endl;
  207. }
  208. }
  209. //----------------------------------------------------------------------------
  210. void cmLocalVisualStudio7Generator
  211. ::CreateSingleVCProj(const std::string& lname, cmTarget &target)
  212. {
  213. cmGlobalVisualStudioGenerator* gg
  214. = static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  215. this->FortranProject = gg->TargetIsFortranOnly(target);
  216. this->WindowsCEProject = gg->TargetsWindowsCE();
  217. // Intel Fortran for VS10 uses VS9 format ".vfproj" files.
  218. cmGlobalVisualStudioGenerator::VSVersion realVersion = gg->GetVersion();
  219. if(this->FortranProject
  220. && gg->GetVersion() >= cmGlobalVisualStudioGenerator::VS10)
  221. {
  222. gg->SetVersion(cmGlobalVisualStudioGenerator::VS9);
  223. }
  224. // add to the list of projects
  225. target.SetProperty("GENERATOR_FILE_NAME",lname.c_str());
  226. // create the dsp.cmake file
  227. std::string fname;
  228. fname = this->Makefile->GetCurrentBinaryDirectory();
  229. fname += "/";
  230. fname += lname;
  231. if(this->FortranProject)
  232. {
  233. fname += ".vfproj";
  234. }
  235. else
  236. {
  237. fname += ".vcproj";
  238. }
  239. // Generate the project file and replace it atomically with
  240. // copy-if-different. We use a separate timestamp so that the IDE
  241. // does not reload project files unnecessarily.
  242. cmGeneratedFileStream fout(fname.c_str());
  243. fout.SetCopyIfDifferent(true);
  244. this->WriteVCProjFile(fout,lname,target);
  245. if (fout.Close())
  246. {
  247. this->GlobalGenerator->FileReplacedDuringGenerate(fname);
  248. }
  249. gg->SetVersion(realVersion);
  250. }
  251. //----------------------------------------------------------------------------
  252. cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
  253. {
  254. std::string stampName = this->Makefile->GetCurrentBinaryDirectory();
  255. stampName += "/";
  256. stampName += cmake::GetCMakeFilesDirectoryPostSlash();
  257. stampName += "generate.stamp";
  258. cmCustomCommandLine commandLine;
  259. commandLine.push_back(cmSystemTools::GetCMakeCommand());
  260. std::string makefileIn = this->Makefile->GetCurrentSourceDirectory();
  261. makefileIn += "/";
  262. makefileIn += "CMakeLists.txt";
  263. makefileIn = cmSystemTools::CollapseFullPath(makefileIn.c_str());
  264. if(!cmSystemTools::FileExists(makefileIn.c_str()))
  265. {
  266. return 0;
  267. }
  268. std::string comment = "Building Custom Rule ";
  269. comment += makefileIn;
  270. std::string args;
  271. args = "-H";
  272. args += this->Convert(this->Makefile->GetHomeDirectory(),
  273. START_OUTPUT, UNCHANGED, true);
  274. commandLine.push_back(args);
  275. args = "-B";
  276. args +=
  277. this->Convert(this->Makefile->GetHomeOutputDirectory(),
  278. START_OUTPUT, UNCHANGED, true);
  279. commandLine.push_back(args);
  280. commandLine.push_back("--check-stamp-file");
  281. std::string stampFilename = this->Convert(stampName.c_str(), FULL,
  282. SHELL);
  283. commandLine.push_back(stampFilename.c_str());
  284. std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
  285. cmCustomCommandLines commandLines;
  286. commandLines.push_back(commandLine);
  287. const char* no_working_directory = 0;
  288. std::string fullpathStampName = this->Convert(stampName.c_str(), FULL,
  289. UNCHANGED);
  290. this->Makefile->AddCustomCommandToOutput(fullpathStampName.c_str(),
  291. listFiles, makefileIn.c_str(),
  292. commandLines, comment.c_str(),
  293. no_working_directory, true);
  294. if(cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str()))
  295. {
  296. return file;
  297. }
  298. else
  299. {
  300. cmSystemTools::Error("Error adding rule for ", makefileIn.c_str());
  301. return 0;
  302. }
  303. }
  304. void cmLocalVisualStudio7Generator::WriteConfigurations(
  305. std::ostream& fout, std::vector<std::string> const& configs,
  306. const std::string& libName, cmTarget &target
  307. )
  308. {
  309. fout << "\t<Configurations>\n";
  310. for (std::vector<std::string>::const_iterator i = configs.begin();
  311. i != configs.end(); ++i)
  312. {
  313. this->WriteConfiguration(fout, i->c_str(), libName, target);
  314. }
  315. fout << "\t</Configurations>\n";
  316. }
  317. cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranFlagTable[] =
  318. {
  319. {"Preprocess", "fpp", "Run Preprocessor on files", "preprocessYes", 0},
  320. {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "true", 0},
  321. {"SourceFileFormat", "fixed", "Use Fixed Format", "fileFormatFixed", 0},
  322. {"SourceFileFormat", "free", "Use Free Format", "fileFormatFree", 0},
  323. {"DebugInformationFormat", "Zi", "full debug", "debugEnabled", 0},
  324. {"DebugInformationFormat", "debug:full", "full debug", "debugEnabled", 0},
  325. {"DebugInformationFormat", "Z7", "c7 compat", "debugOldStyleInfo", 0},
  326. {"DebugInformationFormat", "Zd", "line numbers", "debugLineInfoOnly", 0},
  327. {"Optimization", "Od", "disable optimization", "optimizeDisabled", 0},
  328. {"Optimization", "O1", "min space", "optimizeMinSpace", 0},
  329. {"Optimization", "O3", "full optimize", "optimizeFull", 0},
  330. {"GlobalOptimizations", "Og", "global optimize", "true", 0},
  331. {"InlineFunctionExpansion", "Ob0", "", "expandDisable", 0},
  332. {"InlineFunctionExpansion", "Ob1", "", "expandOnlyInline", 0},
  333. {"FavorSizeOrSpeed", "Os", "", "favorSize", 0},
  334. {"OmitFramePointers", "Oy-", "", "false", 0},
  335. {"OptimizeForProcessor", "GB", "", "procOptimizeBlended", 0},
  336. {"OptimizeForProcessor", "G5", "", "procOptimizePentium", 0},
  337. {"OptimizeForProcessor", "G6", "", "procOptimizePentiumProThruIII", 0},
  338. {"UseProcessorExtensions", "QzxK", "", "codeForStreamingSIMD", 0},
  339. {"OptimizeForProcessor", "QaxN", "", "codeForPentium4", 0},
  340. {"OptimizeForProcessor", "QaxB", "", "codeForPentiumM", 0},
  341. {"OptimizeForProcessor", "QaxP", "", "codeForCodeNamedPrescott", 0},
  342. {"OptimizeForProcessor", "QaxT", "", "codeForCore2Duo", 0},
  343. {"OptimizeForProcessor", "QxK", "", "codeExclusivelyStreamingSIMD", 0},
  344. {"OptimizeForProcessor", "QxN", "", "codeExclusivelyPentium4", 0},
  345. {"OptimizeForProcessor", "QxB", "", "codeExclusivelyPentiumM", 0},
  346. {"OptimizeForProcessor", "QxP", "", "codeExclusivelyCodeNamedPrescott", 0},
  347. {"OptimizeForProcessor", "QxT", "", "codeExclusivelyCore2Duo", 0},
  348. {"OptimizeForProcessor", "QxO", "", "codeExclusivelyCore2StreamingSIMD", 0},
  349. {"OptimizeForProcessor", "QxS", "", "codeExclusivelyCore2StreamingSIMD4", 0},
  350. {"OpenMP", "Qopenmp", "", "OpenMPParallelCode", 0},
  351. {"OpenMP", "Qopenmp-stubs", "", "OpenMPSequentialCode", 0},
  352. {"Traceback", "traceback", "", "true", 0},
  353. {"Traceback", "notraceback", "", "false", 0},
  354. {"FloatingPointExceptionHandling", "fpe:0", "", "fpe0", 0},
  355. {"FloatingPointExceptionHandling", "fpe:1", "", "fpe1", 0},
  356. {"FloatingPointExceptionHandling", "fpe:3", "", "fpe3", 0},
  357. {"ModulePath", "module:", "", "",
  358. cmVS7FlagTable::UserValueRequired},
  359. {"LoopUnrolling", "Qunroll:", "", "",
  360. cmVS7FlagTable::UserValueRequired},
  361. {"AutoParallelThreshold", "Qpar-threshold:", "", "",
  362. cmVS7FlagTable::UserValueRequired},
  363. {"HeapArrays", "heap-arrays:", "", "",
  364. cmVS7FlagTable::UserValueRequired},
  365. {"ObjectText", "bintext:", "", "",
  366. cmVS7FlagTable::UserValueRequired},
  367. {"Parallelization", "Qparallel", "", "true", 0},
  368. {"PrefetchInsertion", "Qprefetch-", "", "false", 0},
  369. {"BufferedIO", "assume:buffered_io", "", "true", 0},
  370. {"CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0},
  371. {"CallingConvention", "iface:cref", "", "callConventionCRef", 0},
  372. {"CallingConvention", "iface:stdref", "", "callConventionStdRef", 0},
  373. {"CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0},
  374. {"CallingConvention", "iface:cvf", "", "callConventionCVF", 0},
  375. {"EnableRecursion", "recursive", "", "true", 0},
  376. {"ReentrantCode", "reentrancy", "", "true", 0},
  377. // done up to Language
  378. {0,0,0,0,0}
  379. };
  380. // fill the table here currently the comment field is not used for
  381. // anything other than documentation NOTE: Make sure the longer
  382. // commandFlag comes FIRST!
  383. cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[] =
  384. {
  385. // option flags (some flags map to the same option)
  386. {"BasicRuntimeChecks", "GZ", "Stack frame checks", "1", 0},
  387. {"BasicRuntimeChecks", "RTCsu",
  388. "Both stack and uninitialized checks", "3", 0},
  389. {"BasicRuntimeChecks", "RTCs", "Stack frame checks", "1", 0},
  390. {"BasicRuntimeChecks", "RTCu", "Uninitialized Variables ", "2", 0},
  391. {"BasicRuntimeChecks", "RTC1",
  392. "Both stack and uninitialized checks", "3", 0},
  393. {"DebugInformationFormat", "Z7", "debug format", "1", 0},
  394. {"DebugInformationFormat", "Zd", "debug format", "2", 0},
  395. {"DebugInformationFormat", "Zi", "debug format", "3", 0},
  396. {"DebugInformationFormat", "ZI", "debug format", "4", 0},
  397. {"EnableEnhancedInstructionSet", "arch:SSE2",
  398. "Use sse2 instructions", "2", 0},
  399. {"EnableEnhancedInstructionSet", "arch:SSE",
  400. "Use sse instructions", "1", 0},
  401. {"FloatingPointModel", "fp:precise",
  402. "Use precise floating point model", "0", 0},
  403. {"FloatingPointModel", "fp:strict",
  404. "Use strict floating point model", "1", 0},
  405. {"FloatingPointModel", "fp:fast", "Use fast floating point model", "2", 0},
  406. {"FavorSizeOrSpeed", "Ot", "Favor fast code", "1", 0},
  407. {"FavorSizeOrSpeed", "Os", "Favor small code", "2", 0},
  408. {"CompileAs", "TC", "Compile as c code", "1", 0},
  409. {"CompileAs", "TP", "Compile as c++ code", "2", 0},
  410. {"Optimization", "Od", "Non Debug", "0", 0},
  411. {"Optimization", "O1", "Min Size", "1", 0},
  412. {"Optimization", "O2", "Max Speed", "2", 0},
  413. {"Optimization", "Ox", "Max Optimization", "3", 0},
  414. {"OptimizeForProcessor", "GB", "Blended processor mode", "0", 0},
  415. {"OptimizeForProcessor", "G5", "Pentium", "1", 0},
  416. {"OptimizeForProcessor", "G6", "PPro PII PIII", "2", 0},
  417. {"OptimizeForProcessor", "G7", "Pentium 4 or Athlon", "3", 0},
  418. {"InlineFunctionExpansion", "Ob0", "no inlines", "0", 0},
  419. {"InlineFunctionExpansion", "Ob1", "when inline keyword", "1", 0},
  420. {"InlineFunctionExpansion", "Ob2", "any time you can inline", "2", 0},
  421. {"RuntimeLibrary", "MTd", "Multithreaded debug", "1", 0},
  422. {"RuntimeLibrary", "MT", "Multithreaded", "0", 0},
  423. {"RuntimeLibrary", "MDd", "Multithreaded dll debug", "3", 0},
  424. {"RuntimeLibrary", "MD", "Multithreaded dll", "2", 0},
  425. {"RuntimeLibrary", "MLd", "Single Thread debug", "5", 0},
  426. {"RuntimeLibrary", "ML", "Single Thread", "4", 0},
  427. {"StructMemberAlignment", "Zp16", "struct align 16 byte ", "5", 0},
  428. {"StructMemberAlignment", "Zp1", "struct align 1 byte ", "1", 0},
  429. {"StructMemberAlignment", "Zp2", "struct align 2 byte ", "2", 0},
  430. {"StructMemberAlignment", "Zp4", "struct align 4 byte ", "3", 0},
  431. {"StructMemberAlignment", "Zp8", "struct align 8 byte ", "4", 0},
  432. {"WarningLevel", "W0", "Warning level", "0", 0},
  433. {"WarningLevel", "W1", "Warning level", "1", 0},
  434. {"WarningLevel", "W2", "Warning level", "2", 0},
  435. {"WarningLevel", "W3", "Warning level", "3", 0},
  436. {"WarningLevel", "W4", "Warning level", "4", 0},
  437. {"DisableSpecificWarnings", "wd", "Disable specific warnings", "",
  438. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
  439. // Precompiled header and related options. Note that the
  440. // UsePrecompiledHeader entries are marked as "Continue" so that the
  441. // corresponding PrecompiledHeaderThrough entry can be found.
  442. {"UsePrecompiledHeader", "Yc", "Create Precompiled Header", "1",
  443. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  444. {"PrecompiledHeaderThrough", "Yc", "Precompiled Header Name", "",
  445. cmVS7FlagTable::UserValueRequired},
  446. {"PrecompiledHeaderFile", "Fp", "Generated Precompiled Header", "",
  447. cmVS7FlagTable::UserValue},
  448. // The YX and Yu options are in a per-global-generator table because
  449. // their values differ based on the VS IDE version.
  450. {"ForcedIncludeFiles", "FI", "Forced include files", "",
  451. cmVS7FlagTable::UserValueRequired | cmVS7FlagTable::SemicolonAppendable},
  452. {"AssemblerListingLocation", "Fa", "ASM List Location", "",
  453. cmVS7FlagTable::UserValue},
  454. {"ProgramDataBaseFileName", "Fd", "Program Database File Name", "",
  455. cmVS7FlagTable::UserValue},
  456. // boolean flags
  457. {"BufferSecurityCheck", "GS", "Buffer security check", "true", 0},
  458. {"BufferSecurityCheck", "GS-", "Turn off Buffer security check", "false", 0},
  459. {"Detect64BitPortabilityProblems", "Wp64",
  460. "Detect 64-bit Portability Problems", "true", 0},
  461. {"EnableFiberSafeOptimizations", "GT", "Enable Fiber-safe Optimizations",
  462. "true", 0},
  463. {"EnableFunctionLevelLinking", "Gy",
  464. "EnableFunctionLevelLinking", "true", 0},
  465. {"EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "true", 0},
  466. {"GlobalOptimizations", "Og", "Global Optimize", "true", 0},
  467. {"ImproveFloatingPointConsistency", "Op",
  468. "ImproveFloatingPointConsistency", "true", 0},
  469. {"MinimalRebuild", "Gm", "minimal rebuild", "true", 0},
  470. {"OmitFramePointers", "Oy", "OmitFramePointers", "true", 0},
  471. {"OptimizeForWindowsApplication", "GA", "Optimize for windows", "true", 0},
  472. {"RuntimeTypeInfo", "GR",
  473. "Turn on Run time type information for c++", "true", 0},
  474. {"RuntimeTypeInfo", "GR-",
  475. "Turn off Run time type information for c++", "false", 0},
  476. {"SmallerTypeCheck", "RTCc", "smaller type check", "true", 0},
  477. {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "true", 0},
  478. {"WholeProgramOptimization", "GL",
  479. "Enables whole program optimization", "true", 0},
  480. {"WholeProgramOptimization", "GL-",
  481. "Disables whole program optimization", "false", 0},
  482. {"WarnAsError", "WX", "Treat warnings as errors", "true", 0},
  483. {"BrowseInformation", "FR", "Generate browse information", "1", 0},
  484. {"StringPooling", "GF", "Enable StringPooling", "true", 0},
  485. {0,0,0,0,0}
  486. };
  487. cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] =
  488. {
  489. // option flags (some flags map to the same option)
  490. {"GenerateManifest", "MANIFEST:NO",
  491. "disable manifest generation", "false", 0},
  492. {"GenerateManifest", "MANIFEST", "enable manifest generation", "true", 0},
  493. {"LinkIncremental", "INCREMENTAL:NO", "link incremental", "1", 0},
  494. {"LinkIncremental", "INCREMENTAL:YES", "link incremental", "2", 0},
  495. {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK:NO", "", "false", 0},
  496. {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK", "", "true", 0},
  497. {"DataExecutionPrevention", "NXCOMPAT:NO",
  498. "Not known to work with Windows Data Execution Prevention", "1", 0},
  499. {"DataExecutionPrevention", "NXCOMPAT",
  500. "Known to work with Windows Data Execution Prevention", "2", 0},
  501. {"DelaySign", "DELAYSIGN:NO", "", "false", 0},
  502. {"DelaySign", "DELAYSIGN", "", "true", 0},
  503. {"EntryPointSymbol", "ENTRY:", "sets the starting address", "",
  504. cmVS7FlagTable::UserValue},
  505. {"IgnoreDefaultLibraryNames", "NODEFAULTLIB:", "default libs to ignore", "",
  506. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
  507. {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "ignore all default libs",
  508. "true", 0},
  509. {"FixedBaseAddress", "FIXED:NO", "Generate a relocation section", "1", 0},
  510. {"FixedBaseAddress", "FIXED", "Image must be loaded at a fixed address",
  511. "2", 0},
  512. {"EnableCOMDATFolding", "OPT:NOICF", "Do not remove redundant COMDATs",
  513. "1", 0},
  514. {"EnableCOMDATFolding", "OPT:ICF", "Remove redundant COMDATs", "2", 0},
  515. {"ResourceOnlyDLL", "NOENTRY", "Create DLL with no entry point", "true", 0},
  516. {"OptimizeReferences", "OPT:NOREF", "Keep unreferenced data", "1", 0},
  517. {"OptimizeReferences", "OPT:REF", "Eliminate unreferenced data", "2", 0},
  518. {"Profile", "PROFILE", "", "true", 0},
  519. {"RandomizedBaseAddress", "DYNAMICBASE:NO",
  520. "Image may not be rebased at load-time", "1", 0},
  521. {"RandomizedBaseAddress", "DYNAMICBASE",
  522. "Image may be rebased at load-time", "2", 0},
  523. {"SetChecksum", "RELEASE", "Enable setting checksum in header", "true", 0},
  524. {"SupportUnloadOfDelayLoadedDLL", "DELAY:UNLOAD", "", "true", 0},
  525. {"TargetMachine", "MACHINE:I386", "Machine x86", "1", 0},
  526. {"TargetMachine", "MACHINE:X86", "Machine x86", "1", 0},
  527. {"TargetMachine", "MACHINE:AM33", "Machine AM33", "2", 0},
  528. {"TargetMachine", "MACHINE:ARM", "Machine ARM", "3", 0},
  529. {"TargetMachine", "MACHINE:EBC", "Machine EBC", "4", 0},
  530. {"TargetMachine", "MACHINE:IA64", "Machine IA64", "5", 0},
  531. {"TargetMachine", "MACHINE:M32R", "Machine M32R", "6", 0},
  532. {"TargetMachine", "MACHINE:MIPS", "Machine MIPS", "7", 0},
  533. {"TargetMachine", "MACHINE:MIPS16", "Machine MIPS16", "8", 0},
  534. {"TargetMachine", "MACHINE:MIPSFPU)", "Machine MIPSFPU", "9", 0},
  535. {"TargetMachine", "MACHINE:MIPSFPU16", "Machine MIPSFPU16", "10", 0},
  536. {"TargetMachine", "MACHINE:MIPSR41XX", "Machine MIPSR41XX", "11", 0},
  537. {"TargetMachine", "MACHINE:SH3", "Machine SH3", "12", 0},
  538. {"TargetMachine", "MACHINE:SH3DSP", "Machine SH3DSP", "13", 0},
  539. {"TargetMachine", "MACHINE:SH4", "Machine SH4", "14", 0},
  540. {"TargetMachine", "MACHINE:SH5", "Machine SH5", "15", 0},
  541. {"TargetMachine", "MACHINE:THUMB", "Machine THUMB", "16", 0},
  542. {"TargetMachine", "MACHINE:X64", "Machine x64", "17", 0},
  543. {"TurnOffAssemblyGeneration", "NOASSEMBLY",
  544. "No assembly even if CLR information is present in objects.", "true", 0},
  545. {"ModuleDefinitionFile", "DEF:", "add an export def file", "",
  546. cmVS7FlagTable::UserValue},
  547. {"GenerateMapFile", "MAP", "enable generation of map file", "true", 0},
  548. {0,0,0,0,0}
  549. };
  550. cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranLinkFlagTable[] =
  551. {
  552. {"LinkIncremental", "INCREMENTAL:NO", "link incremental",
  553. "linkIncrementalNo", 0},
  554. {"LinkIncremental", "INCREMENTAL:YES", "link incremental",
  555. "linkIncrementalYes", 0},
  556. {0,0,0,0,0}
  557. };
  558. //----------------------------------------------------------------------------
  559. // Helper class to write build event <Tool .../> elements.
  560. class cmLocalVisualStudio7Generator::EventWriter
  561. {
  562. public:
  563. EventWriter(cmLocalVisualStudio7Generator* lg,
  564. const std::string& config, std::ostream& os):
  565. LG(lg), Config(config), Stream(os), First(true) {}
  566. void Start(const char* tool)
  567. {
  568. this->First = true;
  569. this->Stream << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
  570. }
  571. void Finish()
  572. {
  573. this->Stream << (this->First? "" : "\"") << "/>\n";
  574. }
  575. void Write(std::vector<cmCustomCommand> const& ccs)
  576. {
  577. for(std::vector<cmCustomCommand>::const_iterator ci = ccs.begin();
  578. ci != ccs.end(); ++ci)
  579. {
  580. this->Write(*ci);
  581. }
  582. }
  583. void Write(cmCustomCommand const& cc)
  584. {
  585. cmCustomCommandGenerator ccg(cc, this->Config, this->LG->GetMakefile());
  586. if(this->First)
  587. {
  588. const char* comment = ccg.GetComment();
  589. if(comment && *comment)
  590. {
  591. this->Stream << "\nDescription=\""
  592. << this->LG->EscapeForXML(comment) << "\"";
  593. }
  594. this->Stream << "\nCommandLine=\"";
  595. this->First = false;
  596. }
  597. else
  598. {
  599. this->Stream << this->LG->EscapeForXML("\n");
  600. }
  601. std::string script = this->LG->ConstructScript(ccg);
  602. this->Stream << this->LG->EscapeForXML(script.c_str());
  603. }
  604. private:
  605. cmLocalVisualStudio7Generator* LG;
  606. std::string Config;
  607. std::ostream& Stream;
  608. bool First;
  609. };
  610. //----------------------------------------------------------------------------
  611. void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
  612. const std::string& configName,
  613. const std::string& libName,
  614. cmTarget &target)
  615. {
  616. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  617. if(!mfcFlag)
  618. {
  619. mfcFlag = "0";
  620. }
  621. cmGlobalVisualStudio7Generator* gg =
  622. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  623. fout << "\t\t<Configuration\n"
  624. << "\t\t\tName=\"" << configName
  625. << "|" << gg->GetPlatformName() << "\"\n";
  626. // This is an internal type to Visual Studio, it seems that:
  627. // 4 == static library
  628. // 2 == dll
  629. // 1 == executable
  630. // 10 == utility
  631. const char* configType = "10";
  632. const char* projectType = 0;
  633. bool targetBuilds = true;
  634. switch(target.GetType())
  635. {
  636. case cmTarget::OBJECT_LIBRARY:
  637. targetBuilds = false; // no manifest tool for object library
  638. case cmTarget::STATIC_LIBRARY:
  639. projectType = "typeStaticLibrary";
  640. configType = "4";
  641. break;
  642. case cmTarget::SHARED_LIBRARY:
  643. case cmTarget::MODULE_LIBRARY:
  644. projectType = "typeDynamicLibrary";
  645. configType = "2";
  646. break;
  647. case cmTarget::EXECUTABLE:
  648. configType = "1";
  649. break;
  650. case cmTarget::UTILITY:
  651. case cmTarget::GLOBAL_TARGET:
  652. configType = "10";
  653. default:
  654. targetBuilds = false;
  655. break;
  656. }
  657. if(this->FortranProject && projectType)
  658. {
  659. configType = projectType;
  660. }
  661. std::string flags;
  662. if(strcmp(configType, "10") != 0)
  663. {
  664. const std::string& linkLanguage = (this->FortranProject?
  665. std::string("Fortran"):
  666. target.GetLinkerLanguage(configName));
  667. if(linkLanguage.empty())
  668. {
  669. cmSystemTools::Error
  670. ("CMake can not determine linker language for target: ",
  671. target.GetName().c_str());
  672. return;
  673. }
  674. if(linkLanguage == "C" || linkLanguage == "CXX"
  675. || linkLanguage == "Fortran")
  676. {
  677. std::string baseFlagVar = "CMAKE_";
  678. baseFlagVar += linkLanguage;
  679. baseFlagVar += "_FLAGS";
  680. flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  681. std::string flagVar = baseFlagVar + std::string("_") +
  682. cmSystemTools::UpperCase(configName);
  683. flags += " ";
  684. flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
  685. }
  686. // set the correct language
  687. if(linkLanguage == "C")
  688. {
  689. flags += " /TC ";
  690. }
  691. if(linkLanguage == "CXX")
  692. {
  693. flags += " /TP ";
  694. }
  695. // Add the target-specific flags.
  696. this->AddCompileOptions(flags, &target, linkLanguage, configName);
  697. }
  698. if(this->FortranProject)
  699. {
  700. switch(this->GetFortranFormat(target.GetProperty("Fortran_FORMAT")))
  701. {
  702. case FortranFormatFixed: flags += " -fixed"; break;
  703. case FortranFormatFree: flags += " -free"; break;
  704. default: break;
  705. }
  706. }
  707. // Get preprocessor definitions for this directory.
  708. std::string defineFlags = this->Makefile->GetDefineFlags();
  709. Options::Tool t = Options::Compiler;
  710. cmVS7FlagTable const* table = cmLocalVisualStudio7GeneratorFlagTable;
  711. if(this->FortranProject)
  712. {
  713. t = Options::FortranCompiler;
  714. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  715. }
  716. Options targetOptions(this, t,
  717. table,
  718. gg->ExtraFlagTable);
  719. targetOptions.FixExceptionHandlingDefault();
  720. std::string asmLocation = configName + "/";
  721. targetOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  722. targetOptions.Parse(flags.c_str());
  723. targetOptions.Parse(defineFlags.c_str());
  724. targetOptions.ParseFinish();
  725. cmGeneratorTarget* gt =
  726. this->GlobalGenerator->GetGeneratorTarget(&target);
  727. std::vector<std::string> targetDefines;
  728. target.GetCompileDefinitions(targetDefines, configName, "CXX");
  729. targetOptions.AddDefines(targetDefines);
  730. targetOptions.SetVerboseMakefile(
  731. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  732. // Add a definition for the configuration name.
  733. std::string configDefine = "CMAKE_INTDIR=\"";
  734. configDefine += configName;
  735. configDefine += "\"";
  736. targetOptions.AddDefine(configDefine);
  737. // Add the export symbol definition for shared library objects.
  738. if(const char* exportMacro = target.GetExportMacro())
  739. {
  740. targetOptions.AddDefine(exportMacro);
  741. }
  742. // The intermediate directory name consists of a directory for the
  743. // target and a subdirectory for the configuration name.
  744. std::string intermediateDir = this->GetTargetDirectory(target);
  745. intermediateDir += "/";
  746. intermediateDir += configName;
  747. if (target.GetType() < cmTarget::UTILITY)
  748. {
  749. std::string const& outDir =
  750. target.GetType() == cmTarget::OBJECT_LIBRARY?
  751. intermediateDir : target.GetDirectory(configName);
  752. fout << "\t\t\tOutputDirectory=\""
  753. << this->ConvertToXMLOutputPathSingle(outDir.c_str()) << "\"\n";
  754. }
  755. fout << "\t\t\tIntermediateDirectory=\""
  756. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  757. << "\"\n"
  758. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  759. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  760. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"false\"\n";
  761. if (this->FortranProject)
  762. {
  763. // Intel Fortran >= 15.0 uses TargetName property.
  764. std::string targetNameFull = target.GetFullName(configName);
  765. std::string targetName =
  766. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  767. std::string targetExt =
  768. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  769. fout <<
  770. "\t\t\tTargetName=\"" << this->EscapeForXML(targetName) << "\"\n"
  771. "\t\t\tTargetExt=\"" << this->EscapeForXML(targetExt) << "\"\n"
  772. ;
  773. }
  774. // If unicode is enabled change the character set to unicode, if not
  775. // then default to MBCS.
  776. if(targetOptions.UsingUnicode())
  777. {
  778. fout << "\t\t\tCharacterSet=\"1\">\n";
  779. }
  780. else if(targetOptions.UsingSBCS())
  781. {
  782. fout << "\t\t\tCharacterSet=\"0\">\n";
  783. }
  784. else
  785. {
  786. fout << "\t\t\tCharacterSet=\"2\">\n";
  787. }
  788. const char* tool = "VCCLCompilerTool";
  789. if(this->FortranProject)
  790. {
  791. tool = "VFFortranCompilerTool";
  792. }
  793. fout << "\t\t\t<Tool\n"
  794. << "\t\t\t\tName=\"" << tool << "\"\n";
  795. if(this->FortranProject)
  796. {
  797. const char* target_mod_dir =
  798. target.GetProperty("Fortran_MODULE_DIRECTORY");
  799. std::string modDir;
  800. if(target_mod_dir)
  801. {
  802. modDir = this->Convert(target_mod_dir,
  803. cmLocalGenerator::START_OUTPUT,
  804. cmLocalGenerator::UNCHANGED);
  805. }
  806. else
  807. {
  808. modDir = ".";
  809. }
  810. fout << "\t\t\t\tModulePath=\""
  811. << this->ConvertToXMLOutputPath(modDir.c_str())
  812. << "\\$(ConfigurationName)\"\n";
  813. }
  814. targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  815. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  816. std::vector<std::string> includes;
  817. this->GetIncludeDirectories(includes, gt, "C", configName);
  818. std::vector<std::string>::iterator i = includes.begin();
  819. for(;i != includes.end(); ++i)
  820. {
  821. // output the include path
  822. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  823. fout << ipath << ";";
  824. // if this is fortran then output the include with
  825. // a ConfigurationName on the end of it.
  826. if(this->FortranProject)
  827. {
  828. ipath = i->c_str();
  829. ipath += "/$(ConfigurationName)";
  830. ipath = this->ConvertToXMLOutputPath(ipath.c_str());
  831. fout << ipath << ";";
  832. }
  833. }
  834. fout << "\"\n";
  835. targetOptions.OutputFlagMap(fout, "\t\t\t\t");
  836. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n", "CXX");
  837. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  838. if(target.GetType() <= cmTarget::OBJECT_LIBRARY)
  839. {
  840. // Specify the compiler program database file if configured.
  841. std::string pdb = target.GetCompilePDBPath(configName);
  842. if(!pdb.empty())
  843. {
  844. fout << "\t\t\t\tProgramDataBaseFileName=\""
  845. << this->ConvertToXMLOutputPathSingle(pdb.c_str())
  846. << "\"\n";
  847. }
  848. }
  849. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  850. if(gg->IsMasmEnabled() && !this->FortranProject)
  851. {
  852. Options masmOptions(this, Options::MasmCompiler, 0, 0);
  853. fout <<
  854. "\t\t\t<Tool\n"
  855. "\t\t\t\tName=\"MASM\"\n"
  856. "\t\t\t\tIncludePaths=\""
  857. ;
  858. const char* sep = "";
  859. for(i = includes.begin(); i != includes.end(); ++i)
  860. {
  861. std::string inc = *i;
  862. cmConvertToWindowsSlash(inc);
  863. fout << sep << this->EscapeForXML(inc);
  864. sep = ";";
  865. }
  866. fout << "\"\n";
  867. // Use same preprocessor definitions as VCCLCompilerTool.
  868. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n",
  869. "ASM_MASM");
  870. masmOptions.OutputFlagMap(fout, "\t\t\t\t");
  871. fout <<
  872. "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n"
  873. "\t\t\t/>\n";
  874. }
  875. tool = "VCCustomBuildTool";
  876. if(this->FortranProject)
  877. {
  878. tool = "VFCustomBuildTool";
  879. }
  880. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"/>\n";
  881. tool = "VCResourceCompilerTool";
  882. if(this->FortranProject)
  883. {
  884. tool = "VFResourceCompilerTool";
  885. }
  886. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  887. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  888. for(i = includes.begin();i != includes.end(); ++i)
  889. {
  890. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  891. fout << ipath << ";";
  892. }
  893. // add the -D flags to the RC tool
  894. fout << "\"";
  895. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "", "RC");
  896. fout << "/>\n";
  897. tool = "VCMIDLTool";
  898. if(this->FortranProject)
  899. {
  900. tool = "VFMIDLTool";
  901. }
  902. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n";
  903. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  904. for(i = includes.begin(); i != includes.end(); ++i)
  905. {
  906. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  907. fout << ipath << ";";
  908. }
  909. fout << "\"\n";
  910. fout << "\t\t\t\tMkTypLibCompatible=\"false\"\n";
  911. if( gg->GetPlatformName() == "x64" )
  912. {
  913. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  914. }
  915. else if( gg->GetPlatformName() == "ia64" )
  916. {
  917. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  918. }
  919. else
  920. {
  921. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  922. }
  923. fout << "\t\t\t\tGenerateStublessProxies=\"true\"\n";
  924. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  925. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  926. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  927. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  928. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  929. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  930. // end of <Tool Name=VCMIDLTool
  931. // Check if we need the FAT32 workaround.
  932. if(targetBuilds && this->GetVersion() >= cmGlobalVisualStudioGenerator::VS8)
  933. {
  934. // Check the filesystem type where the target will be written.
  935. if(cmLVS6G_IsFAT(target.GetDirectory(configName).c_str()))
  936. {
  937. // Add a flag telling the manifest tool to use a workaround
  938. // for FAT32 file systems, which can cause an empty manifest
  939. // to be embedded into the resulting executable. See CMake
  940. // bug #2617.
  941. const char* manifestTool = "VCManifestTool";
  942. if(this->FortranProject)
  943. {
  944. manifestTool = "VFManifestTool";
  945. }
  946. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << manifestTool << "\"\n"
  947. << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
  948. << "\t\t\t/>\n";
  949. }
  950. }
  951. this->OutputTargetRules(fout, configName, target, libName);
  952. this->OutputBuildTool(fout, configName, target, targetOptions);
  953. fout << "\t\t</Configuration>\n";
  954. }
  955. //----------------------------------------------------------------------------
  956. std::string
  957. cmLocalVisualStudio7Generator
  958. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags,
  959. const std::string& configName)
  960. {
  961. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  962. std::string extraLinkOptionsBuildTypeDef =
  963. rootLinkerFlags + "_" + configTypeUpper;
  964. std::string extraLinkOptionsBuildType =
  965. this->Makefile->GetRequiredDefinition
  966. (extraLinkOptionsBuildTypeDef.c_str());
  967. return extraLinkOptionsBuildType;
  968. }
  969. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  970. const std::string& configName, cmTarget &target,
  971. const Options& targetOptions)
  972. {
  973. cmGlobalVisualStudio7Generator* gg =
  974. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  975. std::string temp;
  976. std::string extraLinkOptions;
  977. if(target.GetType() == cmTarget::EXECUTABLE)
  978. {
  979. extraLinkOptions =
  980. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
  981. + std::string(" ")
  982. + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  983. }
  984. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  985. {
  986. extraLinkOptions =
  987. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
  988. + std::string(" ")
  989. + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  990. }
  991. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  992. {
  993. extraLinkOptions =
  994. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
  995. + std::string(" ")
  996. + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  997. }
  998. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  999. if(targetLinkFlags)
  1000. {
  1001. extraLinkOptions += " ";
  1002. extraLinkOptions += targetLinkFlags;
  1003. }
  1004. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  1005. std::string linkFlagsConfig = "LINK_FLAGS_";
  1006. linkFlagsConfig += configTypeUpper;
  1007. targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
  1008. if(targetLinkFlags)
  1009. {
  1010. extraLinkOptions += " ";
  1011. extraLinkOptions += targetLinkFlags;
  1012. }
  1013. Options linkOptions(this, Options::Linker);
  1014. if(this->FortranProject)
  1015. {
  1016. linkOptions.AddTable(cmLocalVisualStudio7GeneratorFortranLinkFlagTable);
  1017. }
  1018. linkOptions.AddTable(cmLocalVisualStudio7GeneratorLinkFlagTable);
  1019. linkOptions.Parse(extraLinkOptions.c_str());
  1020. if(!this->ModuleDefinitionFile.empty())
  1021. {
  1022. std::string defFile =
  1023. this->ConvertToOptionallyRelativeOutputPath(this->ModuleDefinitionFile);
  1024. linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
  1025. }
  1026. switch(target.GetType())
  1027. {
  1028. case cmTarget::UNKNOWN_LIBRARY:
  1029. break;
  1030. case cmTarget::OBJECT_LIBRARY:
  1031. {
  1032. std::string libpath = this->GetTargetDirectory(target);
  1033. libpath += "/";
  1034. libpath += configName;
  1035. libpath += "/";
  1036. libpath += target.GetName();
  1037. libpath += ".lib";
  1038. const char* tool =
  1039. this->FortranProject? "VFLibrarianTool":"VCLibrarianTool";
  1040. fout << "\t\t\t<Tool\n"
  1041. << "\t\t\t\tName=\"" << tool << "\"\n";
  1042. fout << "\t\t\t\tOutputFile=\""
  1043. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  1044. break;
  1045. }
  1046. case cmTarget::STATIC_LIBRARY:
  1047. {
  1048. std::string targetNameFull = target.GetFullName(configName);
  1049. std::string libpath = target.GetDirectory(configName);
  1050. libpath += "/";
  1051. libpath += targetNameFull;
  1052. const char* tool = "VCLibrarianTool";
  1053. if(this->FortranProject)
  1054. {
  1055. tool = "VFLibrarianTool";
  1056. }
  1057. fout << "\t\t\t<Tool\n"
  1058. << "\t\t\t\tName=\"" << tool << "\"\n";
  1059. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS8
  1060. || this->FortranProject)
  1061. {
  1062. std::ostringstream libdeps;
  1063. this->Internal->OutputObjects(libdeps, &target);
  1064. if(!libdeps.str().empty())
  1065. {
  1066. fout << "\t\t\t\tAdditionalDependencies=\"" << libdeps.str() << "\"\n";
  1067. }
  1068. }
  1069. std::string libflags;
  1070. this->GetStaticLibraryFlags(libflags, configTypeUpper, &target);
  1071. if(!libflags.empty())
  1072. {
  1073. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  1074. }
  1075. fout << "\t\t\t\tOutputFile=\""
  1076. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  1077. break;
  1078. }
  1079. case cmTarget::SHARED_LIBRARY:
  1080. case cmTarget::MODULE_LIBRARY:
  1081. {
  1082. std::string targetName;
  1083. std::string targetNameSO;
  1084. std::string targetNameFull;
  1085. std::string targetNameImport;
  1086. std::string targetNamePDB;
  1087. target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
  1088. targetNameImport, targetNamePDB, configName);
  1089. // Compute the link library and directory information.
  1090. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  1091. if(!pcli)
  1092. {
  1093. return;
  1094. }
  1095. cmComputeLinkInformation& cli = *pcli;
  1096. std::string linkLanguage = cli.GetLinkLanguage();
  1097. // Compute the variable name to lookup standard libraries for this
  1098. // language.
  1099. std::string standardLibsVar = "CMAKE_";
  1100. standardLibsVar += linkLanguage;
  1101. standardLibsVar += "_STANDARD_LIBRARIES";
  1102. const char* tool = "VCLinkerTool";
  1103. if(this->FortranProject)
  1104. {
  1105. tool = "VFLinkerTool";
  1106. }
  1107. fout << "\t\t\t<Tool\n"
  1108. << "\t\t\t\tName=\"" << tool << "\"\n";
  1109. if(!gg->NeedLinkLibraryDependencies(target))
  1110. {
  1111. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1112. }
  1113. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1114. // Use the NOINHERIT macro to avoid getting VS project default
  1115. // libraries which may be set by the user to something bad.
  1116. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1117. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1118. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS8
  1119. || this->FortranProject)
  1120. {
  1121. this->Internal->OutputObjects(fout, &target, " ");
  1122. }
  1123. fout << " ";
  1124. this->Internal->OutputLibraries(fout, cli.GetItems());
  1125. fout << "\"\n";
  1126. temp = target.GetDirectory(configName);
  1127. temp += "/";
  1128. temp += targetNameFull;
  1129. fout << "\t\t\t\tOutputFile=\""
  1130. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1131. this->WriteTargetVersionAttribute(fout, target);
  1132. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1133. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1134. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1135. fout << "\"\n";
  1136. temp = target.GetPDBDirectory(configName);
  1137. temp += "/";
  1138. temp += targetNamePDB;
  1139. fout << "\t\t\t\tProgramDatabaseFile=\"" <<
  1140. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1141. if(targetOptions.IsDebug())
  1142. {
  1143. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1144. }
  1145. if(this->WindowsCEProject)
  1146. {
  1147. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS9)
  1148. {
  1149. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1150. }
  1151. else
  1152. {
  1153. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1154. }
  1155. }
  1156. std::string stackVar = "CMAKE_";
  1157. stackVar += linkLanguage;
  1158. stackVar += "_STACK_SIZE";
  1159. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1160. if(stackVal)
  1161. {
  1162. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  1163. }
  1164. temp = target.GetDirectory(configName, true);
  1165. temp += "/";
  1166. temp += targetNameImport;
  1167. fout << "\t\t\t\tImportLibrary=\""
  1168. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"";
  1169. if(this->FortranProject)
  1170. {
  1171. fout << "\n\t\t\t\tLinkDLL=\"true\"";
  1172. }
  1173. fout << "/>\n";
  1174. }
  1175. break;
  1176. case cmTarget::EXECUTABLE:
  1177. {
  1178. std::string targetName;
  1179. std::string targetNameFull;
  1180. std::string targetNameImport;
  1181. std::string targetNamePDB;
  1182. target.GetExecutableNames(targetName, targetNameFull,
  1183. targetNameImport, targetNamePDB, configName);
  1184. // Compute the link library and directory information.
  1185. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  1186. if(!pcli)
  1187. {
  1188. return;
  1189. }
  1190. cmComputeLinkInformation& cli = *pcli;
  1191. std::string linkLanguage = cli.GetLinkLanguage();
  1192. bool isWin32Executable = target.GetPropertyAsBool("WIN32_EXECUTABLE");
  1193. // Compute the variable name to lookup standard libraries for this
  1194. // language.
  1195. std::string standardLibsVar = "CMAKE_";
  1196. standardLibsVar += linkLanguage;
  1197. standardLibsVar += "_STANDARD_LIBRARIES";
  1198. const char* tool = "VCLinkerTool";
  1199. if(this->FortranProject)
  1200. {
  1201. tool = "VFLinkerTool";
  1202. }
  1203. fout << "\t\t\t<Tool\n"
  1204. << "\t\t\t\tName=\"" << tool << "\"\n";
  1205. if(!gg->NeedLinkLibraryDependencies(target))
  1206. {
  1207. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1208. }
  1209. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1210. // Use the NOINHERIT macro to avoid getting VS project default
  1211. // libraries which may be set by the user to something bad.
  1212. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1213. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1214. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS8
  1215. || this->FortranProject)
  1216. {
  1217. this->Internal->OutputObjects(fout, &target, " ");
  1218. }
  1219. fout << " ";
  1220. this->Internal->OutputLibraries(fout, cli.GetItems());
  1221. fout << "\"\n";
  1222. temp = target.GetDirectory(configName);
  1223. temp += "/";
  1224. temp += targetNameFull;
  1225. fout << "\t\t\t\tOutputFile=\""
  1226. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1227. this->WriteTargetVersionAttribute(fout, target);
  1228. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1229. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1230. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1231. fout << "\"\n";
  1232. std::string path = this->ConvertToXMLOutputPathSingle(
  1233. target.GetPDBDirectory(configName).c_str());
  1234. fout << "\t\t\t\tProgramDatabaseFile=\""
  1235. << path << "/" << targetNamePDB
  1236. << "\"\n";
  1237. if(targetOptions.IsDebug())
  1238. {
  1239. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1240. }
  1241. if ( this->WindowsCEProject )
  1242. {
  1243. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS9)
  1244. {
  1245. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1246. }
  1247. else
  1248. {
  1249. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1250. }
  1251. if(!linkOptions.GetFlag("EntryPointSymbol"))
  1252. {
  1253. const char* entryPointSymbol = targetOptions.UsingUnicode() ?
  1254. (isWin32Executable ? "wWinMainCRTStartup" : "mainWCRTStartup") :
  1255. (isWin32Executable ? "WinMainCRTStartup" : "mainACRTStartup");
  1256. fout << "\t\t\t\tEntryPointSymbol=\"" << entryPointSymbol << "\"\n";
  1257. }
  1258. }
  1259. else if ( this->FortranProject )
  1260. {
  1261. fout << "\t\t\t\tSubSystem=\""
  1262. << (isWin32Executable ? "subSystemWindows" : "subSystemConsole")
  1263. << "\"\n";
  1264. }
  1265. else
  1266. {
  1267. fout << "\t\t\t\tSubSystem=\""
  1268. << (isWin32Executable ? "2" : "1")
  1269. << "\"\n";
  1270. }
  1271. std::string stackVar = "CMAKE_";
  1272. stackVar += linkLanguage;
  1273. stackVar += "_STACK_SIZE";
  1274. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1275. if(stackVal)
  1276. {
  1277. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  1278. }
  1279. temp = target.GetDirectory(configName, true);
  1280. temp += "/";
  1281. temp += targetNameImport;
  1282. fout << "\t\t\t\tImportLibrary=\""
  1283. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  1284. break;
  1285. }
  1286. case cmTarget::UTILITY:
  1287. case cmTarget::GLOBAL_TARGET:
  1288. case cmTarget::INTERFACE_LIBRARY:
  1289. break;
  1290. }
  1291. }
  1292. //----------------------------------------------------------------------------
  1293. void
  1294. cmLocalVisualStudio7Generator
  1295. ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
  1296. {
  1297. int major;
  1298. int minor;
  1299. target.GetTargetVersion(major, minor);
  1300. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  1301. }
  1302. //----------------------------------------------------------------------------
  1303. void
  1304. cmLocalVisualStudio7GeneratorInternals
  1305. ::OutputLibraries(std::ostream& fout, ItemVector const& libs)
  1306. {
  1307. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1308. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  1309. {
  1310. if(l->IsPath)
  1311. {
  1312. std::string rel = lg->Convert(l->Value.c_str(),
  1313. cmLocalGenerator::START_OUTPUT,
  1314. cmLocalGenerator::UNCHANGED);
  1315. fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
  1316. }
  1317. else if (!l->Target
  1318. || l->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  1319. {
  1320. fout << l->Value << " ";
  1321. }
  1322. }
  1323. }
  1324. //----------------------------------------------------------------------------
  1325. void
  1326. cmLocalVisualStudio7GeneratorInternals
  1327. ::OutputObjects(std::ostream& fout, cmTarget* t, const char* isep)
  1328. {
  1329. // VS < 8 does not support per-config source locations so we
  1330. // list object library content on the link line instead.
  1331. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1332. cmGeneratorTarget* gt =
  1333. lg->GetGlobalGenerator()->GetGeneratorTarget(t);
  1334. std::vector<std::string> objs;
  1335. gt->UseObjectLibraries(objs, "");
  1336. const char* sep = isep? isep : "";
  1337. for(std::vector<std::string>::const_iterator
  1338. oi = objs.begin(); oi != objs.end(); ++oi)
  1339. {
  1340. std::string rel = lg->Convert(oi->c_str(),
  1341. cmLocalGenerator::START_OUTPUT,
  1342. cmLocalGenerator::UNCHANGED);
  1343. fout << sep << lg->ConvertToXMLOutputPath(rel.c_str());
  1344. sep = " ";
  1345. }
  1346. }
  1347. //----------------------------------------------------------------------------
  1348. void
  1349. cmLocalVisualStudio7Generator
  1350. ::OutputLibraryDirectories(std::ostream& fout,
  1351. std::vector<std::string> const& dirs)
  1352. {
  1353. const char* comma = "";
  1354. for(std::vector<std::string>::const_iterator d = dirs.begin();
  1355. d != dirs.end(); ++d)
  1356. {
  1357. // Remove any trailing slash and skip empty paths.
  1358. std::string dir = *d;
  1359. if(dir[dir.size()-1] == '/')
  1360. {
  1361. dir = dir.substr(0, dir.size()-1);
  1362. }
  1363. if(dir.empty())
  1364. {
  1365. continue;
  1366. }
  1367. // Switch to a relative path specification if it is shorter.
  1368. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  1369. {
  1370. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  1371. if(rel.size() < dir.size())
  1372. {
  1373. dir = rel;
  1374. }
  1375. }
  1376. // First search a configuration-specific subdirectory and then the
  1377. // original directory.
  1378. fout << comma
  1379. << this->ConvertToXMLOutputPath((dir+"/$(ConfigurationName)").c_str())
  1380. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  1381. comma = ",";
  1382. }
  1383. }
  1384. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1385. const std::string& libName,
  1386. cmTarget &target)
  1387. {
  1388. std::vector<std::string> configs;
  1389. this->Makefile->GetConfigurations(configs);
  1390. // We may be modifying the source groups temporarily, so make a copy.
  1391. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1392. // get the classes from the source lists then add them to the groups
  1393. this->ModuleDefinitionFile = "";
  1394. std::vector<cmSourceFile*> classes;
  1395. if (!target.GetConfigCommonSourceFiles(classes))
  1396. {
  1397. return;
  1398. }
  1399. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1400. i != classes.end(); i++)
  1401. {
  1402. if (!(*i)->GetObjectLibrary().empty())
  1403. {
  1404. continue;
  1405. }
  1406. // Add the file to the list of sources.
  1407. std::string source = (*i)->GetFullPath();
  1408. if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF")
  1409. {
  1410. this->ModuleDefinitionFile = (*i)->GetFullPath();
  1411. }
  1412. cmSourceGroup* sourceGroup =
  1413. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1414. sourceGroup->AssignSource(*i);
  1415. }
  1416. // open the project
  1417. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1418. // write the configuration information
  1419. this->WriteConfigurations(fout, configs, libName, target);
  1420. fout << "\t<Files>\n";
  1421. // Loop through every source group.
  1422. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  1423. {
  1424. cmSourceGroup sg = sourceGroups[i];
  1425. this->WriteGroup(&sg, target, fout, libName, configs);
  1426. }
  1427. if(this->GetVersion() >= cmGlobalVisualStudioGenerator::VS8
  1428. && !this->FortranProject)
  1429. {
  1430. // VS >= 8 support per-config source locations so we
  1431. // list object library content as external objects.
  1432. cmGeneratorTarget* gt =
  1433. this->GlobalGenerator->GetGeneratorTarget(&target);
  1434. std::vector<std::string> objs;
  1435. gt->UseObjectLibraries(objs, "");
  1436. if(!objs.empty())
  1437. {
  1438. // TODO: Separate sub-filter for each object library used?
  1439. fout << "\t\t<Filter Name=\"Object Libraries\">\n";
  1440. for(std::vector<std::string>::const_iterator
  1441. oi = objs.begin(); oi != objs.end(); ++oi)
  1442. {
  1443. std::string o = this->ConvertToXMLOutputPathSingle(oi->c_str());
  1444. fout << "\t\t\t<File RelativePath=\"" << o << "\" />\n";
  1445. }
  1446. fout << "\t\t</Filter>\n";
  1447. }
  1448. }
  1449. fout << "\t</Files>\n";
  1450. // Write the VCProj file's footer.
  1451. this->WriteVCProjFooter(fout, target);
  1452. }
  1453. struct cmLVS7GFileConfig
  1454. {
  1455. std::string ObjectName;
  1456. std::string CompileFlags;
  1457. std::string CompileDefs;
  1458. std::string CompileDefsConfig;
  1459. std::string AdditionalDeps;
  1460. bool ExcludedFromBuild;
  1461. };
  1462. class cmLocalVisualStudio7GeneratorFCInfo
  1463. {
  1464. public:
  1465. cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1466. cmTarget& target,
  1467. cmSourceFile const& sf,
  1468. std::vector<std::string> const& configs);
  1469. std::map<std::string, cmLVS7GFileConfig> FileConfigMap;
  1470. };
  1471. cmLocalVisualStudio7GeneratorFCInfo
  1472. ::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1473. cmTarget& target,
  1474. cmSourceFile const& sf,
  1475. std::vector<std::string> const& configs)
  1476. {
  1477. cmGeneratorTarget* gt =
  1478. lg->GetGlobalGenerator()->GetGeneratorTarget(&target);
  1479. std::string objectName;
  1480. if(gt->HasExplicitObjectName(&sf))
  1481. {
  1482. objectName = gt->GetObjectName(&sf);
  1483. }
  1484. // Compute per-source, per-config information.
  1485. for(std::vector<std::string>::const_iterator i = configs.begin();
  1486. i != configs.end(); ++i)
  1487. {
  1488. std::string configUpper = cmSystemTools::UpperCase(*i);
  1489. cmLVS7GFileConfig fc;
  1490. bool needfc = false;
  1491. if(!objectName.empty())
  1492. {
  1493. fc.ObjectName = objectName;
  1494. needfc = true;
  1495. }
  1496. if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
  1497. {
  1498. fc.CompileFlags = cflags;
  1499. needfc = true;
  1500. }
  1501. if(lg->FortranProject)
  1502. {
  1503. switch(lg->GetFortranFormat(sf.GetProperty("Fortran_FORMAT")))
  1504. {
  1505. case cmLocalGenerator::FortranFormatFixed:
  1506. fc.CompileFlags = "-fixed " + fc.CompileFlags;
  1507. needfc = true;
  1508. break;
  1509. case cmLocalGenerator::FortranFormatFree:
  1510. fc.CompileFlags = "-free " + fc.CompileFlags;
  1511. needfc = true;
  1512. break;
  1513. default: break;
  1514. }
  1515. }
  1516. if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
  1517. {
  1518. fc.CompileDefs = cdefs;
  1519. needfc = true;
  1520. }
  1521. std::string defPropName = "COMPILE_DEFINITIONS_";
  1522. defPropName += configUpper;
  1523. if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
  1524. {
  1525. fc.CompileDefsConfig = ccdefs;
  1526. needfc = true;
  1527. }
  1528. // Check for extra object-file dependencies.
  1529. if(const char* deps = sf.GetProperty("OBJECT_DEPENDS"))
  1530. {
  1531. std::vector<std::string> depends;
  1532. cmSystemTools::ExpandListArgument(deps, depends);
  1533. const char* sep = "";
  1534. for(std::vector<std::string>::iterator j = depends.begin();
  1535. j != depends.end(); ++j)
  1536. {
  1537. fc.AdditionalDeps += sep;
  1538. fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
  1539. sep = ";";
  1540. needfc = true;
  1541. }
  1542. }
  1543. std::string lang =
  1544. lg->GlobalGenerator->GetLanguageFromExtension
  1545. (sf.GetExtension().c_str());
  1546. const std::string& sourceLang = lg->GetSourceFileLanguage(sf);
  1547. const std::string& linkLanguage = target.GetLinkerLanguage(i->c_str());
  1548. bool needForceLang = false;
  1549. // source file does not match its extension language
  1550. if(lang != sourceLang)
  1551. {
  1552. needForceLang = true;
  1553. lang = sourceLang;
  1554. }
  1555. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1556. // the project file
  1557. fc.ExcludedFromBuild =
  1558. (sf.GetPropertyAsBool("HEADER_FILE_ONLY"));
  1559. if(fc.ExcludedFromBuild)
  1560. {
  1561. needfc = true;
  1562. }
  1563. // if the source file does not match the linker language
  1564. // then force c or c++
  1565. if(needForceLang || (linkLanguage != lang))
  1566. {
  1567. if(lang == "CXX")
  1568. {
  1569. // force a C++ file type
  1570. fc.CompileFlags += " /TP ";
  1571. needfc = true;
  1572. }
  1573. else if(lang == "C")
  1574. {
  1575. // force to c
  1576. fc.CompileFlags += " /TC ";
  1577. needfc = true;
  1578. }
  1579. }
  1580. if(needfc)
  1581. {
  1582. this->FileConfigMap[*i] = fc;
  1583. }
  1584. }
  1585. }
  1586. //----------------------------------------------------------------------------
  1587. std::string
  1588. cmLocalVisualStudio7Generator
  1589. ::ComputeLongestObjectDirectory(cmTarget& target) const
  1590. {
  1591. std::vector<std::string> configs;
  1592. target.GetMakefile()->GetConfigurations(configs);
  1593. // Compute the maximum length configuration name.
  1594. std::string config_max;
  1595. for(std::vector<std::string>::iterator i = configs.begin();
  1596. i != configs.end(); ++i)
  1597. {
  1598. if(i->size() > config_max.size())
  1599. {
  1600. config_max = *i;
  1601. }
  1602. }
  1603. // Compute the maximum length full path to the intermediate
  1604. // files directory for any configuration. This is used to construct
  1605. // object file names that do not produce paths that are too long.
  1606. std::string dir_max;
  1607. dir_max += this->Makefile->GetCurrentBinaryDirectory();
  1608. dir_max += "/";
  1609. dir_max += this->GetTargetDirectory(target);
  1610. dir_max += "/";
  1611. dir_max += config_max;
  1612. dir_max += "/";
  1613. return dir_max;
  1614. }
  1615. bool cmLocalVisualStudio7Generator
  1616. ::WriteGroup(const cmSourceGroup *sg, cmTarget& target,
  1617. std::ostream &fout, const std::string& libName,
  1618. std::vector<std::string> const& configs)
  1619. {
  1620. cmGlobalVisualStudio7Generator* gg =
  1621. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1622. const std::vector<const cmSourceFile *> &sourceFiles =
  1623. sg->GetSourceFiles();
  1624. std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
  1625. // Write the children to temporary output.
  1626. bool hasChildrenWithSources = false;
  1627. std::ostringstream tmpOut;
  1628. for(unsigned int i=0;i<children.size();++i)
  1629. {
  1630. if(this->WriteGroup(&children[i], target, tmpOut, libName, configs))
  1631. {
  1632. hasChildrenWithSources = true;
  1633. }
  1634. }
  1635. // If the group is empty, don't write it at all.
  1636. if(sourceFiles.empty() && !hasChildrenWithSources)
  1637. {
  1638. return false;
  1639. }
  1640. // If the group has a name, write the header.
  1641. std::string name = sg->GetName();
  1642. if(name != "")
  1643. {
  1644. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1645. }
  1646. // Loop through each source in the source group.
  1647. std::string objectName;
  1648. for(std::vector<const cmSourceFile *>::const_iterator sf =
  1649. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  1650. {
  1651. std::string source = (*sf)->GetFullPath();
  1652. FCInfo fcinfo(this, target, *(*sf), configs);
  1653. if (source != libName || target.GetType() == cmTarget::UTILITY ||
  1654. target.GetType() == cmTarget::GLOBAL_TARGET )
  1655. {
  1656. fout << "\t\t\t<File\n";
  1657. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1658. // Tell MS-Dev what the source is. If the compiler knows how to
  1659. // build it, then it will.
  1660. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1661. if(cmCustomCommand const* command = (*sf)->GetCustomCommand())
  1662. {
  1663. this->WriteCustomRule(fout, configs, source.c_str(),
  1664. *command, fcinfo);
  1665. }
  1666. else if(!fcinfo.FileConfigMap.empty())
  1667. {
  1668. const char* aCompilerTool = "VCCLCompilerTool";
  1669. const char* ppLang = "CXX";
  1670. if(this->FortranProject)
  1671. {
  1672. aCompilerTool = "VFFortranCompilerTool";
  1673. }
  1674. std::string const& lang = (*sf)->GetLanguage();
  1675. std::string ext = (*sf)->GetExtension();
  1676. ext = cmSystemTools::LowerCase(ext);
  1677. if(ext == "idl")
  1678. {
  1679. aCompilerTool = "VCMIDLTool";
  1680. if(this->FortranProject)
  1681. {
  1682. aCompilerTool = "VFMIDLTool";
  1683. }
  1684. }
  1685. if(ext == "rc")
  1686. {
  1687. aCompilerTool = "VCResourceCompilerTool";
  1688. ppLang = "RC";
  1689. if(this->FortranProject)
  1690. {
  1691. aCompilerTool = "VFResourceCompilerTool";
  1692. }
  1693. }
  1694. if(ext == "def")
  1695. {
  1696. aCompilerTool = "VCCustomBuildTool";
  1697. if(this->FortranProject)
  1698. {
  1699. aCompilerTool = "VFCustomBuildTool";
  1700. }
  1701. }
  1702. if (gg->IsMasmEnabled() && !this->FortranProject &&
  1703. lang == "ASM_MASM")
  1704. {
  1705. aCompilerTool = "MASM";
  1706. }
  1707. for(std::map<std::string, cmLVS7GFileConfig>::const_iterator
  1708. fci = fcinfo.FileConfigMap.begin();
  1709. fci != fcinfo.FileConfigMap.end(); ++fci)
  1710. {
  1711. cmLVS7GFileConfig const& fc = fci->second;
  1712. fout << "\t\t\t\t<FileConfiguration\n"
  1713. << "\t\t\t\t\tName=\"" << fci->first
  1714. << "|" << gg->GetPlatformName() << "\"";
  1715. if(fc.ExcludedFromBuild)
  1716. {
  1717. fout << " ExcludedFromBuild=\"true\"";
  1718. }
  1719. fout << ">\n";
  1720. fout << "\t\t\t\t\t<Tool\n"
  1721. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1722. if(!fc.CompileFlags.empty() ||
  1723. !fc.CompileDefs.empty() ||
  1724. !fc.CompileDefsConfig.empty())
  1725. {
  1726. Options::Tool tool = Options::Compiler;
  1727. cmVS7FlagTable const* table =
  1728. cmLocalVisualStudio7GeneratorFlagTable;
  1729. if(this->FortranProject)
  1730. {
  1731. tool = Options::FortranCompiler;
  1732. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  1733. }
  1734. Options fileOptions(this, tool, table,
  1735. gg->ExtraFlagTable);
  1736. fileOptions.Parse(fc.CompileFlags.c_str());
  1737. fileOptions.AddDefines(fc.CompileDefs.c_str());
  1738. fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
  1739. fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n");
  1740. fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
  1741. fileOptions.OutputPreprocessorDefinitions(fout,
  1742. "\t\t\t\t\t", "\n",
  1743. ppLang);
  1744. }
  1745. if(!fc.AdditionalDeps.empty())
  1746. {
  1747. fout << "\t\t\t\t\tAdditionalDependencies=\""
  1748. << fc.AdditionalDeps.c_str() << "\"\n";
  1749. }
  1750. if(!fc.ObjectName.empty())
  1751. {
  1752. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/"
  1753. << fc.ObjectName.c_str() << "\"\n";
  1754. }
  1755. fout << "\t\t\t\t\t/>\n"
  1756. << "\t\t\t\t</FileConfiguration>\n";
  1757. }
  1758. }
  1759. fout << "\t\t\t</File>\n";
  1760. }
  1761. }
  1762. // If the group has children with source files, write the children.
  1763. if(hasChildrenWithSources)
  1764. {
  1765. fout << tmpOut.str();
  1766. }
  1767. // If the group has a name, write the footer.
  1768. if(name != "")
  1769. {
  1770. this->WriteVCProjEndGroup(fout);
  1771. }
  1772. return true;
  1773. }
  1774. void cmLocalVisualStudio7Generator::
  1775. WriteCustomRule(std::ostream& fout,
  1776. std::vector<std::string> const& configs,
  1777. const char* source,
  1778. const cmCustomCommand& command,
  1779. FCInfo& fcinfo)
  1780. {
  1781. cmGlobalVisualStudio7Generator* gg =
  1782. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1783. // Write the rule for each configuration.
  1784. const char* compileTool = "VCCLCompilerTool";
  1785. if(this->FortranProject)
  1786. {
  1787. compileTool = "VFCLCompilerTool";
  1788. }
  1789. const char* customTool = "VCCustomBuildTool";
  1790. if(this->FortranProject)
  1791. {
  1792. customTool = "VFCustomBuildTool";
  1793. }
  1794. for (std::vector<std::string>::const_iterator i = configs.begin();
  1795. i != configs.end(); ++i)
  1796. {
  1797. cmCustomCommandGenerator ccg(command, *i, this->Makefile);
  1798. cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
  1799. fout << "\t\t\t\t<FileConfiguration\n";
  1800. fout << "\t\t\t\t\tName=\"" << *i << "|"
  1801. << gg->GetPlatformName() << "\">\n";
  1802. if(!fc.CompileFlags.empty())
  1803. {
  1804. fout << "\t\t\t\t\t<Tool\n"
  1805. << "\t\t\t\t\tName=\"" << compileTool << "\"\n"
  1806. << "\t\t\t\t\tAdditionalOptions=\""
  1807. << this->EscapeForXML(fc.CompileFlags.c_str()) << "\"/>\n";
  1808. }
  1809. std::string comment = this->ConstructComment(ccg);
  1810. std::string script = this->ConstructScript(ccg);
  1811. if(this->FortranProject)
  1812. {
  1813. cmSystemTools::ReplaceString(script, "$(Configuration)", i->c_str());
  1814. }
  1815. fout << "\t\t\t\t\t<Tool\n"
  1816. << "\t\t\t\t\tName=\"" << customTool << "\"\n"
  1817. << "\t\t\t\t\tDescription=\""
  1818. << this->EscapeForXML(comment.c_str()) << "\"\n"
  1819. << "\t\t\t\t\tCommandLine=\""
  1820. << this->EscapeForXML(script.c_str()) << "\"\n"
  1821. << "\t\t\t\t\tAdditionalDependencies=\"";
  1822. if(ccg.GetDepends().empty())
  1823. {
  1824. // There are no real dependencies. Produce an artificial one to
  1825. // make sure the rule runs reliably.
  1826. if(!cmSystemTools::FileExists(source))
  1827. {
  1828. cmsys::ofstream depout(source);
  1829. depout << "Artificial dependency for a custom command.\n";
  1830. }
  1831. fout << this->ConvertToXMLOutputPath(source);
  1832. }
  1833. else
  1834. {
  1835. // Write out the dependencies for the rule.
  1836. for(std::vector<std::string>::const_iterator d =
  1837. ccg.GetDepends().begin();
  1838. d != ccg.GetDepends().end();
  1839. ++d)
  1840. {
  1841. // Get the real name of the dependency in case it is a CMake target.
  1842. std::string dep;
  1843. if(this->GetRealDependency(d->c_str(), i->c_str(), dep))
  1844. {
  1845. fout << this->ConvertToXMLOutputPath(dep.c_str())
  1846. << ";";
  1847. }
  1848. }
  1849. }
  1850. fout << "\"\n";
  1851. fout << "\t\t\t\t\tOutputs=\"";
  1852. if(ccg.GetOutputs().empty())
  1853. {
  1854. fout << source << "_force";
  1855. }
  1856. else
  1857. {
  1858. // Write a rule for the output generated by this command.
  1859. const char* sep = "";
  1860. for(std::vector<std::string>::const_iterator o =
  1861. ccg.GetOutputs().begin();
  1862. o != ccg.GetOutputs().end();
  1863. ++o)
  1864. {
  1865. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1866. sep = ";";
  1867. }
  1868. }
  1869. fout << "\"/>\n";
  1870. fout << "\t\t\t\t</FileConfiguration>\n";
  1871. }
  1872. }
  1873. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1874. const char* group,
  1875. const char* )
  1876. {
  1877. fout << "\t\t<Filter\n"
  1878. << "\t\t\tName=\"" << group << "\"\n"
  1879. << "\t\t\tFilter=\"\">\n";
  1880. }
  1881. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1882. {
  1883. fout << "\t\t</Filter>\n";
  1884. }
  1885. // look for custom rules on a target and collect them together
  1886. void cmLocalVisualStudio7Generator
  1887. ::OutputTargetRules(std::ostream& fout,
  1888. const std::string& configName,
  1889. cmTarget &target,
  1890. const std::string& /*libName*/)
  1891. {
  1892. if (target.GetType() > cmTarget::GLOBAL_TARGET)
  1893. {
  1894. return;
  1895. }
  1896. EventWriter event(this, configName, fout);
  1897. // Add pre-build event.
  1898. const char* tool =
  1899. this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool";
  1900. event.Start(tool);
  1901. event.Write(target.GetPreBuildCommands());
  1902. event.Finish();
  1903. // Add pre-link event.
  1904. tool = this->FortranProject? "VFPreLinkEventTool":"VCPreLinkEventTool";
  1905. event.Start(tool);
  1906. event.Write(target.GetPreLinkCommands());
  1907. cmsys::auto_ptr<cmCustomCommand> pcc(
  1908. this->MaybeCreateImplibDir(target, configName, this->FortranProject));
  1909. if(pcc.get())
  1910. {
  1911. event.Write(*pcc);
  1912. }
  1913. event.Finish();
  1914. // Add post-build event.
  1915. tool = this->FortranProject? "VFPostBuildEventTool":"VCPostBuildEventTool";
  1916. event.Start(tool);
  1917. event.Write(target.GetPostBuildCommands());
  1918. event.Finish();
  1919. }
  1920. void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout,
  1921. cmTarget& target)
  1922. {
  1923. // if we have all the required Source code control tags
  1924. // then add that to the project
  1925. const char* vsProjectname = target.GetProperty("VS_SCC_PROJECTNAME");
  1926. const char* vsLocalpath = target.GetProperty("VS_SCC_LOCALPATH");
  1927. const char* vsProvider = target.GetProperty("VS_SCC_PROVIDER");
  1928. if(vsProvider && vsLocalpath && vsProjectname)
  1929. {
  1930. fout << "\tSccProjectName=\"" << vsProjectname << "\"\n"
  1931. << "\tSccLocalPath=\"" << vsLocalpath << "\"\n"
  1932. << "\tSccProvider=\"" << vsProvider << "\"\n";
  1933. const char* vsAuxPath = target.GetProperty("VS_SCC_AUXPATH");
  1934. if(vsAuxPath)
  1935. {
  1936. fout << "\tSccAuxPath=\"" << vsAuxPath << "\"\n";
  1937. }
  1938. }
  1939. }
  1940. void
  1941. cmLocalVisualStudio7Generator
  1942. ::WriteProjectStartFortran(std::ostream& fout,
  1943. const std::string& libName,
  1944. cmTarget & target)
  1945. {
  1946. cmGlobalVisualStudio7Generator* gg =
  1947. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1948. fout << "<?xml version=\"1.0\" encoding = \""
  1949. << gg->Encoding() << "\"?>\n"
  1950. << "<VisualStudioProject\n"
  1951. << "\tProjectCreator=\"Intel Fortran\"\n"
  1952. << "\tVersion=\"" << gg->GetIntelProjectVersion() << "\"\n";
  1953. const char* keyword = target.GetProperty("VS_KEYWORD");
  1954. if(!keyword)
  1955. {
  1956. keyword = "Console Application";
  1957. }
  1958. const char* projectType = 0;
  1959. switch(target.GetType())
  1960. {
  1961. case cmTarget::STATIC_LIBRARY:
  1962. projectType = "typeStaticLibrary";
  1963. if(keyword)
  1964. {
  1965. keyword = "Static Library";
  1966. }
  1967. break;
  1968. case cmTarget::SHARED_LIBRARY:
  1969. case cmTarget::MODULE_LIBRARY:
  1970. projectType = "typeDynamicLibrary";
  1971. if(!keyword)
  1972. {
  1973. keyword = "Dll";
  1974. }
  1975. break;
  1976. case cmTarget::EXECUTABLE:
  1977. if(!keyword)
  1978. {
  1979. keyword = "Console Application";
  1980. }
  1981. projectType = 0;
  1982. break;
  1983. case cmTarget::UTILITY:
  1984. case cmTarget::GLOBAL_TARGET:
  1985. default:
  1986. break;
  1987. }
  1988. if(projectType)
  1989. {
  1990. fout << "\tProjectType=\"" << projectType << "\"\n";
  1991. }
  1992. this->WriteProjectSCC(fout, target);
  1993. fout<< "\tKeyword=\"" << keyword << "\">\n"
  1994. << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\">\n"
  1995. << "\t<Platforms>\n"
  1996. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  1997. << "\t</Platforms>\n";
  1998. }
  1999. void
  2000. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  2001. const std::string& libName,
  2002. cmTarget & target,
  2003. std::vector<cmSourceGroup> &)
  2004. {
  2005. if(this->FortranProject)
  2006. {
  2007. this->WriteProjectStartFortran(fout, libName, target);
  2008. return;
  2009. }
  2010. cmGlobalVisualStudio7Generator* gg =
  2011. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  2012. fout << "<?xml version=\"1.0\" encoding = \""
  2013. << gg->Encoding() << "\"?>\n"
  2014. << "<VisualStudioProject\n"
  2015. << "\tProjectType=\"Visual C++\"\n";
  2016. if(gg->GetVersion() == cmGlobalVisualStudioGenerator::VS71)
  2017. {
  2018. fout << "\tVersion=\"7.10\"\n";
  2019. }
  2020. else
  2021. {
  2022. fout << "\tVersion=\"" << (gg->GetVersion()/10) << ".00\"\n";
  2023. }
  2024. const char* projLabel = target.GetProperty("PROJECT_LABEL");
  2025. if(!projLabel)
  2026. {
  2027. projLabel = libName.c_str();
  2028. }
  2029. const char* keyword = target.GetProperty("VS_KEYWORD");
  2030. if(!keyword)
  2031. {
  2032. keyword = "Win32Proj";
  2033. }
  2034. fout << "\tName=\"" << projLabel << "\"\n";
  2035. if(gg->GetVersion() >= cmGlobalVisualStudioGenerator::VS8)
  2036. {
  2037. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\"\n";
  2038. }
  2039. this->WriteProjectSCC(fout, target);
  2040. if(const char* targetFrameworkVersion =
  2041. target.GetProperty("VS_DOTNET_TARGET_FRAMEWORK_VERSION"))
  2042. {
  2043. fout << "\tTargetFrameworkVersion=\"" << targetFrameworkVersion << "\"\n";
  2044. }
  2045. fout << "\tKeyword=\"" << keyword << "\">\n"
  2046. << "\t<Platforms>\n"
  2047. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  2048. << "\t</Platforms>\n";
  2049. if(gg->IsMasmEnabled())
  2050. {
  2051. fout <<
  2052. "\t<ToolFiles>\n"
  2053. "\t\t<DefaultToolFile\n"
  2054. "\t\t\tFileName=\"masm.rules\"\n"
  2055. "\t\t/>\n"
  2056. "\t</ToolFiles>\n"
  2057. ;
  2058. }
  2059. }
  2060. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout,
  2061. cmTarget &target)
  2062. {
  2063. fout << "\t<Globals>\n";
  2064. cmPropertyMap const& props = target.GetProperties();
  2065. for(cmPropertyMap::const_iterator i = props.begin(); i != props.end(); ++i)
  2066. {
  2067. if(i->first.find("VS_GLOBAL_") == 0)
  2068. {
  2069. std::string name = i->first.substr(10);
  2070. if(name != "")
  2071. {
  2072. fout << "\t\t<Global\n"
  2073. << "\t\t\tName=\"" << name << "\"\n"
  2074. << "\t\t\tValue=\"" << i->second.GetValue() << "\"\n"
  2075. << "\t\t/>\n";
  2076. }
  2077. }
  2078. }
  2079. fout << "\t</Globals>\n"
  2080. << "</VisualStudioProject>\n";
  2081. }
  2082. std::string cmLocalVisualStudio7GeneratorEscapeForXML(const std::string& s)
  2083. {
  2084. std::string ret = s;
  2085. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2086. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  2087. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2088. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2089. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  2090. return ret;
  2091. }
  2092. std::string cmLocalVisualStudio7Generator::EscapeForXML(const std::string& s)
  2093. {
  2094. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  2095. }
  2096. std::string cmLocalVisualStudio7Generator
  2097. ::ConvertToXMLOutputPath(const char* path)
  2098. {
  2099. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  2100. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2101. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  2102. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2103. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2104. return ret;
  2105. }
  2106. std::string cmLocalVisualStudio7Generator
  2107. ::ConvertToXMLOutputPathSingle(const char* path)
  2108. {
  2109. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  2110. cmSystemTools::ReplaceString(ret, "\"", "");
  2111. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2112. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2113. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2114. return ret;
  2115. }
  2116. // This class is used to parse an existing vs 7 project
  2117. // and extract the GUID
  2118. class cmVS7XMLParser : public cmXMLParser
  2119. {
  2120. public:
  2121. virtual void EndElement(const std::string& /* name */)
  2122. {
  2123. }
  2124. virtual void StartElement(const std::string& name, const char** atts)
  2125. {
  2126. // once the GUID is found do nothing
  2127. if(this->GUID.size())
  2128. {
  2129. return;
  2130. }
  2131. int i =0;
  2132. if("VisualStudioProject" == name)
  2133. {
  2134. while(atts[i])
  2135. {
  2136. if(strcmp(atts[i], "ProjectGUID") == 0)
  2137. {
  2138. if(atts[i+1])
  2139. {
  2140. this->GUID = atts[i+1];
  2141. this->GUID = this->GUID.substr(1, this->GUID.size()-2);
  2142. }
  2143. else
  2144. {
  2145. this->GUID = "";
  2146. }
  2147. return;
  2148. }
  2149. ++i;
  2150. }
  2151. }
  2152. }
  2153. int InitializeParser()
  2154. {
  2155. int ret = cmXMLParser::InitializeParser();
  2156. if(ret == 0)
  2157. {
  2158. return ret;
  2159. }
  2160. // visual studio projects have a strange encoding, but it is
  2161. // really utf-8
  2162. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  2163. return 1;
  2164. }
  2165. std::string GUID;
  2166. };
  2167. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  2168. const std::string& name,
  2169. const char* path)
  2170. {
  2171. cmVS7XMLParser parser;
  2172. parser.ParseFile(path);
  2173. // if we can not find a GUID then we will generate one later
  2174. if(parser.GUID.size() == 0)
  2175. {
  2176. return;
  2177. }
  2178. std::string guidStoreName = name;
  2179. guidStoreName += "_GUID_CMAKE";
  2180. // save the GUID in the cache
  2181. this->GlobalGenerator->GetCMakeInstance()->
  2182. AddCacheEntry(guidStoreName.c_str(),
  2183. parser.GUID.c_str(),
  2184. "Stored GUID",
  2185. cmState::INTERNAL);
  2186. }
  2187. //----------------------------------------------------------------------------
  2188. std::string cmLocalVisualStudio7Generator
  2189. ::GetTargetDirectory(cmTarget const& target) const
  2190. {
  2191. std::string dir;
  2192. dir += target.GetName();
  2193. dir += ".dir";
  2194. return dir;
  2195. }
  2196. //----------------------------------------------------------------------------
  2197. #include <windows.h>
  2198. static bool cmLVS6G_IsFAT(const char* dir)
  2199. {
  2200. if(dir[0] && dir[1] == ':')
  2201. {
  2202. char volRoot[4] = "_:/";
  2203. volRoot[0] = dir[0];
  2204. char fsName[16];
  2205. if(GetVolumeInformationA(volRoot, 0, 0, 0, 0, 0, fsName, 16) &&
  2206. strstr(fsName, "FAT") != 0)
  2207. {
  2208. return true;
  2209. }
  2210. }
  2211. return false;
  2212. }