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.

1894 lines
84KB

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