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.

1888 lines
86KB

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