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.

227 lines
11KB

  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. #include "../Application/jucer_Headers.h"
  20. #include "jucer_ProjectSaver.h"
  21. #include "jucer_ProjectExport_CLion.h"
  22. //==============================================================================
  23. namespace
  24. {
  25. inline int countMaxPluginChannels (const String& configString, bool isInput)
  26. {
  27. auto configs = StringArray::fromTokens (configString, ", {}", {});
  28. configs.trim();
  29. configs.removeEmptyStrings();
  30. jassert ((configs.size() & 1) == 0); // looks like a syntax error in the configs?
  31. int maxVal = 0;
  32. for (int i = (isInput ? 0 : 1); i < configs.size(); i += 2)
  33. maxVal = jmax (maxVal, configs[i].getIntValue());
  34. return maxVal;
  35. }
  36. inline String boolToString (bool b)
  37. {
  38. return b ? "1" : "0";
  39. }
  40. inline String toStringLiteral (const String& v)
  41. {
  42. return CppTokeniserFunctions::addEscapeChars (v).quoted();
  43. }
  44. inline String toCharLiteral (const String& v)
  45. {
  46. auto fourCharCode = v.substring (0, 4);
  47. uint32 hexRepresentation = 0;
  48. for (int i = 0; i < 4; ++i)
  49. hexRepresentation = (hexRepresentation << 8u)
  50. | (static_cast<unsigned int> (fourCharCode[i]) & 0xffu);
  51. return "0x" + String::toHexString (static_cast<int> (hexRepresentation))
  52. + " // "
  53. + CppTokeniserFunctions::addEscapeChars (fourCharCode).quoted ('\'');
  54. }
  55. }
  56. //==============================================================================
  57. void ProjectSaver::writePluginCharacteristicsFile()
  58. {
  59. StringPairArray flags;
  60. flags.set ("JucePlugin_Build_VST", boolToString (project.shouldBuildVST()));
  61. flags.set ("JucePlugin_Build_VST3", boolToString (project.shouldBuildVST3()));
  62. flags.set ("JucePlugin_Build_AU", boolToString (project.shouldBuildAU()));
  63. flags.set ("JucePlugin_Build_AUv3", boolToString (project.shouldBuildAUv3()));
  64. flags.set ("JucePlugin_Build_RTAS", boolToString (project.shouldBuildRTAS()));
  65. flags.set ("JucePlugin_Build_AAX", boolToString (project.shouldBuildAAX()));
  66. flags.set ("JucePlugin_Build_Standalone", boolToString (project.shouldBuildStandalonePlugin()));
  67. flags.set ("JucePlugin_Build_Unity", boolToString (project.shouldBuildUnityPlugin()));
  68. flags.set ("JucePlugin_Enable_IAA", boolToString (project.shouldEnableIAA()));
  69. flags.set ("JucePlugin_Name", toStringLiteral (project.getPluginNameString()));
  70. flags.set ("JucePlugin_Desc", toStringLiteral (project.getPluginDescriptionString()));
  71. flags.set ("JucePlugin_Manufacturer", toStringLiteral (project.getPluginManufacturerString()));
  72. flags.set ("JucePlugin_ManufacturerWebsite", toStringLiteral (project.getCompanyWebsiteString()));
  73. flags.set ("JucePlugin_ManufacturerEmail", toStringLiteral (project.getCompanyEmailString()));
  74. flags.set ("JucePlugin_ManufacturerCode", toCharLiteral (project.getPluginManufacturerCodeString()));
  75. flags.set ("JucePlugin_PluginCode", toCharLiteral (project.getPluginCodeString()));
  76. flags.set ("JucePlugin_IsSynth", boolToString (project.isPluginSynth()));
  77. flags.set ("JucePlugin_WantsMidiInput", boolToString (project.pluginWantsMidiInput()));
  78. flags.set ("JucePlugin_ProducesMidiOutput", boolToString (project.pluginProducesMidiOutput()));
  79. flags.set ("JucePlugin_IsMidiEffect", boolToString (project.isPluginMidiEffect()));
  80. flags.set ("JucePlugin_EditorRequiresKeyboardFocus", boolToString (project.pluginEditorNeedsKeyFocus()));
  81. flags.set ("JucePlugin_Version", project.getVersionString());
  82. flags.set ("JucePlugin_VersionCode", project.getVersionAsHex());
  83. flags.set ("JucePlugin_VersionString", toStringLiteral (project.getVersionString()));
  84. flags.set ("JucePlugin_VSTUniqueID", "JucePlugin_PluginCode");
  85. flags.set ("JucePlugin_VSTCategory", project.getVSTCategoryString());
  86. flags.set ("JucePlugin_Vst3Category", toStringLiteral (project.getVST3CategoryString()));
  87. flags.set ("JucePlugin_AUMainType", project.getAUMainTypeString());
  88. flags.set ("JucePlugin_AUSubType", "JucePlugin_PluginCode");
  89. flags.set ("JucePlugin_AUExportPrefix", project.getPluginAUExportPrefixString());
  90. flags.set ("JucePlugin_AUExportPrefixQuoted", toStringLiteral (project.getPluginAUExportPrefixString()));
  91. flags.set ("JucePlugin_AUManufacturerCode", "JucePlugin_ManufacturerCode");
  92. flags.set ("JucePlugin_CFBundleIdentifier", project.getBundleIdentifierString());
  93. flags.set ("JucePlugin_RTASCategory", String (project.getRTASCategory()));
  94. flags.set ("JucePlugin_RTASManufacturerCode", "JucePlugin_ManufacturerCode");
  95. flags.set ("JucePlugin_RTASProductId", "JucePlugin_PluginCode");
  96. flags.set ("JucePlugin_RTASDisableBypass", boolToString (project.isPluginRTASBypassDisabled()));
  97. flags.set ("JucePlugin_RTASDisableMultiMono", boolToString (project.isPluginRTASMultiMonoDisabled()));
  98. flags.set ("JucePlugin_AAXIdentifier", project.getAAXIdentifierString());
  99. flags.set ("JucePlugin_AAXManufacturerCode", "JucePlugin_ManufacturerCode");
  100. flags.set ("JucePlugin_AAXProductId", "JucePlugin_PluginCode");
  101. flags.set ("JucePlugin_AAXCategory", String (project.getAAXCategory()));
  102. flags.set ("JucePlugin_AAXDisableBypass", boolToString (project.isPluginAAXBypassDisabled()));
  103. flags.set ("JucePlugin_AAXDisableMultiMono", boolToString (project.isPluginAAXMultiMonoDisabled()));
  104. flags.set ("JucePlugin_IAAType", toCharLiteral (project.getIAATypeCode()));
  105. flags.set ("JucePlugin_IAASubType", "JucePlugin_PluginCode");
  106. flags.set ("JucePlugin_IAAName", project.getIAAPluginName().quoted());
  107. {
  108. String plugInChannelConfig = project.getPluginChannelConfigsString();
  109. if (plugInChannelConfig.isNotEmpty())
  110. {
  111. flags.set ("JucePlugin_MaxNumInputChannels", String (countMaxPluginChannels (plugInChannelConfig, true)));
  112. flags.set ("JucePlugin_MaxNumOutputChannels", String (countMaxPluginChannels (plugInChannelConfig, false)));
  113. flags.set ("JucePlugin_PreferredChannelConfigurations", plugInChannelConfig);
  114. }
  115. }
  116. MemoryOutputStream mem;
  117. mem << "//==============================================================================" << newLine
  118. << "// Audio plugin settings.." << newLine
  119. << newLine;
  120. for (int i = 0; i < flags.size(); ++i)
  121. {
  122. mem << "#ifndef " << flags.getAllKeys()[i] << newLine
  123. << " #define " << flags.getAllKeys()[i].paddedRight (' ', 32) << " "
  124. << flags.getAllValues()[i] << newLine
  125. << "#endif" << newLine;
  126. }
  127. setExtraAppConfigFileContent (mem.toString());
  128. }
  129. void ProjectSaver::writeProjects (const OwnedArray<LibraryModule>& modules, const String& specifiedExporterToSave, bool isCommandLineApp)
  130. {
  131. ThreadPool threadPool;
  132. // keep a copy of the basic generated files group, as each exporter may modify it.
  133. auto originalGeneratedGroup = generatedFilesGroup.state.createCopy();
  134. CLionProjectExporter* clionExporter = nullptr;
  135. OwnedArray<ProjectExporter> exporters;
  136. try
  137. {
  138. for (Project::ExporterIterator exp (project); exp.next();)
  139. {
  140. if (specifiedExporterToSave.isNotEmpty() && exp->getName() != specifiedExporterToSave)
  141. continue;
  142. auto* exporter = exporters.add (exp.exporter.release());
  143. exporter->initialiseDependencyPathValues();
  144. if (exporter->getTargetFolder().createDirectory())
  145. {
  146. if (exporter->isCLion())
  147. {
  148. clionExporter = dynamic_cast<CLionProjectExporter*> (exporter);
  149. }
  150. else
  151. {
  152. exporter->copyMainGroupFromProject();
  153. exporter->settings = exporter->settings.createCopy();
  154. exporter->addToExtraSearchPaths (RelativePath ("JuceLibraryCode", RelativePath::projectFolder));
  155. generatedFilesGroup.state = originalGeneratedGroup.createCopy();
  156. exporter->addSettingsForProjectType (project.getProjectType());
  157. for (auto& module: modules)
  158. module->addSettingsForModuleToExporter (*exporter, *this);
  159. generatedFilesGroup.sortAlphabetically (true, true);
  160. exporter->getAllGroups().add (generatedFilesGroup);
  161. }
  162. if (isCommandLineApp)
  163. saveExporter (exporter, modules);
  164. else
  165. threadPool.addJob (new ExporterJob (*this, exporter, modules), true);
  166. }
  167. else
  168. {
  169. addError ("Can't create folder: " + exporter->getTargetFolder().getFullPathName());
  170. }
  171. }
  172. }
  173. catch (ProjectExporter::SaveError& saveError)
  174. {
  175. addError (saveError.message);
  176. }
  177. if (! isCommandLineApp)
  178. while (threadPool.getNumJobs() > 0)
  179. Thread::sleep (10);
  180. if (clionExporter != nullptr)
  181. {
  182. for (auto* exporter : exporters)
  183. clionExporter->writeCMakeListsExporterSection (exporter);
  184. std::cout << "Finished saving: " << clionExporter->getName() << std::endl;
  185. }
  186. }