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.

1889 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::null, "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. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase)
  612. };
  613. //==============================================================================
  614. class MSVCProjectExporterVC2008 : public MSVCProjectExporterBase
  615. {
  616. public:
  617. //==============================================================================
  618. MSVCProjectExporterVC2008 (Project& p, const ValueTree& s,
  619. const char* folderName = "VisualStudio2008")
  620. : MSVCProjectExporterBase (p, s, folderName)
  621. {
  622. name = getName();
  623. }
  624. static const char* getName() { return "Visual Studio 2008"; }
  625. static const char* getValueTreeTypeName() { return "VS2008"; }
  626. int getVisualStudioVersion() const override { return 9; }
  627. static MSVCProjectExporterVC2008* createForSettings (Project& project, const ValueTree& settings)
  628. {
  629. if (settings.hasType (getValueTreeTypeName()))
  630. return new MSVCProjectExporterVC2008 (project, settings);
  631. return nullptr;
  632. }
  633. //==============================================================================
  634. void create (const OwnedArray<LibraryModule>&) const override
  635. {
  636. createResourcesAndIcon();
  637. if (hasResourceFile())
  638. {
  639. for (int i = 0; i < getAllGroups().size(); ++i)
  640. {
  641. Project::Item& group = getAllGroups().getReference(i);
  642. if (group.getID() == ProjectSaver::getGeneratedGroupID())
  643. {
  644. if (iconFile != File::nonexistent)
  645. {
  646. group.addFileAtIndex (iconFile, -1, true);
  647. group.findItemForFile (iconFile).getShouldAddToBinaryResourcesValue() = false;
  648. }
  649. group.addFileAtIndex (rcFile, -1, true);
  650. group.findItemForFile (rcFile).getShouldAddToBinaryResourcesValue() = false;
  651. break;
  652. }
  653. }
  654. }
  655. {
  656. XmlElement projectXml ("VisualStudioProject");
  657. fillInProjectXml (projectXml);
  658. writeXmlOrThrow (projectXml, getVCProjFile(), "UTF-8", 10);
  659. }
  660. {
  661. MemoryOutputStream mo;
  662. writeSolutionFile (mo, getSolutionVersionString(), String::empty, getVCProjFile());
  663. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  664. }
  665. }
  666. protected:
  667. virtual String getProjectVersionString() const { return "9.00"; }
  668. virtual String getSolutionVersionString() const { return String ("10.00") + newLine + "# Visual C++ Express 2008"; }
  669. File getVCProjFile() const { return getProjectFile (".vcproj"); }
  670. //==============================================================================
  671. void fillInProjectXml (XmlElement& projectXml) const
  672. {
  673. projectXml.setAttribute ("ProjectType", "Visual C++");
  674. projectXml.setAttribute ("Version", getProjectVersionString());
  675. projectXml.setAttribute ("Name", projectName);
  676. projectXml.setAttribute ("ProjectGUID", projectGUID);
  677. projectXml.setAttribute ("TargetFrameworkVersion", "131072");
  678. {
  679. XmlElement* platforms = projectXml.createNewChildElement ("Platforms");
  680. XmlElement* platform = platforms->createNewChildElement ("Platform");
  681. platform->setAttribute ("Name", "Win32");
  682. }
  683. projectXml.createNewChildElement ("ToolFiles");
  684. createConfigs (*projectXml.createNewChildElement ("Configurations"));
  685. projectXml.createNewChildElement ("References");
  686. createFiles (*projectXml.createNewChildElement ("Files"));
  687. projectXml.createNewChildElement ("Globals");
  688. }
  689. //==============================================================================
  690. void addFile (const RelativePath& file, XmlElement& parent, const bool excludeFromBuild, const bool useStdcall) const
  691. {
  692. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  693. XmlElement* fileXml = parent.createNewChildElement ("File");
  694. fileXml->setAttribute ("RelativePath", file.toWindowsStyle());
  695. if (excludeFromBuild || useStdcall)
  696. {
  697. for (ConstConfigIterator i (*this); i.next();)
  698. {
  699. XmlElement* fileConfig = fileXml->createNewChildElement ("FileConfiguration");
  700. fileConfig->setAttribute ("Name", createConfigName (*i));
  701. if (excludeFromBuild)
  702. fileConfig->setAttribute ("ExcludedFromBuild", "true");
  703. XmlElement* tool = createToolElement (*fileConfig, "VCCLCompilerTool");
  704. if (useStdcall)
  705. tool->setAttribute ("CallingConvention", "2");
  706. }
  707. }
  708. }
  709. XmlElement* createGroup (const String& groupName, XmlElement& parent) const
  710. {
  711. XmlElement* filter = parent.createNewChildElement ("Filter");
  712. filter->setAttribute ("Name", groupName);
  713. return filter;
  714. }
  715. void addFiles (const Project::Item& projectItem, XmlElement& parent) const
  716. {
  717. if (projectItem.isGroup())
  718. {
  719. XmlElement* filter = createGroup (projectItem.getName(), parent);
  720. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  721. addFiles (projectItem.getChild(i), *filter);
  722. }
  723. else if (projectItem.shouldBeAddedToTargetProject())
  724. {
  725. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  726. addFile (path, parent,
  727. projectItem.shouldBeAddedToBinaryResources()
  728. || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()),
  729. shouldFileBeCompiledByDefault (path) && projectItem.shouldUseStdCall());
  730. }
  731. }
  732. void createFiles (XmlElement& files) const
  733. {
  734. for (int i = 0; i < getAllGroups().size(); ++i)
  735. {
  736. const Project::Item& group = getAllGroups().getReference(i);
  737. if (group.getNumChildren() > 0)
  738. addFiles (group, files);
  739. }
  740. }
  741. //==============================================================================
  742. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  743. {
  744. XmlElement* const e = parent.createNewChildElement ("Tool");
  745. e->setAttribute ("Name", toolName);
  746. return e;
  747. }
  748. void createConfig (XmlElement& xml, const MSVCBuildConfiguration& config) const
  749. {
  750. const bool isDebug = config.isDebug();
  751. xml.setAttribute ("Name", createConfigName (config));
  752. if (getConfigTargetPath (config).isNotEmpty())
  753. xml.setAttribute ("OutputDirectory", FileHelpers::windowsStylePath (getConfigTargetPath (config)));
  754. if (config.getIntermediatesPath().isNotEmpty())
  755. xml.setAttribute ("IntermediateDirectory", FileHelpers::windowsStylePath (config.getIntermediatesPath()));
  756. xml.setAttribute ("ConfigurationType", isLibraryDLL() ? "2" : (projectType.isStaticLibrary() ? "4" : "1"));
  757. xml.setAttribute ("UseOfMFC", "0");
  758. xml.setAttribute ("ATLMinimizesCRunTimeLibraryUsage", "false");
  759. xml.setAttribute ("CharacterSet", "2");
  760. if (! (isDebug || config.shouldDisableWholeProgramOpt()))
  761. xml.setAttribute ("WholeProgramOptimization", "1");
  762. XmlElement* preBuildEvent = createToolElement (xml, "VCPreBuildEventTool");
  763. if (config.getPrebuildCommandString().isNotEmpty())
  764. {
  765. preBuildEvent->setAttribute ("Description", "Pre-build");
  766. preBuildEvent->setAttribute ("CommandLine", config.getPrebuildCommandString());
  767. }
  768. createToolElement (xml, "VCCustomBuildTool");
  769. createToolElement (xml, "VCXMLDataGeneratorTool");
  770. createToolElement (xml, "VCWebServiceProxyGeneratorTool");
  771. if (! projectType.isStaticLibrary())
  772. {
  773. XmlElement* midl = createToolElement (xml, "VCMIDLTool");
  774. midl->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  775. midl->setAttribute ("MkTypLibCompatible", "true");
  776. midl->setAttribute ("SuppressStartupBanner", "true");
  777. midl->setAttribute ("TargetEnvironment", "1");
  778. midl->setAttribute ("TypeLibraryName", getIntDirFile (config, config.getOutputFilename (".tlb", true)));
  779. midl->setAttribute ("HeaderFileName", "");
  780. }
  781. {
  782. XmlElement* compiler = createToolElement (xml, "VCCLCompilerTool");
  783. compiler->setAttribute ("Optimization", getOptimisationLevelString (config.getOptimisationLevelInt()));
  784. if (isDebug)
  785. {
  786. compiler->setAttribute ("BufferSecurityCheck", "");
  787. compiler->setAttribute ("DebugInformationFormat", projectType.isStaticLibrary() ? "3" : "4");
  788. }
  789. else
  790. {
  791. compiler->setAttribute ("InlineFunctionExpansion", "1");
  792. compiler->setAttribute ("StringPooling", "true");
  793. }
  794. compiler->setAttribute ("AdditionalIncludeDirectories", replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (";")));
  795. compiler->setAttribute ("PreprocessorDefinitions", getPreprocessorDefs (config, ";"));
  796. compiler->setAttribute ("RuntimeLibrary", config.isUsingRuntimeLibDLL() ? (isDebug ? 3 : 2) // MT DLL
  797. : (isDebug ? 1 : 0)); // MT static
  798. compiler->setAttribute ("RuntimeTypeInfo", "true");
  799. compiler->setAttribute ("UsePrecompiledHeader", "0");
  800. compiler->setAttribute ("PrecompiledHeaderFile", getIntDirFile (config, config.getOutputFilename (".pch", true)));
  801. compiler->setAttribute ("AssemblerListingLocation", "$(IntDir)\\");
  802. compiler->setAttribute ("ObjectFile", "$(IntDir)\\");
  803. compiler->setAttribute ("ProgramDataBaseFileName", "$(IntDir)\\");
  804. compiler->setAttribute ("WarningLevel", String (config.getWarningLevel()));
  805. compiler->setAttribute ("SuppressStartupBanner", "true");
  806. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  807. if (extraFlags.isNotEmpty())
  808. compiler->setAttribute ("AdditionalOptions", extraFlags);
  809. }
  810. createToolElement (xml, "VCManagedResourceCompilerTool");
  811. {
  812. XmlElement* resCompiler = createToolElement (xml, "VCResourceCompilerTool");
  813. resCompiler->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  814. }
  815. createToolElement (xml, "VCPreLinkEventTool");
  816. if (! projectType.isStaticLibrary())
  817. {
  818. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  819. linker->setAttribute ("OutputFile", getOutDirFile (config, config.getOutputFilename (msvcTargetSuffix, false)));
  820. linker->setAttribute ("SuppressStartupBanner", "true");
  821. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  822. linker->setAttribute ("GenerateDebugInformation", (isDebug || config.shouldGenerateDebugSymbols()) ? "true" : "false");
  823. linker->setAttribute ("ProgramDatabaseFile", getIntDirFile (config, config.getOutputFilename (".pdb", true)));
  824. linker->setAttribute ("SubSystem", msvcIsWindowsSubsystem ? "2" : "1");
  825. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  826. if (librarySearchPaths.size() > 0)
  827. linker->setAttribute ("AdditionalLibraryDirectories", librarySearchPaths.joinIntoString (";"));
  828. linker->setAttribute ("GenerateManifest", config.shouldGenerateManifest() ? "true" : "false");
  829. if (! isDebug)
  830. {
  831. linker->setAttribute ("OptimizeReferences", "2");
  832. linker->setAttribute ("EnableCOMDATFolding", "2");
  833. }
  834. linker->setAttribute ("TargetMachine", "1"); // (64-bit build = 5)
  835. if (msvcDelayLoadedDLLs.isNotEmpty())
  836. linker->setAttribute ("DelayLoadDLLs", msvcDelayLoadedDLLs);
  837. if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
  838. linker->setAttribute ("ModuleDefinitionFile", config.config [Ids::msvcModuleDefinitionFile].toString());
  839. String externalLibraries (getExternalLibrariesString());
  840. if (externalLibraries.isNotEmpty())
  841. linker->setAttribute ("AdditionalDependencies", replacePreprocessorTokens (config, externalLibraries).trim());
  842. String extraLinkerOptions (getExtraLinkerFlagsString());
  843. if (extraLinkerOptions.isNotEmpty())
  844. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  845. }
  846. else
  847. {
  848. if (isLibraryDLL())
  849. {
  850. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  851. String extraLinkerOptions (getExtraLinkerFlagsString());
  852. extraLinkerOptions << " /IMPLIB:" << getOutDirFile (config, config.getOutputFilename (".lib", true));
  853. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  854. String externalLibraries (getExternalLibrariesString());
  855. if (externalLibraries.isNotEmpty())
  856. linker->setAttribute ("AdditionalDependencies", replacePreprocessorTokens (config, externalLibraries).trim());
  857. linker->setAttribute ("OutputFile", getOutDirFile (config, config.getOutputFilename (msvcTargetSuffix, false)));
  858. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  859. }
  860. else
  861. {
  862. XmlElement* librarian = createToolElement (xml, "VCLibrarianTool");
  863. librarian->setAttribute ("OutputFile", getOutDirFile (config, config.getOutputFilename (msvcTargetSuffix, false)));
  864. librarian->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  865. }
  866. }
  867. createToolElement (xml, "VCALinkTool");
  868. createToolElement (xml, "VCManifestTool");
  869. createToolElement (xml, "VCXDCMakeTool");
  870. {
  871. XmlElement* bscMake = createToolElement (xml, "VCBscMakeTool");
  872. bscMake->setAttribute ("SuppressStartupBanner", "true");
  873. bscMake->setAttribute ("OutputFile", getIntDirFile (config, config.getOutputFilename (".bsc", true)));
  874. }
  875. createToolElement (xml, "VCFxCopTool");
  876. if (! projectType.isStaticLibrary())
  877. createToolElement (xml, "VCAppVerifierTool");
  878. XmlElement* postBuildEvent = createToolElement (xml, "VCPostBuildEventTool");
  879. if (config.getPostbuildCommandString().isNotEmpty())
  880. {
  881. postBuildEvent->setAttribute ("Description", "Post-build");
  882. postBuildEvent->setAttribute ("CommandLine", config.getPostbuildCommandString());
  883. }
  884. }
  885. void createConfigs (XmlElement& xml) const
  886. {
  887. for (ConstConfigIterator config (*this); config.next();)
  888. createConfig (*xml.createNewChildElement ("Configuration"),
  889. dynamic_cast<const MSVCBuildConfiguration&> (*config));
  890. }
  891. static const char* getOptimisationLevelString (int level)
  892. {
  893. switch (level)
  894. {
  895. case optimiseMaxSpeed: return "3";
  896. case optimiseMinSize: return "1";
  897. default: return "0";
  898. }
  899. }
  900. //==============================================================================
  901. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2008)
  902. };
  903. //==============================================================================
  904. class MSVCProjectExporterVC2005 : public MSVCProjectExporterVC2008
  905. {
  906. public:
  907. MSVCProjectExporterVC2005 (Project& p, const ValueTree& t)
  908. : MSVCProjectExporterVC2008 (p, t, "VisualStudio2005")
  909. {
  910. name = getName();
  911. }
  912. static const char* getName() { return "Visual Studio 2005"; }
  913. static const char* getValueTreeTypeName() { return "VS2005"; }
  914. int getVisualStudioVersion() const override { return 8; }
  915. static MSVCProjectExporterVC2005* createForSettings (Project& project, const ValueTree& settings)
  916. {
  917. if (settings.hasType (getValueTreeTypeName()))
  918. return new MSVCProjectExporterVC2005 (project, settings);
  919. return nullptr;
  920. }
  921. protected:
  922. String getProjectVersionString() const override { return "8.00"; }
  923. String getSolutionVersionString() const override { return String ("9.00") + newLine + "# Visual C++ Express 2005"; }
  924. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2005)
  925. };
  926. //==============================================================================
  927. class MSVCProjectExporterVC2010 : public MSVCProjectExporterBase
  928. {
  929. public:
  930. MSVCProjectExporterVC2010 (Project& p, const ValueTree& t, const char* folderName = "VisualStudio2010")
  931. : MSVCProjectExporterBase (p, t, folderName)
  932. {
  933. name = getName();
  934. }
  935. static const char* getName() { return "Visual Studio 2010"; }
  936. static const char* getValueTreeTypeName() { return "VS2010"; }
  937. int getVisualStudioVersion() const override { return 10; }
  938. virtual String getSolutionComment() const { return "# Visual Studio 2010"; }
  939. virtual String getToolsVersion() const { return "4.0"; }
  940. virtual String getDefaultToolset() const { return "Windows7.1SDK"; }
  941. Value getPlatformToolsetValue() { return getSetting (Ids::toolset); }
  942. Value getIPPLibraryValue() { return getSetting (Ids::IPPLibrary); }
  943. String getIPPLibrary() const { return settings [Ids::IPPLibrary]; }
  944. String getPlatformToolset() const
  945. {
  946. const String s (settings [Ids::toolset].toString());
  947. return s.isNotEmpty() ? s : getDefaultToolset();
  948. }
  949. static MSVCProjectExporterVC2010* createForSettings (Project& project, const ValueTree& settings)
  950. {
  951. if (settings.hasType (getValueTreeTypeName()))
  952. return new MSVCProjectExporterVC2010 (project, settings);
  953. return nullptr;
  954. }
  955. void addToolsetProperty (PropertyListBuilder& props, const char** names, const var* values, int num)
  956. {
  957. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  958. StringArray (names, num), Array<var> (values, num)));
  959. }
  960. void addIPPLibraryProperty (PropertyListBuilder& props)
  961. {
  962. static const char* ippOptions[] = { "No", "Yes (Default Mode)", "Multi-Threaded Static Library", "Single-Threaded Static Library", "Multi-Threaded DLL", "Single-Threaded DLL" };
  963. static const var ippValues[] = { var(), "true", "Parallel_Static", "Sequential", "Parallel_Dynamic", "Sequential_Dynamic" };
  964. props.add (new ChoicePropertyComponent (getIPPLibraryValue(), "Use IPP Library",
  965. StringArray (ippOptions, numElementsInArray (ippValues)),
  966. Array<var> (ippValues, numElementsInArray (ippValues))));
  967. }
  968. void createExporterProperties (PropertyListBuilder& props) override
  969. {
  970. MSVCProjectExporterBase::createExporterProperties (props);
  971. static const char* toolsetNames[] = { "(default)", "v100", "v100_xp", "Windows7.1SDK", "CTP_Nov2013" };
  972. const var toolsets[] = { var(), "v100", "v100_xp", "Windows7.1SDK", "CTP_Nov2013" };
  973. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  974. addIPPLibraryProperty (props);
  975. }
  976. //==============================================================================
  977. void create (const OwnedArray<LibraryModule>&) const override
  978. {
  979. createResourcesAndIcon();
  980. {
  981. XmlElement projectXml ("Project");
  982. fillInProjectXml (projectXml);
  983. addPlatformToolsetToPropertyGroup (projectXml);
  984. addIPPSettingToPropertyGroup (projectXml);
  985. writeXmlOrThrow (projectXml, getVCProjFile(), "utf-8", 100);
  986. }
  987. {
  988. XmlElement filtersXml ("Project");
  989. fillInFiltersXml (filtersXml);
  990. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "utf-8", 100);
  991. }
  992. {
  993. MemoryOutputStream mo;
  994. writeSolutionFile (mo, "11.00", getSolutionComment(), getVCProjFile());
  995. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  996. }
  997. }
  998. protected:
  999. //==============================================================================
  1000. class VC2010BuildConfiguration : public MSVCBuildConfiguration
  1001. {
  1002. public:
  1003. VC2010BuildConfiguration (Project& p, const ValueTree& settings, const ProjectExporter& e)
  1004. : MSVCBuildConfiguration (p, settings, e)
  1005. {
  1006. if (getArchitectureType().toString().isEmpty())
  1007. getArchitectureType() = get32BitArchName();
  1008. }
  1009. //==============================================================================
  1010. static const char* get32BitArchName() { return "32-bit"; }
  1011. static const char* get64BitArchName() { return "x64"; }
  1012. Value getArchitectureType() { return getValue (Ids::winArchitecture); }
  1013. bool is64Bit() const { return config [Ids::winArchitecture].toString() == get64BitArchName(); }
  1014. Value getFastMathValue() { return getValue (Ids::fastMath); }
  1015. bool isFastMathEnabled() const { return config [Ids::fastMath]; }
  1016. //==============================================================================
  1017. void createConfigProperties (PropertyListBuilder& props) override
  1018. {
  1019. MSVCBuildConfiguration::createConfigProperties (props);
  1020. const char* const archTypes[] = { get32BitArchName(), get64BitArchName() };
  1021. props.add (new ChoicePropertyComponent (getArchitectureType(), "Architecture",
  1022. StringArray (archTypes, numElementsInArray (archTypes)),
  1023. Array<var> (archTypes, numElementsInArray (archTypes))));
  1024. props.add (new BooleanPropertyComponent (getFastMathValue(), "Relax IEEE compliance", "Enabled"),
  1025. "Enable this to use FAST_MATH non-IEEE mode. (Warning: this can have unexpected results!)");
  1026. }
  1027. };
  1028. virtual void addPlatformToolsetToPropertyGroup (XmlElement&) const {}
  1029. void addIPPSettingToPropertyGroup (XmlElement& p) const
  1030. {
  1031. String ippLibrary = getIPPLibrary();
  1032. if (ippLibrary.isNotEmpty())
  1033. forEachXmlChildElementWithTagName (p, e, "PropertyGroup")
  1034. e->createNewChildElement ("UseIntelIPP")->addTextElement (ippLibrary);
  1035. }
  1036. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override
  1037. {
  1038. return new VC2010BuildConfiguration (project, v, *this);
  1039. }
  1040. static bool is64Bit (const BuildConfiguration& config)
  1041. {
  1042. return dynamic_cast<const VC2010BuildConfiguration&> (config).is64Bit();
  1043. }
  1044. //==============================================================================
  1045. File getVCProjFile() const { return getProjectFile (".vcxproj"); }
  1046. File getVCProjFiltersFile() const { return getProjectFile (".vcxproj.filters"); }
  1047. String createConfigName (const BuildConfiguration& config) const override
  1048. {
  1049. return config.getName() + (is64Bit (config) ? "|x64"
  1050. : "|Win32");
  1051. }
  1052. void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config) const
  1053. {
  1054. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + createConfigName (config) + "'");
  1055. }
  1056. //==============================================================================
  1057. void fillInProjectXml (XmlElement& projectXml) const
  1058. {
  1059. projectXml.setAttribute ("DefaultTargets", "Build");
  1060. projectXml.setAttribute ("ToolsVersion", getToolsVersion());
  1061. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  1062. {
  1063. XmlElement* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  1064. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  1065. for (ConstConfigIterator config (*this); config.next();)
  1066. {
  1067. XmlElement* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  1068. e->setAttribute ("Include", createConfigName (*config));
  1069. e->createNewChildElement ("Configuration")->addTextElement (config->getName());
  1070. e->createNewChildElement ("Platform")->addTextElement (is64Bit (*config) ? "x64" : "Win32");
  1071. }
  1072. }
  1073. {
  1074. XmlElement* globals = projectXml.createNewChildElement ("PropertyGroup");
  1075. globals->setAttribute ("Label", "Globals");
  1076. globals->createNewChildElement ("ProjectGuid")->addTextElement (projectGUID);
  1077. }
  1078. {
  1079. XmlElement* imports = projectXml.createNewChildElement ("Import");
  1080. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  1081. }
  1082. for (ConstConfigIterator i (*this); i.next();)
  1083. {
  1084. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  1085. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  1086. setConditionAttribute (*e, config);
  1087. e->setAttribute ("Label", "Configuration");
  1088. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  1089. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  1090. const String charSet (config.getCharacterSet());
  1091. if (charSet.isNotEmpty())
  1092. e->createNewChildElement ("CharacterSet")->addTextElement (charSet);
  1093. if (! (config.isDebug() || config.shouldDisableWholeProgramOpt()))
  1094. e->createNewChildElement ("WholeProgramOptimization")->addTextElement ("true");
  1095. if (config.is64Bit())
  1096. e->createNewChildElement ("PlatformToolset")->addTextElement (getPlatformToolset());
  1097. }
  1098. {
  1099. XmlElement* e = projectXml.createNewChildElement ("Import");
  1100. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  1101. }
  1102. {
  1103. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  1104. e->setAttribute ("Label", "ExtensionSettings");
  1105. }
  1106. {
  1107. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  1108. e->setAttribute ("Label", "PropertySheets");
  1109. XmlElement* p = e->createNewChildElement ("Import");
  1110. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  1111. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  1112. p->setAttribute ("Label", "LocalAppDataPlatform");
  1113. }
  1114. {
  1115. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  1116. e->setAttribute ("Label", "UserMacros");
  1117. }
  1118. {
  1119. XmlElement* props = projectXml.createNewChildElement ("PropertyGroup");
  1120. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  1121. for (ConstConfigIterator i (*this); i.next();)
  1122. {
  1123. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  1124. if (getConfigTargetPath (config).isNotEmpty())
  1125. {
  1126. XmlElement* outdir = props->createNewChildElement ("OutDir");
  1127. setConditionAttribute (*outdir, config);
  1128. outdir->addTextElement (FileHelpers::windowsStylePath (getConfigTargetPath (config)) + "\\");
  1129. }
  1130. if (config.getIntermediatesPath().isNotEmpty())
  1131. {
  1132. XmlElement* intdir = props->createNewChildElement ("IntDir");
  1133. setConditionAttribute (*intdir, config);
  1134. intdir->addTextElement (FileHelpers::windowsStylePath (config.getIntermediatesPath()) + "\\");
  1135. }
  1136. {
  1137. XmlElement* targetName = props->createNewChildElement ("TargetName");
  1138. setConditionAttribute (*targetName, config);
  1139. targetName->addTextElement (config.getOutputFilename (String::empty, true));
  1140. }
  1141. {
  1142. XmlElement* manifest = props->createNewChildElement ("GenerateManifest");
  1143. setConditionAttribute (*manifest, config);
  1144. manifest->addTextElement (config.shouldGenerateManifest() ? "true" : "false");
  1145. }
  1146. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  1147. if (librarySearchPaths.size() > 0)
  1148. {
  1149. XmlElement* libPath = props->createNewChildElement ("LibraryPath");
  1150. setConditionAttribute (*libPath, config);
  1151. libPath->addTextElement ("$(LibraryPath);" + librarySearchPaths.joinIntoString (";"));
  1152. }
  1153. }
  1154. }
  1155. for (ConstConfigIterator i (*this); i.next();)
  1156. {
  1157. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  1158. const bool isDebug = config.isDebug();
  1159. XmlElement* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  1160. setConditionAttribute (*group, config);
  1161. {
  1162. XmlElement* midl = group->createNewChildElement ("Midl");
  1163. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  1164. : "NDEBUG;%(PreprocessorDefinitions)");
  1165. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  1166. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1167. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  1168. midl->createNewChildElement ("HeaderFileName");
  1169. }
  1170. bool isUsingEditAndContinue = false;
  1171. {
  1172. XmlElement* cl = group->createNewChildElement ("ClCompile");
  1173. cl->createNewChildElement ("Optimization")->addTextElement (getOptimisationLevelString (config.getOptimisationLevelInt()));
  1174. if (isDebug && config.getOptimisationLevelInt() <= optimisationOff)
  1175. {
  1176. isUsingEditAndContinue = ! config.is64Bit();
  1177. cl->createNewChildElement ("DebugInformationFormat")
  1178. ->addTextElement (isUsingEditAndContinue ? "EditAndContinue"
  1179. : "ProgramDatabase");
  1180. }
  1181. StringArray includePaths (getHeaderSearchPaths (config));
  1182. includePaths.add ("%(AdditionalIncludeDirectories)");
  1183. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  1184. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  1185. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (config.isUsingRuntimeLibDLL() ? (isDebug ? "MultiThreadedDebugDLL" : "MultiThreadedDLL")
  1186. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  1187. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  1188. cl->createNewChildElement ("PrecompiledHeader");
  1189. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement ("$(IntDir)\\");
  1190. cl->createNewChildElement ("ObjectFileName")->addTextElement ("$(IntDir)\\");
  1191. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement ("$(IntDir)\\");
  1192. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level" + String (config.getWarningLevel()));
  1193. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1194. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  1195. if (config.isFastMathEnabled())
  1196. cl->createNewChildElement ("FloatingPointModel")->addTextElement ("Fast");
  1197. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  1198. if (extraFlags.isNotEmpty())
  1199. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  1200. if (config.areWarningsTreatedAsErrors())
  1201. cl->createNewChildElement ("TreatWarningAsError")->addTextElement ("true");
  1202. }
  1203. {
  1204. XmlElement* res = group->createNewChildElement ("ResourceCompile");
  1205. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  1206. : "NDEBUG;%(PreprocessorDefinitions)");
  1207. }
  1208. {
  1209. XmlElement* link = group->createNewChildElement ("Link");
  1210. link->createNewChildElement ("OutputFile")->addTextElement (getOutDirFile (config, config.getOutputFilename (msvcTargetSuffix, false)));
  1211. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1212. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  1213. : "%(IgnoreSpecificDefaultLibraries)");
  1214. link->createNewChildElement ("GenerateDebugInformation")->addTextElement ((isDebug || config.shouldGenerateDebugSymbols()) ? "true" : "false");
  1215. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (getIntDirFile (config, config.getOutputFilename (".pdb", true)));
  1216. link->createNewChildElement ("SubSystem")->addTextElement (msvcIsWindowsSubsystem ? "Windows" : "Console");
  1217. if (! config.is64Bit())
  1218. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  1219. if (isUsingEditAndContinue)
  1220. link->createNewChildElement ("ImageHasSafeExceptionHandlers")->addTextElement ("false");
  1221. if (! isDebug)
  1222. {
  1223. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  1224. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  1225. }
  1226. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  1227. if (librarySearchPaths.size() > 0)
  1228. link->createNewChildElement ("AdditionalLibraryDirectories")->addTextElement (replacePreprocessorTokens (config, librarySearchPaths.joinIntoString (";"))
  1229. + ";%(AdditionalLibraryDirectories)");
  1230. link->createNewChildElement ("LargeAddressAware")->addTextElement ("true");
  1231. String externalLibraries (getExternalLibrariesString());
  1232. if (externalLibraries.isNotEmpty())
  1233. link->createNewChildElement ("AdditionalDependencies")->addTextElement (replacePreprocessorTokens (config, externalLibraries).trim()
  1234. + ";%(AdditionalDependencies)");
  1235. String extraLinkerOptions (getExtraLinkerFlagsString());
  1236. if (extraLinkerOptions.isNotEmpty())
  1237. link->createNewChildElement ("AdditionalOptions")->addTextElement (replacePreprocessorTokens (config, extraLinkerOptions).trim()
  1238. + " %(AdditionalOptions)");
  1239. if (msvcDelayLoadedDLLs.isNotEmpty())
  1240. link->createNewChildElement ("DelayLoadDLLs")->addTextElement (msvcDelayLoadedDLLs);
  1241. if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
  1242. link->createNewChildElement ("ModuleDefinitionFile")
  1243. ->addTextElement (config.config [Ids::msvcModuleDefinitionFile].toString());
  1244. }
  1245. {
  1246. XmlElement* bsc = group->createNewChildElement ("Bscmake");
  1247. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1248. bsc->createNewChildElement ("OutputFile")->addTextElement (getIntDirFile (config, config.getOutputFilename (".bsc", true)));
  1249. }
  1250. if (config.getPrebuildCommandString().isNotEmpty())
  1251. group->createNewChildElement ("PreBuildEvent")
  1252. ->createNewChildElement ("Command")
  1253. ->addTextElement (config.getPrebuildCommandString());
  1254. if (config.getPostbuildCommandString().isNotEmpty())
  1255. group->createNewChildElement ("PostBuildEvent")
  1256. ->createNewChildElement ("Command")
  1257. ->addTextElement (config.getPostbuildCommandString());
  1258. }
  1259. ScopedPointer<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  1260. {
  1261. XmlElement* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  1262. XmlElement* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  1263. for (int i = 0; i < getAllGroups().size(); ++i)
  1264. {
  1265. const Project::Item& group = getAllGroups().getReference(i);
  1266. if (group.getNumChildren() > 0)
  1267. addFilesToCompile (group, *cppFiles, *headerFiles, *otherFilesGroup);
  1268. }
  1269. }
  1270. if (iconFile != File::nonexistent)
  1271. {
  1272. XmlElement* e = otherFilesGroup->createNewChildElement ("None");
  1273. e->setAttribute ("Include", prependDot (iconFile.getFileName()));
  1274. }
  1275. if (otherFilesGroup->getFirstChildElement() != nullptr)
  1276. projectXml.addChildElement (otherFilesGroup.release());
  1277. if (hasResourceFile())
  1278. {
  1279. XmlElement* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  1280. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1281. e->setAttribute ("Include", prependDot (rcFile.getFileName()));
  1282. }
  1283. {
  1284. XmlElement* e = projectXml.createNewChildElement ("Import");
  1285. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  1286. }
  1287. {
  1288. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  1289. e->setAttribute ("Label", "ExtensionTargets");
  1290. }
  1291. }
  1292. String getProjectType() const
  1293. {
  1294. if (projectType.isGUIApplication() || projectType.isCommandLineApp()) return "Application";
  1295. if (isLibraryDLL()) return "DynamicLibrary";
  1296. if (projectType.isStaticLibrary()) return "StaticLibrary";
  1297. jassertfalse;
  1298. return String::empty;
  1299. }
  1300. static const char* getOptimisationLevelString (int level)
  1301. {
  1302. switch (level)
  1303. {
  1304. case optimiseMaxSpeed: return "Full";
  1305. case optimiseMinSize: return "MinSpace";
  1306. default: return "Disabled";
  1307. }
  1308. }
  1309. //==============================================================================
  1310. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  1311. {
  1312. if (projectItem.isGroup())
  1313. {
  1314. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1315. addFilesToCompile (projectItem.getChild(i), cpps, headers, otherFiles);
  1316. }
  1317. else if (projectItem.shouldBeAddedToTargetProject())
  1318. {
  1319. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  1320. jassert (path.getRoot() == RelativePath::buildTargetFolder);
  1321. if (path.hasFileExtension (cOrCppFileExtensions))
  1322. {
  1323. XmlElement* e = cpps.createNewChildElement ("ClCompile");
  1324. e->setAttribute ("Include", path.toWindowsStyle());
  1325. if (! projectItem.shouldBeCompiled())
  1326. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  1327. if (projectItem.shouldUseStdCall())
  1328. e->createNewChildElement ("CallingConvention")->addTextElement ("StdCall");
  1329. }
  1330. else if (path.hasFileExtension (headerFileExtensions))
  1331. {
  1332. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", path.toWindowsStyle());
  1333. }
  1334. else if (! path.hasFileExtension (objCFileExtensions))
  1335. {
  1336. otherFiles.createNewChildElement ("None")->setAttribute ("Include", path.toWindowsStyle());
  1337. }
  1338. }
  1339. }
  1340. //==============================================================================
  1341. void addFilterGroup (XmlElement& groups, const String& path) const
  1342. {
  1343. XmlElement* e = groups.createNewChildElement ("Filter");
  1344. e->setAttribute ("Include", path);
  1345. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  1346. }
  1347. void addFileToFilter (const RelativePath& file, const String& groupPath,
  1348. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  1349. {
  1350. XmlElement* e;
  1351. if (file.hasFileExtension (headerFileExtensions))
  1352. e = headers.createNewChildElement ("ClInclude");
  1353. else if (file.hasFileExtension (sourceFileExtensions))
  1354. e = cpps.createNewChildElement ("ClCompile");
  1355. else
  1356. e = otherFiles.createNewChildElement ("None");
  1357. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1358. e->setAttribute ("Include", file.toWindowsStyle());
  1359. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  1360. }
  1361. void addFilesToFilter (const Project::Item& projectItem, const String& path,
  1362. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups) const
  1363. {
  1364. if (projectItem.isGroup())
  1365. {
  1366. addFilterGroup (groups, path);
  1367. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1368. addFilesToFilter (projectItem.getChild(i),
  1369. (path.isEmpty() ? String::empty : (path + "\\")) + projectItem.getChild(i).getName(),
  1370. cpps, headers, otherFiles, groups);
  1371. }
  1372. else if (projectItem.shouldBeAddedToTargetProject())
  1373. {
  1374. addFileToFilter (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder),
  1375. path.upToLastOccurrenceOf ("\\", false, false), cpps, headers, otherFiles);
  1376. }
  1377. }
  1378. void addFilesToFilter (const Array<RelativePath>& files, const String& path,
  1379. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups)
  1380. {
  1381. if (files.size() > 0)
  1382. {
  1383. addFilterGroup (groups, path);
  1384. for (int i = 0; i < files.size(); ++i)
  1385. addFileToFilter (files.getReference(i), path, cpps, headers, otherFiles);
  1386. }
  1387. }
  1388. void fillInFiltersXml (XmlElement& filterXml) const
  1389. {
  1390. filterXml.setAttribute ("ToolsVersion", getToolsVersion());
  1391. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  1392. XmlElement* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  1393. XmlElement* cpps = filterXml.createNewChildElement ("ItemGroup");
  1394. XmlElement* headers = filterXml.createNewChildElement ("ItemGroup");
  1395. ScopedPointer<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  1396. for (int i = 0; i < getAllGroups().size(); ++i)
  1397. {
  1398. const Project::Item& group = getAllGroups().getReference(i);
  1399. if (group.getNumChildren() > 0)
  1400. addFilesToFilter (group, group.getName(), *cpps, *headers, *otherFilesGroup, *groupsXml);
  1401. }
  1402. if (iconFile.exists())
  1403. {
  1404. XmlElement* e = otherFilesGroup->createNewChildElement ("None");
  1405. e->setAttribute ("Include", prependDot (iconFile.getFileName()));
  1406. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1407. }
  1408. if (otherFilesGroup->getFirstChildElement() != nullptr)
  1409. filterXml.addChildElement (otherFilesGroup.release());
  1410. if (hasResourceFile())
  1411. {
  1412. XmlElement* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  1413. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1414. e->setAttribute ("Include", prependDot (rcFile.getFileName()));
  1415. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1416. }
  1417. }
  1418. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2010)
  1419. };
  1420. //==============================================================================
  1421. class MSVCProjectExporterVC2012 : public MSVCProjectExporterVC2010
  1422. {
  1423. public:
  1424. MSVCProjectExporterVC2012 (Project& p, const ValueTree& t,
  1425. const char* folderName = "VisualStudio2012")
  1426. : MSVCProjectExporterVC2010 (p, t, folderName)
  1427. {
  1428. name = getName();
  1429. }
  1430. static const char* getName() { return "Visual Studio 2012"; }
  1431. static const char* getValueTreeTypeName() { return "VS2012"; }
  1432. int getVisualStudioVersion() const override { return 11; }
  1433. String getSolutionComment() const override { return "# Visual Studio 2012"; }
  1434. String getDefaultToolset() const override { return "v110"; }
  1435. static MSVCProjectExporterVC2012* createForSettings (Project& project, const ValueTree& settings)
  1436. {
  1437. if (settings.hasType (getValueTreeTypeName()))
  1438. return new MSVCProjectExporterVC2012 (project, settings);
  1439. return nullptr;
  1440. }
  1441. void createExporterProperties (PropertyListBuilder& props) override
  1442. {
  1443. MSVCProjectExporterBase::createExporterProperties (props);
  1444. static const char* toolsetNames[] = { "(default)", "v110", "v110_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1445. const var toolsets[] = { var(), "v110", "v110_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1446. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1447. addIPPLibraryProperty (props);
  1448. }
  1449. private:
  1450. void addPlatformToolsetToPropertyGroup (XmlElement& p) const override
  1451. {
  1452. forEachXmlChildElementWithTagName (p, e, "PropertyGroup")
  1453. e->createNewChildElement ("PlatformToolset")->addTextElement (getPlatformToolset());
  1454. }
  1455. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2012)
  1456. };
  1457. //==============================================================================
  1458. class MSVCProjectExporterVC2013 : public MSVCProjectExporterVC2012
  1459. {
  1460. public:
  1461. MSVCProjectExporterVC2013 (Project& p, const ValueTree& t)
  1462. : MSVCProjectExporterVC2012 (p, t, "VisualStudio2013")
  1463. {
  1464. name = getName();
  1465. }
  1466. static const char* getName() { return "Visual Studio 2013"; }
  1467. static const char* getValueTreeTypeName() { return "VS2013"; }
  1468. int getVisualStudioVersion() const override { return 12; }
  1469. String getSolutionComment() const override { return "# Visual Studio 2013"; }
  1470. String getToolsVersion() const override { return "12.0"; }
  1471. String getDefaultToolset() const override { return "v120"; }
  1472. static MSVCProjectExporterVC2013* createForSettings (Project& project, const ValueTree& settings)
  1473. {
  1474. if (settings.hasType (getValueTreeTypeName()))
  1475. return new MSVCProjectExporterVC2013 (project, settings);
  1476. return nullptr;
  1477. }
  1478. void createExporterProperties (PropertyListBuilder& props) override
  1479. {
  1480. MSVCProjectExporterBase::createExporterProperties (props);
  1481. static const char* toolsetNames[] = { "(default)", "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1482. const var toolsets[] = { var(), "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1483. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1484. addIPPLibraryProperty (props);
  1485. }
  1486. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2013)
  1487. };
  1488. //==============================================================================
  1489. class MSVCProjectExporterVC2015 : public MSVCProjectExporterVC2012
  1490. {
  1491. public:
  1492. MSVCProjectExporterVC2015 (Project& p, const ValueTree& t)
  1493. : MSVCProjectExporterVC2012 (p, t, "VisualStudio2015")
  1494. {
  1495. name = getName();
  1496. }
  1497. static const char* getName() { return "Visual Studio 2015"; }
  1498. static const char* getValueTreeTypeName() { return "VS2015"; }
  1499. int getVisualStudioVersion() const override { return 14; }
  1500. String getSolutionComment() const override { return "# Visual Studio 2015"; }
  1501. String getToolsVersion() const override { return "14.0"; }
  1502. String getDefaultToolset() const override { return "v140"; }
  1503. static MSVCProjectExporterVC2015* createForSettings (Project& project, const ValueTree& settings)
  1504. {
  1505. if (settings.hasType (getValueTreeTypeName()))
  1506. return new MSVCProjectExporterVC2015 (project, settings);
  1507. return nullptr;
  1508. }
  1509. void createExporterProperties (PropertyListBuilder& props) override
  1510. {
  1511. MSVCProjectExporterBase::createExporterProperties (props);
  1512. static const char* toolsetNames[] = { "(default)", "v140", "v140_xp", "CTP_Nov2013" };
  1513. const var toolsets[] = { var(), "v140", "v140_xp", "CTP_Nov2013" };
  1514. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1515. addIPPLibraryProperty (props);
  1516. }
  1517. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2015)
  1518. };