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.

1123 lines
47KB

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