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.

1227 lines
51KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #include "../Application/jucer_Headers.h"
  19. #include "jucer_ProjectExporter.h"
  20. #include "jucer_ProjectSaver.h"
  21. #include "jucer_ProjectExport_Make.h"
  22. #include "jucer_ProjectExport_MSVC.h"
  23. #include "jucer_ProjectExport_Xcode.h"
  24. #include "jucer_ProjectExport_Android.h"
  25. #include "jucer_ProjectExport_CodeBlocks.h"
  26. #include "../Utility/UI/PropertyComponents/jucer_FilePathPropertyComponent.h"
  27. //==============================================================================
  28. static auto createIcon (const void* iconData, size_t iconDataSize)
  29. {
  30. Image image (Image::ARGB, 200, 200, true);
  31. Graphics g (image);
  32. std::unique_ptr<Drawable> svgDrawable (Drawable::createFromImageData (iconData, iconDataSize));
  33. svgDrawable->drawWithin (g, image.getBounds().toFloat(), RectanglePlacement::fillDestination, 1.0f);
  34. return image;
  35. }
  36. template <typename Exporter>
  37. static ProjectExporter::ExporterTypeInfo createExporterTypeInfo (const void* iconData, size_t iconDataSize)
  38. {
  39. return { Exporter::getValueTreeTypeName(),
  40. Exporter::getDisplayName(),
  41. Exporter::getTargetFolderName(),
  42. createIcon (iconData, iconDataSize) };
  43. }
  44. std::vector<ProjectExporter::ExporterTypeInfo> ProjectExporter::getExporterTypeInfos()
  45. {
  46. using namespace BinaryData;
  47. static std::vector<ProjectExporter::ExporterTypeInfo> infos
  48. {
  49. { XcodeProjectExporter::getValueTreeTypeNameMac(),
  50. XcodeProjectExporter::getDisplayNameMac(),
  51. XcodeProjectExporter::getTargetFolderNameMac(),
  52. createIcon (export_xcode_svg, (size_t) export_xcode_svgSize) },
  53. { XcodeProjectExporter::getValueTreeTypeNameiOS(),
  54. XcodeProjectExporter::getDisplayNameiOS(),
  55. XcodeProjectExporter::getTargetFolderNameiOS(),
  56. createIcon (export_xcode_svg, (size_t) export_xcode_svgSize) },
  57. createExporterTypeInfo<MSVCProjectExporterVC2022> (export_visualStudio_svg, export_visualStudio_svgSize),
  58. createExporterTypeInfo<MSVCProjectExporterVC2019> (export_visualStudio_svg, export_visualStudio_svgSize),
  59. createExporterTypeInfo<MSVCProjectExporterVC2017> (export_visualStudio_svg, export_visualStudio_svgSize),
  60. createExporterTypeInfo<MakefileProjectExporter> (export_linux_svg, export_linux_svgSize),
  61. createExporterTypeInfo<AndroidProjectExporter> (export_android_svg, export_android_svgSize),
  62. { CodeBlocksProjectExporter::getValueTreeTypeNameWindows(),
  63. CodeBlocksProjectExporter::getDisplayNameWindows(),
  64. CodeBlocksProjectExporter::getTargetFolderNameWindows(),
  65. createIcon (export_codeBlocks_svg, export_codeBlocks_svgSize) },
  66. { CodeBlocksProjectExporter::getValueTreeTypeNameLinux(),
  67. CodeBlocksProjectExporter::getDisplayNameLinux(),
  68. CodeBlocksProjectExporter::getTargetFolderNameLinux(),
  69. createIcon (export_codeBlocks_svg, export_codeBlocks_svgSize) }
  70. };
  71. return infos;
  72. }
  73. ProjectExporter::ExporterTypeInfo ProjectExporter::getTypeInfoForExporter (const Identifier& exporterIdentifier)
  74. {
  75. auto typeInfos = getExporterTypeInfos();
  76. auto iter = std::find_if (typeInfos.begin(), typeInfos.end(),
  77. [exporterIdentifier] (const ProjectExporter::ExporterTypeInfo& info) { return info.identifier == exporterIdentifier; });
  78. if (iter != typeInfos.end())
  79. return *iter;
  80. jassertfalse;
  81. return {};
  82. }
  83. ProjectExporter::ExporterTypeInfo ProjectExporter::getCurrentPlatformExporterTypeInfo()
  84. {
  85. #if JUCE_MAC
  86. return ProjectExporter::getTypeInfoForExporter (XcodeProjectExporter::getValueTreeTypeNameMac());
  87. #elif JUCE_WINDOWS
  88. return ProjectExporter::getTypeInfoForExporter (MSVCProjectExporterVC2022::getValueTreeTypeName());
  89. #elif JUCE_LINUX || JUCE_BSD
  90. return ProjectExporter::getTypeInfoForExporter (MakefileProjectExporter::getValueTreeTypeName());
  91. #else
  92. #error "unknown platform!"
  93. #endif
  94. }
  95. std::unique_ptr<ProjectExporter> ProjectExporter::createNewExporter (Project& project, const Identifier& exporterIdentifier)
  96. {
  97. auto exporter = createExporterFromSettings (project, ValueTree (exporterIdentifier));
  98. jassert (exporter != nullptr);
  99. exporter->createDefaultConfigs();
  100. exporter->createDefaultModulePaths();
  101. return exporter;
  102. }
  103. template <typename T> struct Tag {};
  104. static std::unique_ptr<ProjectExporter> tryCreatingExporter (Project&, const ValueTree&) { return nullptr; }
  105. template <typename Exporter, typename... Exporters>
  106. static std::unique_ptr<ProjectExporter> tryCreatingExporter (Project& project,
  107. const ValueTree& settings,
  108. Tag<Exporter>,
  109. Tag<Exporters>... exporters)
  110. {
  111. if (auto* exporter = Exporter::createForSettings (project, settings))
  112. return rawToUniquePtr (exporter);
  113. return tryCreatingExporter (project, settings, exporters...);
  114. }
  115. std::unique_ptr<ProjectExporter> ProjectExporter::createExporterFromSettings (Project& project, const ValueTree& settings)
  116. {
  117. return tryCreatingExporter (project,
  118. settings,
  119. Tag<XcodeProjectExporter>{},
  120. Tag<MSVCProjectExporterVC2022>{},
  121. Tag<MSVCProjectExporterVC2019>{},
  122. Tag<MSVCProjectExporterVC2017>{},
  123. Tag<MakefileProjectExporter>{},
  124. Tag<AndroidProjectExporter>{},
  125. Tag<CodeBlocksProjectExporter>{});
  126. }
  127. bool ProjectExporter::canProjectBeLaunched (Project* project)
  128. {
  129. if (project != nullptr)
  130. {
  131. static Identifier types[]
  132. {
  133. #if JUCE_MAC
  134. XcodeProjectExporter::getValueTreeTypeNameMac(),
  135. XcodeProjectExporter::getValueTreeTypeNameiOS(),
  136. #elif JUCE_WINDOWS
  137. MSVCProjectExporterVC2022::getValueTreeTypeName(),
  138. MSVCProjectExporterVC2019::getValueTreeTypeName(),
  139. MSVCProjectExporterVC2017::getValueTreeTypeName(),
  140. #endif
  141. AndroidProjectExporter::getValueTreeTypeName()
  142. };
  143. for (auto& exporterIdentifier : types)
  144. if (project->getExporters().getChildWithName (exporterIdentifier).isValid())
  145. return true;
  146. }
  147. return false;
  148. }
  149. //==============================================================================
  150. ProjectExporter::ProjectExporter (Project& p, const ValueTree& state)
  151. : settings (state),
  152. project (p),
  153. projectType (p.getProjectType()),
  154. projectName (p.getProjectNameString()),
  155. projectFolder (p.getProjectFolder()),
  156. targetLocationValue (settings, Ids::targetFolder, getUndoManager()),
  157. extraCompilerFlagsValue (settings, Ids::extraCompilerFlags, getUndoManager()),
  158. extraLinkerFlagsValue (settings, Ids::extraLinkerFlags, getUndoManager()),
  159. externalLibrariesValue (settings, Ids::externalLibraries, getUndoManager()),
  160. userNotesValue (settings, Ids::userNotes, getUndoManager()),
  161. gnuExtensionsValue (settings, Ids::enableGNUExtensions, getUndoManager()),
  162. bigIconValue (settings, Ids::bigIcon, getUndoManager()),
  163. smallIconValue (settings, Ids::smallIcon, getUndoManager()),
  164. extraPPDefsValue (settings, Ids::extraDefs, getUndoManager())
  165. {
  166. projectCompilerFlagSchemesValue = project.getProjectValue (Ids::compilerFlagSchemes);
  167. projectCompilerFlagSchemesValue.addListener (this);
  168. updateCompilerFlagValues();
  169. }
  170. String ProjectExporter::getUniqueName() const
  171. {
  172. auto targetLocationString = getTargetLocationString();
  173. auto defaultBuildsRootFolder = getDefaultBuildsRootFolder();
  174. auto typeInfos = getExporterTypeInfos();
  175. auto predicate = [targetLocationString, defaultBuildsRootFolder] (const ProjectExporter::ExporterTypeInfo& info)
  176. {
  177. return defaultBuildsRootFolder + info.targetFolder == targetLocationString;
  178. };
  179. if (std::none_of (typeInfos.begin(), typeInfos.end(), std::move (predicate)))
  180. return name + " - " + targetLocationString;
  181. return name;
  182. }
  183. File ProjectExporter::getTargetFolder() const
  184. {
  185. return project.resolveFilename (getTargetLocationString());
  186. }
  187. build_tools::RelativePath ProjectExporter::rebaseFromProjectFolderToBuildTarget (const build_tools::RelativePath& path) const
  188. {
  189. return path.rebased (project.getProjectFolder(), getTargetFolder(), build_tools::RelativePath::buildTargetFolder);
  190. }
  191. build_tools::RelativePath ProjectExporter::rebaseFromBuildTargetToProjectFolder (const build_tools::RelativePath& path) const
  192. {
  193. jassert (path.getRoot() == build_tools::RelativePath::buildTargetFolder);
  194. return path.rebased (getTargetFolder(), project.getProjectFolder(), build_tools::RelativePath::projectFolder);
  195. }
  196. File ProjectExporter::resolveRelativePath (const build_tools::RelativePath& path) const
  197. {
  198. if (path.isAbsolute())
  199. return path.toUnixStyle();
  200. switch (path.getRoot())
  201. {
  202. case build_tools::RelativePath::buildTargetFolder:
  203. return getTargetFolder().getChildFile (path.toUnixStyle());
  204. case build_tools::RelativePath::projectFolder:
  205. return project.getProjectFolder().getChildFile (path.toUnixStyle());
  206. case build_tools::RelativePath::unknown:
  207. jassertfalse;
  208. }
  209. return path.toUnixStyle();
  210. }
  211. bool ProjectExporter::shouldFileBeCompiledByDefault (const File& file) const
  212. {
  213. return file.hasFileExtension (cOrCppFileExtensions)
  214. || file.hasFileExtension (asmFileExtensions);
  215. }
  216. void ProjectExporter::updateCompilerFlagValues()
  217. {
  218. compilerFlagSchemesMap.clear();
  219. for (auto& scheme : project.getCompilerFlagSchemes())
  220. {
  221. compilerFlagSchemesMap.emplace (std::piecewise_construct,
  222. std::forward_as_tuple (scheme),
  223. std::forward_as_tuple (settings, scheme, getUndoManager()));
  224. }
  225. }
  226. //==============================================================================
  227. void ProjectExporter::createPropertyEditors (PropertyListBuilder& props)
  228. {
  229. props.add (new TextPropertyComponent (targetLocationValue, "Target Project Folder", 2048, false),
  230. "The location of the folder in which the " + name + " project will be created. "
  231. "This path can be absolute, but it's much more sensible to make it relative to the jucer project directory.");
  232. if ((shouldBuildTargetType (build_tools::ProjectType::Target::VSTPlugIn) && project.shouldBuildVST()) || (project.isVSTPluginHost() && supportsTargetType (build_tools::ProjectType::Target::VSTPlugIn)))
  233. {
  234. props.add (new FilePathPropertyComponent (vstLegacyPathValueWrapper.getWrappedValueTreePropertyWithDefault(), "VST (Legacy) SDK Folder", true,
  235. getTargetOSForExporter() == TargetOS::getThisOS(), "*", project.getProjectFolder()),
  236. "If you're building a VST plug-in or host, you can use this field to override the global VST (Legacy) SDK path with a project-specific path. "
  237. "This can be an absolute path, or a path relative to the Projucer project file.");
  238. }
  239. if (shouldBuildTargetType (build_tools::ProjectType::Target::AAXPlugIn) && project.shouldBuildAAX())
  240. {
  241. props.add (new FilePathPropertyComponent (aaxPathValueWrapper.getWrappedValueTreePropertyWithDefault(), "AAX SDK Folder", true,
  242. getTargetOSForExporter() == TargetOS::getThisOS(), "*", project.getProjectFolder()),
  243. "If you're building an AAX plug-in, this must be the folder containing the AAX SDK. This can be an absolute path, or a path relative to the Projucer project file.");
  244. }
  245. if (project.shouldEnableARA() || project.isARAPluginHost())
  246. {
  247. props.add (new FilePathPropertyComponent (araPathValueWrapper.getWrappedValueTreePropertyWithDefault(), "ARA SDK Folder", true,
  248. getTargetOSForExporter() == TargetOS::getThisOS(), "*", project.getProjectFolder()),
  249. "If you're building an ARA enabled plug-in, this must be the folder containing the ARA SDK. This can be an absolute path, or a path relative to the Projucer project file.");
  250. }
  251. props.add (new TextPropertyComponent (extraPPDefsValue, "Extra Preprocessor Definitions", 32768, true),
  252. "Extra preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, "
  253. "or new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  254. props.add (new TextPropertyComponent (extraCompilerFlagsValue, "Extra Compiler Flags", 8192, true),
  255. "Extra command-line flags to be passed to the compiler. This string can contain references to preprocessor definitions in the "
  256. "form ${NAME_OF_DEFINITION}, which will be replaced with their values.");
  257. for (const auto& [key, property] : compilerFlagSchemesMap)
  258. {
  259. props.add (new TextPropertyComponent (property, "Compiler Flags for " + key.quoted(), 8192, false),
  260. "The exporter-specific compiler flags that will be added to files using this scheme.");
  261. }
  262. props.add (new TextPropertyComponent (extraLinkerFlagsValue, "Extra Linker Flags", 8192, true),
  263. "Extra command-line flags to be passed to the linker. You might want to use this for adding additional libraries. "
  264. "This string can contain references to preprocessor definitions in the form ${NAME_OF_VALUE}, which will be replaced with their values.");
  265. props.add (new TextPropertyComponent (externalLibrariesValue, "External Libraries to Link", 8192, true),
  266. "Additional libraries to link (one per line). You should not add any platform specific decoration to these names. "
  267. "This string can contain references to preprocessor definitions in the form ${NAME_OF_VALUE}, which will be replaced with their values.");
  268. if (! isVisualStudio())
  269. props.add (new ChoicePropertyComponent (gnuExtensionsValue, "GNU Compiler Extensions"),
  270. "Enabling this will use the GNU C++ language standard variant for compilation.");
  271. createIconProperties (props);
  272. createExporterProperties (props);
  273. props.add (new TextPropertyComponent (userNotesValue, "Notes", 32768, true),
  274. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  275. }
  276. void ProjectExporter::createIconProperties (PropertyListBuilder& props)
  277. {
  278. OwnedArray<Project::Item> images;
  279. project.findAllImageItems (images);
  280. StringArray choices;
  281. Array<var> ids;
  282. choices.add ("<None>");
  283. ids.add (var());
  284. for (const auto* imageItem : images)
  285. {
  286. choices.add (imageItem->getName());
  287. ids.add (imageItem->getID());
  288. }
  289. props.add (new ChoicePropertyComponent (smallIconValue, "Icon (Small)", choices, ids),
  290. "Sets an icon to use for the executable.");
  291. props.add (new ChoicePropertyComponent (bigIconValue, "Icon (Large)", choices, ids),
  292. "Sets an icon to use for the executable.");
  293. }
  294. //==============================================================================
  295. void ProjectExporter::addSettingsForProjectType (const build_tools::ProjectType& type)
  296. {
  297. addExtraIncludePathsIfPluginOrHost();
  298. addARAPathsIfPluginOrHost();
  299. if (type.isAudioPlugin())
  300. addCommonAudioPluginSettings();
  301. addPlatformSpecificSettingsForProjectType (type);
  302. }
  303. void ProjectExporter::addExtraIncludePathsIfPluginOrHost()
  304. {
  305. using Target = build_tools::ProjectType::Target;
  306. if (((shouldBuildTargetType (Target::VSTPlugIn) && project.shouldBuildVST()) || project.isVSTPluginHost())
  307. || ((shouldBuildTargetType (Target::VST3PlugIn) && project.shouldBuildVST3()) || project.isVST3PluginHost()))
  308. {
  309. addLegacyVSTFolderToPathIfSpecified();
  310. if (! project.isConfigFlagEnabled ("JUCE_CUSTOM_VST3_SDK"))
  311. addToExtraSearchPaths (getInternalVST3SDKPath(), 0);
  312. }
  313. const auto lv2BasePath = getModuleFolderRelativeToProject ("juce_audio_processors").getChildFile ("format_types")
  314. .getChildFile ("LV2_SDK");
  315. if ((shouldBuildTargetType (Target::LV2PlugIn) && project.shouldBuildLV2()) || project.isLV2PluginHost())
  316. {
  317. const std::vector<const char*> paths[] { { "" },
  318. { "lv2" },
  319. { "serd" },
  320. { "sord" },
  321. { "sord", "src" },
  322. { "sratom" },
  323. { "lilv" },
  324. { "lilv", "src" } };
  325. for (const auto& components : paths)
  326. {
  327. const auto appendComponent = [] (const build_tools::RelativePath& f, const char* component)
  328. {
  329. return f.getChildFile (component);
  330. };
  331. const auto includePath = std::accumulate (components.begin(),
  332. components.end(),
  333. lv2BasePath,
  334. appendComponent);
  335. addToExtraSearchPaths (includePath, 0);
  336. }
  337. }
  338. }
  339. void ProjectExporter::addARAPathsIfPluginOrHost()
  340. {
  341. if (project.shouldEnableARA() || project.isARAPluginHost())
  342. addARAFoldersToPath();
  343. }
  344. void ProjectExporter::addCommonAudioPluginSettings()
  345. {
  346. if (shouldBuildTargetType (build_tools::ProjectType::Target::AAXPlugIn))
  347. addAAXFoldersToPath();
  348. }
  349. void ProjectExporter::addLegacyVSTFolderToPathIfSpecified()
  350. {
  351. auto vstFolder = getVSTLegacyPathString();
  352. if (vstFolder.isNotEmpty())
  353. addToExtraSearchPaths (build_tools::RelativePath (vstFolder, build_tools::RelativePath::projectFolder), 0);
  354. }
  355. build_tools::RelativePath ProjectExporter::getInternalVST3SDKPath()
  356. {
  357. return getModuleFolderRelativeToProject ("juce_audio_processors")
  358. .getChildFile ("format_types")
  359. .getChildFile ("VST3_SDK");
  360. }
  361. void ProjectExporter::addAAXFoldersToPath()
  362. {
  363. auto aaxFolder = getAAXPathString();
  364. if (aaxFolder.isNotEmpty())
  365. {
  366. build_tools::RelativePath aaxFolderPath (aaxFolder, build_tools::RelativePath::projectFolder);
  367. addToExtraSearchPaths (aaxFolderPath);
  368. addToExtraSearchPaths (aaxFolderPath.getChildFile ("Interfaces"));
  369. addToExtraSearchPaths (aaxFolderPath.getChildFile ("Interfaces").getChildFile ("ACF"));
  370. }
  371. }
  372. void ProjectExporter::addARAFoldersToPath()
  373. {
  374. const auto araFolder = getARAPathString();
  375. if (araFolder.isNotEmpty())
  376. addToExtraSearchPaths (build_tools::RelativePath (araFolder, build_tools::RelativePath::projectFolder));
  377. }
  378. //==============================================================================
  379. StringPairArray ProjectExporter::getAllPreprocessorDefs (const BuildConfiguration& config, const build_tools::ProjectType::Target::Type targetType) const
  380. {
  381. auto defs = mergePreprocessorDefs (config.getAllPreprocessorDefs(),
  382. parsePreprocessorDefs (getExporterPreprocessorDefsString()));
  383. addDefaultPreprocessorDefs (defs);
  384. addTargetSpecificPreprocessorDefs (defs, targetType);
  385. if (! project.shouldUseAppConfig())
  386. defs = mergePreprocessorDefs (project.getAppConfigDefs(), defs);
  387. return defs;
  388. }
  389. StringPairArray ProjectExporter::getAllPreprocessorDefs() const
  390. {
  391. auto defs = mergePreprocessorDefs (project.getPreprocessorDefs(),
  392. parsePreprocessorDefs (getExporterPreprocessorDefsString()));
  393. addDefaultPreprocessorDefs (defs);
  394. return defs;
  395. }
  396. void ProjectExporter::addTargetSpecificPreprocessorDefs (StringPairArray& defs, const build_tools::ProjectType::Target::Type targetType) const
  397. {
  398. using Target = build_tools::ProjectType::Target::Type;
  399. const std::pair<const char*, Target> targetFlags[] { { "JucePlugin_Build_VST", Target::VSTPlugIn },
  400. { "JucePlugin_Build_VST3", Target::VST3PlugIn },
  401. { "JucePlugin_Build_AU", Target::AudioUnitPlugIn },
  402. { "JucePlugin_Build_AUv3", Target::AudioUnitv3PlugIn },
  403. { "JucePlugin_Build_AAX", Target::AAXPlugIn },
  404. { "JucePlugin_Build_Standalone", Target::StandalonePlugIn },
  405. { "JucePlugin_Build_Unity", Target::UnityPlugIn },
  406. { "JucePlugin_Build_LV2", Target::LV2PlugIn } };
  407. if (targetType == build_tools::ProjectType::Target::SharedCodeTarget)
  408. {
  409. for (auto& flag : targetFlags)
  410. defs.set (flag.first, (shouldBuildTargetType (flag.second) ? "1" : "0"));
  411. defs.set ("JUCE_SHARED_CODE", "1");
  412. }
  413. else if (targetType != build_tools::ProjectType::Target::unspecified)
  414. {
  415. for (auto& flag : targetFlags)
  416. defs.set (flag.first, (targetType == flag.second ? "1" : "0"));
  417. }
  418. if (project.shouldEnableARA())
  419. {
  420. defs.set ("JucePlugin_Enable_ARA", "1");
  421. }
  422. linuxSubprocessHelperProperties.setCompileDefinitionIfNecessary (defs);
  423. }
  424. void ProjectExporter::addDefaultPreprocessorDefs (StringPairArray& defs) const
  425. {
  426. defs.set (getExporterIdentifierMacro(), "1");
  427. defs.set ("JUCE_APP_VERSION", project.getVersionString());
  428. defs.set ("JUCE_APP_VERSION_HEX", project.getVersionAsHex());
  429. }
  430. String ProjectExporter::replacePreprocessorTokens (const ProjectExporter::BuildConfiguration& config,
  431. const String& sourceString) const
  432. {
  433. return build_tools::replacePreprocessorDefs (getAllPreprocessorDefs (config, build_tools::ProjectType::Target::unspecified),
  434. sourceString);
  435. }
  436. String ProjectExporter::getCompilerFlagsForFileCompilerFlagScheme (StringRef schemeName) const
  437. {
  438. if (const auto iter = compilerFlagSchemesMap.find (schemeName); iter != compilerFlagSchemesMap.cend())
  439. return iter->second.get().toString();
  440. return {};
  441. }
  442. String ProjectExporter::getCompilerFlagsForProjectItem (const Project::Item& item) const
  443. {
  444. return getCompilerFlagsForFileCompilerFlagScheme (item.getCompilerFlagSchemeString());
  445. }
  446. void ProjectExporter::copyMainGroupFromProject()
  447. {
  448. jassert (itemGroups.size() == 0);
  449. itemGroups.add (project.getMainGroup().createCopy());
  450. }
  451. Project::Item& ProjectExporter::getModulesGroup()
  452. {
  453. if (modulesGroup == nullptr)
  454. {
  455. jassert (itemGroups.size() > 0); // must call copyMainGroupFromProject before this.
  456. itemGroups.add (Project::Item::createGroup (project, "JUCE Modules", "__modulesgroup__", true));
  457. modulesGroup = &(itemGroups.getReference (itemGroups.size() - 1));
  458. }
  459. return *modulesGroup;
  460. }
  461. //==============================================================================
  462. static bool isWebBrowserComponentEnabled (const Project& project)
  463. {
  464. static String guiExtrasModule ("juce_gui_extra");
  465. return (project.getEnabledModules().isModuleEnabled (guiExtrasModule)
  466. && project.isConfigFlagEnabled ("JUCE_WEB_BROWSER", true));
  467. }
  468. static bool isCurlEnabled (Project& project)
  469. {
  470. static String juceCoreModule ("juce_core");
  471. return (project.getEnabledModules().isModuleEnabled (juceCoreModule)
  472. && project.isConfigFlagEnabled ("JUCE_USE_CURL", true));
  473. }
  474. static bool isLoadCurlSymbolsLazilyEnabled (Project& project)
  475. {
  476. static String juceCoreModule ("juce_core");
  477. return (project.getEnabledModules().isModuleEnabled (juceCoreModule)
  478. && project.isConfigFlagEnabled ("JUCE_LOAD_CURL_SYMBOLS_LAZILY", false));
  479. }
  480. StringArray ProjectExporter::getLinuxPackages (PackageDependencyType type) const
  481. {
  482. auto packages = linuxPackages;
  483. // don't add libcurl if curl symbols are loaded at runtime
  484. if (isCurlEnabled (project) && ! isLoadCurlSymbolsLazilyEnabled (project))
  485. packages.add ("libcurl");
  486. if (isWebBrowserComponentEnabled (project) && type == PackageDependencyType::compile)
  487. {
  488. packages.add ("webkit2gtk-4.0");
  489. packages.add ("gtk+-x11-3.0");
  490. }
  491. packages.removeEmptyStrings();
  492. packages.removeDuplicates (false);
  493. return packages;
  494. }
  495. void ProjectExporter::addProjectPathToBuildPathList (StringArray& pathList,
  496. const build_tools::RelativePath& pathFromProjectFolder,
  497. int index) const
  498. {
  499. auto localPath = build_tools::RelativePath (rebaseFromProjectFolderToBuildTarget (pathFromProjectFolder));
  500. auto path = isVisualStudio() ? localPath.toWindowsStyle() : localPath.toUnixStyle();
  501. if (! pathList.contains (path))
  502. pathList.insert (index, path);
  503. }
  504. void ProjectExporter::addToModuleLibPaths (const build_tools::RelativePath& pathFromProjectFolder)
  505. {
  506. addProjectPathToBuildPathList (moduleLibSearchPaths, pathFromProjectFolder);
  507. }
  508. void ProjectExporter::addToExtraSearchPaths (const build_tools::RelativePath& pathFromProjectFolder, int index)
  509. {
  510. jassert (pathFromProjectFolder.getRoot() == build_tools::RelativePath::projectFolder);
  511. addProjectPathToBuildPathList (extraSearchPaths, pathFromProjectFolder, index);
  512. }
  513. static var getStoredPathForModule (const String& id, const ProjectExporter& exp)
  514. {
  515. return getAppSettings().getStoredPath (isJUCEModule (id) ? Ids::defaultJuceModulePath : Ids::defaultUserModulePath,
  516. exp.getTargetOSForExporter()).get();
  517. }
  518. ValueTreePropertyWithDefault ProjectExporter::getPathForModuleValue (const String& moduleID)
  519. {
  520. auto* um = getUndoManager();
  521. auto paths = settings.getOrCreateChildWithName (Ids::MODULEPATHS, um);
  522. auto m = paths.getChildWithProperty (Ids::ID, moduleID);
  523. if (! m.isValid())
  524. {
  525. m = ValueTree (Ids::MODULEPATH);
  526. m.setProperty (Ids::ID, moduleID, um);
  527. paths.appendChild (m, um);
  528. }
  529. return { m, Ids::path, um, getStoredPathForModule (moduleID, *this) };
  530. }
  531. String ProjectExporter::getPathForModuleString (const String& moduleID) const
  532. {
  533. auto exporterPath = settings.getChildWithName (Ids::MODULEPATHS)
  534. .getChildWithProperty (Ids::ID, moduleID) [Ids::path].toString();
  535. if (exporterPath.isEmpty() || project.getEnabledModules().shouldUseGlobalPath (moduleID))
  536. return getStoredPathForModule (moduleID, *this);
  537. return exporterPath;
  538. }
  539. void ProjectExporter::removePathForModule (const String& moduleID)
  540. {
  541. auto paths = settings.getChildWithName (Ids::MODULEPATHS);
  542. auto m = paths.getChildWithProperty (Ids::ID, moduleID);
  543. paths.removeChild (m, project.getUndoManagerFor (settings));
  544. }
  545. TargetOS::OS ProjectExporter::getTargetOSForExporter() const
  546. {
  547. auto targetOS = TargetOS::unknown;
  548. if (isWindows()) targetOS = TargetOS::windows;
  549. else if (isOSX() || isiOS()) targetOS = TargetOS::osx;
  550. else if (isLinux()) targetOS = TargetOS::linux;
  551. else if (isAndroid()) targetOS = TargetOS::getThisOS();
  552. return targetOS;
  553. }
  554. build_tools::RelativePath ProjectExporter::getModuleFolderRelativeToProject (const String& moduleID) const
  555. {
  556. if (project.getEnabledModules().shouldCopyModuleFilesLocally (moduleID))
  557. return build_tools::RelativePath (project.getRelativePathForFile (project.getLocalModuleFolder (moduleID)),
  558. build_tools::RelativePath::projectFolder);
  559. auto path = getPathForModuleString (moduleID);
  560. if (path.isEmpty())
  561. return getLegacyModulePath (moduleID).getChildFile (moduleID);
  562. return build_tools::RelativePath (path, build_tools::RelativePath::projectFolder).getChildFile (moduleID);
  563. }
  564. String ProjectExporter::getLegacyModulePath() const
  565. {
  566. return getSettingString ("juceFolder");
  567. }
  568. build_tools::RelativePath ProjectExporter::getLegacyModulePath (const String& moduleID) const
  569. {
  570. if (project.getEnabledModules().shouldCopyModuleFilesLocally (moduleID))
  571. return build_tools::RelativePath (project.getRelativePathForFile (project.getGeneratedCodeFolder()
  572. .getChildFile ("modules")
  573. .getChildFile (moduleID)), build_tools::RelativePath::projectFolder);
  574. auto oldJucePath = getLegacyModulePath();
  575. if (oldJucePath.isEmpty())
  576. return build_tools::RelativePath();
  577. build_tools::RelativePath p (oldJucePath, build_tools::RelativePath::projectFolder);
  578. if (p.getFileName() != "modules")
  579. p = p.getChildFile ("modules");
  580. return p.getChildFile (moduleID);
  581. }
  582. void ProjectExporter::updateOldModulePaths()
  583. {
  584. auto oldPath = getLegacyModulePath();
  585. if (oldPath.isNotEmpty())
  586. {
  587. for (int i = project.getEnabledModules().getNumModules(); --i >= 0;)
  588. {
  589. auto modID = project.getEnabledModules().getModuleID (i);
  590. getPathForModuleValue (modID) = getLegacyModulePath (modID).getParentDirectory().toUnixStyle();
  591. }
  592. settings.removeProperty ("juceFolder", nullptr);
  593. }
  594. }
  595. static bool areSameExporters (const ProjectExporter& p1, const ProjectExporter& p2)
  596. {
  597. return p1.getExporterIdentifier() == p2.getExporterIdentifier();
  598. }
  599. static bool areCompatibleExporters (const ProjectExporter& p1, const ProjectExporter& p2)
  600. {
  601. return (p1.isVisualStudio() && p2.isVisualStudio())
  602. || (p1.isXcode() && p2.isXcode())
  603. || (p1.isMakefile() && p2.isMakefile())
  604. || (p1.isAndroidStudio() && p2.isAndroidStudio())
  605. || (p1.isCodeBlocks() && p2.isCodeBlocks() && p1.isWindows() != p2.isLinux());
  606. }
  607. void ProjectExporter::createDefaultModulePaths()
  608. {
  609. auto exporterToCopy = [this]() -> std::unique_ptr<ProjectExporter>
  610. {
  611. std::vector<std::unique_ptr<ProjectExporter>> exporters;
  612. for (Project::ExporterIterator exporter (project); exporter.next();)
  613. exporters.push_back (std::move (exporter.exporter));
  614. auto getIf = [&exporters] (auto predicate)
  615. {
  616. auto iter = std::find_if (exporters.begin(), exporters.end(), predicate);
  617. return iter != exporters.end() ? std::move (*iter) : nullptr;
  618. };
  619. if (auto exporter = getIf ([this] (auto& x) { return areSameExporters (*this, *x); }))
  620. return exporter;
  621. if (auto exporter = getIf ([this] (auto& x) { return areCompatibleExporters (*this, *x); }))
  622. return exporter;
  623. if (auto exporter = getIf ([] (auto& x) { return x->canLaunchProject(); }))
  624. return exporter;
  625. return {};
  626. }();
  627. for (const auto& modID : project.getEnabledModules().getAllModules())
  628. getPathForModuleValue (modID) = (exporterToCopy != nullptr ? exporterToCopy->getPathForModuleString (modID) : "../../juce");
  629. }
  630. //==============================================================================
  631. ValueTree ProjectExporter::getConfigurations() const
  632. {
  633. return settings.getChildWithName (Ids::CONFIGURATIONS);
  634. }
  635. int ProjectExporter::getNumConfigurations() const
  636. {
  637. return getConfigurations().getNumChildren();
  638. }
  639. ProjectExporter::BuildConfiguration::Ptr ProjectExporter::getConfiguration (int index) const
  640. {
  641. return createBuildConfig (getConfigurations().getChild (index));
  642. }
  643. void ProjectExporter::addNewConfigurationFromExisting (const BuildConfiguration& configToCopy)
  644. {
  645. auto configs = getConfigurations();
  646. if (! configs.isValid())
  647. {
  648. settings.addChild (ValueTree (Ids::CONFIGURATIONS), 0, project.getUndoManagerFor (settings));
  649. configs = getConfigurations();
  650. }
  651. ValueTree newConfig (Ids::CONFIGURATION);
  652. newConfig = configToCopy.config.createCopy();
  653. newConfig.setProperty (Ids::name, configToCopy.getName(), nullptr);
  654. configs.appendChild (newConfig, project.getUndoManagerFor (configs));
  655. }
  656. void ProjectExporter::addNewConfiguration (bool isDebugConfig)
  657. {
  658. auto configs = getConfigurations();
  659. if (! configs.isValid())
  660. {
  661. settings.addChild (ValueTree (Ids::CONFIGURATIONS), 0, project.getUndoManagerFor (settings));
  662. configs = getConfigurations();
  663. }
  664. ValueTree newConfig (Ids::CONFIGURATION);
  665. newConfig.setProperty (Ids::isDebug, isDebugConfig, project.getUndoManagerFor (settings));
  666. configs.appendChild (newConfig, project.getUndoManagerFor (settings));
  667. }
  668. void ProjectExporter::BuildConfiguration::removeFromExporter()
  669. {
  670. ValueTree configs (config.getParent());
  671. configs.removeChild (config, project.getUndoManagerFor (configs));
  672. }
  673. void ProjectExporter::createDefaultConfigs()
  674. {
  675. settings.getOrCreateChildWithName (Ids::CONFIGURATIONS, nullptr);
  676. for (int i = 0; i < 2; ++i)
  677. {
  678. auto isDebug = i == 0;
  679. addNewConfiguration (isDebug);
  680. BuildConfiguration::Ptr config (getConfiguration (i));
  681. config->getValue (Ids::name) = (isDebug ? "Debug" : "Release");
  682. }
  683. }
  684. std::unique_ptr<Drawable> ProjectExporter::getBigIcon() const
  685. {
  686. return project.getMainGroup().findItemWithID (settings [Ids::bigIcon]).loadAsImageFile();
  687. }
  688. std::unique_ptr<Drawable> ProjectExporter::getSmallIcon() const
  689. {
  690. return project.getMainGroup().findItemWithID (settings [Ids::smallIcon]).loadAsImageFile();
  691. }
  692. //==============================================================================
  693. ProjectExporter::ConfigIterator::ConfigIterator (ProjectExporter& e)
  694. : index (-1), exporter (e)
  695. {
  696. }
  697. bool ProjectExporter::ConfigIterator::next()
  698. {
  699. if (++index >= exporter.getNumConfigurations())
  700. return false;
  701. config = exporter.getConfiguration (index);
  702. return true;
  703. }
  704. ProjectExporter::ConstConfigIterator::ConstConfigIterator (const ProjectExporter& exporter_)
  705. : index (-1), exporter (exporter_)
  706. {
  707. }
  708. bool ProjectExporter::ConstConfigIterator::next()
  709. {
  710. if (++index >= exporter.getNumConfigurations())
  711. return false;
  712. config = exporter.getConfiguration (index);
  713. return true;
  714. }
  715. //==============================================================================
  716. ProjectExporter::BuildConfiguration::BuildConfiguration (Project& p, const ValueTree& configNode, const ProjectExporter& e)
  717. : config (configNode), project (p), exporter (e),
  718. isDebugValue (config, Ids::isDebug, getUndoManager(), getValue (Ids::isDebug)),
  719. configNameValue (config, Ids::name, getUndoManager(), "Build Configuration"),
  720. targetNameValue (config, Ids::targetName, getUndoManager(), project.getProjectFilenameRootString()),
  721. targetBinaryPathValue (config, Ids::binaryPath, getUndoManager()),
  722. recommendedWarningsValue (config, Ids::recommendedWarnings, getUndoManager()),
  723. optimisationLevelValue (config, Ids::optimisation, getUndoManager()),
  724. linkTimeOptimisationValue (config, Ids::linkTimeOptimisation, getUndoManager(), ! isDebug()),
  725. ppDefinesValue (config, Ids::defines, getUndoManager()),
  726. headerSearchPathValue (config, Ids::headerPath, getUndoManager()),
  727. librarySearchPathValue (config, Ids::libraryPath, getUndoManager()),
  728. userNotesValue (config, Ids::userNotes, getUndoManager()),
  729. usePrecompiledHeaderFileValue (config, Ids::usePrecompiledHeaderFile, getUndoManager(), false),
  730. precompiledHeaderFileValue (config, Ids::precompiledHeaderFile, getUndoManager()),
  731. configCompilerFlagsValue (config, Ids::extraCompilerFlags, getUndoManager()),
  732. configLinkerFlagsValue (config, Ids::extraLinkerFlags, getUndoManager())
  733. {
  734. auto& llvmFlags = recommendedCompilerWarningFlags[CompilerNames::llvm] = BuildConfiguration::CompilerWarningFlags::getRecommendedForGCCAndLLVM();
  735. llvmFlags.common.addArray ({ "-Wshorten-64-to-32", "-Wconversion", "-Wint-conversion",
  736. "-Wconditional-uninitialized", "-Wconstant-conversion", "-Wbool-conversion",
  737. "-Wextra-semi", "-Wshift-sign-overflow",
  738. "-Wshadow-all", "-Wnullable-to-nonnull-conversion",
  739. "-Wmissing-prototypes" });
  740. llvmFlags.cpp.addArray ({ "-Wunused-private-field", "-Winconsistent-missing-destructor-override" });
  741. llvmFlags.objc.addArray ({ "-Wunguarded-availability", "-Wunguarded-availability-new" });
  742. auto& gccFlags = recommendedCompilerWarningFlags[CompilerNames::gcc] = BuildConfiguration::CompilerWarningFlags::getRecommendedForGCCAndLLVM();
  743. gccFlags.common.addArray ({ "-Wextra", "-Wsign-compare", "-Wno-implicit-fallthrough", "-Wno-maybe-uninitialized",
  744. "-Wredundant-decls", "-Wno-strict-overflow", "-Wshadow" });
  745. }
  746. String ProjectExporter::BuildConfiguration::getGCCOptimisationFlag() const
  747. {
  748. switch (getOptimisationLevelInt())
  749. {
  750. case gccO0: return "0";
  751. case gccO1: return "1";
  752. case gccO2: return "2";
  753. case gccO3: return "3";
  754. case gccOs: return "s";
  755. case gccOfast: return "fast";
  756. default: break;
  757. }
  758. return "0";
  759. }
  760. void ProjectExporter::BuildConfiguration::addGCCOptimisationProperty (PropertyListBuilder& props)
  761. {
  762. props.add (new ChoicePropertyComponent (optimisationLevelValue, "Optimisation",
  763. { "-O0 (no optimisation)", "-Os (minimise code size)", "-O1 (fast)", "-O2 (faster)",
  764. "-O3 (fastest with safe optimisations)", "-Ofast (uses aggressive optimisations)" },
  765. { gccO0, gccOs, gccO1, gccO2, gccO3, gccOfast }),
  766. "The optimisation level for this configuration");
  767. }
  768. void ProjectExporter::BuildConfiguration::addRecommendedLinuxCompilerWarningsProperty (PropertyListBuilder& props)
  769. {
  770. recommendedWarningsValue.setDefault ("");
  771. props.add (new ChoicePropertyComponent (recommendedWarningsValue, "Add Recommended Compiler Warning Flags",
  772. { CompilerNames::gcc, CompilerNames::llvm, "Disabled" },
  773. { CompilerNames::gcc, CompilerNames::llvm, "" }),
  774. "Enable this to add a set of recommended compiler warning flags.");
  775. }
  776. void ProjectExporter::BuildConfiguration::addRecommendedLLVMCompilerWarningsProperty (PropertyListBuilder& props)
  777. {
  778. recommendedWarningsValue.setDefault ("");
  779. props.add (new ChoicePropertyComponent (recommendedWarningsValue, "Add Recommended Compiler Warning Flags",
  780. { "Enabled", "Disabled" },
  781. { CompilerNames::llvm, "" }),
  782. "Enable this to add a set of recommended compiler warning flags.");
  783. }
  784. ProjectExporter::BuildConfiguration::CompilerWarningFlags ProjectExporter::BuildConfiguration::getRecommendedCompilerWarningFlags() const
  785. {
  786. auto label = recommendedWarningsValue.get().toString();
  787. if (label == "GCC-7")
  788. label = CompilerNames::gcc;
  789. auto it = recommendedCompilerWarningFlags.find (label);
  790. if (it != recommendedCompilerWarningFlags.end())
  791. return it->second;
  792. return {};
  793. }
  794. void ProjectExporter::BuildConfiguration::createPropertyEditors (PropertyListBuilder& props)
  795. {
  796. if (exporter.supportsUserDefinedConfigurations())
  797. props.add (new TextPropertyComponent (configNameValue, "Name", 96, false),
  798. "The name of this configuration.");
  799. props.add (new ChoicePropertyComponent (isDebugValue, "Debug Mode"),
  800. "If enabled, this means that the configuration should be built with debug symbols.");
  801. props.add (new TextPropertyComponent (targetNameValue, "Binary Name", 256, false),
  802. "The filename to use for the destination binary executable file. If you don't add a suffix to this name, "
  803. "a suitable platform-specific suffix will be added automatically.");
  804. props.add (new TextPropertyComponent (targetBinaryPathValue, "Binary Location", 1024, false),
  805. "The folder in which the finished binary should be placed. Leave this blank to cause the binary to be placed "
  806. "in its default location in the build folder.");
  807. props.addSearchPathProperty (headerSearchPathValue, "Header Search Paths", "Extra header search paths.");
  808. props.addSearchPathProperty (librarySearchPathValue, "Extra Library Search Paths", "Extra library search paths.");
  809. props.add (new TextPropertyComponent (ppDefinesValue, "Preprocessor Definitions", 32768, true),
  810. "Extra preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  811. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  812. props.add (new TextPropertyComponent (configCompilerFlagsValue, "Configuration-specific Compiler Flags", 8192, true),
  813. "Compiler flags that are only to be used in this configuration.");
  814. props.add (new TextPropertyComponent (configLinkerFlagsValue, "Configuration-specific Linker Flags", 8192, true),
  815. "Linker flags that are only to be used in this configuration.");
  816. props.add (new ChoicePropertyComponent (linkTimeOptimisationValue, "Link-Time Optimisation"),
  817. "Enable this to perform link-time code optimisation. This is recommended for release builds.");
  818. if (exporter.supportsPrecompiledHeaders())
  819. {
  820. props.add (new ChoicePropertyComponent (usePrecompiledHeaderFileValue, "Use Precompiled Header"),
  821. "Enable this to turn on precompiled header support for this configuration. Use the setting "
  822. "below to specify the header file to use.");
  823. auto quotedHeaderFileName = (getPrecompiledHeaderFilename() + ".h").quoted();
  824. props.add (new FilePathPropertyComponentWithEnablement (precompiledHeaderFileValue, usePrecompiledHeaderFileValue,
  825. "Precompiled Header File", false, true, "*", project.getProjectFolder()),
  826. "Specify an input header file that will be used to generate a file named " + quotedHeaderFileName + " which is used to generate the "
  827. "PCH file artefact for this exporter configuration. This file can be an absolute path, or relative to the jucer project folder. "
  828. "The " + quotedHeaderFileName + " file will be force included to all source files unless the \"Skip PCH\" setting has been enabled. "
  829. "The generated header will be written on project save and placed in the target folder for this exporter.");
  830. }
  831. createConfigProperties (props);
  832. props.add (new TextPropertyComponent (userNotesValue, "Notes", 32768, true),
  833. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  834. }
  835. StringPairArray ProjectExporter::BuildConfiguration::getAllPreprocessorDefs() const
  836. {
  837. return mergePreprocessorDefs (project.getPreprocessorDefs(),
  838. parsePreprocessorDefs (getBuildConfigPreprocessorDefsString()));
  839. }
  840. StringArray ProjectExporter::BuildConfiguration::getHeaderSearchPaths() const
  841. {
  842. return getSearchPathsFromString (getHeaderSearchPathString() + ';' + project.getHeaderSearchPathsString());
  843. }
  844. StringArray ProjectExporter::BuildConfiguration::getLibrarySearchPaths() const
  845. {
  846. auto separator = exporter.isVisualStudio() ? "\\" : "/";
  847. auto s = getSearchPathsFromString (getLibrarySearchPathString());
  848. for (auto path : exporter.moduleLibSearchPaths)
  849. {
  850. if (exporter.isXcode())
  851. s.add (path);
  852. s.add (path + separator + getModuleLibraryArchName());
  853. }
  854. return s;
  855. }
  856. String ProjectExporter::BuildConfiguration::getPrecompiledHeaderFileContent() const
  857. {
  858. if (shouldUsePrecompiledHeaderFile())
  859. {
  860. auto f = project.getProjectFolder().getChildFile (precompiledHeaderFileValue.get().toString());
  861. if (f.existsAsFile() && f.hasFileExtension (headerFileExtensions))
  862. {
  863. MemoryOutputStream content;
  864. content.setNewLineString (exporter.getNewLineString());
  865. writeAutoGenWarningComment (content);
  866. content << "*/" << newLine << newLine
  867. << "#ifndef " << getSkipPrecompiledHeaderDefine() << newLine << newLine
  868. << f.loadFileAsString() << newLine
  869. << "#endif" << newLine;
  870. return content.toString();
  871. }
  872. }
  873. return {};
  874. }
  875. String ProjectExporter::getExternalLibraryFlags (const BuildConfiguration& config) const
  876. {
  877. auto libraries = StringArray::fromTokens (getExternalLibrariesString(), ";\n", "\"'");
  878. libraries.removeEmptyStrings (true);
  879. if (libraries.size() != 0)
  880. return replacePreprocessorTokens (config, "-l" + libraries.joinIntoString (" -l")).trim();
  881. return {};
  882. }
  883. //==============================================================================
  884. LinuxSubprocessHelperProperties::LinuxSubprocessHelperProperties (ProjectExporter& projectExporter)
  885. : owner (projectExporter)
  886. {}
  887. bool LinuxSubprocessHelperProperties::shouldUseLinuxSubprocessHelper() const
  888. {
  889. const auto& project = owner.getProject();
  890. const auto& projectType = project.getProjectType();
  891. return owner.isLinux()
  892. && isWebBrowserComponentEnabled (project)
  893. && ! (projectType.isCommandLineApp())
  894. && ! (projectType.isGUIApplication());
  895. }
  896. void LinuxSubprocessHelperProperties::deployLinuxSubprocessHelperSourceFilesIfNecessary() const
  897. {
  898. if (shouldUseLinuxSubprocessHelper())
  899. {
  900. const auto deployHelperSourceFile = [] (auto& sourcePath, auto& contents)
  901. {
  902. if (! sourcePath.isRoot() && ! sourcePath.getParentDirectory().exists())
  903. {
  904. sourcePath.getParentDirectory().createDirectory();
  905. }
  906. build_tools::overwriteFileIfDifferentOrThrow (sourcePath, contents);
  907. };
  908. const std::pair<File, const char*> sources[]
  909. {
  910. { owner.resolveRelativePath (getSimpleBinaryBuilderSource()), BinaryData::juce_SimpleBinaryBuilder_cpp },
  911. { owner.resolveRelativePath (getLinuxSubprocessHelperSource()), BinaryData::juce_LinuxSubprocessHelper_cpp }
  912. };
  913. for (const auto& [path, source] : sources)
  914. {
  915. deployHelperSourceFile (path, source);
  916. }
  917. }
  918. }
  919. build_tools::RelativePath LinuxSubprocessHelperProperties::getLinuxSubprocessHelperSource() const
  920. {
  921. return build_tools::RelativePath { "make_helpers", build_tools::RelativePath::buildTargetFolder }
  922. .getChildFile ("juce_LinuxSubprocessHelper.cpp");
  923. }
  924. void LinuxSubprocessHelperProperties::setCompileDefinitionIfNecessary (StringPairArray& defs) const
  925. {
  926. if (shouldUseLinuxSubprocessHelper())
  927. defs.set (useLinuxSubprocessHelperCompileDefinition, "1");
  928. }
  929. build_tools::RelativePath LinuxSubprocessHelperProperties::getSimpleBinaryBuilderSource() const
  930. {
  931. return build_tools::RelativePath { "make_helpers", build_tools::RelativePath::buildTargetFolder }
  932. .getChildFile ("juce_SimpleBinaryBuilder.cpp");
  933. }
  934. build_tools::RelativePath LinuxSubprocessHelperProperties::getLinuxSubprocessHelperBinaryDataSource() const
  935. {
  936. return build_tools::RelativePath ("pre_build", juce::build_tools::RelativePath::buildTargetFolder)
  937. .getChildFile ("juce_LinuxSubprocessHelperBinaryData.cpp");
  938. }
  939. void LinuxSubprocessHelperProperties::addToExtraSearchPathsIfNecessary() const
  940. {
  941. if (shouldUseLinuxSubprocessHelper())
  942. {
  943. const auto subprocessHelperBinaryDir = getLinuxSubprocessHelperBinaryDataSource().getParentDirectory();
  944. owner.addToExtraSearchPaths (owner.rebaseFromBuildTargetToProjectFolder (subprocessHelperBinaryDir));
  945. }
  946. }
  947. std::optional<String> LinuxSubprocessHelperProperties::getParentDirectoryRelativeToBuildTargetFolder (build_tools::RelativePath rp)
  948. {
  949. jassert (rp.getRoot() == juce::build_tools::RelativePath::buildTargetFolder);
  950. const auto parentDir = rp.getParentDirectory().toUnixStyle();
  951. return parentDir == rp.toUnixStyle() ? std::nullopt : std::make_optional (parentDir);
  952. }
  953. String LinuxSubprocessHelperProperties::makeSnakeCase (const String& s)
  954. {
  955. String result;
  956. result.preallocateBytes (128);
  957. bool previousCharacterUnderscore = false;
  958. for (const auto c : s)
  959. {
  960. if ( CharacterFunctions::isUpperCase (c)
  961. && result.length() != 0
  962. && ! (previousCharacterUnderscore))
  963. {
  964. result << "_";
  965. }
  966. result << CharacterFunctions::toLowerCase (c);
  967. previousCharacterUnderscore = c == '_';
  968. }
  969. return result;
  970. }
  971. String LinuxSubprocessHelperProperties::getBinaryNameFromSource (const build_tools::RelativePath& rp)
  972. {
  973. return makeSnakeCase (rp.getFileNameWithoutExtension());
  974. }