The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1699 lines
74KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. class MSVCProjectExporterBase : public ProjectExporter
  18. {
  19. public:
  20. MSVCProjectExporterBase (Project& p, const ValueTree& t, const char* const folderName)
  21. : ProjectExporter (p, t)
  22. {
  23. if (getTargetLocationString().isEmpty())
  24. getTargetLocationValue() = getDefaultBuildsRootFolder() + folderName;
  25. projectGUID = createGUID (project.getProjectUID());
  26. updateOldSettings();
  27. initialiseDependencyPathValues();
  28. }
  29. //==============================================================================
  30. bool usesMMFiles() const override { return false; }
  31. bool isVisualStudio() const override { return true; }
  32. bool isWindows() const override { return true; }
  33. bool canCopeWithDuplicateFiles() override { return false; }
  34. bool launchProject() override
  35. {
  36. #if JUCE_WINDOWS
  37. return getSLNFile().startAsProcess();
  38. #else
  39. return false;
  40. #endif
  41. }
  42. bool canLaunchProject() override
  43. {
  44. #if JUCE_WINDOWS
  45. return true;
  46. #else
  47. return false;
  48. #endif
  49. }
  50. void createExporterProperties (PropertyListBuilder&) override
  51. {
  52. }
  53. enum OptimisationLevel
  54. {
  55. optimisationOff = 1,
  56. optimiseMinSize = 2,
  57. optimiseMaxSpeed = 3
  58. };
  59. protected:
  60. String projectGUID;
  61. mutable File rcFile, iconFile;
  62. File getProjectFile (const String& extension) const { return getTargetFolder().getChildFile (project.getProjectFilenameRoot()).withFileExtension (extension); }
  63. File getSLNFile() const { return getProjectFile (".sln"); }
  64. bool isLibraryDLL() const { return msvcIsDLL || projectType.isDynamicLibrary(); }
  65. static String prependIfNotAbsolute (const String& file, const char* prefix)
  66. {
  67. if (File::isAbsolutePath (file) || file.startsWithChar ('$'))
  68. prefix = "";
  69. return prefix + FileHelpers::windowsStylePath (file);
  70. }
  71. String getIntDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(IntDir)\\"); }
  72. String getOutDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(OutDir)\\"); }
  73. void updateOldSettings()
  74. {
  75. {
  76. const String oldStylePrebuildCommand (getSettingString (Ids::prebuildCommand));
  77. settings.removeProperty (Ids::prebuildCommand, nullptr);
  78. if (oldStylePrebuildCommand.isNotEmpty())
  79. for (ConfigIterator config (*this); config.next();)
  80. dynamic_cast<MSVCBuildConfiguration&> (*config).getPrebuildCommand() = oldStylePrebuildCommand;
  81. }
  82. {
  83. const String oldStyleLibName (getSettingString ("libraryName_Debug"));
  84. settings.removeProperty ("libraryName_Debug", nullptr);
  85. if (oldStyleLibName.isNotEmpty())
  86. for (ConfigIterator config (*this); config.next();)
  87. if (config->isDebug())
  88. config->getTargetBinaryName() = oldStyleLibName;
  89. }
  90. {
  91. const String oldStyleLibName (getSettingString ("libraryName_Release"));
  92. settings.removeProperty ("libraryName_Release", nullptr);
  93. if (oldStyleLibName.isNotEmpty())
  94. for (ConfigIterator config (*this); config.next();)
  95. if (! config->isDebug())
  96. config->getTargetBinaryName() = oldStyleLibName;
  97. }
  98. }
  99. //==============================================================================
  100. class MSVCBuildConfiguration : public BuildConfiguration
  101. {
  102. public:
  103. MSVCBuildConfiguration (Project& p, const ValueTree& settings)
  104. : BuildConfiguration (p, settings)
  105. {
  106. if (getWarningLevel() == 0)
  107. getWarningLevelValue() = 4;
  108. setValueIfVoid (shouldGenerateManifestValue(), true);
  109. }
  110. Value getWarningLevelValue() { return getValue (Ids::winWarningLevel); }
  111. int getWarningLevel() const { return config [Ids::winWarningLevel]; }
  112. Value getWarningsTreatedAsErrors() { return getValue (Ids::warningsAreErrors); }
  113. bool areWarningsTreatedAsErrors() const { return config [Ids::warningsAreErrors]; }
  114. Value getPrebuildCommand() { return getValue (Ids::prebuildCommand); }
  115. String getPrebuildCommandString() const { return config [Ids::prebuildCommand]; }
  116. Value getPostbuildCommand() { return getValue (Ids::postbuildCommand); }
  117. String getPostbuildCommandString() const { return config [Ids::postbuildCommand]; }
  118. Value shouldGenerateDebugSymbolsValue() { return getValue (Ids::alwaysGenerateDebugSymbols); }
  119. bool shouldGenerateDebugSymbols() const { return config [Ids::alwaysGenerateDebugSymbols]; }
  120. Value shouldGenerateManifestValue() { return getValue (Ids::generateManifest); }
  121. bool shouldGenerateManifest() const { return config [Ids::generateManifest]; }
  122. Value getWholeProgramOptValue() { return getValue (Ids::wholeProgramOptimisation); }
  123. bool shouldDisableWholeProgramOpt() const { return static_cast<int> (config [Ids::wholeProgramOptimisation]) > 0; }
  124. Value getUsingRuntimeLibDLL() { return getValue (Ids::useRuntimeLibDLL); }
  125. bool isUsingRuntimeLibDLL() const { return config [Ids::useRuntimeLibDLL]; }
  126. String getIntermediatesPath() const { return config [Ids::intermediatesPath].toString(); }
  127. Value getIntermediatesPathValue() { return getValue (Ids::intermediatesPath); }
  128. String getCharacterSet() const { return config [Ids::characterSet].toString(); }
  129. Value getCharacterSetValue() { return getValue (Ids::characterSet); }
  130. String getOutputFilename (const String& suffix, bool forceSuffix) const
  131. {
  132. const String target (File::createLegalFileName (getTargetBinaryNameString().trim()));
  133. if (forceSuffix || ! target.containsChar ('.'))
  134. return target.upToLastOccurrenceOf (".", false, false) + suffix;
  135. return target;
  136. }
  137. var getDefaultOptimisationLevel() const override { return var ((int) (isDebug() ? optimisationOff : optimiseMaxSpeed)); }
  138. void createConfigProperties (PropertyListBuilder& props) override
  139. {
  140. static const char* optimisationLevels[] = { "No optimisation", "Minimise size", "Maximise speed", 0 };
  141. const int optimisationLevelValues[] = { optimisationOff, optimiseMinSize, optimiseMaxSpeed, 0 };
  142. props.add (new ChoicePropertyComponent (getOptimisationLevel(), "Optimisation",
  143. StringArray (optimisationLevels),
  144. Array<var> (optimisationLevelValues)),
  145. "The optimisation level for this configuration");
  146. props.add (new TextPropertyComponent (getIntermediatesPathValue(), "Intermediates path", 2048, false),
  147. "An optional path to a folder to use for the intermediate build files. Note that Visual Studio allows "
  148. "you to use macros in this path, e.g. \"$(TEMP)\\MyAppBuildFiles\\$(Configuration)\", which is a handy way to "
  149. "send them to the user's temp folder.");
  150. static const char* warningLevelNames[] = { "Low", "Medium", "High", nullptr };
  151. const int warningLevels[] = { 2, 3, 4 };
  152. props.add (new ChoicePropertyComponent (getWarningLevelValue(), "Warning Level",
  153. StringArray (warningLevelNames), Array<var> (warningLevels, numElementsInArray (warningLevels))));
  154. props.add (new BooleanPropertyComponent (getWarningsTreatedAsErrors(), "Warnings", "Treat warnings as errors"));
  155. {
  156. static const char* runtimeNames[] = { "(Default)", "Use static runtime", "Use DLL runtime", nullptr };
  157. const var runtimeValues[] = { var(), var (false), var (true) };
  158. props.add (new ChoicePropertyComponent (getUsingRuntimeLibDLL(), "Runtime Library",
  159. StringArray (runtimeNames), Array<var> (runtimeValues, numElementsInArray (runtimeValues))));
  160. }
  161. {
  162. static const char* wpoNames[] = { "Enable link-time code generation when possible",
  163. "Always disable link-time code generation", nullptr };
  164. const var wpoValues[] = { var(), var (1) };
  165. props.add (new ChoicePropertyComponent (getWholeProgramOptValue(), "Whole Program Optimisation",
  166. StringArray (wpoNames), Array<var> (wpoValues, numElementsInArray (wpoValues))));
  167. }
  168. if (! isDebug())
  169. props.add (new BooleanPropertyComponent (shouldGenerateDebugSymbolsValue(), "Debug Symbols", "Force generation of debug symbols"));
  170. props.add (new TextPropertyComponent (getPrebuildCommand(), "Pre-build Command", 2048, true));
  171. props.add (new TextPropertyComponent (getPostbuildCommand(), "Post-build Command", 2048, true));
  172. props.add (new BooleanPropertyComponent (shouldGenerateManifestValue(), "Manifest", "Generate Manifest"));
  173. {
  174. static const char* characterSetNames[] = { "Default", "MultiByte", "Unicode", nullptr };
  175. const var charSets[] = { var::null, "MultiByte", "Unicode", };
  176. props.add (new ChoicePropertyComponent (getCharacterSetValue(), "Character Set",
  177. StringArray (characterSetNames), Array<var> (charSets, numElementsInArray (charSets))));
  178. }
  179. }
  180. };
  181. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override
  182. {
  183. return new MSVCBuildConfiguration (project, v);
  184. }
  185. //==============================================================================
  186. String getConfigTargetPath (const BuildConfiguration& config) const
  187. {
  188. const String binaryPath (config.getTargetBinaryRelativePathString().trim());
  189. if (binaryPath.isEmpty())
  190. return binaryPath;
  191. RelativePath binaryRelPath (binaryPath, RelativePath::projectFolder);
  192. if (binaryRelPath.isAbsolute())
  193. return binaryRelPath.toWindowsStyle();
  194. return prependDot (binaryRelPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder)
  195. .toWindowsStyle());
  196. }
  197. String getPreprocessorDefs (const BuildConfiguration& config, const String& joinString) const
  198. {
  199. StringPairArray defines (msvcExtraPreprocessorDefs);
  200. defines.set ("WIN32", "");
  201. defines.set ("_WINDOWS", "");
  202. if (config.isDebug())
  203. {
  204. defines.set ("DEBUG", "");
  205. defines.set ("_DEBUG", "");
  206. }
  207. else
  208. {
  209. defines.set ("NDEBUG", "");
  210. }
  211. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  212. StringArray result;
  213. for (int i = 0; i < defines.size(); ++i)
  214. {
  215. String def (defines.getAllKeys()[i]);
  216. const String value (defines.getAllValues()[i]);
  217. if (value.isNotEmpty())
  218. def << "=" << value;
  219. result.add (def);
  220. }
  221. return result.joinIntoString (joinString);
  222. }
  223. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  224. {
  225. StringArray searchPaths (extraSearchPaths);
  226. searchPaths.addArray (config.getHeaderSearchPaths());
  227. return getCleanedStringArray (searchPaths);
  228. }
  229. virtual String createConfigName (const BuildConfiguration& config) const
  230. {
  231. return config.getName() + "|Win32";
  232. }
  233. //==============================================================================
  234. void writeSolutionFile (OutputStream& out, const String& versionString, String commentString, const File& vcProject) const
  235. {
  236. if (commentString.isNotEmpty())
  237. commentString += newLine;
  238. out << "Microsoft Visual Studio Solution File, Format Version " << versionString << newLine
  239. << commentString
  240. << "Project(\"" << createGUID (projectName + "sln_guid") << "\") = \"" << projectName << "\", \""
  241. << vcProject.getFileName() << "\", \"" << projectGUID << '"' << newLine
  242. << "EndProject" << newLine
  243. << "Global" << newLine
  244. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  245. for (ConstConfigIterator i (*this); i.next();)
  246. {
  247. const String configName (createConfigName (*i));
  248. out << "\t\t" << configName << " = " << configName << newLine;
  249. }
  250. out << "\tEndGlobalSection" << newLine
  251. << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" << newLine;
  252. for (ConstConfigIterator i (*this); i.next();)
  253. {
  254. const String configName (createConfigName (*i));
  255. out << "\t\t" << projectGUID << "." << configName << ".ActiveCfg = " << configName << newLine;
  256. out << "\t\t" << projectGUID << "." << configName << ".Build.0 = " << configName << newLine;
  257. }
  258. out << "\tEndGlobalSection" << newLine
  259. << "\tGlobalSection(SolutionProperties) = preSolution" << newLine
  260. << "\t\tHideSolutionNode = FALSE" << newLine
  261. << "\tEndGlobalSection" << newLine
  262. << "EndGlobal" << newLine;
  263. }
  264. //==============================================================================
  265. static void writeBMPImage (const Image& image, const int w, const int h, MemoryOutputStream& out)
  266. {
  267. const int maskStride = (w / 8 + 3) & ~3;
  268. out.writeInt (40); // bitmapinfoheader size
  269. out.writeInt (w);
  270. out.writeInt (h * 2);
  271. out.writeShort (1); // planes
  272. out.writeShort (32); // bits
  273. out.writeInt (0); // compression
  274. out.writeInt ((h * w * 4) + (h * maskStride)); // size image
  275. out.writeInt (0); // x pixels per meter
  276. out.writeInt (0); // y pixels per meter
  277. out.writeInt (0); // clr used
  278. out.writeInt (0); // clr important
  279. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  280. const int alphaThreshold = 5;
  281. int y;
  282. for (y = h; --y >= 0;)
  283. {
  284. for (int x = 0; x < w; ++x)
  285. {
  286. const Colour pixel (bitmap.getPixelColour (x, y));
  287. if (pixel.getAlpha() <= alphaThreshold)
  288. {
  289. out.writeInt (0);
  290. }
  291. else
  292. {
  293. out.writeByte ((char) pixel.getBlue());
  294. out.writeByte ((char) pixel.getGreen());
  295. out.writeByte ((char) pixel.getRed());
  296. out.writeByte ((char) pixel.getAlpha());
  297. }
  298. }
  299. }
  300. for (y = h; --y >= 0;)
  301. {
  302. int mask = 0, count = 0;
  303. for (int x = 0; x < w; ++x)
  304. {
  305. const Colour pixel (bitmap.getPixelColour (x, y));
  306. mask <<= 1;
  307. if (pixel.getAlpha() <= alphaThreshold)
  308. mask |= 1;
  309. if (++count == 8)
  310. {
  311. out.writeByte ((char) mask);
  312. count = 0;
  313. mask = 0;
  314. }
  315. }
  316. if (mask != 0)
  317. out.writeByte ((char) mask);
  318. for (int i = maskStride - w / 8; --i >= 0;)
  319. out.writeByte (0);
  320. }
  321. }
  322. static void writeIconFile (const Array<Image>& images, MemoryOutputStream& out)
  323. {
  324. out.writeShort (0); // reserved
  325. out.writeShort (1); // .ico tag
  326. out.writeShort ((short) images.size());
  327. MemoryOutputStream dataBlock;
  328. const int imageDirEntrySize = 16;
  329. const int dataBlockStart = 6 + images.size() * imageDirEntrySize;
  330. for (int i = 0; i < images.size(); ++i)
  331. {
  332. const size_t oldDataSize = dataBlock.getDataSize();
  333. const Image& image = images.getReference (i);
  334. const int w = image.getWidth();
  335. const int h = image.getHeight();
  336. if (w >= 256 || h >= 256)
  337. {
  338. PNGImageFormat pngFormat;
  339. pngFormat.writeImageToStream (image, dataBlock);
  340. }
  341. else
  342. {
  343. writeBMPImage (image, w, h, dataBlock);
  344. }
  345. out.writeByte ((char) w);
  346. out.writeByte ((char) h);
  347. out.writeByte (0);
  348. out.writeByte (0);
  349. out.writeShort (1); // colour planes
  350. out.writeShort (32); // bits per pixel
  351. out.writeInt ((int) (dataBlock.getDataSize() - oldDataSize));
  352. out.writeInt (dataBlockStart + (int) oldDataSize);
  353. }
  354. jassert (out.getPosition() == dataBlockStart);
  355. out << dataBlock;
  356. }
  357. bool hasResourceFile() const
  358. {
  359. return ! projectType.isStaticLibrary();
  360. }
  361. void createResourcesAndIcon() const
  362. {
  363. if (hasResourceFile())
  364. {
  365. Array<Image> images;
  366. const int sizes[] = { 16, 32, 48, 256 };
  367. for (int i = 0; i < numElementsInArray (sizes); ++i)
  368. {
  369. Image im (getBestIconForSize (sizes[i], true));
  370. if (im.isValid())
  371. images.add (im);
  372. }
  373. if (images.size() > 0)
  374. {
  375. iconFile = getTargetFolder().getChildFile ("icon.ico");
  376. MemoryOutputStream mo;
  377. writeIconFile (images, mo);
  378. overwriteFileIfDifferentOrThrow (iconFile, mo);
  379. }
  380. createRCFile();
  381. }
  382. }
  383. void createRCFile() const
  384. {
  385. rcFile = getTargetFolder().getChildFile ("resources.rc");
  386. const String version (project.getVersionString());
  387. MemoryOutputStream mo;
  388. mo << "#ifdef JUCE_USER_DEFINED_RC_FILE" << newLine
  389. << " #include JUCE_USER_DEFINED_RC_FILE" << newLine
  390. << "#else" << newLine
  391. << newLine
  392. << "#undef WIN32_LEAN_AND_MEAN" << newLine
  393. << "#define WIN32_LEAN_AND_MEAN" << newLine
  394. << "#include <windows.h>" << newLine
  395. << newLine
  396. << "VS_VERSION_INFO VERSIONINFO" << newLine
  397. << "FILEVERSION " << getCommaSeparatedVersionNumber (version) << newLine
  398. << "BEGIN" << newLine
  399. << " BLOCK \"StringFileInfo\"" << newLine
  400. << " BEGIN" << newLine
  401. << " BLOCK \"040904E4\"" << newLine
  402. << " BEGIN" << newLine;
  403. writeRCValue (mo, "CompanyName", project.getCompanyName().toString());
  404. writeRCValue (mo, "FileDescription", project.getTitle());
  405. writeRCValue (mo, "FileVersion", version);
  406. writeRCValue (mo, "ProductName", project.getTitle());
  407. writeRCValue (mo, "ProductVersion", version);
  408. mo << " END" << newLine
  409. << " END" << newLine
  410. << newLine
  411. << " BLOCK \"VarFileInfo\"" << newLine
  412. << " BEGIN" << newLine
  413. << " VALUE \"Translation\", 0x409, 65001" << newLine
  414. << " END" << newLine
  415. << "END" << newLine
  416. << newLine
  417. << "#endif" << newLine;
  418. if (iconFile != File::nonexistent)
  419. mo << newLine
  420. << "IDI_ICON1 ICON DISCARDABLE " << iconFile.getFileName().quoted()
  421. << newLine
  422. << "IDI_ICON2 ICON DISCARDABLE " << iconFile.getFileName().quoted();
  423. overwriteFileIfDifferentOrThrow (rcFile, mo);
  424. }
  425. static void writeRCValue (MemoryOutputStream& mo, const String& name, const String& value)
  426. {
  427. if (value.isNotEmpty())
  428. mo << " VALUE \"" << name << "\", \""
  429. << CppTokeniserFunctions::addEscapeChars (value) << "\\0\"" << newLine;
  430. }
  431. static String getCommaSeparatedVersionNumber (const String& version)
  432. {
  433. StringArray versionParts;
  434. versionParts.addTokens (version, ",.", "");
  435. versionParts.trim();
  436. versionParts.removeEmptyStrings();
  437. while (versionParts.size() < 4)
  438. versionParts.add ("0");
  439. return versionParts.joinIntoString (",");
  440. }
  441. static String prependDot (const String& filename)
  442. {
  443. return FileHelpers::isAbsolutePath (filename) ? filename
  444. : (".\\" + filename);
  445. }
  446. void initialiseDependencyPathValues()
  447. {
  448. vst2Path = Value (new DependencyPathValueSource (
  449. getSetting (Ids::vstFolder),
  450. DependencyPath::vst2KeyName,
  451. DependencyPathOS::windows
  452. ));
  453. vst3Path = Value (new DependencyPathValueSource (
  454. getSetting (Ids::vst3Folder),
  455. DependencyPath::vst3KeyName,
  456. DependencyPathOS::windows
  457. ));
  458. aaxPath = Value (new DependencyPathValueSource (
  459. getSetting (Ids::aaxFolder),
  460. DependencyPath::aaxKeyName,
  461. DependencyPathOS::windows
  462. ));
  463. rtasPath = Value (new DependencyPathValueSource (
  464. getSetting (Ids::rtasFolder),
  465. DependencyPath::rtasKeyName,
  466. DependencyPathOS::windows
  467. ));
  468. }
  469. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase)
  470. };
  471. //==============================================================================
  472. class MSVCProjectExporterVC2008 : public MSVCProjectExporterBase
  473. {
  474. public:
  475. //==============================================================================
  476. MSVCProjectExporterVC2008 (Project& p, const ValueTree& s,
  477. const char* folderName = "VisualStudio2008")
  478. : MSVCProjectExporterBase (p, s, folderName)
  479. {
  480. name = getName();
  481. }
  482. static const char* getName() { return "Visual Studio 2008"; }
  483. static const char* getValueTreeTypeName() { return "VS2008"; }
  484. int getVisualStudioVersion() const override { return 9; }
  485. static MSVCProjectExporterVC2008* createForSettings (Project& project, const ValueTree& settings)
  486. {
  487. if (settings.hasType (getValueTreeTypeName()))
  488. return new MSVCProjectExporterVC2008 (project, settings);
  489. return nullptr;
  490. }
  491. //==============================================================================
  492. void create (const OwnedArray<LibraryModule>&) const
  493. {
  494. createResourcesAndIcon();
  495. if (hasResourceFile())
  496. {
  497. for (int i = 0; i < getAllGroups().size(); ++i)
  498. {
  499. Project::Item& group = getAllGroups().getReference(i);
  500. if (group.getID() == ProjectSaver::getGeneratedGroupID())
  501. {
  502. if (iconFile != File::nonexistent)
  503. {
  504. group.addFile (iconFile, -1, true);
  505. group.findItemForFile (iconFile).getShouldAddToResourceValue() = false;
  506. }
  507. group.addFile (rcFile, -1, true);
  508. group.findItemForFile (rcFile).getShouldAddToResourceValue() = false;
  509. break;
  510. }
  511. }
  512. }
  513. {
  514. XmlElement projectXml ("VisualStudioProject");
  515. fillInProjectXml (projectXml);
  516. writeXmlOrThrow (projectXml, getVCProjFile(), "UTF-8", 10);
  517. }
  518. {
  519. MemoryOutputStream mo;
  520. writeSolutionFile (mo, getSolutionVersionString(), String::empty, getVCProjFile());
  521. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  522. }
  523. }
  524. protected:
  525. virtual String getProjectVersionString() const { return "9.00"; }
  526. virtual String getSolutionVersionString() const { return String ("10.00") + newLine + "# Visual C++ Express 2008"; }
  527. File getVCProjFile() const { return getProjectFile (".vcproj"); }
  528. //==============================================================================
  529. void fillInProjectXml (XmlElement& projectXml) const
  530. {
  531. projectXml.setAttribute ("ProjectType", "Visual C++");
  532. projectXml.setAttribute ("Version", getProjectVersionString());
  533. projectXml.setAttribute ("Name", projectName);
  534. projectXml.setAttribute ("ProjectGUID", projectGUID);
  535. projectXml.setAttribute ("TargetFrameworkVersion", "131072");
  536. {
  537. XmlElement* platforms = projectXml.createNewChildElement ("Platforms");
  538. XmlElement* platform = platforms->createNewChildElement ("Platform");
  539. platform->setAttribute ("Name", "Win32");
  540. }
  541. projectXml.createNewChildElement ("ToolFiles");
  542. createConfigs (*projectXml.createNewChildElement ("Configurations"));
  543. projectXml.createNewChildElement ("References");
  544. createFiles (*projectXml.createNewChildElement ("Files"));
  545. projectXml.createNewChildElement ("Globals");
  546. }
  547. //==============================================================================
  548. void addFile (const RelativePath& file, XmlElement& parent, const bool excludeFromBuild, const bool useStdcall) const
  549. {
  550. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  551. XmlElement* fileXml = parent.createNewChildElement ("File");
  552. fileXml->setAttribute ("RelativePath", file.toWindowsStyle());
  553. if (excludeFromBuild || useStdcall)
  554. {
  555. for (ConstConfigIterator i (*this); i.next();)
  556. {
  557. XmlElement* fileConfig = fileXml->createNewChildElement ("FileConfiguration");
  558. fileConfig->setAttribute ("Name", createConfigName (*i));
  559. if (excludeFromBuild)
  560. fileConfig->setAttribute ("ExcludedFromBuild", "true");
  561. XmlElement* tool = createToolElement (*fileConfig, "VCCLCompilerTool");
  562. if (useStdcall)
  563. tool->setAttribute ("CallingConvention", "2");
  564. }
  565. }
  566. }
  567. XmlElement* createGroup (const String& groupName, XmlElement& parent) const
  568. {
  569. XmlElement* filter = parent.createNewChildElement ("Filter");
  570. filter->setAttribute ("Name", groupName);
  571. return filter;
  572. }
  573. void addFiles (const Project::Item& projectItem, XmlElement& parent) const
  574. {
  575. if (projectItem.isGroup())
  576. {
  577. XmlElement* filter = createGroup (projectItem.getName(), parent);
  578. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  579. addFiles (projectItem.getChild(i), *filter);
  580. }
  581. else if (projectItem.shouldBeAddedToTargetProject())
  582. {
  583. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  584. addFile (path, parent,
  585. projectItem.shouldBeAddedToBinaryResources()
  586. || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()),
  587. shouldFileBeCompiledByDefault (path) && (bool) projectItem.shouldUseStdCall());
  588. }
  589. }
  590. void createFiles (XmlElement& files) const
  591. {
  592. for (int i = 0; i < getAllGroups().size(); ++i)
  593. {
  594. const Project::Item& group = getAllGroups().getReference(i);
  595. if (group.getNumChildren() > 0)
  596. addFiles (group, files);
  597. }
  598. }
  599. //==============================================================================
  600. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  601. {
  602. XmlElement* const e = parent.createNewChildElement ("Tool");
  603. e->setAttribute ("Name", toolName);
  604. return e;
  605. }
  606. void createConfig (XmlElement& xml, const MSVCBuildConfiguration& config) const
  607. {
  608. const bool isDebug = config.isDebug();
  609. xml.setAttribute ("Name", createConfigName (config));
  610. if (getConfigTargetPath (config).isNotEmpty())
  611. xml.setAttribute ("OutputDirectory", FileHelpers::windowsStylePath (getConfigTargetPath (config)));
  612. if (config.getIntermediatesPath().isNotEmpty())
  613. xml.setAttribute ("IntermediateDirectory", FileHelpers::windowsStylePath (config.getIntermediatesPath()));
  614. xml.setAttribute ("ConfigurationType", isLibraryDLL() ? "2" : (projectType.isStaticLibrary() ? "4" : "1"));
  615. xml.setAttribute ("UseOfMFC", "0");
  616. xml.setAttribute ("ATLMinimizesCRunTimeLibraryUsage", "false");
  617. xml.setAttribute ("CharacterSet", "2");
  618. if (! (isDebug || config.shouldDisableWholeProgramOpt()))
  619. xml.setAttribute ("WholeProgramOptimization", "1");
  620. XmlElement* preBuildEvent = createToolElement (xml, "VCPreBuildEventTool");
  621. if (config.getPrebuildCommandString().isNotEmpty())
  622. {
  623. preBuildEvent->setAttribute ("Description", "Pre-build");
  624. preBuildEvent->setAttribute ("CommandLine", config.getPrebuildCommandString());
  625. }
  626. createToolElement (xml, "VCCustomBuildTool");
  627. createToolElement (xml, "VCXMLDataGeneratorTool");
  628. createToolElement (xml, "VCWebServiceProxyGeneratorTool");
  629. if (! projectType.isStaticLibrary())
  630. {
  631. XmlElement* midl = createToolElement (xml, "VCMIDLTool");
  632. midl->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  633. midl->setAttribute ("MkTypLibCompatible", "true");
  634. midl->setAttribute ("SuppressStartupBanner", "true");
  635. midl->setAttribute ("TargetEnvironment", "1");
  636. midl->setAttribute ("TypeLibraryName", getIntDirFile (config, config.getOutputFilename (".tlb", true)));
  637. midl->setAttribute ("HeaderFileName", "");
  638. }
  639. {
  640. XmlElement* compiler = createToolElement (xml, "VCCLCompilerTool");
  641. compiler->setAttribute ("Optimization", getOptimisationLevelString (config.getOptimisationLevelInt()));
  642. if (isDebug)
  643. {
  644. compiler->setAttribute ("BufferSecurityCheck", "");
  645. compiler->setAttribute ("DebugInformationFormat", projectType.isStaticLibrary() ? "3" : "4");
  646. }
  647. else
  648. {
  649. compiler->setAttribute ("InlineFunctionExpansion", "1");
  650. compiler->setAttribute ("StringPooling", "true");
  651. }
  652. compiler->setAttribute ("AdditionalIncludeDirectories", replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (";")));
  653. compiler->setAttribute ("PreprocessorDefinitions", getPreprocessorDefs (config, ";"));
  654. compiler->setAttribute ("RuntimeLibrary", config.isUsingRuntimeLibDLL() ? (isDebug ? 3 : 2) // MT DLL
  655. : (isDebug ? 1 : 0)); // MT static
  656. compiler->setAttribute ("RuntimeTypeInfo", "true");
  657. compiler->setAttribute ("UsePrecompiledHeader", "0");
  658. compiler->setAttribute ("PrecompiledHeaderFile", getIntDirFile (config, config.getOutputFilename (".pch", true)));
  659. compiler->setAttribute ("AssemblerListingLocation", "$(IntDir)\\");
  660. compiler->setAttribute ("ObjectFile", "$(IntDir)\\");
  661. compiler->setAttribute ("ProgramDataBaseFileName", "$(IntDir)\\");
  662. compiler->setAttribute ("WarningLevel", String (config.getWarningLevel()));
  663. compiler->setAttribute ("SuppressStartupBanner", "true");
  664. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  665. if (extraFlags.isNotEmpty())
  666. compiler->setAttribute ("AdditionalOptions", extraFlags);
  667. }
  668. createToolElement (xml, "VCManagedResourceCompilerTool");
  669. {
  670. XmlElement* resCompiler = createToolElement (xml, "VCResourceCompilerTool");
  671. resCompiler->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  672. }
  673. createToolElement (xml, "VCPreLinkEventTool");
  674. if (! projectType.isStaticLibrary())
  675. {
  676. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  677. linker->setAttribute ("OutputFile", getOutDirFile (config, config.getOutputFilename (msvcTargetSuffix, false)));
  678. linker->setAttribute ("SuppressStartupBanner", "true");
  679. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  680. linker->setAttribute ("GenerateDebugInformation", (isDebug || config.shouldGenerateDebugSymbols()) ? "true" : "false");
  681. linker->setAttribute ("ProgramDatabaseFile", getIntDirFile (config, config.getOutputFilename (".pdb", true)));
  682. linker->setAttribute ("SubSystem", msvcIsWindowsSubsystem ? "2" : "1");
  683. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  684. if (librarySearchPaths.size() > 0)
  685. linker->setAttribute ("AdditionalLibraryDirectories", librarySearchPaths.joinIntoString (";"));
  686. linker->setAttribute ("GenerateManifest", config.shouldGenerateManifest() ? "true" : "false");
  687. if (! isDebug)
  688. {
  689. linker->setAttribute ("OptimizeReferences", "2");
  690. linker->setAttribute ("EnableCOMDATFolding", "2");
  691. }
  692. linker->setAttribute ("TargetMachine", "1"); // (64-bit build = 5)
  693. if (msvcDelayLoadedDLLs.isNotEmpty())
  694. linker->setAttribute ("DelayLoadDLLs", msvcDelayLoadedDLLs);
  695. if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
  696. linker->setAttribute ("ModuleDefinitionFile", config.config [Ids::msvcModuleDefinitionFile].toString());
  697. String externalLibraries (getExternalLibrariesString());
  698. if (externalLibraries.isNotEmpty())
  699. linker->setAttribute ("AdditionalDependencies", replacePreprocessorTokens (config, externalLibraries).trim());
  700. String extraLinkerOptions (getExtraLinkerFlagsString());
  701. if (extraLinkerOptions.isNotEmpty())
  702. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  703. }
  704. else
  705. {
  706. if (isLibraryDLL())
  707. {
  708. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  709. String extraLinkerOptions (getExtraLinkerFlagsString());
  710. extraLinkerOptions << " /IMPLIB:" << getOutDirFile (config, config.getOutputFilename (".lib", true));
  711. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  712. String externalLibraries (getExternalLibrariesString());
  713. if (externalLibraries.isNotEmpty())
  714. linker->setAttribute ("AdditionalDependencies", replacePreprocessorTokens (config, externalLibraries).trim());
  715. linker->setAttribute ("OutputFile", getOutDirFile (config, config.getOutputFilename (msvcTargetSuffix, false)));
  716. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  717. }
  718. else
  719. {
  720. XmlElement* librarian = createToolElement (xml, "VCLibrarianTool");
  721. librarian->setAttribute ("OutputFile", getOutDirFile (config, config.getOutputFilename (msvcTargetSuffix, false)));
  722. librarian->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  723. }
  724. }
  725. createToolElement (xml, "VCALinkTool");
  726. createToolElement (xml, "VCManifestTool");
  727. createToolElement (xml, "VCXDCMakeTool");
  728. {
  729. XmlElement* bscMake = createToolElement (xml, "VCBscMakeTool");
  730. bscMake->setAttribute ("SuppressStartupBanner", "true");
  731. bscMake->setAttribute ("OutputFile", getIntDirFile (config, config.getOutputFilename (".bsc", true)));
  732. }
  733. createToolElement (xml, "VCFxCopTool");
  734. if (! projectType.isStaticLibrary())
  735. createToolElement (xml, "VCAppVerifierTool");
  736. XmlElement* postBuildEvent = createToolElement (xml, "VCPostBuildEventTool");
  737. if (config.getPostbuildCommandString().isNotEmpty())
  738. {
  739. postBuildEvent->setAttribute ("Description", "Post-build");
  740. postBuildEvent->setAttribute ("CommandLine", config.getPostbuildCommandString());
  741. }
  742. }
  743. void createConfigs (XmlElement& xml) const
  744. {
  745. for (ConstConfigIterator config (*this); config.next();)
  746. createConfig (*xml.createNewChildElement ("Configuration"),
  747. dynamic_cast<const MSVCBuildConfiguration&> (*config));
  748. }
  749. static const char* getOptimisationLevelString (int level)
  750. {
  751. switch (level)
  752. {
  753. case optimiseMaxSpeed: return "3";
  754. case optimiseMinSize: return "1";
  755. default: return "0";
  756. }
  757. }
  758. //==============================================================================
  759. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2008)
  760. };
  761. //==============================================================================
  762. class MSVCProjectExporterVC2005 : public MSVCProjectExporterVC2008
  763. {
  764. public:
  765. MSVCProjectExporterVC2005 (Project& p, const ValueTree& t)
  766. : MSVCProjectExporterVC2008 (p, t, "VisualStudio2005")
  767. {
  768. name = getName();
  769. }
  770. static const char* getName() { return "Visual Studio 2005"; }
  771. static const char* getValueTreeTypeName() { return "VS2005"; }
  772. int getVisualStudioVersion() const override { return 8; }
  773. static MSVCProjectExporterVC2005* createForSettings (Project& project, const ValueTree& settings)
  774. {
  775. if (settings.hasType (getValueTreeTypeName()))
  776. return new MSVCProjectExporterVC2005 (project, settings);
  777. return nullptr;
  778. }
  779. protected:
  780. String getProjectVersionString() const { return "8.00"; }
  781. String getSolutionVersionString() const { return String ("9.00") + newLine + "# Visual C++ Express 2005"; }
  782. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2005)
  783. };
  784. //==============================================================================
  785. class MSVCProjectExporterVC2010 : public MSVCProjectExporterBase
  786. {
  787. public:
  788. MSVCProjectExporterVC2010 (Project& p, const ValueTree& t, const char* folderName = "VisualStudio2010")
  789. : MSVCProjectExporterBase (p, t, folderName)
  790. {
  791. name = getName();
  792. }
  793. static const char* getName() { return "Visual Studio 2010"; }
  794. static const char* getValueTreeTypeName() { return "VS2010"; }
  795. int getVisualStudioVersion() const override { return 10; }
  796. virtual String getSolutionComment() const { return "# Visual Studio 2010"; }
  797. virtual String getToolsVersion() const { return "4.0"; }
  798. virtual String getDefaultToolset() const { return "Windows7.1SDK"; }
  799. Value getPlatformToolsetValue() { return getSetting (Ids::toolset); }
  800. String getPlatformToolset() const
  801. {
  802. const String s (settings [Ids::toolset].toString());
  803. return s.isNotEmpty() ? s : getDefaultToolset();
  804. }
  805. static MSVCProjectExporterVC2010* createForSettings (Project& project, const ValueTree& settings)
  806. {
  807. if (settings.hasType (getValueTreeTypeName()))
  808. return new MSVCProjectExporterVC2010 (project, settings);
  809. return nullptr;
  810. }
  811. void createExporterProperties (PropertyListBuilder& props) override
  812. {
  813. MSVCProjectExporterBase::createExporterProperties (props);
  814. static const char* toolsetNames[] = { "(default)", "v100", "v100_xp", "Windows7.1SDK", "CTP_Nov2013", nullptr };
  815. const var toolsets[] = { var(), "v100", "v100_xp", "Windows7.1SDK", "CTP_Nov2013" };
  816. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  817. StringArray (toolsetNames),
  818. Array<var> (toolsets, numElementsInArray (toolsets))));
  819. }
  820. //==============================================================================
  821. void create (const OwnedArray<LibraryModule>&) const
  822. {
  823. createResourcesAndIcon();
  824. {
  825. XmlElement projectXml ("Project");
  826. fillInProjectXml (projectXml);
  827. addPlatformToolsetToPropertyGroup (projectXml);
  828. writeXmlOrThrow (projectXml, getVCProjFile(), "utf-8", 100);
  829. }
  830. {
  831. XmlElement filtersXml ("Project");
  832. fillInFiltersXml (filtersXml);
  833. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "utf-8", 100);
  834. }
  835. {
  836. MemoryOutputStream mo;
  837. writeSolutionFile (mo, "11.00", getSolutionComment(), getVCProjFile());
  838. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  839. }
  840. }
  841. protected:
  842. //==============================================================================
  843. class VC2010BuildConfiguration : public MSVCBuildConfiguration
  844. {
  845. public:
  846. VC2010BuildConfiguration (Project& p, const ValueTree& settings)
  847. : MSVCBuildConfiguration (p, settings)
  848. {
  849. if (getArchitectureType().toString().isEmpty())
  850. getArchitectureType() = get32BitArchName();
  851. }
  852. //==============================================================================
  853. static const char* get32BitArchName() { return "32-bit"; }
  854. static const char* get64BitArchName() { return "x64"; }
  855. Value getArchitectureType() { return getValue (Ids::winArchitecture); }
  856. bool is64Bit() const { return config [Ids::winArchitecture].toString() == get64BitArchName(); }
  857. Value getFastMathValue() { return getValue (Ids::fastMath); }
  858. bool isFastMathEnabled() const { return config [Ids::fastMath]; }
  859. //==============================================================================
  860. void createConfigProperties (PropertyListBuilder& props) override
  861. {
  862. MSVCBuildConfiguration::createConfigProperties (props);
  863. const char* const archTypes[] = { get32BitArchName(), get64BitArchName() };
  864. props.add (new ChoicePropertyComponent (getArchitectureType(), "Architecture",
  865. StringArray (archTypes, numElementsInArray (archTypes)),
  866. Array<var> (archTypes, numElementsInArray (archTypes))));
  867. props.add (new BooleanPropertyComponent (getFastMathValue(), "Relax IEEE compliance", "Enabled"),
  868. "Enable this to use FAST_MATH non-IEEE mode. (Warning: this can have unexpected results!)");
  869. }
  870. };
  871. virtual void addPlatformToolsetToPropertyGroup (XmlElement&) const {}
  872. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const
  873. {
  874. return new VC2010BuildConfiguration (project, v);
  875. }
  876. static bool is64Bit (const BuildConfiguration& config)
  877. {
  878. return dynamic_cast<const VC2010BuildConfiguration&> (config).is64Bit();
  879. }
  880. //==============================================================================
  881. File getVCProjFile() const { return getProjectFile (".vcxproj"); }
  882. File getVCProjFiltersFile() const { return getProjectFile (".vcxproj.filters"); }
  883. String createConfigName (const BuildConfiguration& config) const
  884. {
  885. return config.getName() + (is64Bit (config) ? "|x64"
  886. : "|Win32");
  887. }
  888. void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config) const
  889. {
  890. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + createConfigName (config) + "'");
  891. }
  892. //==============================================================================
  893. void fillInProjectXml (XmlElement& projectXml) const
  894. {
  895. projectXml.setAttribute ("DefaultTargets", "Build");
  896. projectXml.setAttribute ("ToolsVersion", getToolsVersion());
  897. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  898. {
  899. XmlElement* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  900. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  901. for (ConstConfigIterator config (*this); config.next();)
  902. {
  903. XmlElement* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  904. e->setAttribute ("Include", createConfigName (*config));
  905. e->createNewChildElement ("Configuration")->addTextElement (config->getName());
  906. e->createNewChildElement ("Platform")->addTextElement (is64Bit (*config) ? "x64" : "Win32");
  907. }
  908. }
  909. {
  910. XmlElement* globals = projectXml.createNewChildElement ("PropertyGroup");
  911. globals->setAttribute ("Label", "Globals");
  912. globals->createNewChildElement ("ProjectGuid")->addTextElement (projectGUID);
  913. }
  914. {
  915. XmlElement* imports = projectXml.createNewChildElement ("Import");
  916. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  917. }
  918. for (ConstConfigIterator i (*this); i.next();)
  919. {
  920. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  921. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  922. setConditionAttribute (*e, config);
  923. e->setAttribute ("Label", "Configuration");
  924. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  925. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  926. const String charSet (config.getCharacterSet());
  927. if (charSet.isNotEmpty())
  928. e->createNewChildElement ("CharacterSet")->addTextElement (charSet);
  929. if (! (config.isDebug() || config.shouldDisableWholeProgramOpt()))
  930. e->createNewChildElement ("WholeProgramOptimization")->addTextElement ("true");
  931. if (config.is64Bit())
  932. e->createNewChildElement ("PlatformToolset")->addTextElement (getPlatformToolset());
  933. }
  934. {
  935. XmlElement* e = projectXml.createNewChildElement ("Import");
  936. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  937. }
  938. {
  939. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  940. e->setAttribute ("Label", "ExtensionSettings");
  941. }
  942. {
  943. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  944. e->setAttribute ("Label", "PropertySheets");
  945. XmlElement* p = e->createNewChildElement ("Import");
  946. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  947. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  948. p->setAttribute ("Label", "LocalAppDataPlatform");
  949. }
  950. {
  951. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  952. e->setAttribute ("Label", "UserMacros");
  953. }
  954. {
  955. XmlElement* props = projectXml.createNewChildElement ("PropertyGroup");
  956. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  957. for (ConstConfigIterator i (*this); i.next();)
  958. {
  959. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  960. if (getConfigTargetPath (config).isNotEmpty())
  961. {
  962. XmlElement* outdir = props->createNewChildElement ("OutDir");
  963. setConditionAttribute (*outdir, config);
  964. outdir->addTextElement (FileHelpers::windowsStylePath (getConfigTargetPath (config)) + "\\");
  965. }
  966. if (config.getIntermediatesPath().isNotEmpty())
  967. {
  968. XmlElement* intdir = props->createNewChildElement ("IntDir");
  969. setConditionAttribute (*intdir, config);
  970. intdir->addTextElement (FileHelpers::windowsStylePath (config.getIntermediatesPath()) + "\\");
  971. }
  972. {
  973. XmlElement* targetName = props->createNewChildElement ("TargetName");
  974. setConditionAttribute (*targetName, config);
  975. targetName->addTextElement (config.getOutputFilename (String::empty, true));
  976. }
  977. {
  978. XmlElement* manifest = props->createNewChildElement ("GenerateManifest");
  979. setConditionAttribute (*manifest, config);
  980. manifest->addTextElement (config.shouldGenerateManifest() ? "true" : "false");
  981. }
  982. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  983. if (librarySearchPaths.size() > 0)
  984. {
  985. XmlElement* libPath = props->createNewChildElement ("LibraryPath");
  986. setConditionAttribute (*libPath, config);
  987. libPath->addTextElement ("$(LibraryPath);" + librarySearchPaths.joinIntoString (";"));
  988. }
  989. }
  990. }
  991. for (ConstConfigIterator i (*this); i.next();)
  992. {
  993. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  994. const bool isDebug = config.isDebug();
  995. XmlElement* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  996. setConditionAttribute (*group, config);
  997. {
  998. XmlElement* midl = group->createNewChildElement ("Midl");
  999. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  1000. : "NDEBUG;%(PreprocessorDefinitions)");
  1001. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  1002. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1003. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  1004. midl->createNewChildElement ("HeaderFileName");
  1005. }
  1006. bool isUsingEditAndContinue = false;
  1007. {
  1008. XmlElement* cl = group->createNewChildElement ("ClCompile");
  1009. cl->createNewChildElement ("Optimization")->addTextElement (getOptimisationLevelString (config.getOptimisationLevelInt()));
  1010. if (isDebug && config.getOptimisationLevelInt() <= optimisationOff)
  1011. {
  1012. isUsingEditAndContinue = ! config.is64Bit();
  1013. cl->createNewChildElement ("DebugInformationFormat")
  1014. ->addTextElement (isUsingEditAndContinue ? "EditAndContinue"
  1015. : "ProgramDatabase");
  1016. }
  1017. StringArray includePaths (getHeaderSearchPaths (config));
  1018. includePaths.add ("%(AdditionalIncludeDirectories)");
  1019. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  1020. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  1021. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (config.isUsingRuntimeLibDLL() ? (isDebug ? "MultiThreadedDebugDLL" : "MultiThreadedDLL")
  1022. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  1023. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  1024. cl->createNewChildElement ("PrecompiledHeader");
  1025. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement ("$(IntDir)\\");
  1026. cl->createNewChildElement ("ObjectFileName")->addTextElement ("$(IntDir)\\");
  1027. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement ("$(IntDir)\\");
  1028. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level" + String (config.getWarningLevel()));
  1029. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1030. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  1031. if (config.isFastMathEnabled())
  1032. cl->createNewChildElement ("FloatingPointModel")->addTextElement ("Fast");
  1033. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  1034. if (extraFlags.isNotEmpty())
  1035. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  1036. if (config.areWarningsTreatedAsErrors())
  1037. cl->createNewChildElement ("TreatWarningAsError")->addTextElement ("true");
  1038. }
  1039. {
  1040. XmlElement* res = group->createNewChildElement ("ResourceCompile");
  1041. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  1042. : "NDEBUG;%(PreprocessorDefinitions)");
  1043. }
  1044. {
  1045. XmlElement* link = group->createNewChildElement ("Link");
  1046. link->createNewChildElement ("OutputFile")->addTextElement (getOutDirFile (config, config.getOutputFilename (msvcTargetSuffix, false)));
  1047. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1048. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  1049. : "%(IgnoreSpecificDefaultLibraries)");
  1050. link->createNewChildElement ("GenerateDebugInformation")->addTextElement ((isDebug || config.shouldGenerateDebugSymbols()) ? "true" : "false");
  1051. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (getIntDirFile (config, config.getOutputFilename (".pdb", true)));
  1052. link->createNewChildElement ("SubSystem")->addTextElement (msvcIsWindowsSubsystem ? "Windows" : "Console");
  1053. if (! config.is64Bit())
  1054. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  1055. if (isUsingEditAndContinue)
  1056. link->createNewChildElement ("ImageHasSafeExceptionHandlers")->addTextElement ("false");
  1057. if (! isDebug)
  1058. {
  1059. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  1060. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  1061. }
  1062. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  1063. if (librarySearchPaths.size() > 0)
  1064. link->createNewChildElement ("AdditionalLibraryDirectories")->addTextElement (replacePreprocessorTokens (config, librarySearchPaths.joinIntoString (";"))
  1065. + ";%(AdditionalLibraryDirectories)");
  1066. link->createNewChildElement ("LargeAddressAware")->addTextElement ("true");
  1067. String externalLibraries (getExternalLibrariesString());
  1068. if (externalLibraries.isNotEmpty())
  1069. link->createNewChildElement ("AdditionalDependencies")->addTextElement (replacePreprocessorTokens (config, externalLibraries).trim()
  1070. + ";%(AdditionalDependencies)");
  1071. String extraLinkerOptions (getExtraLinkerFlagsString());
  1072. if (extraLinkerOptions.isNotEmpty())
  1073. link->createNewChildElement ("AdditionalOptions")->addTextElement (replacePreprocessorTokens (config, extraLinkerOptions).trim()
  1074. + " %(AdditionalOptions)");
  1075. if (msvcDelayLoadedDLLs.isNotEmpty())
  1076. link->createNewChildElement ("DelayLoadDLLs")->addTextElement (msvcDelayLoadedDLLs);
  1077. if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
  1078. link->createNewChildElement ("ModuleDefinitionFile")
  1079. ->addTextElement (config.config [Ids::msvcModuleDefinitionFile].toString());
  1080. }
  1081. {
  1082. XmlElement* bsc = group->createNewChildElement ("Bscmake");
  1083. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1084. bsc->createNewChildElement ("OutputFile")->addTextElement (getIntDirFile (config, config.getOutputFilename (".bsc", true)));
  1085. }
  1086. if (config.getPrebuildCommandString().isNotEmpty())
  1087. group->createNewChildElement ("PreBuildEvent")
  1088. ->createNewChildElement ("Command")
  1089. ->addTextElement (config.getPrebuildCommandString());
  1090. if (config.getPostbuildCommandString().isNotEmpty())
  1091. group->createNewChildElement ("PostBuildEvent")
  1092. ->createNewChildElement ("Command")
  1093. ->addTextElement (config.getPostbuildCommandString());
  1094. }
  1095. ScopedPointer<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  1096. {
  1097. XmlElement* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  1098. XmlElement* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  1099. for (int i = 0; i < getAllGroups().size(); ++i)
  1100. {
  1101. const Project::Item& group = getAllGroups().getReference(i);
  1102. if (group.getNumChildren() > 0)
  1103. addFilesToCompile (group, *cppFiles, *headerFiles, *otherFilesGroup);
  1104. }
  1105. }
  1106. if (iconFile != File::nonexistent)
  1107. {
  1108. XmlElement* e = otherFilesGroup->createNewChildElement ("None");
  1109. e->setAttribute ("Include", prependDot (iconFile.getFileName()));
  1110. }
  1111. if (otherFilesGroup->getFirstChildElement() != nullptr)
  1112. projectXml.addChildElement (otherFilesGroup.release());
  1113. if (hasResourceFile())
  1114. {
  1115. XmlElement* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  1116. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1117. e->setAttribute ("Include", prependDot (rcFile.getFileName()));
  1118. }
  1119. {
  1120. XmlElement* e = projectXml.createNewChildElement ("Import");
  1121. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  1122. }
  1123. {
  1124. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  1125. e->setAttribute ("Label", "ExtensionTargets");
  1126. }
  1127. }
  1128. String getProjectType() const
  1129. {
  1130. if (projectType.isGUIApplication() || projectType.isCommandLineApp()) return "Application";
  1131. if (isLibraryDLL()) return "DynamicLibrary";
  1132. if (projectType.isStaticLibrary()) return "StaticLibrary";
  1133. jassertfalse;
  1134. return String::empty;
  1135. }
  1136. static const char* getOptimisationLevelString (int level)
  1137. {
  1138. switch (level)
  1139. {
  1140. case optimiseMaxSpeed: return "Full";
  1141. case optimiseMinSize: return "MinSpace";
  1142. default: return "Disabled";
  1143. }
  1144. }
  1145. //==============================================================================
  1146. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  1147. {
  1148. if (projectItem.isGroup())
  1149. {
  1150. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1151. addFilesToCompile (projectItem.getChild(i), cpps, headers, otherFiles);
  1152. }
  1153. else if (projectItem.shouldBeAddedToTargetProject())
  1154. {
  1155. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  1156. jassert (path.getRoot() == RelativePath::buildTargetFolder);
  1157. if (path.hasFileExtension (cOrCppFileExtensions))
  1158. {
  1159. XmlElement* e = cpps.createNewChildElement ("ClCompile");
  1160. e->setAttribute ("Include", path.toWindowsStyle());
  1161. if (! projectItem.shouldBeCompiled())
  1162. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  1163. if (projectItem.shouldUseStdCall())
  1164. e->createNewChildElement ("CallingConvention")->addTextElement ("StdCall");
  1165. }
  1166. else if (path.hasFileExtension (headerFileExtensions))
  1167. {
  1168. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", path.toWindowsStyle());
  1169. }
  1170. else if (! path.hasFileExtension (objCFileExtensions))
  1171. {
  1172. otherFiles.createNewChildElement ("None")->setAttribute ("Include", path.toWindowsStyle());
  1173. }
  1174. }
  1175. }
  1176. //==============================================================================
  1177. void addFilterGroup (XmlElement& groups, const String& path) const
  1178. {
  1179. XmlElement* e = groups.createNewChildElement ("Filter");
  1180. e->setAttribute ("Include", path);
  1181. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  1182. }
  1183. void addFileToFilter (const RelativePath& file, const String& groupPath,
  1184. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  1185. {
  1186. XmlElement* e;
  1187. if (file.hasFileExtension (headerFileExtensions))
  1188. e = headers.createNewChildElement ("ClInclude");
  1189. else if (file.hasFileExtension (sourceFileExtensions))
  1190. e = cpps.createNewChildElement ("ClCompile");
  1191. else
  1192. e = otherFiles.createNewChildElement ("None");
  1193. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1194. e->setAttribute ("Include", file.toWindowsStyle());
  1195. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  1196. }
  1197. void addFilesToFilter (const Project::Item& projectItem, const String& path,
  1198. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups) const
  1199. {
  1200. if (projectItem.isGroup())
  1201. {
  1202. addFilterGroup (groups, path);
  1203. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1204. addFilesToFilter (projectItem.getChild(i),
  1205. (path.isEmpty() ? String::empty : (path + "\\")) + projectItem.getChild(i).getName(),
  1206. cpps, headers, otherFiles, groups);
  1207. }
  1208. else if (projectItem.shouldBeAddedToTargetProject())
  1209. {
  1210. addFileToFilter (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder),
  1211. path.upToLastOccurrenceOf ("\\", false, false), cpps, headers, otherFiles);
  1212. }
  1213. }
  1214. void addFilesToFilter (const Array<RelativePath>& files, const String& path,
  1215. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups)
  1216. {
  1217. if (files.size() > 0)
  1218. {
  1219. addFilterGroup (groups, path);
  1220. for (int i = 0; i < files.size(); ++i)
  1221. addFileToFilter (files.getReference(i), path, cpps, headers, otherFiles);
  1222. }
  1223. }
  1224. void fillInFiltersXml (XmlElement& filterXml) const
  1225. {
  1226. filterXml.setAttribute ("ToolsVersion", getToolsVersion());
  1227. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  1228. XmlElement* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  1229. XmlElement* cpps = filterXml.createNewChildElement ("ItemGroup");
  1230. XmlElement* headers = filterXml.createNewChildElement ("ItemGroup");
  1231. ScopedPointer<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  1232. for (int i = 0; i < getAllGroups().size(); ++i)
  1233. {
  1234. const Project::Item& group = getAllGroups().getReference(i);
  1235. if (group.getNumChildren() > 0)
  1236. addFilesToFilter (group, group.getName(), *cpps, *headers, *otherFilesGroup, *groupsXml);
  1237. }
  1238. if (iconFile.exists())
  1239. {
  1240. XmlElement* e = otherFilesGroup->createNewChildElement ("None");
  1241. e->setAttribute ("Include", prependDot (iconFile.getFileName()));
  1242. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1243. }
  1244. if (otherFilesGroup->getFirstChildElement() != nullptr)
  1245. filterXml.addChildElement (otherFilesGroup.release());
  1246. if (hasResourceFile())
  1247. {
  1248. XmlElement* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  1249. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1250. e->setAttribute ("Include", prependDot (rcFile.getFileName()));
  1251. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1252. }
  1253. }
  1254. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2010)
  1255. };
  1256. //==============================================================================
  1257. class MSVCProjectExporterVC2012 : public MSVCProjectExporterVC2010
  1258. {
  1259. public:
  1260. MSVCProjectExporterVC2012 (Project& p, const ValueTree& t,
  1261. const char* folderName = "VisualStudio2012")
  1262. : MSVCProjectExporterVC2010 (p, t, folderName)
  1263. {
  1264. name = getName();
  1265. }
  1266. static const char* getName() { return "Visual Studio 2012"; }
  1267. static const char* getValueTreeTypeName() { return "VS2012"; }
  1268. int getVisualStudioVersion() const override { return 11; }
  1269. String getSolutionComment() const override { return "# Visual Studio 2012"; }
  1270. virtual String getDefaultToolset() const { return "v110"; }
  1271. static MSVCProjectExporterVC2012* createForSettings (Project& project, const ValueTree& settings)
  1272. {
  1273. if (settings.hasType (getValueTreeTypeName()))
  1274. return new MSVCProjectExporterVC2012 (project, settings);
  1275. return nullptr;
  1276. }
  1277. void createExporterProperties (PropertyListBuilder& props) override
  1278. {
  1279. MSVCProjectExporterBase::createExporterProperties (props);
  1280. static const char* toolsetNames[] = { "(default)", "v110", "v110_xp", "Windows7.1SDK", "CTP_Nov2013", nullptr };
  1281. const var toolsets[] = { var(), "v110", "v110_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1282. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  1283. StringArray (toolsetNames),
  1284. Array<var> (toolsets, numElementsInArray (toolsets))));
  1285. }
  1286. private:
  1287. void addPlatformToolsetToPropertyGroup (XmlElement& p) const override
  1288. {
  1289. forEachXmlChildElementWithTagName (p, e, "PropertyGroup")
  1290. {
  1291. XmlElement* platformToolset (new XmlElement ("PlatformToolset"));
  1292. platformToolset->addTextElement (getPlatformToolset());
  1293. e->addChildElement (platformToolset);
  1294. }
  1295. }
  1296. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2012)
  1297. };
  1298. //==============================================================================
  1299. class MSVCProjectExporterVC2013 : public MSVCProjectExporterVC2012
  1300. {
  1301. public:
  1302. MSVCProjectExporterVC2013 (Project& p, const ValueTree& t)
  1303. : MSVCProjectExporterVC2012 (p, t, "VisualStudio2013")
  1304. {
  1305. name = getName();
  1306. }
  1307. static const char* getName() { return "Visual Studio 2013"; }
  1308. static const char* getValueTreeTypeName() { return "VS2013"; }
  1309. int getVisualStudioVersion() const override { return 12; }
  1310. String getSolutionComment() const override { return "# Visual Studio 2013"; }
  1311. String getToolsVersion() const override { return "12.0"; }
  1312. String getDefaultToolset() const override { return "v120"; }
  1313. static MSVCProjectExporterVC2013* createForSettings (Project& project, const ValueTree& settings)
  1314. {
  1315. if (settings.hasType (getValueTreeTypeName()))
  1316. return new MSVCProjectExporterVC2013 (project, settings);
  1317. return nullptr;
  1318. }
  1319. void createExporterProperties (PropertyListBuilder& props) override
  1320. {
  1321. MSVCProjectExporterBase::createExporterProperties (props);
  1322. static const char* toolsetNames[] = { "(default)", "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013", nullptr };
  1323. const var toolsets[] = { var(), "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1324. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  1325. StringArray (toolsetNames),
  1326. Array<var> (toolsets, numElementsInArray (toolsets))));
  1327. }
  1328. private:
  1329. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2013)
  1330. };
  1331. //==============================================================================
  1332. class MSVCProjectExporterVC2015 : public MSVCProjectExporterVC2012
  1333. {
  1334. public:
  1335. MSVCProjectExporterVC2015 (Project& p, const ValueTree& t)
  1336. : MSVCProjectExporterVC2012 (p, t, "VisualStudio2015")
  1337. {
  1338. name = getName();
  1339. }
  1340. static const char* getName() { return "Visual Studio 2015"; }
  1341. static const char* getValueTreeTypeName() { return "VS2015"; }
  1342. int getVisualStudioVersion() const override { return 14; }
  1343. String getSolutionComment() const override { return "# Visual Studio 2015"; }
  1344. String getToolsVersion() const override { return "14.0"; }
  1345. String getDefaultToolset() const override { return "v140"; }
  1346. static MSVCProjectExporterVC2015* createForSettings (Project& project, const ValueTree& settings)
  1347. {
  1348. if (settings.hasType (getValueTreeTypeName()))
  1349. return new MSVCProjectExporterVC2015 (project, settings);
  1350. return nullptr;
  1351. }
  1352. void createExporterProperties (PropertyListBuilder& props) override
  1353. {
  1354. MSVCProjectExporterBase::createExporterProperties (props);
  1355. static const char* toolsetNames[] = { "(default)", "v140", "v140_xp", nullptr };
  1356. const var toolsets[] = { var(), "v140", "v140_xp" };
  1357. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  1358. StringArray (toolsetNames),
  1359. Array<var> (toolsets, numElementsInArray (toolsets))));
  1360. }
  1361. private:
  1362. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2015)
  1363. };