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.

1936 lines
87KB

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