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.

1796 lines
89KB

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