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.

1993 lines
99KB

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