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.

1980 lines
93KB

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