cmLocalVisualStudio7Generator.cxx 79 KB

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