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.

1922 lines
96KB

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