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.

1907 lines
95KB

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