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.

1989 lines
90KB

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