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.

1874 lines
83KB

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