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.

1799 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 (config.isLinkTimeOptimisationEnabled())
  500. link->createNewChildElement ("LinkTimeCodeGeneration")->addTextElement ("UseLinkTimeCodeGeneration");
  501. if (additionalDependencies.isNotEmpty())
  502. link->createNewChildElement ("AdditionalDependencies")->addTextElement (additionalDependencies);
  503. auto extraLinkerOptions = getOwner().getExtraLinkerFlagsString();
  504. if (extraLinkerOptions.isNotEmpty())
  505. link->createNewChildElement ("AdditionalOptions")->addTextElement (getOwner().replacePreprocessorTokens (config, extraLinkerOptions).trim()
  506. + " %(AdditionalOptions)");
  507. auto delayLoadedDLLs = getDelayLoadedDLLs();
  508. if (delayLoadedDLLs.isNotEmpty())
  509. link->createNewChildElement ("DelayLoadDLLs")->addTextElement (delayLoadedDLLs);
  510. auto moduleDefinitionsFile = getModuleDefinitions (config);
  511. if (moduleDefinitionsFile.isNotEmpty())
  512. link->createNewChildElement ("ModuleDefinitionFile")
  513. ->addTextElement (moduleDefinitionsFile);
  514. }
  515. {
  516. auto* bsc = group->createNewChildElement ("Bscmake");
  517. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  518. bsc->createNewChildElement ("OutputFile")->addTextElement (getOwner().getIntDirFile (config, config.getOutputFilename (".bsc", true, type == UnityPlugIn)));
  519. }
  520. if (type != SharedCodeTarget)
  521. {
  522. auto* lib = group->createNewChildElement ("Lib");
  523. if (additionalDependencies.isNotEmpty())
  524. lib->createNewChildElement ("AdditionalDependencies")->addTextElement (additionalDependencies);
  525. if (additionalLibraryDirs.isNotEmpty())
  526. lib->createNewChildElement ("AdditionalLibraryDirectories")->addTextElement (additionalLibraryDirs);
  527. }
  528. auto manifestFile = getOwner().getManifestPath();
  529. if (manifestFile.getRoot() != build_tools::RelativePath::unknown)
  530. {
  531. auto* bsc = group->createNewChildElement ("Manifest");
  532. bsc->createNewChildElement ("AdditionalManifestFiles")
  533. ->addTextElement (manifestFile.rebased (getOwner().getProject().getFile().getParentDirectory(),
  534. getOwner().getTargetFolder(),
  535. build_tools::RelativePath::buildTargetFolder).toWindowsStyle());
  536. }
  537. if (getTargetFileType() == staticLibrary && ! config.is64Bit())
  538. {
  539. auto* lib = group->createNewChildElement ("Lib");
  540. lib->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  541. }
  542. auto preBuild = getPreBuildSteps (config);
  543. if (preBuild.isNotEmpty())
  544. group->createNewChildElement ("PreBuildEvent")
  545. ->createNewChildElement ("Command")
  546. ->addTextElement (preBuild);
  547. auto postBuild = getPostBuildSteps (config);
  548. if (postBuild.isNotEmpty())
  549. group->createNewChildElement ("PostBuildEvent")
  550. ->createNewChildElement ("Command")
  551. ->addTextElement (postBuild);
  552. }
  553. std::unique_ptr<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  554. {
  555. auto* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  556. auto* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  557. for (int i = 0; i < getOwner().getAllGroups().size(); ++i)
  558. {
  559. auto& group = getOwner().getAllGroups().getReference (i);
  560. if (group.getNumChildren() > 0)
  561. addFilesToCompile (group, *cppFiles, *headerFiles, *otherFilesGroup);
  562. }
  563. }
  564. if (getOwner().iconFile.existsAsFile())
  565. {
  566. auto* e = otherFilesGroup->createNewChildElement ("None");
  567. e->setAttribute ("Include", prependDot (getOwner().iconFile.getFileName()));
  568. }
  569. if (getOwner().packagesConfigFile.existsAsFile())
  570. {
  571. auto* e = otherFilesGroup->createNewChildElement ("None");
  572. e->setAttribute ("Include", getOwner().packagesConfigFile.getFileName());
  573. }
  574. if (otherFilesGroup->getFirstChildElement() != nullptr)
  575. projectXml.addChildElement (otherFilesGroup.release());
  576. if (type != SharedCodeTarget && getOwner().hasResourceFile())
  577. {
  578. auto* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  579. auto* e = rcGroup->createNewChildElement ("ResourceCompile");
  580. e->setAttribute ("Include", prependDot (getOwner().rcFile.getFileName()));
  581. }
  582. {
  583. auto* e = projectXml.createNewChildElement ("Import");
  584. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  585. }
  586. {
  587. auto* importGroup = projectXml.createNewChildElement ("ImportGroup");
  588. importGroup->setAttribute ("Label", "ExtensionTargets");
  589. if (owner.shouldAddWebView2Package())
  590. {
  591. auto packageTargetsPath = "packages\\" + getWebView2PackageName() + "." + getWebView2PackageVersion()
  592. + "\\build\\native\\" + getWebView2PackageName() + ".targets";
  593. auto* e = importGroup->createNewChildElement ("Import");
  594. e->setAttribute ("Project", packageTargetsPath);
  595. e->setAttribute ("Condition", "Exists('" + packageTargetsPath + "')");
  596. }
  597. }
  598. }
  599. String getProjectType() const
  600. {
  601. auto targetFileType = getTargetFileType();
  602. if (targetFileType == executable) return "Application";
  603. if (targetFileType == staticLibrary) return "StaticLibrary";
  604. return "DynamicLibrary";
  605. }
  606. //==============================================================================
  607. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  608. {
  609. auto targetType = (getOwner().getProject().isAudioPluginProject() ? type : SharedCodeTarget);
  610. if (projectItem.isGroup())
  611. {
  612. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  613. addFilesToCompile (projectItem.getChild (i), cpps, headers, otherFiles);
  614. }
  615. else if (projectItem.shouldBeAddedToTargetProject() && projectItem.shouldBeAddedToTargetExporter (getOwner())
  616. && getOwner().getProject().getTargetTypeFromFilePath (projectItem.getFile(), true) == targetType)
  617. {
  618. build_tools::RelativePath path (projectItem.getFile(), getOwner().getTargetFolder(), build_tools::RelativePath::buildTargetFolder);
  619. jassert (path.getRoot() == build_tools::RelativePath::buildTargetFolder);
  620. if (path.hasFileExtension (cOrCppFileExtensions) || path.hasFileExtension (asmFileExtensions))
  621. {
  622. auto* e = cpps.createNewChildElement ("ClCompile");
  623. e->setAttribute ("Include", path.toWindowsStyle());
  624. if (shouldUseStdCall (path))
  625. e->createNewChildElement ("CallingConvention")->addTextElement ("StdCall");
  626. if (projectItem.shouldBeCompiled())
  627. {
  628. auto extraCompilerFlags = owner.compilerFlagSchemesMap[projectItem.getCompilerFlagSchemeString()].get().toString();
  629. if (extraCompilerFlags.isNotEmpty())
  630. e->createNewChildElement ("AdditionalOptions")->addTextElement (extraCompilerFlags + " %(AdditionalOptions)");
  631. }
  632. else
  633. {
  634. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  635. }
  636. }
  637. else if (path.hasFileExtension (headerFileExtensions))
  638. {
  639. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", path.toWindowsStyle());
  640. }
  641. else if (! path.hasFileExtension (objCFileExtensions))
  642. {
  643. otherFiles.createNewChildElement ("None")->setAttribute ("Include", path.toWindowsStyle());
  644. }
  645. }
  646. }
  647. void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config) const
  648. {
  649. auto& msvcConfig = dynamic_cast<const MSVCBuildConfiguration&> (config);
  650. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + msvcConfig.createMSVCConfigName() + "'");
  651. }
  652. //==============================================================================
  653. void addFilterGroup (XmlElement& groups, const String& path) const
  654. {
  655. auto* e = groups.createNewChildElement ("Filter");
  656. e->setAttribute ("Include", path);
  657. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  658. }
  659. void addFileToFilter (const build_tools::RelativePath& file, const String& groupPath,
  660. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  661. {
  662. XmlElement* e = nullptr;
  663. if (file.hasFileExtension (headerFileExtensions))
  664. e = headers.createNewChildElement ("ClInclude");
  665. else if (file.hasFileExtension (sourceFileExtensions))
  666. e = cpps.createNewChildElement ("ClCompile");
  667. else
  668. e = otherFiles.createNewChildElement ("None");
  669. jassert (file.getRoot() == build_tools::RelativePath::buildTargetFolder);
  670. e->setAttribute ("Include", file.toWindowsStyle());
  671. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  672. }
  673. bool addFilesToFilter (const Project::Item& projectItem, const String& path,
  674. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups) const
  675. {
  676. auto targetType = (getOwner().getProject().isAudioPluginProject() ? type : SharedCodeTarget);
  677. if (projectItem.isGroup())
  678. {
  679. bool filesWereAdded = false;
  680. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  681. if (addFilesToFilter (projectItem.getChild(i),
  682. (path.isEmpty() ? String() : (path + "\\")) + projectItem.getChild(i).getName(),
  683. cpps, headers, otherFiles, groups))
  684. filesWereAdded = true;
  685. if (filesWereAdded)
  686. addFilterGroup (groups, path);
  687. return filesWereAdded;
  688. }
  689. else if (projectItem.shouldBeAddedToTargetProject()
  690. && projectItem.shouldBeAddedToTargetExporter (getOwner())
  691. && getOwner().getProject().getTargetTypeFromFilePath (projectItem.getFile(), true) == targetType)
  692. {
  693. build_tools::RelativePath relativePath (projectItem.getFile(),
  694. getOwner().getTargetFolder(),
  695. build_tools::RelativePath::buildTargetFolder);
  696. jassert (relativePath.getRoot() == build_tools::RelativePath::buildTargetFolder);
  697. addFileToFilter (relativePath, path.upToLastOccurrenceOf ("\\", false, false), 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 (getOwner().packagesConfigFile.existsAsFile())
  723. {
  724. auto* e = otherFilesGroup->createNewChildElement ("None");
  725. e->setAttribute ("Include", getOwner().packagesConfigFile.getFileName());
  726. }
  727. if (otherFilesGroup->getFirstChildElement() != nullptr)
  728. filterXml.addChildElement (otherFilesGroup.release());
  729. if (type != SharedCodeTarget && getOwner().hasResourceFile())
  730. {
  731. auto* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  732. auto* e = rcGroup->createNewChildElement ("ResourceCompile");
  733. e->setAttribute ("Include", prependDot (getOwner().rcFile.getFileName()));
  734. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  735. }
  736. }
  737. const MSVCProjectExporterBase& getOwner() const { return owner; }
  738. const String& getProjectGuid() const { return projectGuid; }
  739. //==============================================================================
  740. void writeProjectFile()
  741. {
  742. {
  743. XmlElement projectXml (getTopLevelXmlEntity());
  744. fillInProjectXml (projectXml);
  745. writeXmlOrThrow (projectXml, getVCProjFile(), "UTF-8", 10);
  746. }
  747. {
  748. XmlElement filtersXml (getTopLevelXmlEntity());
  749. fillInFiltersXml (filtersXml);
  750. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "UTF-8", 100);
  751. }
  752. }
  753. String getSolutionTargetPath (const BuildConfiguration& config) const
  754. {
  755. auto binaryPath = config.getTargetBinaryRelativePathString().trim();
  756. if (binaryPath.isEmpty())
  757. return "$(SolutionDir)$(Platform)\\$(Configuration)";
  758. build_tools::RelativePath binaryRelPath (binaryPath, build_tools::RelativePath::projectFolder);
  759. if (binaryRelPath.isAbsolute())
  760. return binaryRelPath.toWindowsStyle();
  761. return prependDot (binaryRelPath.rebased (getOwner().projectFolder,
  762. getOwner().getTargetFolder(),
  763. build_tools::RelativePath::buildTargetFolder)
  764. .toWindowsStyle());
  765. }
  766. String getConfigTargetPath (const BuildConfiguration& config) const
  767. {
  768. auto solutionTargetFolder = getSolutionTargetPath (config);
  769. return solutionTargetFolder + "\\" + getName();
  770. }
  771. String getIntermediatesPath (const MSVCBuildConfiguration& config) const
  772. {
  773. auto intDir = (config.getIntermediatesPathString().isNotEmpty() ? config.getIntermediatesPathString()
  774. : "$(Platform)\\$(Configuration)");
  775. if (! intDir.endsWithChar (L'\\'))
  776. intDir += L'\\';
  777. return intDir + getName();
  778. }
  779. static const char* getOptimisationLevelString (int level)
  780. {
  781. switch (level)
  782. {
  783. case optimiseMinSize: return "MinSpace";
  784. case optimiseMaxSpeed: return "MaxSpeed";
  785. case optimiseFull: return "Full";
  786. default: return "Disabled";
  787. }
  788. }
  789. String getTargetSuffix() const
  790. {
  791. auto fileType = getTargetFileType();
  792. if (fileType == executable) return ".exe";
  793. if (fileType == staticLibrary) return ".lib";
  794. if (fileType == sharedLibraryOrDLL) return ".dll";
  795. if (fileType == pluginBundle)
  796. {
  797. if (type == VST3PlugIn) return ".vst3";
  798. if (type == AAXPlugIn) return ".aaxdll";
  799. if (type == RTASPlugIn) return ".dpm";
  800. return ".dll";
  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. build_tools::RelativePath getAAXIconFile() const
  841. {
  842. build_tools::RelativePath aaxSDK (owner.getAAXPathString(), build_tools::RelativePath::projectFolder);
  843. build_tools::RelativePath projectIcon ("icon.ico", build_tools::RelativePath::buildTargetFolder);
  844. if (getOwner().getTargetFolder().getChildFile ("icon.ico").existsAsFile())
  845. return projectIcon.rebased (getOwner().getTargetFolder(),
  846. getOwner().getProject().getProjectFolder(),
  847. build_tools::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. build_tools::RelativePath aaxSDK (owner.getAAXPathString(), build_tools::RelativePath::projectFolder);
  855. build_tools::RelativePath aaxLibsFolder = aaxSDK.getChildFile ("Libs");
  856. build_tools::RelativePath bundleScript = aaxSDK.getChildFile ("Utilities").getChildFile ("CreatePackage.bat");
  857. build_tools::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. build_tools::RelativePath scriptPath (config.project.getGeneratedCodeFolder().getChildFile (config.project.getUnityScriptName()),
  873. getOwner().getTargetFolder(),
  874. build_tools::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().replace ("\n", "\r\n");;
  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().replace ("\n", "\r\n");;
  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. if (type == AAXPlugIn)
  922. {
  923. auto aaxLibsFolder = build_tools::RelativePath (owner.getAAXPathString(), build_tools::RelativePath::projectFolder).getChildFile ("Libs");
  924. defines.set ("JucePlugin_AAXLibs_path", createRebasedPath (aaxLibsFolder));
  925. }
  926. else if (type == RTASPlugIn)
  927. {
  928. build_tools::RelativePath rtasFolder (owner.getRTASPathString(), build_tools::RelativePath::projectFolder);
  929. defines.set ("JucePlugin_WinBag_path", createRebasedPath (rtasFolder.getChildFile ("WinBag")));
  930. }
  931. }
  932. String getExtraLinkerFlags() const
  933. {
  934. if (type == RTASPlugIn)
  935. return "/FORCE:multiple";
  936. return {};
  937. }
  938. StringArray getExtraSearchPaths() const
  939. {
  940. StringArray searchPaths;
  941. if (type == RTASPlugIn)
  942. {
  943. build_tools::RelativePath rtasFolder (owner.getRTASPathString(), build_tools::RelativePath::projectFolder);
  944. static const char* p[] = { "AlturaPorts/TDMPlugins/PluginLibrary/EffectClasses",
  945. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses",
  946. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses/Interfaces",
  947. "AlturaPorts/TDMPlugins/PluginLibrary/Utilities",
  948. "AlturaPorts/TDMPlugins/PluginLibrary/RTASP_Adapt",
  949. "AlturaPorts/TDMPlugins/PluginLibrary/CoreClasses",
  950. "AlturaPorts/TDMPlugins/PluginLibrary/Controls",
  951. "AlturaPorts/TDMPlugins/PluginLibrary/Meters",
  952. "AlturaPorts/TDMPlugins/PluginLibrary/ViewClasses",
  953. "AlturaPorts/TDMPlugins/PluginLibrary/DSPClasses",
  954. "AlturaPorts/TDMPlugins/PluginLibrary/Interfaces",
  955. "AlturaPorts/TDMPlugins/common",
  956. "AlturaPorts/TDMPlugins/common/Platform",
  957. "AlturaPorts/TDMPlugins/common/Macros",
  958. "AlturaPorts/TDMPlugins/SignalProcessing/Public",
  959. "AlturaPorts/TDMPlugIns/DSPManager/Interfaces",
  960. "AlturaPorts/SADriver/Interfaces",
  961. "AlturaPorts/DigiPublic/Interfaces",
  962. "AlturaPorts/DigiPublic",
  963. "AlturaPorts/Fic/Interfaces/DAEClient",
  964. "AlturaPorts/NewFileLibs/Cmn",
  965. "AlturaPorts/NewFileLibs/DOA",
  966. "AlturaPorts/AlturaSource/PPC_H",
  967. "AlturaPorts/AlturaSource/AppSupport",
  968. "AvidCode/AVX2sdk/AVX/avx2/avx2sdk/inc",
  969. "xplat/AVX/avx2/avx2sdk/inc" };
  970. for (auto* path : p)
  971. searchPaths.add (createRebasedPath (rtasFolder.getChildFile (path)));
  972. }
  973. return searchPaths;
  974. }
  975. String getBinaryNameWithSuffix (const MSVCBuildConfiguration& config, bool forceUnityPrefix) const
  976. {
  977. return config.getOutputFilename (getTargetSuffix(), true, forceUnityPrefix);
  978. }
  979. String getOutputFilePath (const MSVCBuildConfiguration& config, bool forceUnityPrefix) const
  980. {
  981. return getOwner().getOutDirFile (config, getBinaryNameWithSuffix (config, forceUnityPrefix));
  982. }
  983. StringArray getLibrarySearchPaths (const BuildConfiguration& config) const
  984. {
  985. auto librarySearchPaths = config.getLibrarySearchPaths();
  986. if (type != SharedCodeTarget)
  987. if (auto* shared = getOwner().getSharedCodeTarget())
  988. librarySearchPaths.add (shared->getConfigTargetPath (config));
  989. return librarySearchPaths;
  990. }
  991. String getExternalLibraries (const MSVCBuildConfiguration& config, const String& otherLibs) const
  992. {
  993. StringArray libraries;
  994. if (otherLibs.isNotEmpty())
  995. libraries.add (otherLibs);
  996. auto moduleLibs = getOwner().getModuleLibs();
  997. if (! moduleLibs.isEmpty())
  998. libraries.addArray (moduleLibs);
  999. if (type != SharedCodeTarget)
  1000. if (auto* shared = getOwner().getSharedCodeTarget())
  1001. libraries.add (shared->getBinaryNameWithSuffix (config, false));
  1002. return libraries.joinIntoString (";");
  1003. }
  1004. String getDelayLoadedDLLs() const
  1005. {
  1006. auto delayLoadedDLLs = getOwner().msvcDelayLoadedDLLs;
  1007. if (type == RTASPlugIn)
  1008. delayLoadedDLLs += "DAE.dll; DigiExt.dll; DSI.dll; PluginLib.dll; "
  1009. "DSPManager.dll; DSPManager.dll; DSPManagerClientLib.dll; RTASClientLib.dll";
  1010. return delayLoadedDLLs;
  1011. }
  1012. String getModuleDefinitions (const MSVCBuildConfiguration& config) const
  1013. {
  1014. auto moduleDefinitions = config.config [Ids::msvcModuleDefinitionFile].toString();
  1015. if (moduleDefinitions.isNotEmpty())
  1016. return moduleDefinitions;
  1017. if (type == RTASPlugIn)
  1018. {
  1019. auto& exp = getOwner();
  1020. auto moduleDefPath
  1021. = build_tools::RelativePath (exp.getPathForModuleString ("juce_audio_plugin_client"), build_tools::RelativePath::projectFolder)
  1022. .getChildFile ("juce_audio_plugin_client").getChildFile ("RTAS").getChildFile ("juce_RTAS_WinExports.def");
  1023. return prependDot (moduleDefPath.rebased (exp.getProject().getProjectFolder(),
  1024. exp.getTargetFolder(),
  1025. build_tools::RelativePath::buildTargetFolder).toWindowsStyle());
  1026. }
  1027. return {};
  1028. }
  1029. File getVCProjFile() const { return getOwner().getProjectFile (getProjectFileSuffix(), getName()); }
  1030. File getVCProjFiltersFile() const { return getOwner().getProjectFile (getFiltersFileSuffix(), getName()); }
  1031. String createRebasedPath (const build_tools::RelativePath& path) const { return getOwner().createRebasedPath (path); }
  1032. void addWindowsTargetPlatformToConfig (XmlElement& e) const
  1033. {
  1034. auto target = owner.getWindowsTargetPlatformVersion();
  1035. if (target == "Latest")
  1036. {
  1037. auto* child = e.createNewChildElement ("WindowsTargetPlatformVersion");
  1038. child->setAttribute ("Condition", "'$(WindowsTargetPlatformVersion)' == ''");
  1039. child->addTextElement ("$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))");
  1040. }
  1041. else
  1042. {
  1043. e.createNewChildElement ("WindowsTargetPlatformVersion")->addTextElement (target);
  1044. }
  1045. }
  1046. protected:
  1047. const MSVCProjectExporterBase& owner;
  1048. String projectGuid;
  1049. };
  1050. //==============================================================================
  1051. bool usesMMFiles() const override { return false; }
  1052. bool canCopeWithDuplicateFiles() override { return false; }
  1053. bool supportsUserDefinedConfigurations() const override { return true; }
  1054. bool isXcode() const override { return false; }
  1055. bool isVisualStudio() const override { return true; }
  1056. bool isCodeBlocks() const override { return false; }
  1057. bool isMakefile() const override { return false; }
  1058. bool isAndroidStudio() const override { return false; }
  1059. bool isCLion() const override { return false; }
  1060. bool isAndroid() const override { return false; }
  1061. bool isWindows() const override { return true; }
  1062. bool isLinux() const override { return false; }
  1063. bool isOSX() const override { return false; }
  1064. bool isiOS() const override { return false; }
  1065. bool supportsTargetType (build_tools::ProjectType::Target::Type type) const override
  1066. {
  1067. switch (type)
  1068. {
  1069. case build_tools::ProjectType::Target::StandalonePlugIn:
  1070. case build_tools::ProjectType::Target::GUIApp:
  1071. case build_tools::ProjectType::Target::ConsoleApp:
  1072. case build_tools::ProjectType::Target::StaticLibrary:
  1073. case build_tools::ProjectType::Target::SharedCodeTarget:
  1074. case build_tools::ProjectType::Target::AggregateTarget:
  1075. case build_tools::ProjectType::Target::VSTPlugIn:
  1076. case build_tools::ProjectType::Target::VST3PlugIn:
  1077. case build_tools::ProjectType::Target::AAXPlugIn:
  1078. case build_tools::ProjectType::Target::RTASPlugIn:
  1079. case build_tools::ProjectType::Target::UnityPlugIn:
  1080. case build_tools::ProjectType::Target::DynamicLibrary:
  1081. return true;
  1082. case build_tools::ProjectType::Target::AudioUnitPlugIn:
  1083. case build_tools::ProjectType::Target::AudioUnitv3PlugIn:
  1084. case build_tools::ProjectType::Target::unspecified:
  1085. default:
  1086. break;
  1087. }
  1088. return false;
  1089. }
  1090. //==============================================================================
  1091. build_tools::RelativePath getManifestPath() const
  1092. {
  1093. auto path = manifestFileValue.get().toString();
  1094. return path.isEmpty() ? build_tools::RelativePath()
  1095. : build_tools::RelativePath (path, build_tools::RelativePath::projectFolder);
  1096. }
  1097. //==============================================================================
  1098. bool launchProject() override
  1099. {
  1100. #if JUCE_WINDOWS
  1101. return getSLNFile().startAsProcess();
  1102. #else
  1103. return false;
  1104. #endif
  1105. }
  1106. bool canLaunchProject() override
  1107. {
  1108. #if JUCE_WINDOWS
  1109. return true;
  1110. #else
  1111. return false;
  1112. #endif
  1113. }
  1114. void createExporterProperties (PropertyListBuilder& props) override
  1115. {
  1116. props.add (new TextPropertyComponent (manifestFileValue, "Manifest file", 8192, false),
  1117. "Path to a manifest input file which should be linked into your binary (path is relative to jucer file).");
  1118. props.add (new ChoicePropertyComponent (IPPLibraryValue, "Use IPP Library",
  1119. { "No", "Yes (Default Linking)", "Multi-Threaded Static Library", "Single-Threaded Static Library", "Multi-Threaded DLL", "Single-Threaded DLL" },
  1120. { var(), "true", "Parallel_Static", "Sequential", "Parallel_Dynamic", "Sequential_Dynamic" }),
  1121. "Enable this to use Intel's Integrated Performance Primitives library.");
  1122. {
  1123. auto isWindows10SDK = getVisualStudioVersion() > 14;
  1124. props.add (new TextPropertyComponent (targetPlatformVersion, "Windows Target Platform", 20, false),
  1125. String ("Specifies the version of the Windows SDK that will be used when building this project. ")
  1126. + (isWindows10SDK ? "Leave this field empty to use the latest Windows 10 SDK installed on the build machine."
  1127. : "The default value for this exporter is " + getDefaultWindowsTargetPlatformVersion()));
  1128. }
  1129. }
  1130. enum OptimisationLevel
  1131. {
  1132. optimisationOff = 1,
  1133. optimiseMinSize = 2,
  1134. optimiseFull = 3,
  1135. optimiseMaxSpeed = 4
  1136. };
  1137. //==============================================================================
  1138. void addPlatformSpecificSettingsForProjectType (const build_tools::ProjectType& type) override
  1139. {
  1140. msvcExtraPreprocessorDefs.set ("_CRT_SECURE_NO_WARNINGS", "");
  1141. if (type.isCommandLineApp())
  1142. msvcExtraPreprocessorDefs.set("_CONSOLE", "");
  1143. callForAllSupportedTargets ([this] (build_tools::ProjectType::Target::Type targetType)
  1144. {
  1145. if (targetType != build_tools::ProjectType::Target::AggregateTarget)
  1146. targets.add (new MSVCTargetBase (targetType, *this));
  1147. });
  1148. // If you hit this assert, you tried to generate a project for an exporter
  1149. // that does not support any of your targets!
  1150. jassert (targets.size() > 0);
  1151. }
  1152. const MSVCTargetBase* getSharedCodeTarget() const
  1153. {
  1154. for (auto target : targets)
  1155. if (target->type == build_tools::ProjectType::Target::SharedCodeTarget)
  1156. return target;
  1157. return nullptr;
  1158. }
  1159. bool hasTarget (build_tools::ProjectType::Target::Type type) const
  1160. {
  1161. for (auto target : targets)
  1162. if (target->type == type)
  1163. return true;
  1164. return false;
  1165. }
  1166. static void createRCFile (const Project& p, const File& iconFile, const File& rcFile)
  1167. {
  1168. build_tools::ResourceRcOptions resourceRc;
  1169. resourceRc.version = p.getVersionString();
  1170. resourceRc.companyName = p.getCompanyNameString();
  1171. resourceRc.companyCopyright = p.getCompanyCopyrightString();
  1172. resourceRc.projectName = p.getProjectNameString();
  1173. resourceRc.icon = iconFile;
  1174. resourceRc.write (rcFile);
  1175. }
  1176. private:
  1177. //==============================================================================
  1178. String createRebasedPath (const build_tools::RelativePath& path) const
  1179. {
  1180. auto rebasedPath = rebaseFromProjectFolderToBuildTarget (path).toWindowsStyle();
  1181. return getVisualStudioVersion() < 10 // (VS10 automatically adds escape characters to the quotes for this definition)
  1182. ? CppTokeniserFunctions::addEscapeChars (rebasedPath.quoted())
  1183. : CppTokeniserFunctions::addEscapeChars (rebasedPath).quoted();
  1184. }
  1185. protected:
  1186. //==============================================================================
  1187. mutable File rcFile, iconFile, packagesConfigFile;
  1188. OwnedArray<MSVCTargetBase> targets;
  1189. ValueWithDefault IPPLibraryValue, platformToolsetValue, targetPlatformVersion, manifestFileValue;
  1190. File getProjectFile (const String& extension, const String& target) const
  1191. {
  1192. auto filename = project.getProjectFilenameRootString();
  1193. if (target.isNotEmpty())
  1194. filename += String ("_") + target.removeCharacters (" ");
  1195. return getTargetFolder().getChildFile (filename).withFileExtension (extension);
  1196. }
  1197. File getSLNFile() const { return getProjectFile (".sln", String()); }
  1198. static String prependIfNotAbsolute (const String& file, const char* prefix)
  1199. {
  1200. if (File::isAbsolutePath (file) || file.startsWithChar ('$'))
  1201. prefix = "";
  1202. return prefix + build_tools::windowsStylePath (file);
  1203. }
  1204. String getIntDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(IntDir)\\"); }
  1205. String getOutDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(OutDir)\\"); }
  1206. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override
  1207. {
  1208. return *new MSVCBuildConfiguration (project, v, *this);
  1209. }
  1210. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  1211. {
  1212. auto searchPaths = extraSearchPaths;
  1213. searchPaths.addArray (config.getHeaderSearchPaths());
  1214. return getCleanedStringArray (searchPaths);
  1215. }
  1216. String getSharedCodeGuid() const
  1217. {
  1218. String sharedCodeGuid;
  1219. for (int i = 0; i < targets.size(); ++i)
  1220. if (auto* target = targets[i])
  1221. if (target->type == build_tools::ProjectType::Target::SharedCodeTarget)
  1222. return target->getProjectGuid();
  1223. return {};
  1224. }
  1225. //==============================================================================
  1226. void writeProjectDependencies (OutputStream& out) const
  1227. {
  1228. auto sharedCodeGuid = getSharedCodeGuid();
  1229. for (int addingOtherTargets = 0; addingOtherTargets < (sharedCodeGuid.isNotEmpty() ? 2 : 1); ++addingOtherTargets)
  1230. {
  1231. for (int i = 0; i < targets.size(); ++i)
  1232. {
  1233. if (auto* target = targets[i])
  1234. {
  1235. if (sharedCodeGuid.isEmpty() || (addingOtherTargets != 0) == (target->type != build_tools::ProjectType::Target::StandalonePlugIn))
  1236. {
  1237. out << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"" << projectName << " - "
  1238. << target->getName() << "\", \""
  1239. << target->getVCProjFile().getFileName() << "\", \"" << target->getProjectGuid() << '"' << newLine;
  1240. if (sharedCodeGuid.isNotEmpty() && target->type != build_tools::ProjectType::Target::SharedCodeTarget)
  1241. out << "\tProjectSection(ProjectDependencies) = postProject" << newLine
  1242. << "\t\t" << sharedCodeGuid << " = " << sharedCodeGuid << newLine
  1243. << "\tEndProjectSection" << newLine;
  1244. out << "EndProject" << newLine;
  1245. }
  1246. }
  1247. }
  1248. }
  1249. }
  1250. void writeSolutionFile (OutputStream& out, const String& versionString, String commentString) const
  1251. {
  1252. if (commentString.isNotEmpty())
  1253. commentString += newLine;
  1254. out << "Microsoft Visual Studio Solution File, Format Version " << versionString << newLine
  1255. << commentString << newLine;
  1256. writeProjectDependencies (out);
  1257. out << "Global" << newLine
  1258. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  1259. for (ConstConfigIterator i (*this); i.next();)
  1260. {
  1261. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  1262. auto configName = config.createMSVCConfigName();
  1263. out << "\t\t" << configName << " = " << configName << newLine;
  1264. }
  1265. out << "\tEndGlobalSection" << newLine
  1266. << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" << newLine;
  1267. for (auto& target : targets)
  1268. for (ConstConfigIterator i (*this); i.next();)
  1269. {
  1270. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  1271. auto configName = config.createMSVCConfigName();
  1272. for (auto& suffix : { "ActiveCfg", "Build.0" })
  1273. out << "\t\t" << target->getProjectGuid() << "." << configName << "." << suffix << " = " << configName << newLine;
  1274. }
  1275. out << "\tEndGlobalSection" << newLine
  1276. << "\tGlobalSection(SolutionProperties) = preSolution" << newLine
  1277. << "\t\tHideSolutionNode = FALSE" << newLine
  1278. << "\tEndGlobalSection" << newLine;
  1279. out << "EndGlobal" << newLine;
  1280. }
  1281. //==============================================================================
  1282. bool hasResourceFile() const
  1283. {
  1284. return ! projectType.isStaticLibrary();
  1285. }
  1286. void createResourcesAndIcon() const
  1287. {
  1288. if (hasResourceFile())
  1289. {
  1290. iconFile = getTargetFolder().getChildFile ("icon.ico");
  1291. build_tools::writeWinIcon (getIcons(), iconFile);
  1292. rcFile = getTargetFolder().getChildFile ("resources.rc");
  1293. createRCFile (project, iconFile, rcFile);
  1294. }
  1295. }
  1296. bool shouldAddWebView2Package() const
  1297. {
  1298. return project.getEnabledModules().isModuleEnabled ("juce_gui_extra")
  1299. && project.isConfigFlagEnabled ("JUCE_USE_WIN_WEBVIEW2", false);
  1300. }
  1301. static String getWebView2PackageName() { return "Microsoft.Web.WebView2"; }
  1302. static String getWebView2PackageVersion() { return "0.9.488"; }
  1303. void createPackagesConfigFile() const
  1304. {
  1305. if (shouldAddWebView2Package())
  1306. {
  1307. packagesConfigFile = getTargetFolder().getChildFile ("packages.config");
  1308. build_tools::writeStreamToFile (packagesConfigFile, [] (MemoryOutputStream& mo)
  1309. {
  1310. mo.setNewLineString ("\r\n");
  1311. mo << "<?xml version=\"1.0\" encoding=\"utf-8\"?>" << newLine
  1312. << "<packages>" << newLine
  1313. << "\t" << "<package id=" << getWebView2PackageName().quoted()
  1314. << " version=" << getWebView2PackageVersion().quoted()
  1315. << " />" << newLine
  1316. << "</packages>" << newLine;
  1317. });
  1318. }
  1319. }
  1320. static String prependDot (const String& filename)
  1321. {
  1322. return build_tools::isAbsolutePath (filename) ? filename
  1323. : (".\\" + filename);
  1324. }
  1325. static bool shouldUseStdCall (const build_tools::RelativePath& path)
  1326. {
  1327. return path.getFileNameWithoutExtension().startsWithIgnoreCase ("include_juce_audio_plugin_client_RTAS_");
  1328. }
  1329. StringArray getModuleLibs() const
  1330. {
  1331. StringArray result;
  1332. for (auto& lib : windowsLibs)
  1333. result.add (lib + ".lib");
  1334. return result;
  1335. }
  1336. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase)
  1337. };
  1338. //==============================================================================
  1339. class MSVCProjectExporterVC2015 : public MSVCProjectExporterBase
  1340. {
  1341. public:
  1342. MSVCProjectExporterVC2015 (Project& p, const ValueTree& t)
  1343. : MSVCProjectExporterBase (p, t, getTargetFolderName())
  1344. {
  1345. name = getDisplayName();
  1346. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1347. platformToolsetValue.setDefault (getDefaultToolset());
  1348. }
  1349. static String getDisplayName() { return "Visual Studio 2015"; }
  1350. static String getValueTreeTypeName() { return "VS2015"; }
  1351. static String getTargetFolderName() { return "VisualStudio2015"; }
  1352. int getVisualStudioVersion() const override { return 14; }
  1353. String getSolutionComment() const override { return "# Visual Studio 2015"; }
  1354. String getToolsVersion() const override { return "14.0"; }
  1355. String getDefaultToolset() const override { return "v140"; }
  1356. String getDefaultWindowsTargetPlatformVersion() const override { return "8.1"; }
  1357. static MSVCProjectExporterVC2015* createForSettings (Project& projectToUse, const ValueTree& settingsToUse)
  1358. {
  1359. if (settingsToUse.hasType (getValueTreeTypeName()))
  1360. return new MSVCProjectExporterVC2015 (projectToUse, settingsToUse);
  1361. return nullptr;
  1362. }
  1363. void createExporterProperties (PropertyListBuilder& props) override
  1364. {
  1365. static const char* toolsetNames[] = { "v140", "v140_xp", "CTP_Nov2013" };
  1366. const var toolsets[] = { "v140", "v140_xp", "CTP_Nov2013" };
  1367. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1368. MSVCProjectExporterBase::createExporterProperties (props);
  1369. }
  1370. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2015)
  1371. };
  1372. //==============================================================================
  1373. class MSVCProjectExporterVC2017 : public MSVCProjectExporterBase
  1374. {
  1375. public:
  1376. MSVCProjectExporterVC2017 (Project& p, const ValueTree& t)
  1377. : MSVCProjectExporterBase (p, t, getTargetFolderName())
  1378. {
  1379. name = getDisplayName();
  1380. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1381. platformToolsetValue.setDefault (getDefaultToolset());
  1382. }
  1383. static String getDisplayName() { return "Visual Studio 2017"; }
  1384. static String getValueTreeTypeName() { return "VS2017"; }
  1385. static String getTargetFolderName() { return "VisualStudio2017"; }
  1386. int getVisualStudioVersion() const override { return 15; }
  1387. String getSolutionComment() const override { return "# Visual Studio 2017"; }
  1388. String getToolsVersion() const override { return "15.0"; }
  1389. String getDefaultToolset() const override { return "v141"; }
  1390. String getDefaultWindowsTargetPlatformVersion() const override { return "Latest"; }
  1391. static MSVCProjectExporterVC2017* createForSettings (Project& projectToUse, const ValueTree& settingsToUse)
  1392. {
  1393. if (settingsToUse.hasType (getValueTreeTypeName()))
  1394. return new MSVCProjectExporterVC2017 (projectToUse, settingsToUse);
  1395. return nullptr;
  1396. }
  1397. void createExporterProperties (PropertyListBuilder& props) override
  1398. {
  1399. static const char* toolsetNames[] = { "v140", "v140_xp", "v141", "v141_xp" };
  1400. const var toolsets[] = { "v140", "v140_xp", "v141", "v141_xp" };
  1401. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1402. MSVCProjectExporterBase::createExporterProperties (props);
  1403. }
  1404. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2017)
  1405. };
  1406. //==============================================================================
  1407. class MSVCProjectExporterVC2019 : public MSVCProjectExporterBase
  1408. {
  1409. public:
  1410. MSVCProjectExporterVC2019 (Project& p, const ValueTree& t)
  1411. : MSVCProjectExporterBase (p, t, getTargetFolderName())
  1412. {
  1413. name = getDisplayName();
  1414. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1415. platformToolsetValue.setDefault (getDefaultToolset());
  1416. }
  1417. static String getDisplayName() { return "Visual Studio 2019"; }
  1418. static String getValueTreeTypeName() { return "VS2019"; }
  1419. static String getTargetFolderName() { return "VisualStudio2019"; }
  1420. int getVisualStudioVersion() const override { return 16; }
  1421. String getSolutionComment() const override { return "# Visual Studio 2019"; }
  1422. String getToolsVersion() const override { return "16.0"; }
  1423. String getDefaultToolset() const override { return "v142"; }
  1424. String getDefaultWindowsTargetPlatformVersion() const override { return "10.0"; }
  1425. static MSVCProjectExporterVC2019* createForSettings (Project& projectToUse, const ValueTree& settingsToUse)
  1426. {
  1427. if (settingsToUse.hasType (getValueTreeTypeName()))
  1428. return new MSVCProjectExporterVC2019 (projectToUse, settingsToUse);
  1429. return nullptr;
  1430. }
  1431. void createExporterProperties (PropertyListBuilder& props) override
  1432. {
  1433. static const char* toolsetNames[] = { "v140", "v140_xp", "v141", "v141_xp", "v142" };
  1434. const var toolsets[] = { "v140", "v140_xp", "v141", "v141_xp", "v142" };
  1435. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1436. MSVCProjectExporterBase::createExporterProperties (props);
  1437. }
  1438. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2019)
  1439. };