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.

1875 lines
85KB

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