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.

2004 lines
100KB

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