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.

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