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.

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