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.

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