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.

1967 lines
97KB

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