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.

1077 lines
45KB

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