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.

1909 lines
85KB

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