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.

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