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.

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