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.

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