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.

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