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.

1872 lines
93KB

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