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.

1119 lines
46KB

  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. bool ProjectExporter::shouldFileBeCompiledByDefault (const File& file) const
  192. {
  193. return file.hasFileExtension (cOrCppFileExtensions)
  194. || file.hasFileExtension (asmFileExtensions);
  195. }
  196. void ProjectExporter::updateCompilerFlagValues()
  197. {
  198. compilerFlagSchemesMap.clear();
  199. for (auto& scheme : project.getCompilerFlagSchemes())
  200. compilerFlagSchemesMap.set (scheme, { settings, scheme, getUndoManager() });
  201. }
  202. //==============================================================================
  203. void ProjectExporter::createPropertyEditors (PropertyListBuilder& props)
  204. {
  205. props.add (new TextPropertyComponent (targetLocationValue, "Target Project Folder", 2048, false),
  206. "The location of the folder in which the " + name + " project will be created. "
  207. "This path can be absolute, but it's much more sensible to make it relative to the jucer project directory.");
  208. if ((shouldBuildTargetType (build_tools::ProjectType::Target::VSTPlugIn) && project.shouldBuildVST()) || (project.isVSTPluginHost() && supportsTargetType (build_tools::ProjectType::Target::VSTPlugIn)))
  209. {
  210. props.add (new FilePathPropertyComponent (vstLegacyPathValueWrapper.getWrappedValueTreePropertyWithDefault(), "VST (Legacy) SDK Folder", true,
  211. getTargetOSForExporter() == TargetOS::getThisOS(), "*", project.getProjectFolder()),
  212. "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. "
  213. "This can be an absolute path, or a path relative to the Projucer project file.");
  214. }
  215. if (shouldBuildTargetType (build_tools::ProjectType::Target::AAXPlugIn) && project.shouldBuildAAX())
  216. {
  217. props.add (new FilePathPropertyComponent (aaxPathValueWrapper.getWrappedValueTreePropertyWithDefault(), "AAX SDK Folder", true,
  218. getTargetOSForExporter() == TargetOS::getThisOS(), "*", project.getProjectFolder()),
  219. "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.");
  220. }
  221. if (project.shouldEnableARA() || project.isARAPluginHost())
  222. {
  223. props.add (new FilePathPropertyComponent (araPathValueWrapper.getWrappedValueTreePropertyWithDefault(), "ARA SDK Folder", true,
  224. getTargetOSForExporter() == TargetOS::getThisOS(), "*", project.getProjectFolder()),
  225. "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.");
  226. }
  227. props.add (new TextPropertyComponent (extraPPDefsValue, "Extra Preprocessor Definitions", 32768, true),
  228. "Extra preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, "
  229. "or new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  230. props.add (new TextPropertyComponent (extraCompilerFlagsValue, "Extra Compiler Flags", 8192, true),
  231. "Extra command-line flags to be passed to the compiler. This string can contain references to preprocessor definitions in the "
  232. "form ${NAME_OF_DEFINITION}, which will be replaced with their values.");
  233. for (HashMap<String, ValueTreePropertyWithDefault>::Iterator i (compilerFlagSchemesMap); i.next();)
  234. props.add (new TextPropertyComponent (compilerFlagSchemesMap.getReference (i.getKey()), "Compiler Flags for " + i.getKey().quoted(), 8192, false),
  235. "The exporter-specific compiler flags that will be added to files using this scheme.");
  236. props.add (new TextPropertyComponent (extraLinkerFlagsValue, "Extra Linker Flags", 8192, true),
  237. "Extra command-line flags to be passed to the linker. You might want to use this for adding additional libraries. "
  238. "This string can contain references to preprocessor definitions in the form ${NAME_OF_VALUE}, which will be replaced with their values.");
  239. props.add (new TextPropertyComponent (externalLibrariesValue, "External Libraries to Link", 8192, true),
  240. "Additional libraries to link (one per line). You should not add any platform specific decoration to these names. "
  241. "This string can contain references to preprocessor definitions in the form ${NAME_OF_VALUE}, which will be replaced with their values.");
  242. if (! isVisualStudio())
  243. props.add (new ChoicePropertyComponent (gnuExtensionsValue, "GNU Compiler Extensions"),
  244. "Enabling this will use the GNU C++ language standard variant for compilation.");
  245. createIconProperties (props);
  246. createExporterProperties (props);
  247. props.add (new TextPropertyComponent (userNotesValue, "Notes", 32768, true),
  248. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  249. }
  250. void ProjectExporter::createIconProperties (PropertyListBuilder& props)
  251. {
  252. OwnedArray<Project::Item> images;
  253. project.findAllImageItems (images);
  254. StringArray choices;
  255. Array<var> ids;
  256. choices.add ("<None>");
  257. ids.add (var());
  258. for (const auto* imageItem : images)
  259. {
  260. choices.add (imageItem->getName());
  261. ids.add (imageItem->getID());
  262. }
  263. props.add (new ChoicePropertyComponent (smallIconValue, "Icon (Small)", choices, ids),
  264. "Sets an icon to use for the executable.");
  265. props.add (new ChoicePropertyComponent (bigIconValue, "Icon (Large)", choices, ids),
  266. "Sets an icon to use for the executable.");
  267. }
  268. //==============================================================================
  269. void ProjectExporter::addSettingsForProjectType (const build_tools::ProjectType& type)
  270. {
  271. addExtraIncludePathsIfPluginOrHost();
  272. addARAPathsIfPluginOrHost();
  273. if (type.isAudioPlugin())
  274. addCommonAudioPluginSettings();
  275. addPlatformSpecificSettingsForProjectType (type);
  276. }
  277. void ProjectExporter::addExtraIncludePathsIfPluginOrHost()
  278. {
  279. using Target = build_tools::ProjectType::Target;
  280. if (((shouldBuildTargetType (Target::VSTPlugIn) && project.shouldBuildVST()) || project.isVSTPluginHost())
  281. || ((shouldBuildTargetType (Target::VST3PlugIn) && project.shouldBuildVST3()) || project.isVST3PluginHost()))
  282. {
  283. addLegacyVSTFolderToPathIfSpecified();
  284. if (! project.isConfigFlagEnabled ("JUCE_CUSTOM_VST3_SDK"))
  285. addToExtraSearchPaths (getInternalVST3SDKPath(), 0);
  286. }
  287. const auto lv2BasePath = getModuleFolderRelativeToProject ("juce_audio_processors").getChildFile ("format_types")
  288. .getChildFile ("LV2_SDK");
  289. if ((shouldBuildTargetType (Target::LV2PlugIn) && project.shouldBuildLV2()) || project.isLV2PluginHost())
  290. {
  291. const std::vector<const char*> paths[] { { "" },
  292. { "lv2" },
  293. { "serd" },
  294. { "sord" },
  295. { "sord", "src" },
  296. { "sratom" },
  297. { "lilv" },
  298. { "lilv", "src" } };
  299. for (const auto& components : paths)
  300. {
  301. const auto appendComponent = [] (const build_tools::RelativePath& f, const char* component)
  302. {
  303. return f.getChildFile (component);
  304. };
  305. const auto includePath = std::accumulate (components.begin(),
  306. components.end(),
  307. lv2BasePath,
  308. appendComponent);
  309. addToExtraSearchPaths (includePath, 0);
  310. }
  311. }
  312. }
  313. void ProjectExporter::addARAPathsIfPluginOrHost()
  314. {
  315. if (project.shouldEnableARA() || project.isARAPluginHost())
  316. addARAFoldersToPath();
  317. }
  318. void ProjectExporter::addCommonAudioPluginSettings()
  319. {
  320. if (shouldBuildTargetType (build_tools::ProjectType::Target::AAXPlugIn))
  321. addAAXFoldersToPath();
  322. }
  323. void ProjectExporter::addLegacyVSTFolderToPathIfSpecified()
  324. {
  325. auto vstFolder = getVSTLegacyPathString();
  326. if (vstFolder.isNotEmpty())
  327. addToExtraSearchPaths (build_tools::RelativePath (vstFolder, build_tools::RelativePath::projectFolder), 0);
  328. }
  329. build_tools::RelativePath ProjectExporter::getInternalVST3SDKPath()
  330. {
  331. return getModuleFolderRelativeToProject ("juce_audio_processors")
  332. .getChildFile ("format_types")
  333. .getChildFile ("VST3_SDK");
  334. }
  335. void ProjectExporter::addAAXFoldersToPath()
  336. {
  337. auto aaxFolder = getAAXPathString();
  338. if (aaxFolder.isNotEmpty())
  339. {
  340. build_tools::RelativePath aaxFolderPath (aaxFolder, build_tools::RelativePath::projectFolder);
  341. addToExtraSearchPaths (aaxFolderPath);
  342. addToExtraSearchPaths (aaxFolderPath.getChildFile ("Interfaces"));
  343. addToExtraSearchPaths (aaxFolderPath.getChildFile ("Interfaces").getChildFile ("ACF"));
  344. }
  345. }
  346. void ProjectExporter::addARAFoldersToPath()
  347. {
  348. const auto araFolder = getARAPathString();
  349. if (araFolder.isNotEmpty())
  350. addToExtraSearchPaths (build_tools::RelativePath (araFolder, build_tools::RelativePath::projectFolder));
  351. }
  352. //==============================================================================
  353. StringPairArray ProjectExporter::getAllPreprocessorDefs (const BuildConfiguration& config, const build_tools::ProjectType::Target::Type targetType) const
  354. {
  355. auto defs = mergePreprocessorDefs (config.getAllPreprocessorDefs(),
  356. parsePreprocessorDefs (getExporterPreprocessorDefsString()));
  357. addDefaultPreprocessorDefs (defs);
  358. addTargetSpecificPreprocessorDefs (defs, targetType);
  359. if (! project.shouldUseAppConfig())
  360. defs = mergePreprocessorDefs (project.getAppConfigDefs(), defs);
  361. return defs;
  362. }
  363. StringPairArray ProjectExporter::getAllPreprocessorDefs() const
  364. {
  365. auto defs = mergePreprocessorDefs (project.getPreprocessorDefs(),
  366. parsePreprocessorDefs (getExporterPreprocessorDefsString()));
  367. addDefaultPreprocessorDefs (defs);
  368. return defs;
  369. }
  370. void ProjectExporter::addTargetSpecificPreprocessorDefs (StringPairArray& defs, const build_tools::ProjectType::Target::Type targetType) const
  371. {
  372. using Target = build_tools::ProjectType::Target::Type;
  373. const std::pair<const char*, Target> targetFlags[] { { "JucePlugin_Build_VST", Target::VSTPlugIn },
  374. { "JucePlugin_Build_VST3", Target::VST3PlugIn },
  375. { "JucePlugin_Build_AU", Target::AudioUnitPlugIn },
  376. { "JucePlugin_Build_AUv3", Target::AudioUnitv3PlugIn },
  377. { "JucePlugin_Build_AAX", Target::AAXPlugIn },
  378. { "JucePlugin_Build_Standalone", Target::StandalonePlugIn },
  379. { "JucePlugin_Build_Unity", Target::UnityPlugIn },
  380. { "JucePlugin_Build_LV2", Target::LV2PlugIn } };
  381. if (targetType == build_tools::ProjectType::Target::SharedCodeTarget)
  382. {
  383. for (auto& flag : targetFlags)
  384. defs.set (flag.first, (shouldBuildTargetType (flag.second) ? "1" : "0"));
  385. defs.set ("JUCE_SHARED_CODE", "1");
  386. }
  387. else if (targetType != build_tools::ProjectType::Target::unspecified)
  388. {
  389. for (auto& flag : targetFlags)
  390. defs.set (flag.first, (targetType == flag.second ? "1" : "0"));
  391. }
  392. if (project.shouldEnableARA())
  393. {
  394. defs.set ("JucePlugin_Enable_ARA", "1");
  395. }
  396. }
  397. void ProjectExporter::addDefaultPreprocessorDefs (StringPairArray& defs) const
  398. {
  399. defs.set (getExporterIdentifierMacro(), "1");
  400. defs.set ("JUCE_APP_VERSION", project.getVersionString());
  401. defs.set ("JUCE_APP_VERSION_HEX", project.getVersionAsHex());
  402. }
  403. String ProjectExporter::replacePreprocessorTokens (const ProjectExporter::BuildConfiguration& config,
  404. const String& sourceString) const
  405. {
  406. return build_tools::replacePreprocessorDefs (getAllPreprocessorDefs (config, build_tools::ProjectType::Target::unspecified),
  407. sourceString);
  408. }
  409. void ProjectExporter::copyMainGroupFromProject()
  410. {
  411. jassert (itemGroups.size() == 0);
  412. itemGroups.add (project.getMainGroup().createCopy());
  413. }
  414. Project::Item& ProjectExporter::getModulesGroup()
  415. {
  416. if (modulesGroup == nullptr)
  417. {
  418. jassert (itemGroups.size() > 0); // must call copyMainGroupFromProject before this.
  419. itemGroups.add (Project::Item::createGroup (project, "JUCE Modules", "__modulesgroup__", true));
  420. modulesGroup = &(itemGroups.getReference (itemGroups.size() - 1));
  421. }
  422. return *modulesGroup;
  423. }
  424. //==============================================================================
  425. static bool isWebBrowserComponentEnabled (Project& project)
  426. {
  427. static String guiExtrasModule ("juce_gui_extra");
  428. return (project.getEnabledModules().isModuleEnabled (guiExtrasModule)
  429. && project.isConfigFlagEnabled ("JUCE_WEB_BROWSER", true));
  430. }
  431. static bool isCurlEnabled (Project& project)
  432. {
  433. static String juceCoreModule ("juce_core");
  434. return (project.getEnabledModules().isModuleEnabled (juceCoreModule)
  435. && project.isConfigFlagEnabled ("JUCE_USE_CURL", true));
  436. }
  437. static bool isLoadCurlSymbolsLazilyEnabled (Project& project)
  438. {
  439. static String juceCoreModule ("juce_core");
  440. return (project.getEnabledModules().isModuleEnabled (juceCoreModule)
  441. && project.isConfigFlagEnabled ("JUCE_LOAD_CURL_SYMBOLS_LAZILY", false));
  442. }
  443. StringArray ProjectExporter::getLinuxPackages (PackageDependencyType type) const
  444. {
  445. auto packages = linuxPackages;
  446. // don't add libcurl if curl symbols are loaded at runtime
  447. if (isCurlEnabled (project) && ! isLoadCurlSymbolsLazilyEnabled (project))
  448. packages.add ("libcurl");
  449. if (isWebBrowserComponentEnabled (project) && type == PackageDependencyType::compile)
  450. {
  451. packages.add ("webkit2gtk-4.0");
  452. packages.add ("gtk+-x11-3.0");
  453. }
  454. packages.removeEmptyStrings();
  455. packages.removeDuplicates (false);
  456. return packages;
  457. }
  458. void ProjectExporter::addProjectPathToBuildPathList (StringArray& pathList,
  459. const build_tools::RelativePath& pathFromProjectFolder,
  460. int index) const
  461. {
  462. auto localPath = build_tools::RelativePath (rebaseFromProjectFolderToBuildTarget (pathFromProjectFolder));
  463. auto path = isVisualStudio() ? localPath.toWindowsStyle() : localPath.toUnixStyle();
  464. if (! pathList.contains (path))
  465. pathList.insert (index, path);
  466. }
  467. void ProjectExporter::addToModuleLibPaths (const build_tools::RelativePath& pathFromProjectFolder)
  468. {
  469. addProjectPathToBuildPathList (moduleLibSearchPaths, pathFromProjectFolder);
  470. }
  471. void ProjectExporter::addToExtraSearchPaths (const build_tools::RelativePath& pathFromProjectFolder, int index)
  472. {
  473. addProjectPathToBuildPathList (extraSearchPaths, pathFromProjectFolder, index);
  474. }
  475. static var getStoredPathForModule (const String& id, const ProjectExporter& exp)
  476. {
  477. return getAppSettings().getStoredPath (isJUCEModule (id) ? Ids::defaultJuceModulePath : Ids::defaultUserModulePath,
  478. exp.getTargetOSForExporter()).get();
  479. }
  480. ValueTreePropertyWithDefault ProjectExporter::getPathForModuleValue (const String& moduleID)
  481. {
  482. auto* um = getUndoManager();
  483. auto paths = settings.getOrCreateChildWithName (Ids::MODULEPATHS, um);
  484. auto m = paths.getChildWithProperty (Ids::ID, moduleID);
  485. if (! m.isValid())
  486. {
  487. m = ValueTree (Ids::MODULEPATH);
  488. m.setProperty (Ids::ID, moduleID, um);
  489. paths.appendChild (m, um);
  490. }
  491. return { m, Ids::path, um, getStoredPathForModule (moduleID, *this) };
  492. }
  493. String ProjectExporter::getPathForModuleString (const String& moduleID) const
  494. {
  495. auto exporterPath = settings.getChildWithName (Ids::MODULEPATHS)
  496. .getChildWithProperty (Ids::ID, moduleID) [Ids::path].toString();
  497. if (exporterPath.isEmpty() || project.getEnabledModules().shouldUseGlobalPath (moduleID))
  498. return getStoredPathForModule (moduleID, *this);
  499. return exporterPath;
  500. }
  501. void ProjectExporter::removePathForModule (const String& moduleID)
  502. {
  503. auto paths = settings.getChildWithName (Ids::MODULEPATHS);
  504. auto m = paths.getChildWithProperty (Ids::ID, moduleID);
  505. paths.removeChild (m, project.getUndoManagerFor (settings));
  506. }
  507. TargetOS::OS ProjectExporter::getTargetOSForExporter() const
  508. {
  509. auto targetOS = TargetOS::unknown;
  510. if (isWindows()) targetOS = TargetOS::windows;
  511. else if (isOSX() || isiOS()) targetOS = TargetOS::osx;
  512. else if (isLinux()) targetOS = TargetOS::linux;
  513. else if (isAndroid()) targetOS = TargetOS::getThisOS();
  514. return targetOS;
  515. }
  516. build_tools::RelativePath ProjectExporter::getModuleFolderRelativeToProject (const String& moduleID) const
  517. {
  518. if (project.getEnabledModules().shouldCopyModuleFilesLocally (moduleID))
  519. return build_tools::RelativePath (project.getRelativePathForFile (project.getLocalModuleFolder (moduleID)),
  520. build_tools::RelativePath::projectFolder);
  521. auto path = getPathForModuleString (moduleID);
  522. if (path.isEmpty())
  523. return getLegacyModulePath (moduleID).getChildFile (moduleID);
  524. return build_tools::RelativePath (path, build_tools::RelativePath::projectFolder).getChildFile (moduleID);
  525. }
  526. String ProjectExporter::getLegacyModulePath() const
  527. {
  528. return getSettingString ("juceFolder");
  529. }
  530. build_tools::RelativePath ProjectExporter::getLegacyModulePath (const String& moduleID) const
  531. {
  532. if (project.getEnabledModules().shouldCopyModuleFilesLocally (moduleID))
  533. return build_tools::RelativePath (project.getRelativePathForFile (project.getGeneratedCodeFolder()
  534. .getChildFile ("modules")
  535. .getChildFile (moduleID)), build_tools::RelativePath::projectFolder);
  536. auto oldJucePath = getLegacyModulePath();
  537. if (oldJucePath.isEmpty())
  538. return build_tools::RelativePath();
  539. build_tools::RelativePath p (oldJucePath, build_tools::RelativePath::projectFolder);
  540. if (p.getFileName() != "modules")
  541. p = p.getChildFile ("modules");
  542. return p.getChildFile (moduleID);
  543. }
  544. void ProjectExporter::updateOldModulePaths()
  545. {
  546. auto oldPath = getLegacyModulePath();
  547. if (oldPath.isNotEmpty())
  548. {
  549. for (int i = project.getEnabledModules().getNumModules(); --i >= 0;)
  550. {
  551. auto modID = project.getEnabledModules().getModuleID (i);
  552. getPathForModuleValue (modID) = getLegacyModulePath (modID).getParentDirectory().toUnixStyle();
  553. }
  554. settings.removeProperty ("juceFolder", nullptr);
  555. }
  556. }
  557. static bool areSameExporters (const ProjectExporter& p1, const ProjectExporter& p2)
  558. {
  559. return p1.getExporterIdentifier() == p2.getExporterIdentifier();
  560. }
  561. static bool areCompatibleExporters (const ProjectExporter& p1, const ProjectExporter& p2)
  562. {
  563. return (p1.isVisualStudio() && p2.isVisualStudio())
  564. || (p1.isXcode() && p2.isXcode())
  565. || (p1.isMakefile() && p2.isMakefile())
  566. || (p1.isAndroidStudio() && p2.isAndroidStudio())
  567. || (p1.isCodeBlocks() && p2.isCodeBlocks() && p1.isWindows() != p2.isLinux());
  568. }
  569. void ProjectExporter::createDefaultModulePaths()
  570. {
  571. auto exporterToCopy = [this]() -> std::unique_ptr<ProjectExporter>
  572. {
  573. std::vector<std::unique_ptr<ProjectExporter>> exporters;
  574. for (Project::ExporterIterator exporter (project); exporter.next();)
  575. exporters.push_back (std::move (exporter.exporter));
  576. auto getIf = [&exporters] (auto predicate)
  577. {
  578. auto iter = std::find_if (exporters.begin(), exporters.end(), predicate);
  579. return iter != exporters.end() ? std::move (*iter) : nullptr;
  580. };
  581. if (auto exporter = getIf ([this] (auto& x) { return areSameExporters (*this, *x); }))
  582. return exporter;
  583. if (auto exporter = getIf ([this] (auto& x) { return areCompatibleExporters (*this, *x); }))
  584. return exporter;
  585. if (auto exporter = getIf ([] (auto& x) { return x->canLaunchProject(); }))
  586. return exporter;
  587. return {};
  588. }();
  589. for (const auto& modID : project.getEnabledModules().getAllModules())
  590. getPathForModuleValue (modID) = (exporterToCopy != nullptr ? exporterToCopy->getPathForModuleString (modID) : "../../juce");
  591. }
  592. //==============================================================================
  593. ValueTree ProjectExporter::getConfigurations() const
  594. {
  595. return settings.getChildWithName (Ids::CONFIGURATIONS);
  596. }
  597. int ProjectExporter::getNumConfigurations() const
  598. {
  599. return getConfigurations().getNumChildren();
  600. }
  601. ProjectExporter::BuildConfiguration::Ptr ProjectExporter::getConfiguration (int index) const
  602. {
  603. return createBuildConfig (getConfigurations().getChild (index));
  604. }
  605. bool ProjectExporter::hasConfigurationNamed (const String& nameToFind) const
  606. {
  607. auto configs = getConfigurations();
  608. for (int i = configs.getNumChildren(); --i >= 0;)
  609. if (configs.getChild(i) [Ids::name].toString() == nameToFind)
  610. return true;
  611. return false;
  612. }
  613. String ProjectExporter::getUniqueConfigName (String nm) const
  614. {
  615. auto nameRoot = nm;
  616. while (CharacterFunctions::isDigit (nameRoot.getLastCharacter()))
  617. nameRoot = nameRoot.dropLastCharacters (1);
  618. nameRoot = nameRoot.trim();
  619. int suffix = 2;
  620. while (hasConfigurationNamed (name))
  621. nm = nameRoot + " " + String (suffix++);
  622. return nm;
  623. }
  624. void ProjectExporter::addNewConfigurationFromExisting (const BuildConfiguration& configToCopy)
  625. {
  626. auto configs = getConfigurations();
  627. if (! configs.isValid())
  628. {
  629. settings.addChild (ValueTree (Ids::CONFIGURATIONS), 0, project.getUndoManagerFor (settings));
  630. configs = getConfigurations();
  631. }
  632. ValueTree newConfig (Ids::CONFIGURATION);
  633. newConfig = configToCopy.config.createCopy();
  634. newConfig.setProperty (Ids::name, configToCopy.getName(), nullptr);
  635. configs.appendChild (newConfig, project.getUndoManagerFor (configs));
  636. }
  637. void ProjectExporter::addNewConfiguration (bool isDebugConfig)
  638. {
  639. auto configs = getConfigurations();
  640. if (! configs.isValid())
  641. {
  642. settings.addChild (ValueTree (Ids::CONFIGURATIONS), 0, project.getUndoManagerFor (settings));
  643. configs = getConfigurations();
  644. }
  645. ValueTree newConfig (Ids::CONFIGURATION);
  646. newConfig.setProperty (Ids::isDebug, isDebugConfig, project.getUndoManagerFor (settings));
  647. configs.appendChild (newConfig, project.getUndoManagerFor (settings));
  648. }
  649. void ProjectExporter::BuildConfiguration::removeFromExporter()
  650. {
  651. ValueTree configs (config.getParent());
  652. configs.removeChild (config, project.getUndoManagerFor (configs));
  653. }
  654. void ProjectExporter::createDefaultConfigs()
  655. {
  656. settings.getOrCreateChildWithName (Ids::CONFIGURATIONS, nullptr);
  657. for (int i = 0; i < 2; ++i)
  658. {
  659. auto isDebug = i == 0;
  660. addNewConfiguration (isDebug);
  661. BuildConfiguration::Ptr config (getConfiguration (i));
  662. config->getValue (Ids::name) = (isDebug ? "Debug" : "Release");
  663. }
  664. }
  665. std::unique_ptr<Drawable> ProjectExporter::getBigIcon() const
  666. {
  667. return project.getMainGroup().findItemWithID (settings [Ids::bigIcon]).loadAsImageFile();
  668. }
  669. std::unique_ptr<Drawable> ProjectExporter::getSmallIcon() const
  670. {
  671. return project.getMainGroup().findItemWithID (settings [Ids::smallIcon]).loadAsImageFile();
  672. }
  673. //==============================================================================
  674. ProjectExporter::ConfigIterator::ConfigIterator (ProjectExporter& e)
  675. : index (-1), exporter (e)
  676. {
  677. }
  678. bool ProjectExporter::ConfigIterator::next()
  679. {
  680. if (++index >= exporter.getNumConfigurations())
  681. return false;
  682. config = exporter.getConfiguration (index);
  683. return true;
  684. }
  685. ProjectExporter::ConstConfigIterator::ConstConfigIterator (const ProjectExporter& exporter_)
  686. : index (-1), exporter (exporter_)
  687. {
  688. }
  689. bool ProjectExporter::ConstConfigIterator::next()
  690. {
  691. if (++index >= exporter.getNumConfigurations())
  692. return false;
  693. config = exporter.getConfiguration (index);
  694. return true;
  695. }
  696. //==============================================================================
  697. ProjectExporter::BuildConfiguration::BuildConfiguration (Project& p, const ValueTree& configNode, const ProjectExporter& e)
  698. : config (configNode), project (p), exporter (e),
  699. isDebugValue (config, Ids::isDebug, getUndoManager(), getValue (Ids::isDebug)),
  700. configNameValue (config, Ids::name, getUndoManager(), "Build Configuration"),
  701. targetNameValue (config, Ids::targetName, getUndoManager(), project.getProjectFilenameRootString()),
  702. targetBinaryPathValue (config, Ids::binaryPath, getUndoManager()),
  703. recommendedWarningsValue (config, Ids::recommendedWarnings, getUndoManager()),
  704. optimisationLevelValue (config, Ids::optimisation, getUndoManager()),
  705. linkTimeOptimisationValue (config, Ids::linkTimeOptimisation, getUndoManager(), ! isDebug()),
  706. ppDefinesValue (config, Ids::defines, getUndoManager()),
  707. headerSearchPathValue (config, Ids::headerPath, getUndoManager()),
  708. librarySearchPathValue (config, Ids::libraryPath, getUndoManager()),
  709. userNotesValue (config, Ids::userNotes, getUndoManager()),
  710. usePrecompiledHeaderFileValue (config, Ids::usePrecompiledHeaderFile, getUndoManager(), false),
  711. precompiledHeaderFileValue (config, Ids::precompiledHeaderFile, getUndoManager())
  712. {
  713. auto& llvmFlags = recommendedCompilerWarningFlags[CompilerNames::llvm] = BuildConfiguration::CompilerWarningFlags::getRecommendedForGCCAndLLVM();
  714. llvmFlags.common.addArray ({
  715. "-Wshorten-64-to-32", "-Wconversion", "-Wint-conversion",
  716. "-Wconditional-uninitialized", "-Wconstant-conversion", "-Wbool-conversion",
  717. "-Wextra-semi", "-Wshift-sign-overflow",
  718. "-Wshadow-all", "-Wnullable-to-nonnull-conversion",
  719. "-Wmissing-prototypes"
  720. });
  721. llvmFlags.cpp.addArray ({
  722. "-Wunused-private-field", "-Winconsistent-missing-destructor-override"
  723. });
  724. llvmFlags.objc.addArray ({
  725. "-Wunguarded-availability", "-Wunguarded-availability-new"
  726. });
  727. auto& gccFlags = recommendedCompilerWarningFlags[CompilerNames::gcc] = BuildConfiguration::CompilerWarningFlags::getRecommendedForGCCAndLLVM();
  728. gccFlags.common.addArray ({
  729. "-Wextra", "-Wsign-compare", "-Wno-implicit-fallthrough", "-Wno-maybe-uninitialized",
  730. "-Wredundant-decls", "-Wno-strict-overflow",
  731. "-Wshadow"
  732. });
  733. }
  734. ProjectExporter::BuildConfiguration::~BuildConfiguration()
  735. {
  736. }
  737. String ProjectExporter::BuildConfiguration::getGCCOptimisationFlag() const
  738. {
  739. switch (getOptimisationLevelInt())
  740. {
  741. case gccO0: return "0";
  742. case gccO1: return "1";
  743. case gccO2: return "2";
  744. case gccO3: return "3";
  745. case gccOs: return "s";
  746. case gccOfast: return "fast";
  747. default: break;
  748. }
  749. return "0";
  750. }
  751. void ProjectExporter::BuildConfiguration::addGCCOptimisationProperty (PropertyListBuilder& props)
  752. {
  753. props.add (new ChoicePropertyComponent (optimisationLevelValue, "Optimisation",
  754. { "-O0 (no optimisation)", "-Os (minimise code size)", "-O1 (fast)", "-O2 (faster)",
  755. "-O3 (fastest with safe optimisations)", "-Ofast (uses aggressive optimisations)" },
  756. { gccO0, gccOs, gccO1, gccO2, gccO3, gccOfast }),
  757. "The optimisation level for this configuration");
  758. }
  759. void ProjectExporter::BuildConfiguration::addRecommendedLinuxCompilerWarningsProperty (PropertyListBuilder& props)
  760. {
  761. recommendedWarningsValue.setDefault ("");
  762. props.add (new ChoicePropertyComponent (recommendedWarningsValue, "Add Recommended Compiler Warning Flags",
  763. { CompilerNames::gcc, CompilerNames::llvm, "Disabled" },
  764. { CompilerNames::gcc, CompilerNames::llvm, "" }),
  765. "Enable this to add a set of recommended compiler warning flags.");
  766. }
  767. void ProjectExporter::BuildConfiguration::addRecommendedLLVMCompilerWarningsProperty (PropertyListBuilder& props)
  768. {
  769. recommendedWarningsValue.setDefault ("");
  770. props.add (new ChoicePropertyComponent (recommendedWarningsValue, "Add Recommended Compiler Warning Flags",
  771. { "Enabled", "Disabled" },
  772. { CompilerNames::llvm, "" }),
  773. "Enable this to add a set of recommended compiler warning flags.");
  774. }
  775. ProjectExporter::BuildConfiguration::CompilerWarningFlags ProjectExporter::BuildConfiguration::getRecommendedCompilerWarningFlags() const
  776. {
  777. auto label = recommendedWarningsValue.get().toString();
  778. if (label == "GCC-7")
  779. label = CompilerNames::gcc;
  780. auto it = recommendedCompilerWarningFlags.find (label);
  781. if (it != recommendedCompilerWarningFlags.end())
  782. return it->second;
  783. return {};
  784. }
  785. void ProjectExporter::BuildConfiguration::createPropertyEditors (PropertyListBuilder& props)
  786. {
  787. if (exporter.supportsUserDefinedConfigurations())
  788. props.add (new TextPropertyComponent (configNameValue, "Name", 96, false),
  789. "The name of this configuration.");
  790. props.add (new ChoicePropertyComponent (isDebugValue, "Debug Mode"),
  791. "If enabled, this means that the configuration should be built with debug symbols.");
  792. props.add (new TextPropertyComponent (targetNameValue, "Binary Name", 256, false),
  793. "The filename to use for the destination binary executable file. If you don't add a suffix to this name, "
  794. "a suitable platform-specific suffix will be added automatically.");
  795. props.add (new TextPropertyComponent (targetBinaryPathValue, "Binary Location", 1024, false),
  796. "The folder in which the finished binary should be placed. Leave this blank to cause the binary to be placed "
  797. "in its default location in the build folder.");
  798. props.addSearchPathProperty (headerSearchPathValue, "Header Search Paths", "Extra header search paths.");
  799. props.addSearchPathProperty (librarySearchPathValue, "Extra Library Search Paths", "Extra library search paths.");
  800. props.add (new TextPropertyComponent (ppDefinesValue, "Preprocessor Definitions", 32768, true),
  801. "Extra preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  802. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  803. props.add (new ChoicePropertyComponent (linkTimeOptimisationValue, "Link-Time Optimisation"),
  804. "Enable this to perform link-time code optimisation. This is recommended for release builds.");
  805. if (exporter.supportsPrecompiledHeaders())
  806. {
  807. props.add (new ChoicePropertyComponent (usePrecompiledHeaderFileValue, "Use Precompiled Header"),
  808. "Enable this to turn on precompiled header support for this configuration. Use the setting "
  809. "below to specify the header file to use.");
  810. auto quotedHeaderFileName = (getPrecompiledHeaderFilename() + ".h").quoted();
  811. props.add (new FilePathPropertyComponentWithEnablement (precompiledHeaderFileValue, usePrecompiledHeaderFileValue,
  812. "Precompiled Header File", false, true, "*", project.getProjectFolder()),
  813. "Specify an input header file that will be used to generate a file named " + quotedHeaderFileName + " which is used to generate the "
  814. "PCH file artefact for this exporter configuration. This file can be an absolute path, or relative to the jucer project folder. "
  815. "The " + quotedHeaderFileName + " file will be force included to all source files unless the \"Skip PCH\" setting has been enabled. "
  816. "The generated header will be written on project save and placed in the target folder for this exporter.");
  817. }
  818. createConfigProperties (props);
  819. props.add (new TextPropertyComponent (userNotesValue, "Notes", 32768, true),
  820. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  821. }
  822. StringPairArray ProjectExporter::BuildConfiguration::getAllPreprocessorDefs() const
  823. {
  824. return mergePreprocessorDefs (project.getPreprocessorDefs(),
  825. parsePreprocessorDefs (getBuildConfigPreprocessorDefsString()));
  826. }
  827. StringPairArray ProjectExporter::BuildConfiguration::getUniquePreprocessorDefs() const
  828. {
  829. auto perConfigurationDefs = parsePreprocessorDefs (getBuildConfigPreprocessorDefsString());
  830. auto globalDefs = project.getPreprocessorDefs();
  831. for (int i = 0; i < globalDefs.size(); ++i)
  832. {
  833. auto globalKey = globalDefs.getAllKeys()[i];
  834. int idx = perConfigurationDefs.getAllKeys().indexOf (globalKey);
  835. if (idx >= 0)
  836. {
  837. auto globalValue = globalDefs.getAllValues()[i];
  838. if (globalValue == perConfigurationDefs.getAllValues()[idx])
  839. perConfigurationDefs.remove (idx);
  840. }
  841. }
  842. return perConfigurationDefs;
  843. }
  844. StringArray ProjectExporter::BuildConfiguration::getHeaderSearchPaths() const
  845. {
  846. return getSearchPathsFromString (getHeaderSearchPathString() + ';' + project.getHeaderSearchPathsString());
  847. }
  848. StringArray ProjectExporter::BuildConfiguration::getLibrarySearchPaths() const
  849. {
  850. auto separator = exporter.isVisualStudio() ? "\\" : "/";
  851. auto s = getSearchPathsFromString (getLibrarySearchPathString());
  852. for (auto path : exporter.moduleLibSearchPaths)
  853. {
  854. if (exporter.isXcode())
  855. s.add (path);
  856. s.add (path + separator + getModuleLibraryArchName());
  857. }
  858. return s;
  859. }
  860. String ProjectExporter::BuildConfiguration::getPrecompiledHeaderFileContent() const
  861. {
  862. if (shouldUsePrecompiledHeaderFile())
  863. {
  864. auto f = project.getProjectFolder().getChildFile (precompiledHeaderFileValue.get().toString());
  865. if (f.existsAsFile() && f.hasFileExtension (headerFileExtensions))
  866. {
  867. MemoryOutputStream content;
  868. content.setNewLineString (exporter.getNewLineString());
  869. writeAutoGenWarningComment (content);
  870. content << "*/" << newLine << newLine
  871. << "#ifndef " << getSkipPrecompiledHeaderDefine() << newLine << newLine
  872. << f.loadFileAsString() << newLine
  873. << "#endif" << newLine;
  874. return content.toString();
  875. }
  876. }
  877. return {};
  878. }
  879. String ProjectExporter::getExternalLibraryFlags (const BuildConfiguration& config) const
  880. {
  881. auto libraries = StringArray::fromTokens (getExternalLibrariesString(), ";\n", "\"'");
  882. libraries.removeEmptyStrings (true);
  883. if (libraries.size() != 0)
  884. return replacePreprocessorTokens (config, "-l" + libraries.joinIntoString (" -l")).trim();
  885. return {};
  886. }