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.

2033 lines
96KB

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