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.

1895 lines
94KB

  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. const auto pdbFilename = getOwner().getIntDirFile (config, config.getOutputFilename (".pdb", true, type == UnityPlugIn));
  431. {
  432. auto* cl = group->createNewChildElement ("ClCompile");
  433. cl->createNewChildElement ("Optimization")->addTextElement (getOptimisationLevelString (config.getOptimisationLevelInt()));
  434. if (isDebug || config.shouldGenerateDebugSymbols())
  435. {
  436. cl->createNewChildElement ("DebugInformationFormat")
  437. ->addTextElement (config.getDebugInformationFormatString());
  438. }
  439. auto includePaths = getOwner().getHeaderSearchPaths (config);
  440. includePaths.addArray (getExtraSearchPaths());
  441. includePaths.add ("%(AdditionalIncludeDirectories)");
  442. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  443. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  444. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (config.isUsingRuntimeLibDLL() ? (isDebug ? "MultiThreadedDebugDLL" : "MultiThreadedDLL")
  445. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  446. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  447. cl->createNewChildElement ("PrecompiledHeader")->addTextElement ("NotUsing");
  448. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement ("$(IntDir)\\");
  449. cl->createNewChildElement ("ObjectFileName")->addTextElement ("$(IntDir)\\");
  450. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement (pdbFilename);
  451. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level" + String (config.getWarningLevel()));
  452. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  453. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement (config.shouldUseMultiProcessorCompilation() ? "true" : "false");
  454. if (config.isFastMathEnabled())
  455. cl->createNewChildElement ("FloatingPointModel")->addTextElement ("Fast");
  456. auto extraFlags = getOwner().replacePreprocessorTokens (config, getOwner().getExtraCompilerFlagsString()).trim();
  457. if (extraFlags.isNotEmpty())
  458. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  459. if (config.areWarningsTreatedAsErrors())
  460. cl->createNewChildElement ("TreatWarningAsError")->addTextElement ("true");
  461. auto cppStandard = owner.project.getCppStandardString();
  462. if (cppStandard == "11") // VS doesn't support the C++11 flag so we have to bump it to C++14
  463. cppStandard = "14";
  464. cl->createNewChildElement ("LanguageStandard")->addTextElement ("stdcpp" + cppStandard);
  465. }
  466. {
  467. auto* res = group->createNewChildElement ("ResourceCompile");
  468. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  469. : "NDEBUG;%(PreprocessorDefinitions)");
  470. }
  471. auto externalLibraries = getExternalLibraries (config, getOwner().getExternalLibrariesString());
  472. auto additionalDependencies = type != SharedCodeTarget && externalLibraries.isNotEmpty()
  473. ? getOwner().replacePreprocessorTokens (config, externalLibraries).trim() + ";%(AdditionalDependencies)"
  474. : String();
  475. auto librarySearchPaths = config.getLibrarySearchPaths();
  476. auto additionalLibraryDirs = type != SharedCodeTarget && librarySearchPaths.size() > 0
  477. ? getOwner().replacePreprocessorTokens (config, librarySearchPaths.joinIntoString (";")) + ";%(AdditionalLibraryDirectories)"
  478. : String();
  479. {
  480. auto* link = group->createNewChildElement ("Link");
  481. link->createNewChildElement ("OutputFile")->addTextElement (getOutputFilePath (config, type == UnityPlugIn));
  482. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  483. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  484. : "%(IgnoreSpecificDefaultLibraries)");
  485. link->createNewChildElement ("GenerateDebugInformation")->addTextElement ((isDebug || config.shouldGenerateDebugSymbols()) ? "true" : "false");
  486. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (pdbFilename);
  487. link->createNewChildElement ("SubSystem")->addTextElement (type == ConsoleApp ? "Console" : "Windows");
  488. if (! config.is64Bit())
  489. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  490. if (isUsingEditAndContinue)
  491. link->createNewChildElement ("ImageHasSafeExceptionHandlers")->addTextElement ("false");
  492. if (! isDebug)
  493. {
  494. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  495. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  496. }
  497. if (additionalLibraryDirs.isNotEmpty())
  498. link->createNewChildElement ("AdditionalLibraryDirectories")->addTextElement (additionalLibraryDirs);
  499. link->createNewChildElement ("LargeAddressAware")->addTextElement ("true");
  500. if (config.isLinkTimeOptimisationEnabled())
  501. link->createNewChildElement ("LinkTimeCodeGeneration")->addTextElement ("UseLinkTimeCodeGeneration");
  502. if (additionalDependencies.isNotEmpty())
  503. link->createNewChildElement ("AdditionalDependencies")->addTextElement (additionalDependencies);
  504. auto extraLinkerOptions = getOwner().getExtraLinkerFlagsString();
  505. if (extraLinkerOptions.isNotEmpty())
  506. link->createNewChildElement ("AdditionalOptions")->addTextElement (getOwner().replacePreprocessorTokens (config, extraLinkerOptions).trim()
  507. + " %(AdditionalOptions)");
  508. auto delayLoadedDLLs = getDelayLoadedDLLs();
  509. if (delayLoadedDLLs.isNotEmpty())
  510. link->createNewChildElement ("DelayLoadDLLs")->addTextElement (delayLoadedDLLs);
  511. auto moduleDefinitionsFile = getModuleDefinitions (config);
  512. if (moduleDefinitionsFile.isNotEmpty())
  513. link->createNewChildElement ("ModuleDefinitionFile")
  514. ->addTextElement (moduleDefinitionsFile);
  515. }
  516. {
  517. auto* bsc = group->createNewChildElement ("Bscmake");
  518. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  519. bsc->createNewChildElement ("OutputFile")->addTextElement (getOwner().getIntDirFile (config, config.getOutputFilename (".bsc", true, type == UnityPlugIn)));
  520. }
  521. if (type != SharedCodeTarget)
  522. {
  523. auto* lib = group->createNewChildElement ("Lib");
  524. if (additionalDependencies.isNotEmpty())
  525. lib->createNewChildElement ("AdditionalDependencies")->addTextElement (additionalDependencies);
  526. if (additionalLibraryDirs.isNotEmpty())
  527. lib->createNewChildElement ("AdditionalLibraryDirectories")->addTextElement (additionalLibraryDirs);
  528. }
  529. auto manifestFile = getOwner().getManifestPath();
  530. if (manifestFile.getRoot() != build_tools::RelativePath::unknown)
  531. {
  532. auto* bsc = group->createNewChildElement ("Manifest");
  533. bsc->createNewChildElement ("AdditionalManifestFiles")
  534. ->addTextElement (manifestFile.rebased (getOwner().getProject().getFile().getParentDirectory(),
  535. getOwner().getTargetFolder(),
  536. build_tools::RelativePath::buildTargetFolder).toWindowsStyle());
  537. }
  538. if (getTargetFileType() == staticLibrary && ! config.is64Bit())
  539. {
  540. auto* lib = group->createNewChildElement ("Lib");
  541. lib->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  542. }
  543. auto preBuild = getPreBuildSteps (config);
  544. if (preBuild.isNotEmpty())
  545. group->createNewChildElement ("PreBuildEvent")
  546. ->createNewChildElement ("Command")
  547. ->addTextElement (preBuild);
  548. auto postBuild = getPostBuildSteps (config);
  549. if (postBuild.isNotEmpty())
  550. group->createNewChildElement ("PostBuildEvent")
  551. ->createNewChildElement ("Command")
  552. ->addTextElement (postBuild);
  553. }
  554. std::unique_ptr<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  555. {
  556. auto* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  557. auto* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  558. writePrecompiledHeaderFiles (*cppFiles);
  559. for (int i = 0; i < getOwner().getAllGroups().size(); ++i)
  560. {
  561. auto& group = getOwner().getAllGroups().getReference (i);
  562. if (group.getNumChildren() > 0)
  563. addFilesToCompile (group, *cppFiles, *headerFiles, *otherFilesGroup);
  564. }
  565. }
  566. if (getOwner().iconFile.existsAsFile())
  567. {
  568. auto* e = otherFilesGroup->createNewChildElement ("None");
  569. e->setAttribute ("Include", prependDot (getOwner().iconFile.getFileName()));
  570. }
  571. if (getOwner().packagesConfigFile.existsAsFile())
  572. {
  573. auto* e = otherFilesGroup->createNewChildElement ("None");
  574. e->setAttribute ("Include", getOwner().packagesConfigFile.getFileName());
  575. }
  576. if (otherFilesGroup->getFirstChildElement() != nullptr)
  577. projectXml.addChildElement (otherFilesGroup.release());
  578. if (type != SharedCodeTarget && getOwner().hasResourceFile())
  579. {
  580. auto* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  581. auto* e = rcGroup->createNewChildElement ("ResourceCompile");
  582. e->setAttribute ("Include", prependDot (getOwner().rcFile.getFileName()));
  583. }
  584. {
  585. auto* e = projectXml.createNewChildElement ("Import");
  586. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  587. }
  588. {
  589. auto* importGroup = projectXml.createNewChildElement ("ImportGroup");
  590. importGroup->setAttribute ("Label", "ExtensionTargets");
  591. if (owner.shouldAddWebView2Package())
  592. {
  593. auto packageTargetsPath = "packages\\" + getWebView2PackageName() + "." + getWebView2PackageVersion()
  594. + "\\build\\native\\" + getWebView2PackageName() + ".targets";
  595. auto* e = importGroup->createNewChildElement ("Import");
  596. e->setAttribute ("Project", packageTargetsPath);
  597. e->setAttribute ("Condition", "Exists('" + packageTargetsPath + "')");
  598. }
  599. }
  600. }
  601. String getProjectType() const
  602. {
  603. auto targetFileType = getTargetFileType();
  604. if (targetFileType == executable) return "Application";
  605. if (targetFileType == staticLibrary) return "StaticLibrary";
  606. return "DynamicLibrary";
  607. }
  608. //==============================================================================
  609. static void setSourceFilePCHSettings (XmlElement& element, const File& pchFile, const String& option, const BuildConfiguration& config)
  610. {
  611. auto setConfigConditionAttribute = [&config] (XmlElement* elementToSet) -> XmlElement*
  612. {
  613. setConditionAttribute (*elementToSet, config);
  614. return elementToSet;
  615. };
  616. setConfigConditionAttribute (element.createNewChildElement ("PrecompiledHeader"))->addTextElement (option);
  617. setConfigConditionAttribute (element.createNewChildElement ("PrecompiledHeaderFile"))->addTextElement (pchFile.getFileName());
  618. setConfigConditionAttribute (element.createNewChildElement ("PrecompiledHeaderOutputFile"))->addTextElement ("$(Platform)\\$(Configuration)\\JucePrecompiledHeader.pch");
  619. setConfigConditionAttribute (element.createNewChildElement ("ForcedIncludeFiles"))->addTextElement (pchFile.getFileName());
  620. }
  621. void writePrecompiledHeaderFiles (XmlElement& cpps) const
  622. {
  623. for (ConstConfigIterator config (owner); config.next();)
  624. {
  625. if (config->shouldUsePrecompiledHeaderFile())
  626. {
  627. auto pchFileContent = config->getPrecompiledHeaderFileContent();
  628. if (pchFileContent.isNotEmpty())
  629. {
  630. auto pchFile = owner.getTargetFolder().getChildFile (config->getPrecompiledHeaderFilename()).withFileExtension (".h");
  631. build_tools::writeStreamToFile (pchFile, [&] (MemoryOutputStream& mo)
  632. {
  633. mo << pchFileContent;
  634. });
  635. auto pchSourceFile = pchFile.withFileExtension (".cpp");
  636. build_tools::writeStreamToFile (pchSourceFile, [this] (MemoryOutputStream& mo)
  637. {
  638. mo.setNewLineString (owner.getNewLineString());
  639. writeAutoGenWarningComment (mo);
  640. mo << " This is an empty source file generated by JUCE required for Visual Studio PCH." << newLine
  641. << newLine
  642. << "*/" << newLine
  643. << newLine;
  644. });
  645. auto* pchSourceElement = cpps.createNewChildElement ("ClCompile");
  646. pchSourceElement->setAttribute ("Include", prependDot (pchSourceFile.getFileName()));
  647. setSourceFilePCHSettings (*pchSourceElement, pchFile, "Create", *config);
  648. }
  649. }
  650. }
  651. }
  652. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  653. {
  654. auto targetType = (getOwner().getProject().isAudioPluginProject() ? type : SharedCodeTarget);
  655. if (projectItem.isGroup())
  656. {
  657. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  658. addFilesToCompile (projectItem.getChild (i), cpps, headers, otherFiles);
  659. }
  660. else if (projectItem.shouldBeAddedToTargetProject() && projectItem.shouldBeAddedToTargetExporter (getOwner())
  661. && getOwner().getProject().getTargetTypeFromFilePath (projectItem.getFile(), true) == targetType)
  662. {
  663. build_tools::RelativePath path (projectItem.getFile(), getOwner().getTargetFolder(), build_tools::RelativePath::buildTargetFolder);
  664. jassert (path.getRoot() == build_tools::RelativePath::buildTargetFolder);
  665. if (path.hasFileExtension (cOrCppFileExtensions) || path.hasFileExtension (asmFileExtensions))
  666. {
  667. auto* e = cpps.createNewChildElement ("ClCompile");
  668. e->setAttribute ("Include", path.toWindowsStyle());
  669. if (shouldUseStdCall (path))
  670. e->createNewChildElement ("CallingConvention")->addTextElement ("StdCall");
  671. if (projectItem.shouldBeCompiled())
  672. {
  673. auto extraCompilerFlags = owner.compilerFlagSchemesMap[projectItem.getCompilerFlagSchemeString()].get().toString();
  674. if (shouldAddBigobjFlag (path))
  675. {
  676. const String bigobjFlag ("/bigobj");
  677. if (! extraCompilerFlags.contains (bigobjFlag))
  678. {
  679. extraCompilerFlags << " " << bigobjFlag;
  680. extraCompilerFlags.trim();
  681. }
  682. }
  683. if (extraCompilerFlags.isNotEmpty())
  684. e->createNewChildElement ("AdditionalOptions")->addTextElement (extraCompilerFlags + " %(AdditionalOptions)");
  685. if (! projectItem.shouldSkipPCH())
  686. {
  687. for (ConstConfigIterator i (owner); i.next();)
  688. {
  689. if (i->shouldUsePrecompiledHeaderFile())
  690. {
  691. auto pchFile = owner.getTargetFolder().getChildFile (i->getPrecompiledHeaderFilename()).withFileExtension (".h");
  692. if (pchFile.existsAsFile())
  693. setSourceFilePCHSettings (*e, pchFile, "Use", *i);
  694. }
  695. }
  696. }
  697. }
  698. else
  699. {
  700. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  701. }
  702. }
  703. else if (path.hasFileExtension (headerFileExtensions))
  704. {
  705. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", path.toWindowsStyle());
  706. }
  707. else if (! path.hasFileExtension (objCFileExtensions))
  708. {
  709. otherFiles.createNewChildElement ("None")->setAttribute ("Include", path.toWindowsStyle());
  710. }
  711. }
  712. }
  713. static void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config)
  714. {
  715. auto& msvcConfig = dynamic_cast<const MSVCBuildConfiguration&> (config);
  716. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + msvcConfig.createMSVCConfigName() + "'");
  717. }
  718. //==============================================================================
  719. void addFilterGroup (XmlElement& groups, const String& path) const
  720. {
  721. auto* e = groups.createNewChildElement ("Filter");
  722. e->setAttribute ("Include", path);
  723. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  724. }
  725. void addFileToFilter (const build_tools::RelativePath& file, const String& groupPath,
  726. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  727. {
  728. XmlElement* e = nullptr;
  729. if (file.hasFileExtension (headerFileExtensions))
  730. e = headers.createNewChildElement ("ClInclude");
  731. else if (file.hasFileExtension (sourceFileExtensions))
  732. e = cpps.createNewChildElement ("ClCompile");
  733. else
  734. e = otherFiles.createNewChildElement ("None");
  735. jassert (file.getRoot() == build_tools::RelativePath::buildTargetFolder);
  736. e->setAttribute ("Include", file.toWindowsStyle());
  737. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  738. }
  739. bool addFilesToFilter (const Project::Item& projectItem, const String& path,
  740. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups) const
  741. {
  742. auto targetType = (getOwner().getProject().isAudioPluginProject() ? type : SharedCodeTarget);
  743. if (projectItem.isGroup())
  744. {
  745. bool filesWereAdded = false;
  746. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  747. if (addFilesToFilter (projectItem.getChild(i),
  748. (path.isEmpty() ? String() : (path + "\\")) + projectItem.getChild(i).getName(),
  749. cpps, headers, otherFiles, groups))
  750. filesWereAdded = true;
  751. if (filesWereAdded)
  752. addFilterGroup (groups, path);
  753. return filesWereAdded;
  754. }
  755. else if (projectItem.shouldBeAddedToTargetProject()
  756. && projectItem.shouldBeAddedToTargetExporter (getOwner())
  757. && getOwner().getProject().getTargetTypeFromFilePath (projectItem.getFile(), true) == targetType)
  758. {
  759. build_tools::RelativePath relativePath (projectItem.getFile(),
  760. getOwner().getTargetFolder(),
  761. build_tools::RelativePath::buildTargetFolder);
  762. jassert (relativePath.getRoot() == build_tools::RelativePath::buildTargetFolder);
  763. addFileToFilter (relativePath, path.upToLastOccurrenceOf ("\\", false, false), cpps, headers, otherFiles);
  764. return true;
  765. }
  766. return false;
  767. }
  768. void fillInFiltersXml (XmlElement& filterXml) const
  769. {
  770. filterXml.setAttribute ("ToolsVersion", getOwner().getToolsVersion());
  771. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  772. auto* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  773. auto* cpps = filterXml.createNewChildElement ("ItemGroup");
  774. auto* headers = filterXml.createNewChildElement ("ItemGroup");
  775. std::unique_ptr<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  776. for (int i = 0; i < getOwner().getAllGroups().size(); ++i)
  777. {
  778. auto& group = getOwner().getAllGroups().getReference(i);
  779. if (group.getNumChildren() > 0)
  780. addFilesToFilter (group, group.getName(), *cpps, *headers, *otherFilesGroup, *groupsXml);
  781. }
  782. if (getOwner().iconFile.existsAsFile())
  783. {
  784. auto* e = otherFilesGroup->createNewChildElement ("None");
  785. e->setAttribute ("Include", prependDot (getOwner().iconFile.getFileName()));
  786. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  787. }
  788. if (getOwner().packagesConfigFile.existsAsFile())
  789. {
  790. auto* e = otherFilesGroup->createNewChildElement ("None");
  791. e->setAttribute ("Include", getOwner().packagesConfigFile.getFileName());
  792. }
  793. if (otherFilesGroup->getFirstChildElement() != nullptr)
  794. filterXml.addChildElement (otherFilesGroup.release());
  795. if (type != SharedCodeTarget && getOwner().hasResourceFile())
  796. {
  797. auto* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  798. auto* e = rcGroup->createNewChildElement ("ResourceCompile");
  799. e->setAttribute ("Include", prependDot (getOwner().rcFile.getFileName()));
  800. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  801. }
  802. }
  803. const MSVCProjectExporterBase& getOwner() const { return owner; }
  804. const String& getProjectGuid() const { return projectGuid; }
  805. //==============================================================================
  806. void writeProjectFile()
  807. {
  808. {
  809. XmlElement projectXml (getTopLevelXmlEntity());
  810. fillInProjectXml (projectXml);
  811. writeXmlOrThrow (projectXml, getVCProjFile(), "UTF-8", 10);
  812. }
  813. {
  814. XmlElement filtersXml (getTopLevelXmlEntity());
  815. fillInFiltersXml (filtersXml);
  816. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "UTF-8", 100);
  817. }
  818. }
  819. String getSolutionTargetPath (const BuildConfiguration& config) const
  820. {
  821. auto binaryPath = config.getTargetBinaryRelativePathString().trim();
  822. if (binaryPath.isEmpty())
  823. return "$(SolutionDir)$(Platform)\\$(Configuration)";
  824. build_tools::RelativePath binaryRelPath (binaryPath, build_tools::RelativePath::projectFolder);
  825. if (binaryRelPath.isAbsolute())
  826. return binaryRelPath.toWindowsStyle();
  827. return prependDot (binaryRelPath.rebased (getOwner().projectFolder,
  828. getOwner().getTargetFolder(),
  829. build_tools::RelativePath::buildTargetFolder)
  830. .toWindowsStyle());
  831. }
  832. String getConfigTargetPath (const BuildConfiguration& config) const
  833. {
  834. auto solutionTargetFolder = getSolutionTargetPath (config);
  835. return solutionTargetFolder + "\\" + getName();
  836. }
  837. String getIntermediatesPath (const MSVCBuildConfiguration& config) const
  838. {
  839. auto intDir = (config.getIntermediatesPathString().isNotEmpty() ? config.getIntermediatesPathString()
  840. : "$(Platform)\\$(Configuration)");
  841. if (! intDir.endsWithChar (L'\\'))
  842. intDir += L'\\';
  843. return intDir + getName();
  844. }
  845. static const char* getOptimisationLevelString (int level)
  846. {
  847. switch (level)
  848. {
  849. case optimiseMinSize: return "MinSpace";
  850. case optimiseMaxSpeed: return "MaxSpeed";
  851. case optimiseFull: return "Full";
  852. default: return "Disabled";
  853. }
  854. }
  855. String getTargetSuffix() const
  856. {
  857. auto fileType = getTargetFileType();
  858. if (fileType == executable) return ".exe";
  859. if (fileType == staticLibrary) return ".lib";
  860. if (fileType == sharedLibraryOrDLL) return ".dll";
  861. if (fileType == pluginBundle)
  862. {
  863. if (type == VST3PlugIn) return ".vst3";
  864. if (type == AAXPlugIn) return ".aaxdll";
  865. if (type == RTASPlugIn) return ".dpm";
  866. return ".dll";
  867. }
  868. return {};
  869. }
  870. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  871. {
  872. auto* e = parent.createNewChildElement ("Tool");
  873. e->setAttribute ("Name", toolName);
  874. return e;
  875. }
  876. String getPreprocessorDefs (const BuildConfiguration& config, const String& joinString) const
  877. {
  878. auto defines = getOwner().msvcExtraPreprocessorDefs;
  879. defines.set ("WIN32", "");
  880. defines.set ("_WINDOWS", "");
  881. if (config.isDebug())
  882. {
  883. defines.set ("DEBUG", "");
  884. defines.set ("_DEBUG", "");
  885. }
  886. else
  887. {
  888. defines.set ("NDEBUG", "");
  889. }
  890. defines = mergePreprocessorDefs (defines, getOwner().getAllPreprocessorDefs (config, type));
  891. addExtraPreprocessorDefines (defines);
  892. if (getTargetFileType() == staticLibrary || getTargetFileType() == sharedLibraryOrDLL)
  893. defines.set("_LIB", "");
  894. StringArray result;
  895. for (int i = 0; i < defines.size(); ++i)
  896. {
  897. auto def = defines.getAllKeys()[i];
  898. auto value = defines.getAllValues()[i];
  899. if (value.isNotEmpty())
  900. def << "=" << value;
  901. result.add (def);
  902. }
  903. return result.joinIntoString (joinString);
  904. }
  905. //==============================================================================
  906. build_tools::RelativePath getAAXIconFile() const
  907. {
  908. build_tools::RelativePath aaxSDK (owner.getAAXPathString(), build_tools::RelativePath::projectFolder);
  909. build_tools::RelativePath projectIcon ("icon.ico", build_tools::RelativePath::buildTargetFolder);
  910. if (getOwner().getTargetFolder().getChildFile ("icon.ico").existsAsFile())
  911. return projectIcon.rebased (getOwner().getTargetFolder(),
  912. getOwner().getProject().getProjectFolder(),
  913. build_tools::RelativePath::projectFolder);
  914. return aaxSDK.getChildFile ("Utilities").getChildFile ("PlugIn.ico");
  915. }
  916. String getExtraPostBuildSteps (const MSVCBuildConfiguration& config) const
  917. {
  918. if (type == AAXPlugIn)
  919. {
  920. build_tools::RelativePath aaxSDK (owner.getAAXPathString(), build_tools::RelativePath::projectFolder);
  921. build_tools::RelativePath aaxLibsFolder = aaxSDK.getChildFile ("Libs");
  922. build_tools::RelativePath bundleScript = aaxSDK.getChildFile ("Utilities").getChildFile ("CreatePackage.bat");
  923. build_tools::RelativePath iconFilePath = getAAXIconFile();
  924. auto outputFilename = config.getOutputFilename (".aaxplugin", true, false);
  925. auto bundleDir = getOwner().getOutDirFile (config, outputFilename);
  926. auto bundleContents = bundleDir + "\\Contents";
  927. auto archDir = bundleContents + String ("\\") + (config.is64Bit() ? "x64" : "Win32");
  928. auto executable = archDir + String ("\\") + outputFilename;
  929. auto pkgScript = String ("copy /Y ") + getOutputFilePath (config, false).quoted() + String (" ") + executable.quoted() + String ("\r\ncall ")
  930. + createRebasedPath (bundleScript) + String (" ") + archDir.quoted() + String (" ") + createRebasedPath (iconFilePath);
  931. if (config.isPluginBinaryCopyStepEnabled())
  932. return pkgScript + "\r\n" + "xcopy " + bundleDir.quoted() + " "
  933. + String (config.getAAXBinaryLocationString() + "\\" + outputFilename + "\\").quoted() + " /E /H /K /R /Y";
  934. return pkgScript;
  935. }
  936. else if (type == UnityPlugIn)
  937. {
  938. build_tools::RelativePath scriptPath (config.project.getGeneratedCodeFolder().getChildFile (config.project.getUnityScriptName()),
  939. getOwner().getTargetFolder(),
  940. build_tools::RelativePath::projectFolder);
  941. auto pkgScript = String ("copy /Y ") + scriptPath.toWindowsStyle().quoted() + " \"$(OutDir)\"";
  942. if (config.isPluginBinaryCopyStepEnabled())
  943. {
  944. auto copyLocation = config.getUnityPluginBinaryLocationString();
  945. pkgScript += "\r\ncopy /Y \"$(OutDir)$(TargetFileName)\" " + String (copyLocation + "\\$(TargetFileName)").quoted();
  946. pkgScript += "\r\ncopy /Y " + String ("$(OutDir)" + config.project.getUnityScriptName()).quoted() + " " + String (copyLocation + "\\" + config.project.getUnityScriptName()).quoted();
  947. }
  948. return pkgScript;
  949. }
  950. else if (config.isPluginBinaryCopyStepEnabled())
  951. {
  952. auto copyScript = String ("copy /Y \"$(OutDir)$(TargetFileName)\"") + String (" \"$COPYDIR$\\$(TargetFileName)\"");
  953. if (type == VSTPlugIn) return copyScript.replace ("$COPYDIR$", config.getVSTBinaryLocationString());
  954. if (type == VST3PlugIn) return copyScript.replace ("$COPYDIR$", config.getVST3BinaryLocationString());
  955. if (type == RTASPlugIn) return copyScript.replace ("$COPYDIR$", config.getRTASBinaryLocationString());
  956. }
  957. return {};
  958. }
  959. String getExtraPreBuildSteps (const MSVCBuildConfiguration& config) const
  960. {
  961. if (type == AAXPlugIn)
  962. {
  963. String script;
  964. auto bundleDir = getOwner().getOutDirFile (config, config.getOutputFilename (".aaxplugin", false, false));
  965. auto bundleContents = bundleDir + "\\Contents";
  966. auto archDir = bundleContents + String ("\\") + (config.is64Bit() ? "x64" : "Win32");
  967. for (auto& folder : StringArray { bundleDir, bundleContents, archDir })
  968. script += String ("if not exist \"") + folder + String ("\" mkdir \"") + folder + String ("\"\r\n");
  969. return script;
  970. }
  971. return {};
  972. }
  973. String getPostBuildSteps (const MSVCBuildConfiguration& config) const
  974. {
  975. auto postBuild = config.getPostbuildCommandString().replace ("\n", "\r\n");;
  976. auto extraPostBuild = getExtraPostBuildSteps (config);
  977. return postBuild + String (postBuild.isNotEmpty() && extraPostBuild.isNotEmpty() ? "\r\n" : "") + extraPostBuild;
  978. }
  979. String getPreBuildSteps (const MSVCBuildConfiguration& config) const
  980. {
  981. auto preBuild = config.getPrebuildCommandString().replace ("\n", "\r\n");;
  982. auto extraPreBuild = getExtraPreBuildSteps (config);
  983. return preBuild + String (preBuild.isNotEmpty() && extraPreBuild.isNotEmpty() ? "\r\n" : "") + extraPreBuild;
  984. }
  985. void addExtraPreprocessorDefines (StringPairArray& defines) const
  986. {
  987. if (type == AAXPlugIn)
  988. {
  989. auto aaxLibsFolder = build_tools::RelativePath (owner.getAAXPathString(), build_tools::RelativePath::projectFolder).getChildFile ("Libs");
  990. defines.set ("JucePlugin_AAXLibs_path", createRebasedPath (aaxLibsFolder));
  991. }
  992. else if (type == RTASPlugIn)
  993. {
  994. build_tools::RelativePath rtasFolder (owner.getRTASPathString(), build_tools::RelativePath::projectFolder);
  995. defines.set ("JucePlugin_WinBag_path", createRebasedPath (rtasFolder.getChildFile ("WinBag")));
  996. }
  997. }
  998. String getExtraLinkerFlags() const
  999. {
  1000. if (type == RTASPlugIn)
  1001. return "/FORCE:multiple";
  1002. return {};
  1003. }
  1004. StringArray getExtraSearchPaths() const
  1005. {
  1006. StringArray searchPaths;
  1007. if (type == RTASPlugIn)
  1008. {
  1009. build_tools::RelativePath rtasFolder (owner.getRTASPathString(), build_tools::RelativePath::projectFolder);
  1010. static const char* p[] = { "AlturaPorts/TDMPlugins/PluginLibrary/EffectClasses",
  1011. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses",
  1012. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses/Interfaces",
  1013. "AlturaPorts/TDMPlugins/PluginLibrary/Utilities",
  1014. "AlturaPorts/TDMPlugins/PluginLibrary/RTASP_Adapt",
  1015. "AlturaPorts/TDMPlugins/PluginLibrary/CoreClasses",
  1016. "AlturaPorts/TDMPlugins/PluginLibrary/Controls",
  1017. "AlturaPorts/TDMPlugins/PluginLibrary/Meters",
  1018. "AlturaPorts/TDMPlugins/PluginLibrary/ViewClasses",
  1019. "AlturaPorts/TDMPlugins/PluginLibrary/DSPClasses",
  1020. "AlturaPorts/TDMPlugins/PluginLibrary/Interfaces",
  1021. "AlturaPorts/TDMPlugins/common",
  1022. "AlturaPorts/TDMPlugins/common/Platform",
  1023. "AlturaPorts/TDMPlugins/common/Macros",
  1024. "AlturaPorts/TDMPlugins/SignalProcessing/Public",
  1025. "AlturaPorts/TDMPlugIns/DSPManager/Interfaces",
  1026. "AlturaPorts/SADriver/Interfaces",
  1027. "AlturaPorts/DigiPublic/Interfaces",
  1028. "AlturaPorts/DigiPublic",
  1029. "AlturaPorts/Fic/Interfaces/DAEClient",
  1030. "AlturaPorts/NewFileLibs/Cmn",
  1031. "AlturaPorts/NewFileLibs/DOA",
  1032. "AlturaPorts/AlturaSource/PPC_H",
  1033. "AlturaPorts/AlturaSource/AppSupport",
  1034. "AvidCode/AVX2sdk/AVX/avx2/avx2sdk/inc",
  1035. "xplat/AVX/avx2/avx2sdk/inc" };
  1036. for (auto* path : p)
  1037. searchPaths.add (createRebasedPath (rtasFolder.getChildFile (path)));
  1038. }
  1039. return searchPaths;
  1040. }
  1041. String getBinaryNameWithSuffix (const MSVCBuildConfiguration& config, bool forceUnityPrefix) const
  1042. {
  1043. return config.getOutputFilename (getTargetSuffix(), true, forceUnityPrefix);
  1044. }
  1045. String getOutputFilePath (const MSVCBuildConfiguration& config, bool forceUnityPrefix) const
  1046. {
  1047. return getOwner().getOutDirFile (config, getBinaryNameWithSuffix (config, forceUnityPrefix));
  1048. }
  1049. StringArray getLibrarySearchPaths (const BuildConfiguration& config) const
  1050. {
  1051. auto librarySearchPaths = config.getLibrarySearchPaths();
  1052. if (type != SharedCodeTarget)
  1053. if (auto* shared = getOwner().getSharedCodeTarget())
  1054. librarySearchPaths.add (shared->getConfigTargetPath (config));
  1055. return librarySearchPaths;
  1056. }
  1057. String getExternalLibraries (const MSVCBuildConfiguration& config, const String& otherLibs) const
  1058. {
  1059. StringArray libraries;
  1060. if (otherLibs.isNotEmpty())
  1061. libraries.add (otherLibs);
  1062. auto moduleLibs = getOwner().getModuleLibs();
  1063. if (! moduleLibs.isEmpty())
  1064. libraries.addArray (moduleLibs);
  1065. if (type != SharedCodeTarget)
  1066. if (auto* shared = getOwner().getSharedCodeTarget())
  1067. libraries.add (shared->getBinaryNameWithSuffix (config, false));
  1068. return libraries.joinIntoString (";");
  1069. }
  1070. String getDelayLoadedDLLs() const
  1071. {
  1072. auto delayLoadedDLLs = getOwner().msvcDelayLoadedDLLs;
  1073. if (type == RTASPlugIn)
  1074. delayLoadedDLLs += "DAE.dll; DigiExt.dll; DSI.dll; PluginLib.dll; "
  1075. "DSPManager.dll; DSPManager.dll; DSPManagerClientLib.dll; RTASClientLib.dll";
  1076. return delayLoadedDLLs;
  1077. }
  1078. String getModuleDefinitions (const MSVCBuildConfiguration& config) const
  1079. {
  1080. auto moduleDefinitions = config.config [Ids::msvcModuleDefinitionFile].toString();
  1081. if (moduleDefinitions.isNotEmpty())
  1082. return moduleDefinitions;
  1083. if (type == RTASPlugIn)
  1084. {
  1085. auto& exp = getOwner();
  1086. auto moduleDefPath
  1087. = build_tools::RelativePath (exp.getPathForModuleString ("juce_audio_plugin_client"), build_tools::RelativePath::projectFolder)
  1088. .getChildFile ("juce_audio_plugin_client").getChildFile ("RTAS").getChildFile ("juce_RTAS_WinExports.def");
  1089. return prependDot (moduleDefPath.rebased (exp.getProject().getProjectFolder(),
  1090. exp.getTargetFolder(),
  1091. build_tools::RelativePath::buildTargetFolder).toWindowsStyle());
  1092. }
  1093. return {};
  1094. }
  1095. File getVCProjFile() const { return getOwner().getProjectFile (getProjectFileSuffix(), getName()); }
  1096. File getVCProjFiltersFile() const { return getOwner().getProjectFile (getFiltersFileSuffix(), getName()); }
  1097. String createRebasedPath (const build_tools::RelativePath& path) const { return getOwner().createRebasedPath (path); }
  1098. void addWindowsTargetPlatformToConfig (XmlElement& e) const
  1099. {
  1100. auto target = owner.getWindowsTargetPlatformVersion();
  1101. if (target == "Latest")
  1102. {
  1103. auto* child = e.createNewChildElement ("WindowsTargetPlatformVersion");
  1104. child->setAttribute ("Condition", "'$(WindowsTargetPlatformVersion)' == ''");
  1105. child->addTextElement ("$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))");
  1106. }
  1107. else
  1108. {
  1109. e.createNewChildElement ("WindowsTargetPlatformVersion")->addTextElement (target);
  1110. }
  1111. }
  1112. protected:
  1113. const MSVCProjectExporterBase& owner;
  1114. String projectGuid;
  1115. };
  1116. //==============================================================================
  1117. bool usesMMFiles() const override { return false; }
  1118. bool canCopeWithDuplicateFiles() override { return false; }
  1119. bool supportsUserDefinedConfigurations() const override { return true; }
  1120. bool isXcode() const override { return false; }
  1121. bool isVisualStudio() const override { return true; }
  1122. bool isCodeBlocks() const override { return false; }
  1123. bool isMakefile() const override { return false; }
  1124. bool isAndroidStudio() const override { return false; }
  1125. bool isCLion() const override { return false; }
  1126. bool isAndroid() const override { return false; }
  1127. bool isWindows() const override { return true; }
  1128. bool isLinux() const override { return false; }
  1129. bool isOSX() const override { return false; }
  1130. bool isiOS() const override { return false; }
  1131. bool supportsPrecompiledHeaders() const override { return true; }
  1132. String getNewLineString() const override { return "\r\n"; }
  1133. bool supportsTargetType (build_tools::ProjectType::Target::Type type) const override
  1134. {
  1135. switch (type)
  1136. {
  1137. case build_tools::ProjectType::Target::StandalonePlugIn:
  1138. case build_tools::ProjectType::Target::GUIApp:
  1139. case build_tools::ProjectType::Target::ConsoleApp:
  1140. case build_tools::ProjectType::Target::StaticLibrary:
  1141. case build_tools::ProjectType::Target::SharedCodeTarget:
  1142. case build_tools::ProjectType::Target::AggregateTarget:
  1143. case build_tools::ProjectType::Target::VSTPlugIn:
  1144. case build_tools::ProjectType::Target::VST3PlugIn:
  1145. case build_tools::ProjectType::Target::AAXPlugIn:
  1146. case build_tools::ProjectType::Target::RTASPlugIn:
  1147. case build_tools::ProjectType::Target::UnityPlugIn:
  1148. case build_tools::ProjectType::Target::DynamicLibrary:
  1149. return true;
  1150. case build_tools::ProjectType::Target::AudioUnitPlugIn:
  1151. case build_tools::ProjectType::Target::AudioUnitv3PlugIn:
  1152. case build_tools::ProjectType::Target::unspecified:
  1153. default:
  1154. break;
  1155. }
  1156. return false;
  1157. }
  1158. //==============================================================================
  1159. build_tools::RelativePath getManifestPath() const
  1160. {
  1161. auto path = manifestFileValue.get().toString();
  1162. return path.isEmpty() ? build_tools::RelativePath()
  1163. : build_tools::RelativePath (path, build_tools::RelativePath::projectFolder);
  1164. }
  1165. //==============================================================================
  1166. bool launchProject() override
  1167. {
  1168. #if JUCE_WINDOWS
  1169. return getSLNFile().startAsProcess();
  1170. #else
  1171. return false;
  1172. #endif
  1173. }
  1174. bool canLaunchProject() override
  1175. {
  1176. #if JUCE_WINDOWS
  1177. return true;
  1178. #else
  1179. return false;
  1180. #endif
  1181. }
  1182. void createExporterProperties (PropertyListBuilder& props) override
  1183. {
  1184. props.add (new TextPropertyComponent (manifestFileValue, "Manifest file", 8192, false),
  1185. "Path to a manifest input file which should be linked into your binary (path is relative to jucer file).");
  1186. props.add (new ChoicePropertyComponent (IPPLibraryValue, "Use IPP Library",
  1187. { "No", "Yes (Default Linking)", "Multi-Threaded Static Library", "Single-Threaded Static Library", "Multi-Threaded DLL", "Single-Threaded DLL" },
  1188. { var(), "true", "Parallel_Static", "Sequential", "Parallel_Dynamic", "Sequential_Dynamic" }),
  1189. "Enable this to use Intel's Integrated Performance Primitives library.");
  1190. {
  1191. auto isWindows10SDK = getVisualStudioVersion() > 14;
  1192. props.add (new TextPropertyComponent (targetPlatformVersion, "Windows Target Platform", 20, false),
  1193. String ("Specifies the version of the Windows SDK that will be used when building this project. ")
  1194. + (isWindows10SDK ? "Leave this field empty to use the latest Windows 10 SDK installed on the build machine."
  1195. : "The default value for this exporter is " + getDefaultWindowsTargetPlatformVersion()));
  1196. }
  1197. }
  1198. enum OptimisationLevel
  1199. {
  1200. optimisationOff = 1,
  1201. optimiseMinSize = 2,
  1202. optimiseFull = 3,
  1203. optimiseMaxSpeed = 4
  1204. };
  1205. //==============================================================================
  1206. void addPlatformSpecificSettingsForProjectType (const build_tools::ProjectType& type) override
  1207. {
  1208. msvcExtraPreprocessorDefs.set ("_CRT_SECURE_NO_WARNINGS", "");
  1209. if (type.isCommandLineApp())
  1210. msvcExtraPreprocessorDefs.set("_CONSOLE", "");
  1211. callForAllSupportedTargets ([this] (build_tools::ProjectType::Target::Type targetType)
  1212. {
  1213. if (targetType != build_tools::ProjectType::Target::AggregateTarget)
  1214. targets.add (new MSVCTargetBase (targetType, *this));
  1215. });
  1216. // If you hit this assert, you tried to generate a project for an exporter
  1217. // that does not support any of your targets!
  1218. jassert (targets.size() > 0);
  1219. }
  1220. const MSVCTargetBase* getSharedCodeTarget() const
  1221. {
  1222. for (auto target : targets)
  1223. if (target->type == build_tools::ProjectType::Target::SharedCodeTarget)
  1224. return target;
  1225. return nullptr;
  1226. }
  1227. bool hasTarget (build_tools::ProjectType::Target::Type type) const
  1228. {
  1229. for (auto target : targets)
  1230. if (target->type == type)
  1231. return true;
  1232. return false;
  1233. }
  1234. static void createRCFile (const Project& p, const File& iconFile, const File& rcFile)
  1235. {
  1236. build_tools::ResourceRcOptions resourceRc;
  1237. resourceRc.version = p.getVersionString();
  1238. resourceRc.companyName = p.getCompanyNameString();
  1239. resourceRc.companyCopyright = p.getCompanyCopyrightString();
  1240. resourceRc.projectName = p.getProjectNameString();
  1241. resourceRc.icon = iconFile;
  1242. resourceRc.write (rcFile);
  1243. }
  1244. private:
  1245. //==============================================================================
  1246. String createRebasedPath (const build_tools::RelativePath& path) const
  1247. {
  1248. auto rebasedPath = rebaseFromProjectFolderToBuildTarget (path).toWindowsStyle();
  1249. return getVisualStudioVersion() < 10 // (VS10 automatically adds escape characters to the quotes for this definition)
  1250. ? CppTokeniserFunctions::addEscapeChars (rebasedPath.quoted())
  1251. : CppTokeniserFunctions::addEscapeChars (rebasedPath).quoted();
  1252. }
  1253. protected:
  1254. //==============================================================================
  1255. mutable File rcFile, iconFile, packagesConfigFile;
  1256. OwnedArray<MSVCTargetBase> targets;
  1257. ValueWithDefault IPPLibraryValue, platformToolsetValue, targetPlatformVersion, manifestFileValue;
  1258. File getProjectFile (const String& extension, const String& target) const
  1259. {
  1260. auto filename = project.getProjectFilenameRootString();
  1261. if (target.isNotEmpty())
  1262. filename += String ("_") + target.removeCharacters (" ");
  1263. return getTargetFolder().getChildFile (filename).withFileExtension (extension);
  1264. }
  1265. File getSLNFile() const { return getProjectFile (".sln", String()); }
  1266. static String prependIfNotAbsolute (const String& file, const char* prefix)
  1267. {
  1268. if (File::isAbsolutePath (file) || file.startsWithChar ('$'))
  1269. prefix = "";
  1270. return prefix + build_tools::windowsStylePath (file);
  1271. }
  1272. String getIntDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(IntDir)\\"); }
  1273. String getOutDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(OutDir)\\"); }
  1274. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override
  1275. {
  1276. return *new MSVCBuildConfiguration (project, v, *this);
  1277. }
  1278. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  1279. {
  1280. auto searchPaths = extraSearchPaths;
  1281. searchPaths.addArray (config.getHeaderSearchPaths());
  1282. return getCleanedStringArray (searchPaths);
  1283. }
  1284. String getSharedCodeGuid() const
  1285. {
  1286. String sharedCodeGuid;
  1287. for (int i = 0; i < targets.size(); ++i)
  1288. if (auto* target = targets[i])
  1289. if (target->type == build_tools::ProjectType::Target::SharedCodeTarget)
  1290. return target->getProjectGuid();
  1291. return {};
  1292. }
  1293. //==============================================================================
  1294. void writeProjectDependencies (OutputStream& out) const
  1295. {
  1296. auto sharedCodeGuid = getSharedCodeGuid();
  1297. for (int addingOtherTargets = 0; addingOtherTargets < (sharedCodeGuid.isNotEmpty() ? 2 : 1); ++addingOtherTargets)
  1298. {
  1299. for (int i = 0; i < targets.size(); ++i)
  1300. {
  1301. if (auto* target = targets[i])
  1302. {
  1303. if (sharedCodeGuid.isEmpty() || (addingOtherTargets != 0) == (target->type != build_tools::ProjectType::Target::StandalonePlugIn))
  1304. {
  1305. out << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"" << projectName << " - "
  1306. << target->getName() << "\", \""
  1307. << target->getVCProjFile().getFileName() << "\", \"" << target->getProjectGuid() << '"' << newLine;
  1308. if (sharedCodeGuid.isNotEmpty() && target->type != build_tools::ProjectType::Target::SharedCodeTarget)
  1309. out << "\tProjectSection(ProjectDependencies) = postProject" << newLine
  1310. << "\t\t" << sharedCodeGuid << " = " << sharedCodeGuid << newLine
  1311. << "\tEndProjectSection" << newLine;
  1312. out << "EndProject" << newLine;
  1313. }
  1314. }
  1315. }
  1316. }
  1317. }
  1318. void writeSolutionFile (OutputStream& out, const String& versionString, String commentString) const
  1319. {
  1320. if (commentString.isNotEmpty())
  1321. commentString += newLine;
  1322. out << "Microsoft Visual Studio Solution File, Format Version " << versionString << newLine
  1323. << commentString << newLine;
  1324. writeProjectDependencies (out);
  1325. out << "Global" << newLine
  1326. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  1327. for (ConstConfigIterator i (*this); i.next();)
  1328. {
  1329. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  1330. auto configName = config.createMSVCConfigName();
  1331. out << "\t\t" << configName << " = " << configName << newLine;
  1332. }
  1333. out << "\tEndGlobalSection" << newLine
  1334. << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" << newLine;
  1335. for (auto& target : targets)
  1336. for (ConstConfigIterator i (*this); i.next();)
  1337. {
  1338. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  1339. auto configName = config.createMSVCConfigName();
  1340. for (auto& suffix : { "ActiveCfg", "Build.0" })
  1341. out << "\t\t" << target->getProjectGuid() << "." << configName << "." << suffix << " = " << configName << newLine;
  1342. }
  1343. out << "\tEndGlobalSection" << newLine
  1344. << "\tGlobalSection(SolutionProperties) = preSolution" << newLine
  1345. << "\t\tHideSolutionNode = FALSE" << newLine
  1346. << "\tEndGlobalSection" << newLine;
  1347. out << "EndGlobal" << newLine;
  1348. }
  1349. //==============================================================================
  1350. bool hasResourceFile() const
  1351. {
  1352. return ! projectType.isStaticLibrary();
  1353. }
  1354. void createResourcesAndIcon() const
  1355. {
  1356. if (hasResourceFile())
  1357. {
  1358. iconFile = getTargetFolder().getChildFile ("icon.ico");
  1359. build_tools::writeWinIcon (getIcons(), iconFile);
  1360. rcFile = getTargetFolder().getChildFile ("resources.rc");
  1361. createRCFile (project, iconFile, rcFile);
  1362. }
  1363. }
  1364. bool shouldAddWebView2Package() const
  1365. {
  1366. return project.getEnabledModules().isModuleEnabled ("juce_gui_extra")
  1367. && project.isConfigFlagEnabled ("JUCE_USE_WIN_WEBVIEW2", false);
  1368. }
  1369. static String getWebView2PackageName() { return "Microsoft.Web.WebView2"; }
  1370. static String getWebView2PackageVersion() { return "0.9.488"; }
  1371. void createPackagesConfigFile() const
  1372. {
  1373. if (shouldAddWebView2Package())
  1374. {
  1375. packagesConfigFile = getTargetFolder().getChildFile ("packages.config");
  1376. build_tools::writeStreamToFile (packagesConfigFile, [] (MemoryOutputStream& mo)
  1377. {
  1378. mo.setNewLineString ("\r\n");
  1379. mo << "<?xml version=\"1.0\" encoding=\"utf-8\"?>" << newLine
  1380. << "<packages>" << newLine
  1381. << "\t" << "<package id=" << getWebView2PackageName().quoted()
  1382. << " version=" << getWebView2PackageVersion().quoted()
  1383. << " />" << newLine
  1384. << "</packages>" << newLine;
  1385. });
  1386. }
  1387. }
  1388. static String prependDot (const String& filename)
  1389. {
  1390. return build_tools::isAbsolutePath (filename) ? filename
  1391. : (".\\" + filename);
  1392. }
  1393. static bool shouldUseStdCall (const build_tools::RelativePath& path)
  1394. {
  1395. return path.getFileNameWithoutExtension().startsWithIgnoreCase ("include_juce_audio_plugin_client_RTAS_");
  1396. }
  1397. static bool shouldAddBigobjFlag (const build_tools::RelativePath& path)
  1398. {
  1399. return path.getFileNameWithoutExtension().equalsIgnoreCase ("include_juce_gui_basics");
  1400. }
  1401. StringArray getModuleLibs() const
  1402. {
  1403. StringArray result;
  1404. for (auto& lib : windowsLibs)
  1405. result.add (lib + ".lib");
  1406. return result;
  1407. }
  1408. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase)
  1409. };
  1410. //==============================================================================
  1411. class MSVCProjectExporterVC2015 : public MSVCProjectExporterBase
  1412. {
  1413. public:
  1414. MSVCProjectExporterVC2015 (Project& p, const ValueTree& t)
  1415. : MSVCProjectExporterBase (p, t, getTargetFolderName())
  1416. {
  1417. name = getDisplayName();
  1418. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1419. platformToolsetValue.setDefault (getDefaultToolset());
  1420. }
  1421. static String getDisplayName() { return "Visual Studio 2015"; }
  1422. static String getValueTreeTypeName() { return "VS2015"; }
  1423. static String getTargetFolderName() { return "VisualStudio2015"; }
  1424. Identifier getExporterIdentifier() const override { return getValueTreeTypeName(); }
  1425. int getVisualStudioVersion() const override { return 14; }
  1426. String getSolutionComment() const override { return "# Visual Studio 2015"; }
  1427. String getToolsVersion() const override { return "14.0"; }
  1428. String getDefaultToolset() const override { return "v140"; }
  1429. String getDefaultWindowsTargetPlatformVersion() const override { return "8.1"; }
  1430. static MSVCProjectExporterVC2015* createForSettings (Project& projectToUse, const ValueTree& settingsToUse)
  1431. {
  1432. if (settingsToUse.hasType (getValueTreeTypeName()))
  1433. return new MSVCProjectExporterVC2015 (projectToUse, settingsToUse);
  1434. return nullptr;
  1435. }
  1436. void createExporterProperties (PropertyListBuilder& props) override
  1437. {
  1438. static const char* toolsetNames[] = { "v140", "v140_xp", "CTP_Nov2013" };
  1439. const var toolsets[] = { "v140", "v140_xp", "CTP_Nov2013" };
  1440. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1441. MSVCProjectExporterBase::createExporterProperties (props);
  1442. }
  1443. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2015)
  1444. };
  1445. //==============================================================================
  1446. class MSVCProjectExporterVC2017 : public MSVCProjectExporterBase
  1447. {
  1448. public:
  1449. MSVCProjectExporterVC2017 (Project& p, const ValueTree& t)
  1450. : MSVCProjectExporterBase (p, t, getTargetFolderName())
  1451. {
  1452. name = getDisplayName();
  1453. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1454. platformToolsetValue.setDefault (getDefaultToolset());
  1455. }
  1456. static String getDisplayName() { return "Visual Studio 2017"; }
  1457. static String getValueTreeTypeName() { return "VS2017"; }
  1458. static String getTargetFolderName() { return "VisualStudio2017"; }
  1459. Identifier getExporterIdentifier() const override { return getValueTreeTypeName(); }
  1460. int getVisualStudioVersion() const override { return 15; }
  1461. String getSolutionComment() const override { return "# Visual Studio 2017"; }
  1462. String getToolsVersion() const override { return "15.0"; }
  1463. String getDefaultToolset() const override { return "v141"; }
  1464. String getDefaultWindowsTargetPlatformVersion() const override { return "Latest"; }
  1465. static MSVCProjectExporterVC2017* createForSettings (Project& projectToUse, const ValueTree& settingsToUse)
  1466. {
  1467. if (settingsToUse.hasType (getValueTreeTypeName()))
  1468. return new MSVCProjectExporterVC2017 (projectToUse, settingsToUse);
  1469. return nullptr;
  1470. }
  1471. void createExporterProperties (PropertyListBuilder& props) override
  1472. {
  1473. static const char* toolsetNames[] = { "v140", "v140_xp", "v141", "v141_xp" };
  1474. const var toolsets[] = { "v140", "v140_xp", "v141", "v141_xp" };
  1475. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1476. MSVCProjectExporterBase::createExporterProperties (props);
  1477. }
  1478. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2017)
  1479. };
  1480. //==============================================================================
  1481. class MSVCProjectExporterVC2019 : public MSVCProjectExporterBase
  1482. {
  1483. public:
  1484. MSVCProjectExporterVC2019 (Project& p, const ValueTree& t)
  1485. : MSVCProjectExporterBase (p, t, getTargetFolderName())
  1486. {
  1487. name = getDisplayName();
  1488. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1489. platformToolsetValue.setDefault (getDefaultToolset());
  1490. }
  1491. static String getDisplayName() { return "Visual Studio 2019"; }
  1492. static String getValueTreeTypeName() { return "VS2019"; }
  1493. static String getTargetFolderName() { return "VisualStudio2019"; }
  1494. Identifier getExporterIdentifier() const override { return getValueTreeTypeName(); }
  1495. int getVisualStudioVersion() const override { return 16; }
  1496. String getSolutionComment() const override { return "# Visual Studio 2019"; }
  1497. String getToolsVersion() const override { return "16.0"; }
  1498. String getDefaultToolset() const override { return "v142"; }
  1499. String getDefaultWindowsTargetPlatformVersion() const override { return "10.0"; }
  1500. static MSVCProjectExporterVC2019* createForSettings (Project& projectToUse, const ValueTree& settingsToUse)
  1501. {
  1502. if (settingsToUse.hasType (getValueTreeTypeName()))
  1503. return new MSVCProjectExporterVC2019 (projectToUse, settingsToUse);
  1504. return nullptr;
  1505. }
  1506. void createExporterProperties (PropertyListBuilder& props) override
  1507. {
  1508. static const char* toolsetNames[] = { "v140", "v140_xp", "v141", "v141_xp", "v142" };
  1509. const var toolsets[] = { "v140", "v140_xp", "v141", "v141_xp", "v142" };
  1510. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1511. MSVCProjectExporterBase::createExporterProperties (props);
  1512. }
  1513. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2019)
  1514. };