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.

1921 lines
86KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. class MSVCProjectExporterBase : public ProjectExporter
  20. {
  21. public:
  22. MSVCProjectExporterBase (Project& p, const ValueTree& t, const char* const folderName)
  23. : ProjectExporter (p, t)
  24. {
  25. if (getTargetLocationString().isEmpty())
  26. getTargetLocationValue() = getDefaultBuildsRootFolder() + folderName;
  27. updateOldSettings();
  28. initialiseDependencyPathValues();
  29. }
  30. //==============================================================================
  31. class MSVCBuildConfiguration : public BuildConfiguration
  32. {
  33. public:
  34. MSVCBuildConfiguration (Project& p, const ValueTree& settings, const ProjectExporter& e)
  35. : BuildConfiguration (p, settings, e)
  36. {
  37. if (getWarningLevel() == 0)
  38. getWarningLevelValue() = 4;
  39. setValueIfVoid (shouldGenerateManifestValue(), true);
  40. }
  41. Value getWarningLevelValue() { return getValue (Ids::winWarningLevel); }
  42. int getWarningLevel() const { return config [Ids::winWarningLevel]; }
  43. Value getWarningsTreatedAsErrors() { return getValue (Ids::warningsAreErrors); }
  44. bool areWarningsTreatedAsErrors() const { return config [Ids::warningsAreErrors]; }
  45. Value getPrebuildCommand() { return getValue (Ids::prebuildCommand); }
  46. String getPrebuildCommandString() const { return config [Ids::prebuildCommand]; }
  47. Value getPostbuildCommand() { return getValue (Ids::postbuildCommand); }
  48. String getPostbuildCommandString() const { return config [Ids::postbuildCommand]; }
  49. Value shouldGenerateDebugSymbolsValue() { return getValue (Ids::alwaysGenerateDebugSymbols); }
  50. bool shouldGenerateDebugSymbols() const { return config [Ids::alwaysGenerateDebugSymbols]; }
  51. Value shouldGenerateManifestValue() { return getValue (Ids::generateManifest); }
  52. bool shouldGenerateManifest() const { return config [Ids::generateManifest]; }
  53. Value shouldLinkIncrementalValue() { return getValue (Ids::enableIncrementalLinking); }
  54. bool shouldLinkIncremental() const { return config [Ids::enableIncrementalLinking]; }
  55. Value getWholeProgramOptValue() { return getValue (Ids::wholeProgramOptimisation); }
  56. bool shouldDisableWholeProgramOpt() const { return static_cast<int> (config [Ids::wholeProgramOptimisation]) > 0; }
  57. Value getUsingRuntimeLibDLL() { return getValue (Ids::useRuntimeLibDLL); }
  58. bool isUsingRuntimeLibDLL() const { return config [Ids::useRuntimeLibDLL]; }
  59. String getIntermediatesPath() const { return config [Ids::intermediatesPath].toString(); }
  60. Value getIntermediatesPathValue() { return getValue (Ids::intermediatesPath); }
  61. String getCharacterSet() const { return config [Ids::characterSet].toString(); }
  62. Value getCharacterSetValue() { return getValue (Ids::characterSet); }
  63. String createMSVCConfigName() const
  64. {
  65. return getName() + "|" + (config [Ids::winArchitecture] == "x64" ? "x64" : "Win32");
  66. }
  67. String getOutputFilename (const String& suffix, bool forceSuffix) const
  68. {
  69. const String target (File::createLegalFileName (getTargetBinaryNameString().trim()));
  70. if (forceSuffix || ! target.containsChar ('.'))
  71. return target.upToLastOccurrenceOf (".", false, false) + suffix;
  72. return target;
  73. }
  74. var getDefaultOptimisationLevel() const override { return var ((int) (isDebug() ? optimisationOff : optimiseMaxSpeed)); }
  75. void createConfigProperties (PropertyListBuilder& props) override
  76. {
  77. static const char* optimisationLevels[] = { "No optimisation", "Minimise size", "Maximise speed", 0 };
  78. const int optimisationLevelValues[] = { optimisationOff, optimiseMinSize, optimiseMaxSpeed, 0 };
  79. props.add (new ChoicePropertyComponent (getOptimisationLevel(), "Optimisation",
  80. StringArray (optimisationLevels),
  81. Array<var> (optimisationLevelValues)),
  82. "The optimisation level for this configuration");
  83. props.add (new TextPropertyComponent (getIntermediatesPathValue(), "Intermediates path", 2048, false),
  84. "An optional path to a folder to use for the intermediate build files. Note that Visual Studio allows "
  85. "you to use macros in this path, e.g. \"$(TEMP)\\MyAppBuildFiles\\$(Configuration)\", which is a handy way to "
  86. "send them to the user's temp folder.");
  87. static const char* warningLevelNames[] = { "Low", "Medium", "High", nullptr };
  88. const int warningLevels[] = { 2, 3, 4 };
  89. props.add (new ChoicePropertyComponent (getWarningLevelValue(), "Warning Level",
  90. StringArray (warningLevelNames), Array<var> (warningLevels, numElementsInArray (warningLevels))));
  91. props.add (new BooleanPropertyComponent (getWarningsTreatedAsErrors(), "Warnings", "Treat warnings as errors"));
  92. {
  93. static const char* runtimeNames[] = { "(Default)", "Use static runtime", "Use DLL runtime", nullptr };
  94. const var runtimeValues[] = { var(), var (false), var (true) };
  95. props.add (new ChoicePropertyComponent (getUsingRuntimeLibDLL(), "Runtime Library",
  96. StringArray (runtimeNames), Array<var> (runtimeValues, numElementsInArray (runtimeValues))),
  97. "If the static runtime is selected then your app/plug-in will not be dependent upon users having Microsoft's redistributable "
  98. "C++ runtime installed. However, if you are linking libraries from different sources you must select the same type of runtime "
  99. "used by the libraries.");
  100. }
  101. {
  102. static const char* wpoNames[] = { "Enable link-time code generation when possible",
  103. "Always disable link-time code generation", nullptr };
  104. const var wpoValues[] = { var(), var (1) };
  105. props.add (new ChoicePropertyComponent (getWholeProgramOptValue(), "Whole Program Optimisation",
  106. StringArray (wpoNames), Array<var> (wpoValues, numElementsInArray (wpoValues))));
  107. }
  108. {
  109. props.add (new BooleanPropertyComponent (shouldLinkIncrementalValue(), "Incremental Linking", "Enable"),
  110. "Enable to avoid linking from scratch for every new build. "
  111. "Disable to ensure that your final release build does not contain padding or thunks.");
  112. }
  113. if (! isDebug())
  114. props.add (new BooleanPropertyComponent (shouldGenerateDebugSymbolsValue(), "Debug Symbols", "Force generation of debug symbols"));
  115. props.add (new TextPropertyComponent (getPrebuildCommand(), "Pre-build Command", 2048, true));
  116. props.add (new TextPropertyComponent (getPostbuildCommand(), "Post-build Command", 2048, true));
  117. props.add (new BooleanPropertyComponent (shouldGenerateManifestValue(), "Manifest", "Generate Manifest"));
  118. {
  119. static const char* characterSetNames[] = { "Default", "MultiByte", "Unicode", nullptr };
  120. const var charSets[] = { var(), "MultiByte", "Unicode", };
  121. props.add (new ChoicePropertyComponent (getCharacterSetValue(), "Character Set",
  122. StringArray (characterSetNames), Array<var> (charSets, numElementsInArray (charSets))));
  123. }
  124. }
  125. String getLibrarySubdirPath() const override
  126. {
  127. String result ("$(Platform)\\");
  128. result += isUsingRuntimeLibDLL() ? "MD" : "MT";
  129. if (isDebug())
  130. result += "d";
  131. return result;
  132. }
  133. };
  134. //==============================================================================
  135. class MSVCTargetBase : public ProjectType::Target
  136. {
  137. public:
  138. MSVCTargetBase (ProjectType::Target::Type targetType, const MSVCProjectExporterBase& exporter)
  139. : ProjectType::Target (targetType), owner (exporter)
  140. {
  141. projectGuid = createGUID (owner.getProject().getProjectUID() + getName());
  142. }
  143. virtual ~MSVCTargetBase() {}
  144. const MSVCProjectExporterBase& getOwner() const { return owner; }
  145. virtual String getTopLevelXmlEntity() const = 0;
  146. const String& getProjectGuid() const { return projectGuid; }
  147. //==============================================================================
  148. void writeProjectFile()
  149. {
  150. XmlElement projectXml (getTopLevelXmlEntity());
  151. fillInProjectXml (projectXml);
  152. writeXmlOrThrow (projectXml, getVCProjFile(), "UTF-8", 10);
  153. }
  154. virtual void fillInProjectXml (XmlElement& projectXml) const = 0;
  155. String getSolutionTargetPath (const BuildConfiguration& config) const
  156. {
  157. const String binaryPath (config.getTargetBinaryRelativePathString().trim());
  158. if (binaryPath.isEmpty())
  159. return "$(SolutionDir)\\$(Platform)\\$(Configuration)";
  160. RelativePath binaryRelPath (binaryPath, RelativePath::projectFolder);
  161. if (binaryRelPath.isAbsolute())
  162. return binaryRelPath.toWindowsStyle();
  163. return prependDot (binaryRelPath.rebased (getOwner().projectFolder, getOwner().getTargetFolder(), RelativePath::buildTargetFolder)
  164. .toWindowsStyle());
  165. }
  166. String getConfigTargetPath (const BuildConfiguration& config) const
  167. {
  168. String solutionTargetFolder (getSolutionTargetPath (config));
  169. return solutionTargetFolder + String ("\\") + getName();
  170. }
  171. String getIntermediatesPath (const MSVCBuildConfiguration& config) const
  172. {
  173. String intDir = (config.getIntermediatesPath().isNotEmpty() ? config.getIntermediatesPath() : "$(Platform)\\$(Configuration)");
  174. if (! intDir.endsWithChar (L'\\'))
  175. intDir += L'\\';
  176. return intDir + getName();
  177. }
  178. static const char* getOptimisationLevelString (int level)
  179. {
  180. switch (level)
  181. {
  182. case optimiseMaxSpeed: return "Full";
  183. case optimiseMinSize: return "MinSpace";
  184. default: return "Disabled";
  185. }
  186. }
  187. String getTargetSuffix() const
  188. {
  189. const ProjectType::Target::TargetFileType fileType = getTargetFileType();
  190. switch (fileType)
  191. {
  192. case executable: return ".exe";
  193. case staticLibrary: return ".lib";
  194. case sharedLibraryOrDLL: return ".dll";
  195. case pluginBundle:
  196. switch (type)
  197. {
  198. case VST3PlugIn: return ".vst3";
  199. case AAXPlugIn: return ".aaxdll";
  200. case RTASPlugIn: return ".dpm";
  201. default: break;
  202. }
  203. return ".dll";
  204. default:
  205. break;
  206. }
  207. return {};
  208. }
  209. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  210. {
  211. XmlElement* const e = parent.createNewChildElement ("Tool");
  212. e->setAttribute ("Name", toolName);
  213. return e;
  214. }
  215. String getPreprocessorDefs (const BuildConfiguration& config, const String& joinString) const
  216. {
  217. StringPairArray defines (getOwner().msvcExtraPreprocessorDefs);
  218. defines.set ("WIN32", "");
  219. defines.set ("_WINDOWS", "");
  220. if (config.isDebug())
  221. {
  222. defines.set ("DEBUG", "");
  223. defines.set ("_DEBUG", "");
  224. }
  225. else
  226. {
  227. defines.set ("NDEBUG", "");
  228. }
  229. defines = mergePreprocessorDefs (defines, getOwner().getAllPreprocessorDefs (config, type));
  230. addExtraPreprocessorDefines (defines);
  231. if (getTargetFileType() == staticLibrary || getTargetFileType() == sharedLibraryOrDLL)
  232. defines.set("_LIB", "");
  233. StringArray result;
  234. for (int i = 0; i < defines.size(); ++i)
  235. {
  236. String def (defines.getAllKeys()[i]);
  237. const String value (defines.getAllValues()[i]);
  238. if (value.isNotEmpty())
  239. def << "=" << value;
  240. result.add (def);
  241. }
  242. return result.joinIntoString (joinString);
  243. }
  244. //==============================================================================
  245. RelativePath getAAXIconFile() const
  246. {
  247. const RelativePath aaxSDK (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder);
  248. const RelativePath projectIcon ("icon.ico", RelativePath::buildTargetFolder);
  249. if (getOwner().getTargetFolder().getChildFile ("icon.ico").existsAsFile())
  250. return projectIcon.rebased (getOwner().getTargetFolder(),
  251. getOwner().getProject().getProjectFolder(),
  252. RelativePath::projectFolder);
  253. else
  254. return aaxSDK.getChildFile ("Utilities").getChildFile ("PlugIn.ico");
  255. }
  256. String getExtraPostBuildSteps (const MSVCBuildConfiguration& config) const
  257. {
  258. if (type == AAXPlugIn)
  259. {
  260. const RelativePath aaxSDK (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder);
  261. const RelativePath aaxLibsFolder = aaxSDK.getChildFile ("Libs");
  262. const RelativePath bundleScript = aaxSDK.getChildFile ("Utilities").getChildFile ("CreatePackage.bat");
  263. const RelativePath iconFilePath = getAAXIconFile();
  264. const bool is64Bit = (config.config [Ids::winArchitecture] == "x64");
  265. const String bundleDir = getOwner().getOutDirFile (config, config.getOutputFilename (".aaxplugin", true));
  266. const String bundleContents = bundleDir + "\\Contents";
  267. const String macOSDir = bundleContents + String ("\\") + (is64Bit ? "x64" : "Win32");
  268. const String executable = macOSDir + String ("\\") + config.getOutputFilename (".aaxplugin", true);
  269. return String ("copy /Y \"") + getOutputFilePath (config) + String ("\" \"") + executable + String ("\"\r\ncall ") +
  270. createRebasedPath (bundleScript) + String (" \"") + macOSDir + String ("\" ") + createRebasedPath (iconFilePath);
  271. }
  272. return {};
  273. }
  274. String getExtraPreBuildSteps (const MSVCBuildConfiguration& config) const
  275. {
  276. if (type == AAXPlugIn)
  277. {
  278. String script;
  279. const bool is64Bit = (config.config [Ids::winArchitecture] == "x64");
  280. const String bundleDir = getOwner().getOutDirFile (config, config.getOutputFilename (".aaxplugin", false));
  281. const String bundleContents = bundleDir + "\\Contents";
  282. const String macOSDir = bundleContents + String ("\\") + (is64Bit ? "x64" : "Win32");
  283. StringArray folders = {bundleDir.toRawUTF8(), bundleContents.toRawUTF8(), macOSDir.toRawUTF8()};
  284. for (int i = 0; i < folders.size(); ++i)
  285. script += String ("if not exist \"") + folders[i] + String ("\" mkdir \"") + folders[i] + String ("\"\r\n");
  286. return script;
  287. }
  288. return {};
  289. }
  290. String getPostBuildSteps (const MSVCBuildConfiguration& config) const
  291. {
  292. String postBuild = config.getPostbuildCommandString();
  293. const String extraPostBuild = getExtraPostBuildSteps (config);
  294. postBuild += String (postBuild.isNotEmpty() && extraPostBuild.isNotEmpty() ? "\r\n" : "") + extraPostBuild;
  295. return postBuild;
  296. }
  297. String getPreBuildSteps (const MSVCBuildConfiguration& config) const
  298. {
  299. String preBuild = config.getPrebuildCommandString();
  300. const String extraPreBuild = getExtraPreBuildSteps (config);
  301. preBuild += String (preBuild.isNotEmpty() && extraPreBuild.isNotEmpty() ? "\r\n" : "") + extraPreBuild;
  302. return preBuild;
  303. }
  304. void addExtraPreprocessorDefines (StringPairArray& defines) const
  305. {
  306. switch (type)
  307. {
  308. case AAXPlugIn:
  309. {
  310. const RelativePath aaxLibsFolder = RelativePath (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder).getChildFile ("Libs");
  311. defines.set ("JucePlugin_AAXLibs_path", createRebasedPath (aaxLibsFolder));
  312. }
  313. break;
  314. case RTASPlugIn:
  315. {
  316. const RelativePath rtasFolder (getOwner().getRTASPathValue().toString(), RelativePath::projectFolder);
  317. defines.set ("JucePlugin_WinBag_path", createRebasedPath (rtasFolder.getChildFile ("WinBag")));
  318. }
  319. break;
  320. default:
  321. break;
  322. }
  323. }
  324. String getExtraLinkerFlags() const
  325. {
  326. if (type == RTASPlugIn)
  327. return "/FORCE:multiple";
  328. return {};
  329. }
  330. StringArray getExtraSearchPaths() const
  331. {
  332. StringArray searchPaths;
  333. if (type == RTASPlugIn)
  334. {
  335. const RelativePath rtasFolder (getOwner().getRTASPathValue().toString(), RelativePath::projectFolder);
  336. static const char* p[] = { "AlturaPorts/TDMPlugins/PluginLibrary/EffectClasses",
  337. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses",
  338. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses/Interfaces",
  339. "AlturaPorts/TDMPlugins/PluginLibrary/Utilities",
  340. "AlturaPorts/TDMPlugins/PluginLibrary/RTASP_Adapt",
  341. "AlturaPorts/TDMPlugins/PluginLibrary/CoreClasses",
  342. "AlturaPorts/TDMPlugins/PluginLibrary/Controls",
  343. "AlturaPorts/TDMPlugins/PluginLibrary/Meters",
  344. "AlturaPorts/TDMPlugins/PluginLibrary/ViewClasses",
  345. "AlturaPorts/TDMPlugins/PluginLibrary/DSPClasses",
  346. "AlturaPorts/TDMPlugins/PluginLibrary/Interfaces",
  347. "AlturaPorts/TDMPlugins/common",
  348. "AlturaPorts/TDMPlugins/common/Platform",
  349. "AlturaPorts/TDMPlugins/common/Macros",
  350. "AlturaPorts/TDMPlugins/SignalProcessing/Public",
  351. "AlturaPorts/TDMPlugIns/DSPManager/Interfaces",
  352. "AlturaPorts/SADriver/Interfaces",
  353. "AlturaPorts/DigiPublic/Interfaces",
  354. "AlturaPorts/DigiPublic",
  355. "AlturaPorts/Fic/Interfaces/DAEClient",
  356. "AlturaPorts/NewFileLibs/Cmn",
  357. "AlturaPorts/NewFileLibs/DOA",
  358. "AlturaPorts/AlturaSource/PPC_H",
  359. "AlturaPorts/AlturaSource/AppSupport",
  360. "AvidCode/AVX2sdk/AVX/avx2/avx2sdk/inc",
  361. "xplat/AVX/avx2/avx2sdk/inc" };
  362. for (int i = 0; i < numElementsInArray (p); ++i)
  363. searchPaths.add (createRebasedPath (rtasFolder.getChildFile (p[i])));
  364. }
  365. return searchPaths;
  366. }
  367. String getBinaryNameWithSuffix (const MSVCBuildConfiguration& config) const
  368. {
  369. return config.getOutputFilename (getTargetSuffix(), true);
  370. }
  371. String getOutputFilePath (const MSVCBuildConfiguration& config) const
  372. {
  373. return getOwner().getOutDirFile (config, getBinaryNameWithSuffix (config));
  374. }
  375. StringArray getLibrarySearchPaths (const BuildConfiguration& config) const
  376. {
  377. StringArray librarySearchPaths (config.getLibrarySearchPaths());
  378. if (type != SharedCodeTarget)
  379. if (const MSVCTargetBase* shared = getOwner().getSharedCodeTarget())
  380. librarySearchPaths.add (shared->getConfigTargetPath (config));
  381. return librarySearchPaths;
  382. }
  383. String getExternalLibraries (const MSVCBuildConfiguration& config, const String& otherLibs) const
  384. {
  385. StringArray libraries;
  386. if (otherLibs.isNotEmpty())
  387. libraries.add (otherLibs);
  388. StringArray moduleLibs = getOwner().getModuleLibs();
  389. if (! moduleLibs.isEmpty())
  390. libraries.addArray (moduleLibs);
  391. if (type != SharedCodeTarget)
  392. if (const MSVCTargetBase* shared = getOwner().getSharedCodeTarget())
  393. libraries.add (shared->getBinaryNameWithSuffix (config));
  394. return libraries.joinIntoString (";");
  395. }
  396. String getDelayLoadedDLLs() const
  397. {
  398. String delayLoadedDLLs = getOwner().msvcDelayLoadedDLLs;
  399. if (type == RTASPlugIn)
  400. delayLoadedDLLs += "DAE.dll; DigiExt.dll; DSI.dll; PluginLib.dll; "
  401. "DSPManager.dll; DSPManager.dll; DSPManagerClientLib.dll; RTASClientLib.dll";
  402. return delayLoadedDLLs;
  403. }
  404. String getModuleDefinitions (const MSVCBuildConfiguration& config) const
  405. {
  406. const String& moduleDefinitions = config.config [Ids::msvcModuleDefinitionFile].toString();
  407. if (moduleDefinitions.isNotEmpty())
  408. return moduleDefinitions;
  409. if (type == RTASPlugIn)
  410. {
  411. const ProjectExporter& exp = getOwner();
  412. RelativePath moduleDefPath
  413. = RelativePath (exp.getPathForModuleString ("juce_audio_plugin_client"), RelativePath::projectFolder)
  414. .getChildFile ("juce_audio_plugin_client").getChildFile ("RTAS").getChildFile ("juce_RTAS_WinExports.def");
  415. return prependDot (moduleDefPath.rebased (exp.getProject().getProjectFolder(),
  416. exp.getTargetFolder(),
  417. RelativePath::buildTargetFolder).toWindowsStyle());
  418. }
  419. return {};
  420. }
  421. bool shouldUseRuntimeDLL (const MSVCBuildConfiguration& config) const
  422. {
  423. return (config.config [Ids::useRuntimeLibDLL].isVoid() ? (getOwner().hasTarget (AAXPlugIn) || getOwner().hasTarget (RTASPlugIn))
  424. : config.isUsingRuntimeLibDLL());
  425. }
  426. virtual String getProjectFileSuffix() const = 0;
  427. File getVCProjFile() const { return getOwner().getProjectFile (getProjectFileSuffix(), getName()); }
  428. String createRebasedPath (const RelativePath& path) const { return getOwner().createRebasedPath (path); }
  429. //==============================================================================
  430. virtual String getProjectVersionString() const = 0;
  431. protected:
  432. const MSVCProjectExporterBase& owner;
  433. String projectGuid;
  434. };
  435. //==============================================================================
  436. bool usesMMFiles() const override { return false; }
  437. bool canCopeWithDuplicateFiles() override { return false; }
  438. bool supportsUserDefinedConfigurations() const override { return true; }
  439. bool isXcode() const override { return false; }
  440. bool isVisualStudio() const override { return true; }
  441. bool isCodeBlocks() const override { return false; }
  442. bool isMakefile() const override { return false; }
  443. bool isAndroidStudio() const override { return false; }
  444. bool isAndroid() const override { return false; }
  445. bool isWindows() const override { return true; }
  446. bool isLinux() const override { return false; }
  447. bool isOSX() const override { return false; }
  448. bool isiOS() const override { return false; }
  449. bool supportsTargetType (ProjectType::Target::Type type) const override
  450. {
  451. switch (type)
  452. {
  453. case ProjectType::Target::StandalonePlugIn:
  454. case ProjectType::Target::GUIApp:
  455. case ProjectType::Target::ConsoleApp:
  456. case ProjectType::Target::StaticLibrary:
  457. case ProjectType::Target::SharedCodeTarget:
  458. case ProjectType::Target::AggregateTarget:
  459. case ProjectType::Target::VSTPlugIn:
  460. case ProjectType::Target::VST3PlugIn:
  461. case ProjectType::Target::AAXPlugIn:
  462. case ProjectType::Target::RTASPlugIn:
  463. case ProjectType::Target::DynamicLibrary:
  464. return true;
  465. default:
  466. break;
  467. }
  468. return false;
  469. }
  470. //==============================================================================
  471. Value getManifestFile() { return getSetting (Ids::msvcManifestFile); }
  472. RelativePath getManifestPath() const
  473. {
  474. const String& path = settings [Ids::msvcManifestFile].toString();
  475. return path.isEmpty() ? RelativePath() : RelativePath (settings [Ids::msvcManifestFile], RelativePath::projectFolder);
  476. }
  477. //==============================================================================
  478. const String& getProjectName() const { return projectName; }
  479. virtual int getVisualStudioVersion() const = 0;
  480. bool launchProject() override
  481. {
  482. #if JUCE_WINDOWS
  483. return getSLNFile().startAsProcess();
  484. #else
  485. return false;
  486. #endif
  487. }
  488. bool canLaunchProject() override
  489. {
  490. #if JUCE_WINDOWS
  491. return true;
  492. #else
  493. return false;
  494. #endif
  495. }
  496. void createExporterProperties (PropertyListBuilder& props) override
  497. {
  498. props.add(new TextPropertyComponent(getManifestFile(), "Manifest file", 8192, false),
  499. "Path to a manifest input file which should be linked into your binary (path is relative to jucer file).");
  500. }
  501. enum OptimisationLevel
  502. {
  503. optimisationOff = 1,
  504. optimiseMinSize = 2,
  505. optimiseMaxSpeed = 3
  506. };
  507. //==============================================================================
  508. void addPlatformSpecificSettingsForProjectType (const ProjectType& type) override
  509. {
  510. msvcExtraPreprocessorDefs.set ("_CRT_SECURE_NO_WARNINGS", "");
  511. if (type.isCommandLineApp())
  512. msvcExtraPreprocessorDefs.set("_CONSOLE", "");
  513. }
  514. const MSVCTargetBase* getSharedCodeTarget() const
  515. {
  516. for (auto target : targets)
  517. if (target->type == ProjectType::Target::SharedCodeTarget)
  518. return target;
  519. return nullptr;
  520. }
  521. bool hasTarget (ProjectType::Target::Type type) const
  522. {
  523. for (auto target : targets)
  524. if (target->type == type)
  525. return true;
  526. return false;
  527. }
  528. private:
  529. //==============================================================================
  530. String createRebasedPath (const RelativePath& path) const
  531. {
  532. String rebasedPath = rebaseFromProjectFolderToBuildTarget (path).toWindowsStyle();
  533. return getVisualStudioVersion() < 10 // (VS10 automatically adds escape characters to the quotes for this definition)
  534. ? CppTokeniserFunctions::addEscapeChars (rebasedPath.quoted())
  535. : CppTokeniserFunctions::addEscapeChars (rebasedPath).quoted();
  536. }
  537. protected:
  538. //==============================================================================
  539. mutable File rcFile, iconFile;
  540. OwnedArray<MSVCTargetBase> targets;
  541. File getProjectFile (const String& extension, const String& target) const
  542. {
  543. String filename = project.getProjectFilenameRoot();
  544. if (target.isNotEmpty())
  545. filename += String ("_") + target.removeCharacters (" ");
  546. return getTargetFolder().getChildFile (filename).withFileExtension (extension);
  547. }
  548. File getSLNFile() const { return getProjectFile (".sln", String()); }
  549. static String prependIfNotAbsolute (const String& file, const char* prefix)
  550. {
  551. if (File::isAbsolutePath (file) || file.startsWithChar ('$'))
  552. prefix = "";
  553. return prefix + FileHelpers::windowsStylePath (file);
  554. }
  555. String getIntDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(IntDir)\\"); }
  556. String getOutDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(OutDir)\\"); }
  557. void updateOldSettings()
  558. {
  559. {
  560. const String oldStylePrebuildCommand (getSettingString (Ids::prebuildCommand));
  561. settings.removeProperty (Ids::prebuildCommand, nullptr);
  562. if (oldStylePrebuildCommand.isNotEmpty())
  563. for (ConfigIterator config (*this); config.next();)
  564. dynamic_cast<MSVCBuildConfiguration&> (*config).getPrebuildCommand() = oldStylePrebuildCommand;
  565. }
  566. {
  567. const String oldStyleLibName (getSettingString ("libraryName_Debug"));
  568. settings.removeProperty ("libraryName_Debug", nullptr);
  569. if (oldStyleLibName.isNotEmpty())
  570. for (ConfigIterator config (*this); config.next();)
  571. if (config->isDebug())
  572. config->getTargetBinaryName() = oldStyleLibName;
  573. }
  574. {
  575. const String oldStyleLibName (getSettingString ("libraryName_Release"));
  576. settings.removeProperty ("libraryName_Release", nullptr);
  577. if (oldStyleLibName.isNotEmpty())
  578. for (ConfigIterator config (*this); config.next();)
  579. if (! config->isDebug())
  580. config->getTargetBinaryName() = oldStyleLibName;
  581. }
  582. }
  583. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override
  584. {
  585. return new MSVCBuildConfiguration (project, v, *this);
  586. }
  587. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  588. {
  589. StringArray searchPaths (extraSearchPaths);
  590. searchPaths.addArray (config.getHeaderSearchPaths());
  591. return getCleanedStringArray (searchPaths);
  592. }
  593. String getSharedCodeGuid() const
  594. {
  595. String sharedCodeGuid;
  596. for (int i = 0; i < targets.size(); ++i)
  597. if (MSVCTargetBase* target = targets[i])
  598. if (target->type == ProjectType::Target::SharedCodeTarget)
  599. return target->getProjectGuid();
  600. return {};
  601. }
  602. //==============================================================================
  603. virtual void addSolutionFiles (OutputStream&, StringArray&) const
  604. {
  605. // older VS targets do not support solution files, so do nothing!
  606. }
  607. void writeProjectDependencies (OutputStream& out) const
  608. {
  609. const String sharedCodeGuid = getSharedCodeGuid();
  610. for (int i = 0; i < targets.size(); ++i)
  611. {
  612. if (MSVCTargetBase* target = targets[i])
  613. {
  614. out << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"" << projectName << " - "
  615. << target->getName() << "\", \""
  616. << target->getVCProjFile().getFileName() << "\", \"" << target->getProjectGuid() << '"' << newLine;
  617. if (sharedCodeGuid.isNotEmpty() && target->type != ProjectType::Target::SharedCodeTarget)
  618. out << "\tProjectSection(ProjectDependencies) = postProject" << newLine
  619. << "\t\t" << sharedCodeGuid << " = " << sharedCodeGuid << newLine
  620. << "\tEndProjectSection" << newLine;
  621. out << "EndProject" << newLine;
  622. }
  623. }
  624. }
  625. void writeSolutionFile (OutputStream& out, const String& versionString, String commentString) const
  626. {
  627. StringArray nestedProjects;
  628. if (commentString.isNotEmpty())
  629. commentString += newLine;
  630. out << "Microsoft Visual Studio Solution File, Format Version " << versionString << newLine
  631. << commentString << newLine;
  632. writeProjectDependencies (out);
  633. addSolutionFiles (out, nestedProjects);
  634. out << "Global" << newLine
  635. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  636. for (ConstConfigIterator i (*this); i.next();)
  637. {
  638. const MSVCBuildConfiguration& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  639. const String configName = config.createMSVCConfigName();
  640. out << "\t\t" << configName << " = " << configName << newLine;
  641. }
  642. out << "\tEndGlobalSection" << newLine
  643. << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" << newLine;
  644. for (auto& target : targets)
  645. for (ConstConfigIterator i (*this); i.next();)
  646. {
  647. const MSVCBuildConfiguration& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  648. const String configName = config.createMSVCConfigName();
  649. for (auto& suffix : { ".Build.0", ".ActiveCfg" })
  650. out << "\t\t" << target->getProjectGuid() << "." << configName << suffix << " = " << configName << newLine;
  651. }
  652. out << "\tEndGlobalSection" << newLine
  653. << "\tGlobalSection(SolutionProperties) = preSolution" << newLine
  654. << "\t\tHideSolutionNode = FALSE" << newLine
  655. << "\tEndGlobalSection" << newLine;
  656. if (nestedProjects.size() > 0)
  657. {
  658. out << "\tGlobalSection(NestedProjects) = preSolution" << newLine << "\t\t";
  659. out << nestedProjects.joinIntoString ("\n\t\t") << newLine;
  660. out << "\tEndGlobalSection" << newLine;
  661. }
  662. out << "EndGlobal" << newLine;
  663. }
  664. //==============================================================================
  665. static void writeBMPImage (const Image& image, const int w, const int h, MemoryOutputStream& out)
  666. {
  667. const int maskStride = (w / 8 + 3) & ~3;
  668. out.writeInt (40); // bitmapinfoheader size
  669. out.writeInt (w);
  670. out.writeInt (h * 2);
  671. out.writeShort (1); // planes
  672. out.writeShort (32); // bits
  673. out.writeInt (0); // compression
  674. out.writeInt ((h * w * 4) + (h * maskStride)); // size image
  675. out.writeInt (0); // x pixels per meter
  676. out.writeInt (0); // y pixels per meter
  677. out.writeInt (0); // clr used
  678. out.writeInt (0); // clr important
  679. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  680. const int alphaThreshold = 5;
  681. int y;
  682. for (y = h; --y >= 0;)
  683. {
  684. for (int x = 0; x < w; ++x)
  685. {
  686. const Colour pixel (bitmap.getPixelColour (x, y));
  687. if (pixel.getAlpha() <= alphaThreshold)
  688. {
  689. out.writeInt (0);
  690. }
  691. else
  692. {
  693. out.writeByte ((char) pixel.getBlue());
  694. out.writeByte ((char) pixel.getGreen());
  695. out.writeByte ((char) pixel.getRed());
  696. out.writeByte ((char) pixel.getAlpha());
  697. }
  698. }
  699. }
  700. for (y = h; --y >= 0;)
  701. {
  702. int mask = 0, count = 0;
  703. for (int x = 0; x < w; ++x)
  704. {
  705. const Colour pixel (bitmap.getPixelColour (x, y));
  706. mask <<= 1;
  707. if (pixel.getAlpha() <= alphaThreshold)
  708. mask |= 1;
  709. if (++count == 8)
  710. {
  711. out.writeByte ((char) mask);
  712. count = 0;
  713. mask = 0;
  714. }
  715. }
  716. if (mask != 0)
  717. out.writeByte ((char) mask);
  718. for (int i = maskStride - w / 8; --i >= 0;)
  719. out.writeByte (0);
  720. }
  721. }
  722. static void writeIconFile (const Array<Image>& images, MemoryOutputStream& out)
  723. {
  724. out.writeShort (0); // reserved
  725. out.writeShort (1); // .ico tag
  726. out.writeShort ((short) images.size());
  727. MemoryOutputStream dataBlock;
  728. const int imageDirEntrySize = 16;
  729. const int dataBlockStart = 6 + images.size() * imageDirEntrySize;
  730. for (int i = 0; i < images.size(); ++i)
  731. {
  732. const size_t oldDataSize = dataBlock.getDataSize();
  733. const Image& image = images.getReference (i);
  734. const int w = image.getWidth();
  735. const int h = image.getHeight();
  736. if (w >= 256 || h >= 256)
  737. {
  738. PNGImageFormat pngFormat;
  739. pngFormat.writeImageToStream (image, dataBlock);
  740. }
  741. else
  742. {
  743. writeBMPImage (image, w, h, dataBlock);
  744. }
  745. out.writeByte ((char) w);
  746. out.writeByte ((char) h);
  747. out.writeByte (0);
  748. out.writeByte (0);
  749. out.writeShort (1); // colour planes
  750. out.writeShort (32); // bits per pixel
  751. out.writeInt ((int) (dataBlock.getDataSize() - oldDataSize));
  752. out.writeInt (dataBlockStart + (int) oldDataSize);
  753. }
  754. jassert (out.getPosition() == dataBlockStart);
  755. out << dataBlock;
  756. }
  757. bool hasResourceFile() const
  758. {
  759. return ! projectType.isStaticLibrary();
  760. }
  761. void createResourcesAndIcon() const
  762. {
  763. if (hasResourceFile())
  764. {
  765. Array<Image> images;
  766. const int sizes[] = { 16, 32, 48, 256 };
  767. for (int i = 0; i < numElementsInArray (sizes); ++i)
  768. {
  769. Image im (getBestIconForSize (sizes[i], true));
  770. if (im.isValid())
  771. images.add (im);
  772. }
  773. if (images.size() > 0)
  774. {
  775. iconFile = getTargetFolder().getChildFile ("icon.ico");
  776. MemoryOutputStream mo;
  777. writeIconFile (images, mo);
  778. overwriteFileIfDifferentOrThrow (iconFile, mo);
  779. }
  780. createRCFile();
  781. }
  782. }
  783. void createRCFile() const
  784. {
  785. rcFile = getTargetFolder().getChildFile ("resources.rc");
  786. const String version (project.getVersionString());
  787. MemoryOutputStream mo;
  788. mo << "#ifdef JUCE_USER_DEFINED_RC_FILE" << newLine
  789. << " #include JUCE_USER_DEFINED_RC_FILE" << newLine
  790. << "#else" << newLine
  791. << newLine
  792. << "#undef WIN32_LEAN_AND_MEAN" << newLine
  793. << "#define WIN32_LEAN_AND_MEAN" << newLine
  794. << "#include <windows.h>" << newLine
  795. << newLine
  796. << "VS_VERSION_INFO VERSIONINFO" << newLine
  797. << "FILEVERSION " << getCommaSeparatedVersionNumber (version) << newLine
  798. << "BEGIN" << newLine
  799. << " BLOCK \"StringFileInfo\"" << newLine
  800. << " BEGIN" << newLine
  801. << " BLOCK \"040904E4\"" << newLine
  802. << " BEGIN" << newLine;
  803. writeRCValue (mo, "CompanyName", project.getCompanyName().toString());
  804. writeRCValue (mo, "FileDescription", project.getTitle());
  805. writeRCValue (mo, "FileVersion", version);
  806. writeRCValue (mo, "ProductName", project.getTitle());
  807. writeRCValue (mo, "ProductVersion", version);
  808. mo << " END" << newLine
  809. << " END" << newLine
  810. << newLine
  811. << " BLOCK \"VarFileInfo\"" << newLine
  812. << " BEGIN" << newLine
  813. << " VALUE \"Translation\", 0x409, 1252" << newLine
  814. << " END" << newLine
  815. << "END" << newLine
  816. << newLine
  817. << "#endif" << newLine;
  818. if (iconFile != File())
  819. mo << newLine
  820. << "IDI_ICON1 ICON DISCARDABLE " << iconFile.getFileName().quoted()
  821. << newLine
  822. << "IDI_ICON2 ICON DISCARDABLE " << iconFile.getFileName().quoted();
  823. overwriteFileIfDifferentOrThrow (rcFile, mo);
  824. }
  825. static void writeRCValue (MemoryOutputStream& mo, const String& name, const String& value)
  826. {
  827. if (value.isNotEmpty())
  828. mo << " VALUE \"" << name << "\", \""
  829. << CppTokeniserFunctions::addEscapeChars (value) << "\\0\"" << newLine;
  830. }
  831. static String getCommaSeparatedVersionNumber (const String& version)
  832. {
  833. StringArray versionParts;
  834. versionParts.addTokens (version, ",.", "");
  835. versionParts.trim();
  836. versionParts.removeEmptyStrings();
  837. while (versionParts.size() < 4)
  838. versionParts.add ("0");
  839. return versionParts.joinIntoString (",");
  840. }
  841. static String prependDot (const String& filename)
  842. {
  843. return FileHelpers::isAbsolutePath (filename) ? filename
  844. : (".\\" + filename);
  845. }
  846. void initialiseDependencyPathValues()
  847. {
  848. vst3Path.referTo (Value (new DependencyPathValueSource (getSetting (Ids::vst3Folder),
  849. Ids::vst3Path,
  850. TargetOS::windows)));
  851. aaxPath.referTo (Value (new DependencyPathValueSource (getSetting (Ids::aaxFolder),
  852. Ids::aaxPath,
  853. TargetOS::windows)));
  854. rtasPath.referTo (Value (new DependencyPathValueSource (getSetting (Ids::rtasFolder),
  855. Ids::rtasPath,
  856. TargetOS::windows)));
  857. }
  858. static bool shouldUseStdCall (const RelativePath& path)
  859. {
  860. return path.getFileNameWithoutExtension().startsWithIgnoreCase ("juce_audio_plugin_client_RTAS_");
  861. }
  862. StringArray getModuleLibs() const
  863. {
  864. StringArray result;
  865. for (auto& lib : windowsLibs)
  866. result.add (lib + ".lib");
  867. return result;
  868. }
  869. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase)
  870. };
  871. //==============================================================================
  872. class MSVCProjectExporterVC2010 : public MSVCProjectExporterBase
  873. {
  874. public:
  875. MSVCProjectExporterVC2010 (Project& p, const ValueTree& t, const char* folderName = "VisualStudio2010")
  876. : MSVCProjectExporterBase (p, t, folderName)
  877. {
  878. name = getName();
  879. }
  880. //==============================================================================
  881. class MSVC2010Target : public MSVCTargetBase
  882. {
  883. public:
  884. MSVC2010Target (ProjectType::Target::Type targetType, const MSVCProjectExporterVC2010& exporter)
  885. : MSVCTargetBase (targetType, exporter)
  886. {}
  887. const MSVCProjectExporterVC2010& getOwner() const { return dynamic_cast<const MSVCProjectExporterVC2010&> (owner); }
  888. String getProjectVersionString() const override { return "10.00"; }
  889. String getProjectFileSuffix() const override { return ".vcxproj"; }
  890. String getTopLevelXmlEntity() const override { return "Project"; }
  891. //==============================================================================
  892. void fillInProjectXml (XmlElement& projectXml) const override
  893. {
  894. projectXml.setAttribute ("DefaultTargets", "Build");
  895. projectXml.setAttribute ("ToolsVersion", getOwner().getToolsVersion());
  896. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  897. {
  898. XmlElement* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  899. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  900. for (ConstConfigIterator i (owner); i.next();)
  901. {
  902. const MSVCBuildConfiguration& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  903. XmlElement* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  904. e->setAttribute ("Include", config.createMSVCConfigName());
  905. e->createNewChildElement ("Configuration")->addTextElement (config.getName());
  906. e->createNewChildElement ("Platform")->addTextElement (is64Bit (config) ? "x64" : "Win32");
  907. }
  908. }
  909. {
  910. XmlElement* globals = projectXml.createNewChildElement ("PropertyGroup");
  911. globals->setAttribute ("Label", "Globals");
  912. globals->createNewChildElement ("ProjectGuid")->addTextElement (getProjectGuid());
  913. }
  914. {
  915. XmlElement* imports = projectXml.createNewChildElement ("Import");
  916. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  917. }
  918. for (ConstConfigIterator i (owner); i.next();)
  919. {
  920. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  921. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  922. setConditionAttribute (*e, config);
  923. e->setAttribute ("Label", "Configuration");
  924. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  925. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  926. const String charSet (config.getCharacterSet());
  927. if (charSet.isNotEmpty())
  928. e->createNewChildElement ("CharacterSet")->addTextElement (charSet);
  929. if (! (config.isDebug() || config.shouldDisableWholeProgramOpt()))
  930. e->createNewChildElement ("WholeProgramOptimization")->addTextElement ("true");
  931. if (config.shouldLinkIncremental())
  932. e->createNewChildElement ("LinkIncremental")->addTextElement ("true");
  933. if (config.is64Bit())
  934. e->createNewChildElement ("PlatformToolset")->addTextElement (getOwner().getPlatformToolset());
  935. }
  936. {
  937. XmlElement* e = projectXml.createNewChildElement ("Import");
  938. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  939. }
  940. {
  941. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  942. e->setAttribute ("Label", "ExtensionSettings");
  943. }
  944. {
  945. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  946. e->setAttribute ("Label", "PropertySheets");
  947. XmlElement* p = e->createNewChildElement ("Import");
  948. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  949. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  950. p->setAttribute ("Label", "LocalAppDataPlatform");
  951. }
  952. {
  953. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  954. e->setAttribute ("Label", "UserMacros");
  955. }
  956. {
  957. XmlElement* props = projectXml.createNewChildElement ("PropertyGroup");
  958. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  959. props->createNewChildElement ("TargetExt")->addTextElement (getTargetSuffix());
  960. for (ConstConfigIterator i (owner); i.next();)
  961. {
  962. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  963. if (getConfigTargetPath (config).isNotEmpty())
  964. {
  965. XmlElement* outdir = props->createNewChildElement ("OutDir");
  966. setConditionAttribute (*outdir, config);
  967. outdir->addTextElement (FileHelpers::windowsStylePath (getConfigTargetPath (config)) + "\\");
  968. }
  969. {
  970. XmlElement* intdir = props->createNewChildElement("IntDir");
  971. setConditionAttribute (*intdir, config);
  972. String intermediatesPath = getIntermediatesPath (config);
  973. if (! intermediatesPath.endsWithChar (L'\\'))
  974. intermediatesPath += L'\\';
  975. intdir->addTextElement (FileHelpers::windowsStylePath (intermediatesPath));
  976. }
  977. {
  978. XmlElement* targetName = props->createNewChildElement ("TargetName");
  979. setConditionAttribute (*targetName, config);
  980. targetName->addTextElement (config.getOutputFilename ("", false));
  981. }
  982. {
  983. XmlElement* manifest = props->createNewChildElement ("GenerateManifest");
  984. setConditionAttribute (*manifest, config);
  985. manifest->addTextElement (config.shouldGenerateManifest() ? "true" : "false");
  986. }
  987. const StringArray librarySearchPaths (getLibrarySearchPaths (config));
  988. if (librarySearchPaths.size() > 0)
  989. {
  990. XmlElement* libPath = props->createNewChildElement ("LibraryPath");
  991. setConditionAttribute (*libPath, config);
  992. libPath->addTextElement ("$(LibraryPath);" + librarySearchPaths.joinIntoString (";"));
  993. }
  994. }
  995. }
  996. for (ConstConfigIterator i (owner); i.next();)
  997. {
  998. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  999. const bool isDebug = config.isDebug();
  1000. XmlElement* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  1001. setConditionAttribute (*group, config);
  1002. {
  1003. XmlElement* midl = group->createNewChildElement ("Midl");
  1004. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  1005. : "NDEBUG;%(PreprocessorDefinitions)");
  1006. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  1007. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1008. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  1009. midl->createNewChildElement ("HeaderFileName");
  1010. }
  1011. bool isUsingEditAndContinue = false;
  1012. {
  1013. XmlElement* cl = group->createNewChildElement ("ClCompile");
  1014. cl->createNewChildElement ("Optimization")->addTextElement (getOptimisationLevelString (config.getOptimisationLevelInt()));
  1015. if (isDebug && config.getOptimisationLevelInt() <= optimisationOff)
  1016. {
  1017. isUsingEditAndContinue = ! config.is64Bit();
  1018. cl->createNewChildElement ("DebugInformationFormat")
  1019. ->addTextElement (isUsingEditAndContinue ? "EditAndContinue"
  1020. : "ProgramDatabase");
  1021. }
  1022. StringArray includePaths (getOwner().getHeaderSearchPaths (config));
  1023. includePaths.addArray (getExtraSearchPaths());
  1024. includePaths.add ("%(AdditionalIncludeDirectories)");
  1025. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  1026. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  1027. const bool runtimeDLL = shouldUseRuntimeDLL (config);
  1028. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (runtimeDLL ? (isDebug ? "MultiThreadedDebugDLL" : "MultiThreadedDLL")
  1029. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  1030. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  1031. cl->createNewChildElement ("PrecompiledHeader");
  1032. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement ("$(IntDir)\\");
  1033. cl->createNewChildElement ("ObjectFileName")->addTextElement ("$(IntDir)\\");
  1034. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement ("$(IntDir)\\");
  1035. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level" + String (config.getWarningLevel()));
  1036. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1037. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  1038. if (config.isFastMathEnabled())
  1039. cl->createNewChildElement ("FloatingPointModel")->addTextElement ("Fast");
  1040. const String extraFlags (getOwner().replacePreprocessorTokens (config, getOwner().getExtraCompilerFlagsString()).trim());
  1041. if (extraFlags.isNotEmpty())
  1042. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  1043. if (config.areWarningsTreatedAsErrors())
  1044. cl->createNewChildElement ("TreatWarningAsError")->addTextElement ("true");
  1045. String cppLanguageStandard = getOwner().getCppLanguageStandard();
  1046. if (cppLanguageStandard.isNotEmpty())
  1047. cl->createNewChildElement ("LanguageStandard")->addTextElement (cppLanguageStandard);
  1048. }
  1049. {
  1050. XmlElement* res = group->createNewChildElement ("ResourceCompile");
  1051. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  1052. : "NDEBUG;%(PreprocessorDefinitions)");
  1053. }
  1054. {
  1055. XmlElement* link = group->createNewChildElement ("Link");
  1056. link->createNewChildElement ("OutputFile")->addTextElement (getOutputFilePath (config));
  1057. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1058. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  1059. : "%(IgnoreSpecificDefaultLibraries)");
  1060. link->createNewChildElement ("GenerateDebugInformation")->addTextElement ((isDebug || config.shouldGenerateDebugSymbols()) ? "true" : "false");
  1061. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (getOwner().getIntDirFile (config, config.getOutputFilename (".pdb", true)));
  1062. link->createNewChildElement ("SubSystem")->addTextElement (type == ConsoleApp ? "Console" : "Windows");
  1063. if (! config.is64Bit())
  1064. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  1065. if (isUsingEditAndContinue)
  1066. link->createNewChildElement ("ImageHasSafeExceptionHandlers")->addTextElement ("false");
  1067. if (! isDebug)
  1068. {
  1069. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  1070. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  1071. }
  1072. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  1073. if (librarySearchPaths.size() > 0)
  1074. link->createNewChildElement ("AdditionalLibraryDirectories")->addTextElement (getOwner().replacePreprocessorTokens (config, librarySearchPaths.joinIntoString (";"))
  1075. + ";%(AdditionalLibraryDirectories)");
  1076. link->createNewChildElement ("LargeAddressAware")->addTextElement ("true");
  1077. const String externalLibraries (getExternalLibraries (config, getOwner().getExternalLibrariesString()));
  1078. if (externalLibraries.isNotEmpty())
  1079. link->createNewChildElement ("AdditionalDependencies")->addTextElement (getOwner().replacePreprocessorTokens (config, externalLibraries).trim()
  1080. + ";%(AdditionalDependencies)");
  1081. String extraLinkerOptions (getOwner().getExtraLinkerFlagsString());
  1082. if (extraLinkerOptions.isNotEmpty())
  1083. link->createNewChildElement ("AdditionalOptions")->addTextElement (getOwner().replacePreprocessorTokens (config, extraLinkerOptions).trim()
  1084. + " %(AdditionalOptions)");
  1085. const String delayLoadedDLLs (getDelayLoadedDLLs());
  1086. if (delayLoadedDLLs.isNotEmpty())
  1087. link->createNewChildElement ("DelayLoadDLLs")->addTextElement (delayLoadedDLLs);
  1088. const String moduleDefinitionsFile (getModuleDefinitions (config));
  1089. if (moduleDefinitionsFile.isNotEmpty())
  1090. link->createNewChildElement ("ModuleDefinitionFile")
  1091. ->addTextElement (moduleDefinitionsFile);
  1092. }
  1093. {
  1094. XmlElement* bsc = group->createNewChildElement ("Bscmake");
  1095. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1096. bsc->createNewChildElement ("OutputFile")->addTextElement (getOwner().getIntDirFile (config, config.getOutputFilename (".bsc", true)));
  1097. }
  1098. const RelativePath& manifestFile = getOwner().getManifestPath();
  1099. if (manifestFile.getRoot() != RelativePath::unknown)
  1100. {
  1101. XmlElement* bsc = group->createNewChildElement ("Manifest");
  1102. bsc->createNewChildElement ("AdditionalManifestFiles")
  1103. ->addTextElement (manifestFile.rebased (getOwner().getProject().getFile().getParentDirectory(),
  1104. getOwner().getTargetFolder(),
  1105. RelativePath::buildTargetFolder).toWindowsStyle());
  1106. }
  1107. if (getTargetFileType() == staticLibrary && ! config.is64Bit())
  1108. {
  1109. XmlElement* lib = group->createNewChildElement ("Lib");
  1110. lib->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  1111. }
  1112. const String preBuild = getPreBuildSteps (config);
  1113. if (preBuild.isNotEmpty())
  1114. group->createNewChildElement ("PreBuildEvent")
  1115. ->createNewChildElement ("Command")
  1116. ->addTextElement (preBuild);
  1117. const String postBuild = getPostBuildSteps (config);
  1118. if (postBuild.isNotEmpty())
  1119. group->createNewChildElement ("PostBuildEvent")
  1120. ->createNewChildElement ("Command")
  1121. ->addTextElement (postBuild);
  1122. }
  1123. ScopedPointer<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  1124. {
  1125. XmlElement* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  1126. XmlElement* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  1127. for (int i = 0; i < getOwner().getAllGroups().size(); ++i)
  1128. {
  1129. const Project::Item& group = getOwner().getAllGroups().getReference (i);
  1130. if (group.getNumChildren() > 0)
  1131. addFilesToCompile (group, *cppFiles, *headerFiles, *otherFilesGroup);
  1132. }
  1133. }
  1134. if (getOwner().iconFile != File())
  1135. {
  1136. XmlElement* e = otherFilesGroup->createNewChildElement ("None");
  1137. e->setAttribute ("Include", prependDot (getOwner().iconFile.getFileName()));
  1138. }
  1139. if (otherFilesGroup->getFirstChildElement() != nullptr)
  1140. projectXml.addChildElement (otherFilesGroup.release());
  1141. if (getOwner().hasResourceFile())
  1142. {
  1143. XmlElement* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  1144. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1145. e->setAttribute ("Include", prependDot (getOwner().rcFile.getFileName()));
  1146. }
  1147. {
  1148. XmlElement* e = projectXml.createNewChildElement ("Import");
  1149. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  1150. }
  1151. {
  1152. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  1153. e->setAttribute ("Label", "ExtensionTargets");
  1154. }
  1155. getOwner().addPlatformToolsetToPropertyGroup (projectXml);
  1156. getOwner().addWindowsTargetPlatformVersionToPropertyGroup (projectXml);
  1157. getOwner().addIPPSettingToPropertyGroup (projectXml);
  1158. }
  1159. String getProjectType() const
  1160. {
  1161. switch (getTargetFileType())
  1162. {
  1163. case executable:
  1164. return "Application";
  1165. case staticLibrary:
  1166. return "StaticLibrary";
  1167. default:
  1168. break;
  1169. }
  1170. return "DynamicLibrary";
  1171. }
  1172. //==============================================================================
  1173. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  1174. {
  1175. const Type targetType = (getOwner().getProject().getProjectType().isAudioPlugin() ? type : SharedCodeTarget);
  1176. if (projectItem.isGroup())
  1177. {
  1178. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1179. addFilesToCompile (projectItem.getChild (i), cpps, headers, otherFiles);
  1180. }
  1181. else if (projectItem.shouldBeAddedToTargetProject())
  1182. {
  1183. const RelativePath path (projectItem.getFile(), getOwner().getTargetFolder(), RelativePath::buildTargetFolder);
  1184. jassert (path.getRoot() == RelativePath::buildTargetFolder);
  1185. if (projectItem.shouldBeCompiled() && (path.hasFileExtension (cOrCppFileExtensions) || path.hasFileExtension (asmFileExtensions))
  1186. && getOwner().getProject().getTargetTypeFromFilePath (projectItem.getFile(), true) == targetType)
  1187. {
  1188. XmlElement* e = cpps.createNewChildElement ("ClCompile");
  1189. e->setAttribute ("Include", path.toWindowsStyle());
  1190. if (shouldUseStdCall (path))
  1191. e->createNewChildElement ("CallingConvention")->addTextElement ("StdCall");
  1192. }
  1193. }
  1194. }
  1195. void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config) const
  1196. {
  1197. const MSVCBuildConfiguration& msvcConfig = dynamic_cast<const MSVCBuildConfiguration&> (config);
  1198. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + msvcConfig.createMSVCConfigName() + "'");
  1199. }
  1200. };
  1201. static const char* getName() { return "Visual Studio 2010"; }
  1202. static const char* getValueTreeTypeName() { return "VS2010"; }
  1203. int getVisualStudioVersion() const override { return 10; }
  1204. virtual String getSolutionComment() const { return "# Visual Studio 2010"; }
  1205. virtual String getToolsVersion() const { return "4.0"; }
  1206. virtual String getDefaultToolset() const { return "Windows7.1SDK"; }
  1207. Value getPlatformToolsetValue() { return getSetting (Ids::toolset); }
  1208. Value getIPPLibraryValue() { return getSetting (Ids::IPPLibrary); }
  1209. String getIPPLibrary() const { return settings [Ids::IPPLibrary]; }
  1210. virtual String getCppLanguageStandard() const { return {}; }
  1211. String getPlatformToolset() const
  1212. {
  1213. const String s (settings [Ids::toolset].toString());
  1214. return s.isNotEmpty() ? s : getDefaultToolset();
  1215. }
  1216. static MSVCProjectExporterVC2010* createForSettings (Project& project, const ValueTree& settings)
  1217. {
  1218. if (settings.hasType (getValueTreeTypeName()))
  1219. return new MSVCProjectExporterVC2010 (project, settings);
  1220. return nullptr;
  1221. }
  1222. void addToolsetProperty (PropertyListBuilder& props, const char** names, const var* values, int num)
  1223. {
  1224. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  1225. StringArray (names, num), Array<var> (values, num)));
  1226. }
  1227. void addIPPLibraryProperty (PropertyListBuilder& props)
  1228. {
  1229. static const char* ippOptions[] = { "No", "Yes (Default Mode)", "Multi-Threaded Static Library", "Single-Threaded Static Library", "Multi-Threaded DLL", "Single-Threaded DLL" };
  1230. static const var ippValues[] = { var(), "true", "Parallel_Static", "Sequential", "Parallel_Dynamic", "Sequential_Dynamic" };
  1231. props.add (new ChoicePropertyComponent (getIPPLibraryValue(), "Use IPP Library",
  1232. StringArray (ippOptions, numElementsInArray (ippValues)),
  1233. Array<var> (ippValues, numElementsInArray (ippValues))));
  1234. }
  1235. void createExporterProperties (PropertyListBuilder& props) override
  1236. {
  1237. MSVCProjectExporterBase::createExporterProperties (props);
  1238. static const char* toolsetNames[] = { "(default)", "v100", "v100_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1239. const var toolsets[] = { var(), "v100", "v100_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1240. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1241. addIPPLibraryProperty (props);
  1242. }
  1243. //==============================================================================
  1244. void addSolutionFiles (OutputStream& out, StringArray& nestedProjects) const override
  1245. {
  1246. const bool ignoreRootGroup = (getAllGroups().size() == 1);
  1247. const int numberOfGroups = (ignoreRootGroup ? getAllGroups().getReference (0).getNumChildren()
  1248. : getAllGroups().size());
  1249. for (int i = 0; i < numberOfGroups; ++i)
  1250. {
  1251. const Project::Item& group = (ignoreRootGroup ? getAllGroups().getReference (0).getChild (i)
  1252. : getAllGroups().getReference (i));
  1253. if (group.getNumChildren() > 0)
  1254. addSolutionFiles (out, group, nestedProjects, String());
  1255. }
  1256. }
  1257. void addSolutionFiles (OutputStream& out, const Project::Item& item, StringArray& nestedProjectList, const String& parentGuid) const
  1258. {
  1259. jassert (item.isGroup());
  1260. const String groupGuid = createGUID (item.getID());
  1261. out << "Project(\"{2150E333-8FDC-42A3-9474-1A3956D46DE8}\") = \"" << item.getName() << "\""
  1262. << ", \"" << item.getName() << "\", \"" << groupGuid << "\"" << newLine;
  1263. bool hasSubFiles = false;
  1264. const int n = item.getNumChildren();
  1265. for (int i = 0; i < n; ++i)
  1266. {
  1267. const Project::Item& child = item.getChild (i);
  1268. if (child.isFile())
  1269. {
  1270. if (! hasSubFiles)
  1271. {
  1272. out << "\tProjectSection(SolutionItems) = preProject" << newLine;
  1273. hasSubFiles = true;
  1274. }
  1275. const RelativePath path = RelativePath (child.getFilePath(), RelativePath::projectFolder)
  1276. .rebased (getProject().getProjectFolder(), getSLNFile().getParentDirectory(),
  1277. RelativePath::buildTargetFolder);
  1278. out << "\t\t" << path.toWindowsStyle() << " = " << path.toWindowsStyle() << newLine;
  1279. }
  1280. }
  1281. if (hasSubFiles)
  1282. out << "\tEndProjectSection" << newLine;
  1283. out << "EndProject" << newLine;
  1284. for (int i = 0; i < n; ++i)
  1285. {
  1286. const Project::Item& child = item.getChild (i);
  1287. if (child.isGroup())
  1288. addSolutionFiles (out, child, nestedProjectList, groupGuid);
  1289. }
  1290. if (parentGuid.isNotEmpty())
  1291. nestedProjectList.add (groupGuid + String (" = ") + parentGuid);
  1292. }
  1293. //==============================================================================
  1294. void addPlatformSpecificSettingsForProjectType (const ProjectType& type) override
  1295. {
  1296. MSVCProjectExporterBase::addPlatformSpecificSettingsForProjectType (type);
  1297. callForAllSupportedTargets ([this] (ProjectType::Target::Type targetType)
  1298. {
  1299. if (MSVCTargetBase* target = new MSVC2010Target (targetType, *this))
  1300. {
  1301. if (targetType != ProjectType::Target::AggregateTarget)
  1302. targets.add (target);
  1303. }
  1304. });
  1305. // If you hit this assert, you tried to generate a project for an exporter
  1306. // that does not support any of your targets!
  1307. jassert (targets.size() > 0);
  1308. }
  1309. void create (const OwnedArray<LibraryModule>&) const override
  1310. {
  1311. createResourcesAndIcon();
  1312. for (int i = 0; i < targets.size(); ++i)
  1313. if (MSVCTargetBase* target = targets[i])
  1314. target->writeProjectFile();
  1315. {
  1316. MemoryOutputStream mo;
  1317. writeSolutionFile (mo, "11.00", getSolutionComment());
  1318. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  1319. }
  1320. }
  1321. protected:
  1322. //==============================================================================
  1323. class VC2010BuildConfiguration : public MSVCBuildConfiguration
  1324. {
  1325. public:
  1326. VC2010BuildConfiguration (Project& p, const ValueTree& settings, const ProjectExporter& e)
  1327. : MSVCBuildConfiguration (p, settings, e)
  1328. {
  1329. if (getArchitectureType().toString().isEmpty())
  1330. getArchitectureType() = get64BitArchName();
  1331. }
  1332. //==============================================================================
  1333. static const char* get32BitArchName() { return "32-bit"; }
  1334. static const char* get64BitArchName() { return "x64"; }
  1335. Value getArchitectureType() { return getValue (Ids::winArchitecture); }
  1336. bool is64Bit() const { return config [Ids::winArchitecture].toString() == get64BitArchName(); }
  1337. Value getFastMathValue() { return getValue (Ids::fastMath); }
  1338. bool isFastMathEnabled() const { return config [Ids::fastMath]; }
  1339. //==============================================================================
  1340. void createConfigProperties (PropertyListBuilder& props) override
  1341. {
  1342. MSVCBuildConfiguration::createConfigProperties (props);
  1343. const char* const archTypes[] = { get32BitArchName(), get64BitArchName() };
  1344. props.add (new ChoicePropertyComponent (getArchitectureType(), "Architecture",
  1345. StringArray (archTypes, numElementsInArray (archTypes)),
  1346. Array<var> (archTypes, numElementsInArray (archTypes))));
  1347. props.add (new BooleanPropertyComponent (getFastMathValue(), "Relax IEEE compliance", "Enabled"),
  1348. "Enable this to use FAST_MATH non-IEEE mode. (Warning: this can have unexpected results!)");
  1349. }
  1350. };
  1351. virtual void addPlatformToolsetToPropertyGroup (XmlElement&) const {}
  1352. virtual void addWindowsTargetPlatformVersionToPropertyGroup (XmlElement&) const {}
  1353. void addIPPSettingToPropertyGroup (XmlElement& p) const
  1354. {
  1355. String ippLibrary = getIPPLibrary();
  1356. if (ippLibrary.isNotEmpty())
  1357. forEachXmlChildElementWithTagName (p, e, "PropertyGroup")
  1358. e->createNewChildElement ("UseIntelIPP")->addTextElement (ippLibrary);
  1359. }
  1360. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override
  1361. {
  1362. return new VC2010BuildConfiguration (project, v, *this);
  1363. }
  1364. static bool is64Bit (const BuildConfiguration& config)
  1365. {
  1366. return dynamic_cast<const VC2010BuildConfiguration&> (config).is64Bit();
  1367. }
  1368. //==============================================================================
  1369. File getVCProjFile() const { return getProjectFile (".vcxproj", "App"); }
  1370. File getVCProjFiltersFile() const { return getProjectFile (".vcxproj.filters", String()); }
  1371. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2010)
  1372. };
  1373. //==============================================================================
  1374. class MSVCProjectExporterVC2012 : public MSVCProjectExporterVC2010
  1375. {
  1376. public:
  1377. MSVCProjectExporterVC2012 (Project& p, const ValueTree& t,
  1378. const char* folderName = "VisualStudio2012")
  1379. : MSVCProjectExporterVC2010 (p, t, folderName)
  1380. {
  1381. name = getName();
  1382. }
  1383. static const char* getName() { return "Visual Studio 2012"; }
  1384. static const char* getValueTreeTypeName() { return "VS2012"; }
  1385. int getVisualStudioVersion() const override { return 11; }
  1386. String getSolutionComment() const override { return "# Visual Studio 2012"; }
  1387. String getDefaultToolset() const override { return "v110"; }
  1388. Value getWindowsTargetPlatformVersionValue() { return getSetting (Ids::windowsTargetPlatformVersion); }
  1389. String getWindowsTargetPlatformVersion() const { return settings [Ids::windowsTargetPlatformVersion]; }
  1390. static MSVCProjectExporterVC2012* createForSettings (Project& project, const ValueTree& settings)
  1391. {
  1392. if (settings.hasType (getValueTreeTypeName()))
  1393. return new MSVCProjectExporterVC2012 (project, settings);
  1394. return nullptr;
  1395. }
  1396. void createExporterProperties (PropertyListBuilder& props) override
  1397. {
  1398. MSVCProjectExporterBase::createExporterProperties (props);
  1399. static const char* toolsetNames[] = { "(default)", "v110", "v110_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1400. const var toolsets[] = { var(), "v110", "v110_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1401. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1402. addIPPLibraryProperty (props);
  1403. }
  1404. void addWindowsTargetPlatformProperties (PropertyListBuilder& props)
  1405. {
  1406. static const char* targetPlatformNames[] = { "(default)", "8.1", "10.0.10240.0", "10.0.10586.0", "10.0.14393.0", "10.0.15063.0", nullptr };
  1407. const var targetPlatforms[] = { var(), "8.1", "10.0.10240.0", "10.0.10586.0", "10.0.14393.0", "10.0.15063.0" };
  1408. props.add (new ChoicePropertyComponent (getWindowsTargetPlatformVersionValue(), "Windows Target Platform",
  1409. StringArray (targetPlatformNames), Array<var> (targetPlatforms, numElementsInArray (targetPlatforms))),
  1410. "The Windows target platform version to use");
  1411. }
  1412. private:
  1413. void addPlatformToolsetToPropertyGroup (XmlElement& p) const override
  1414. {
  1415. forEachXmlChildElementWithTagName (p, e, "PropertyGroup")
  1416. e->createNewChildElement ("PlatformToolset")->addTextElement (getPlatformToolset());
  1417. }
  1418. void addWindowsTargetPlatformVersionToPropertyGroup (XmlElement& p) const override
  1419. {
  1420. const String& targetVersion = getWindowsTargetPlatformVersion();
  1421. if (targetVersion.isNotEmpty())
  1422. forEachXmlChildElementWithTagName (p, e, "PropertyGroup")
  1423. e->createNewChildElement ("WindowsTargetPlatformVersion")->addTextElement (getWindowsTargetPlatformVersion());
  1424. }
  1425. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2012)
  1426. };
  1427. //==============================================================================
  1428. class MSVCProjectExporterVC2013 : public MSVCProjectExporterVC2012
  1429. {
  1430. public:
  1431. MSVCProjectExporterVC2013 (Project& p, const ValueTree& t)
  1432. : MSVCProjectExporterVC2012 (p, t, "VisualStudio2013")
  1433. {
  1434. name = getName();
  1435. }
  1436. static const char* getName() { return "Visual Studio 2013"; }
  1437. static const char* getValueTreeTypeName() { return "VS2013"; }
  1438. int getVisualStudioVersion() const override { return 12; }
  1439. String getSolutionComment() const override { return "# Visual Studio 2013"; }
  1440. String getToolsVersion() const override { return "12.0"; }
  1441. String getDefaultToolset() const override { return "v120"; }
  1442. static MSVCProjectExporterVC2013* createForSettings (Project& project, const ValueTree& settings)
  1443. {
  1444. if (settings.hasType (getValueTreeTypeName()))
  1445. return new MSVCProjectExporterVC2013 (project, settings);
  1446. return nullptr;
  1447. }
  1448. void createExporterProperties (PropertyListBuilder& props) override
  1449. {
  1450. MSVCProjectExporterBase::createExporterProperties (props);
  1451. static const char* toolsetNames[] = { "(default)", "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1452. const var toolsets[] = { var(), "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1453. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1454. addIPPLibraryProperty (props);
  1455. addWindowsTargetPlatformProperties (props);
  1456. }
  1457. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2013)
  1458. };
  1459. //==============================================================================
  1460. class MSVCProjectExporterVC2015 : public MSVCProjectExporterVC2012
  1461. {
  1462. public:
  1463. MSVCProjectExporterVC2015 (Project& p, const ValueTree& t)
  1464. : MSVCProjectExporterVC2012 (p, t, "VisualStudio2015")
  1465. {
  1466. name = getName();
  1467. }
  1468. static const char* getName() { return "Visual Studio 2015"; }
  1469. static const char* getValueTreeTypeName() { return "VS2015"; }
  1470. int getVisualStudioVersion() const override { return 14; }
  1471. String getSolutionComment() const override { return "# Visual Studio 2015"; }
  1472. String getToolsVersion() const override { return "14.0"; }
  1473. String getDefaultToolset() const override { return "v140"; }
  1474. static MSVCProjectExporterVC2015* createForSettings (Project& project, const ValueTree& settings)
  1475. {
  1476. if (settings.hasType (getValueTreeTypeName()))
  1477. return new MSVCProjectExporterVC2015 (project, settings);
  1478. return nullptr;
  1479. }
  1480. void createExporterProperties (PropertyListBuilder& props) override
  1481. {
  1482. MSVCProjectExporterBase::createExporterProperties (props);
  1483. static const char* toolsetNames[] = { "(default)", "v140", "v140_xp", "CTP_Nov2013" };
  1484. const var toolsets[] = { var(), "v140", "v140_xp", "CTP_Nov2013" };
  1485. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1486. addIPPLibraryProperty (props);
  1487. addWindowsTargetPlatformProperties (props);
  1488. }
  1489. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2015)
  1490. };
  1491. //==============================================================================
  1492. class MSVCProjectExporterVC2017 : public MSVCProjectExporterVC2012
  1493. {
  1494. public:
  1495. MSVCProjectExporterVC2017 (Project& p, const ValueTree& t)
  1496. : MSVCProjectExporterVC2012 (p, t, "VisualStudio2017")
  1497. {
  1498. name = getName();
  1499. }
  1500. static const char* getName() { return "Visual Studio 2017"; }
  1501. static const char* getValueTreeTypeName() { return "VS2017"; }
  1502. int getVisualStudioVersion() const override { return 15; }
  1503. String getSolutionComment() const override { return "# Visual Studio 2017"; }
  1504. String getToolsVersion() const override { return "15.0"; }
  1505. String getDefaultToolset() const override { return "v141"; }
  1506. static MSVCProjectExporterVC2017* createForSettings (Project& project, const ValueTree& settings)
  1507. {
  1508. if (settings.hasType (getValueTreeTypeName()))
  1509. return new MSVCProjectExporterVC2017 (project, settings);
  1510. return nullptr;
  1511. }
  1512. Value getCppStandardValue() { return getSetting (Ids::cppLanguageStandard); }
  1513. String getCppLanguageStandard() const override { return settings [Ids::cppLanguageStandard]; }
  1514. void createExporterProperties (PropertyListBuilder& props) override
  1515. {
  1516. MSVCProjectExporterBase::createExporterProperties (props);
  1517. static const char* toolsetNames[] = { "(default)", "v140", "v140_xp", "v141", "v141_xp" };
  1518. const var toolsets[] = { var(), "v140", "v140_xp", "v141", "v141_xp" };
  1519. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1520. addIPPLibraryProperty (props);
  1521. addWindowsTargetPlatformProperties (props);
  1522. static const char* cppStandardNames[] = { "(default)", "C++14", "Latest C++ Standard", nullptr };
  1523. Array<var> cppStandardValues;
  1524. cppStandardValues.add (var());
  1525. cppStandardValues.add ("stdcpp14");
  1526. cppStandardValues.add ("stdcpplatest");
  1527. props.add (new ChoicePropertyComponent (getCppStandardValue(), "C++ standard to use",
  1528. StringArray (cppStandardNames), cppStandardValues),
  1529. "The C++ language standard to use");
  1530. }
  1531. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2017)
  1532. };