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.

1965 lines
88KB

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