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.

228 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_Enable_IAA", boolToString (project.shouldEnableIAA()));
  68. flags.set ("JucePlugin_Name", toStringLiteral (project.getPluginNameString()));
  69. flags.set ("JucePlugin_Desc", toStringLiteral (project.getPluginDescriptionString()));
  70. flags.set ("JucePlugin_Manufacturer", toStringLiteral (project.getPluginManufacturerString()));
  71. flags.set ("JucePlugin_ManufacturerWebsite", toStringLiteral (project.getCompanyWebsiteString()));
  72. flags.set ("JucePlugin_ManufacturerEmail", toStringLiteral (project.getCompanyEmailString()));
  73. flags.set ("JucePlugin_ManufacturerCode", toCharLiteral (project.getPluginManufacturerCodeString()));
  74. flags.set ("JucePlugin_PluginCode", toCharLiteral (project.getPluginCodeString()));
  75. flags.set ("JucePlugin_IsSynth", boolToString (project.isPluginSynth()));
  76. flags.set ("JucePlugin_WantsMidiInput", boolToString (project.pluginWantsMidiInput()));
  77. flags.set ("JucePlugin_ProducesMidiOutput", boolToString (project.pluginProducesMidiOutput()));
  78. flags.set ("JucePlugin_IsMidiEffect", boolToString (project.isPluginMidiEffect()));
  79. flags.set ("JucePlugin_EditorRequiresKeyboardFocus", boolToString (project.pluginEditorNeedsKeyFocus()));
  80. flags.set ("JucePlugin_Version", project.getVersionString());
  81. flags.set ("JucePlugin_VersionCode", project.getVersionAsHex());
  82. flags.set ("JucePlugin_VersionString", toStringLiteral (project.getVersionString()));
  83. flags.set ("JucePlugin_VSTUniqueID", "JucePlugin_PluginCode");
  84. flags.set ("JucePlugin_VSTCategory", project.getPluginVSTCategoryString());
  85. flags.set ("JucePlugin_AUMainType", project.getAUMainTypeString());
  86. flags.set ("JucePlugin_AUSubType", "JucePlugin_PluginCode");
  87. flags.set ("JucePlugin_AUExportPrefix", project.getPluginAUExportPrefixString());
  88. flags.set ("JucePlugin_AUExportPrefixQuoted", toStringLiteral (project.getPluginAUExportPrefixString()));
  89. flags.set ("JucePlugin_AUManufacturerCode", "JucePlugin_ManufacturerCode");
  90. flags.set ("JucePlugin_CFBundleIdentifier", project.getBundleIdentifierString());
  91. flags.set ("JucePlugin_RTASCategory", project.getPluginRTASCategoryCode());
  92. flags.set ("JucePlugin_RTASManufacturerCode", "JucePlugin_ManufacturerCode");
  93. flags.set ("JucePlugin_RTASProductId", "JucePlugin_PluginCode");
  94. flags.set ("JucePlugin_RTASDisableBypass", boolToString (project.isPluginRTASBypassDisabled()));
  95. flags.set ("JucePlugin_RTASDisableMultiMono", boolToString (project.isPluginRTASMultiMonoDisabled()));
  96. flags.set ("JucePlugin_AAXIdentifier", project.getAAXIdentifierString());
  97. flags.set ("JucePlugin_AAXManufacturerCode", "JucePlugin_ManufacturerCode");
  98. flags.set ("JucePlugin_AAXProductId", "JucePlugin_PluginCode");
  99. flags.set ("JucePlugin_AAXCategory", project.getPluginAAXCategoryString());
  100. flags.set ("JucePlugin_AAXDisableBypass", boolToString (project.isPluginAAXBypassDisabled()));
  101. flags.set ("JucePlugin_AAXDisableMultiMono", boolToString (project.isPluginAAXMultiMonoDisabled()));
  102. flags.set ("JucePlugin_IAAType", toCharLiteral (project.getIAATypeCode()));
  103. flags.set ("JucePlugin_IAASubType", "JucePlugin_PluginCode");
  104. flags.set ("JucePlugin_IAAName", project.getIAAPluginName().quoted());
  105. {
  106. String plugInChannelConfig = project.getPluginChannelConfigsString();
  107. if (plugInChannelConfig.isNotEmpty())
  108. {
  109. flags.set ("JucePlugin_MaxNumInputChannels", String (countMaxPluginChannels (plugInChannelConfig, true)));
  110. flags.set ("JucePlugin_MaxNumOutputChannels", String (countMaxPluginChannels (plugInChannelConfig, false)));
  111. flags.set ("JucePlugin_PreferredChannelConfigurations", plugInChannelConfig);
  112. }
  113. }
  114. MemoryOutputStream mem;
  115. mem << "//==============================================================================" << newLine
  116. << "// Audio plugin settings.." << newLine
  117. << newLine;
  118. for (int i = 0; i < flags.size(); ++i)
  119. {
  120. mem << "#ifndef " << flags.getAllKeys()[i] << newLine
  121. << " #define " << flags.getAllKeys()[i].paddedRight (' ', 32) << " "
  122. << flags.getAllValues()[i] << newLine
  123. << "#endif" << newLine;
  124. }
  125. setExtraAppConfigFileContent (mem.toString());
  126. }
  127. void ProjectSaver::writeProjects (const OwnedArray<LibraryModule>& modules, const String& specifiedExporterToSave, bool isCommandLineApp)
  128. {
  129. ThreadPool threadPool;
  130. // keep a copy of the basic generated files group, as each exporter may modify it.
  131. auto originalGeneratedGroup = generatedFilesGroup.state.createCopy();
  132. CLionProjectExporter* clionExporter = nullptr;
  133. OwnedArray<ProjectExporter> exporters;
  134. try
  135. {
  136. for (Project::ExporterIterator exp (project); exp.next();)
  137. {
  138. if (specifiedExporterToSave.isNotEmpty() && exp->getName() != specifiedExporterToSave)
  139. continue;
  140. auto* exporter = exporters.add (exp.exporter.release());
  141. exporter->initialiseDependencyPathValues();
  142. if (exporter->getTargetFolder().createDirectory())
  143. {
  144. if (exporter->isCLion())
  145. {
  146. clionExporter = dynamic_cast<CLionProjectExporter*> (exporter);
  147. }
  148. else
  149. {
  150. exporter->copyMainGroupFromProject();
  151. exporter->settings = exporter->settings.createCopy();
  152. exporter->addToExtraSearchPaths (RelativePath ("JuceLibraryCode", RelativePath::projectFolder));
  153. generatedFilesGroup.state = originalGeneratedGroup.createCopy();
  154. exporter->addSettingsForProjectType (project.getProjectType());
  155. for (auto& module: modules)
  156. module->addSettingsForModuleToExporter (*exporter, *this);
  157. if (project.getProjectType().isAudioPlugin())
  158. writePluginCharacteristicsFile();
  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. }