cmLocalVisualStudio7Generator.cxx 79 KB

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