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.

1768 lines
88KB

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