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.

1076 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.getWrappedValueWithDefault(), "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.getWrappedValueWithDefault(), "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.getWrappedValueWithDefault(), "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, ValueWithDefault>::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. ValueWithDefault 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 areCompatibleExporters (const ProjectExporter& p1, const ProjectExporter& p2)
  527. {
  528. return (p1.isVisualStudio() && p2.isVisualStudio())
  529. || (p1.isXcode() && p2.isXcode())
  530. || (p1.isMakefile() && p2.isMakefile())
  531. || (p1.isAndroidStudio() && p2.isAndroidStudio())
  532. || (p1.isCodeBlocks() && p2.isCodeBlocks() && p1.isWindows() != p2.isLinux());
  533. }
  534. void ProjectExporter::createDefaultModulePaths()
  535. {
  536. for (Project::ExporterIterator exporter (project); exporter.next();)
  537. {
  538. if (areCompatibleExporters (*this, *exporter))
  539. {
  540. for (int i = project.getEnabledModules().getNumModules(); --i >= 0;)
  541. {
  542. auto modID = project.getEnabledModules().getModuleID (i);
  543. getPathForModuleValue (modID) = exporter->getPathForModuleValue (modID);
  544. }
  545. return;
  546. }
  547. }
  548. for (Project::ExporterIterator exporter (project); exporter.next();)
  549. {
  550. if (exporter->canLaunchProject())
  551. {
  552. for (int i = project.getEnabledModules().getNumModules(); --i >= 0;)
  553. {
  554. auto modID = project.getEnabledModules().getModuleID (i);
  555. getPathForModuleValue (modID) = exporter->getPathForModuleValue (modID);
  556. }
  557. return;
  558. }
  559. }
  560. for (int i = project.getEnabledModules().getNumModules(); --i >= 0;)
  561. {
  562. auto modID = project.getEnabledModules().getModuleID (i);
  563. getPathForModuleValue (modID) = "../../juce";
  564. }
  565. }
  566. //==============================================================================
  567. ValueTree ProjectExporter::getConfigurations() const
  568. {
  569. return settings.getChildWithName (Ids::CONFIGURATIONS);
  570. }
  571. int ProjectExporter::getNumConfigurations() const
  572. {
  573. return getConfigurations().getNumChildren();
  574. }
  575. ProjectExporter::BuildConfiguration::Ptr ProjectExporter::getConfiguration (int index) const
  576. {
  577. return createBuildConfig (getConfigurations().getChild (index));
  578. }
  579. bool ProjectExporter::hasConfigurationNamed (const String& nameToFind) const
  580. {
  581. auto configs = getConfigurations();
  582. for (int i = configs.getNumChildren(); --i >= 0;)
  583. if (configs.getChild(i) [Ids::name].toString() == nameToFind)
  584. return true;
  585. return false;
  586. }
  587. String ProjectExporter::getUniqueConfigName (String nm) const
  588. {
  589. auto nameRoot = nm;
  590. while (CharacterFunctions::isDigit (nameRoot.getLastCharacter()))
  591. nameRoot = nameRoot.dropLastCharacters (1);
  592. nameRoot = nameRoot.trim();
  593. int suffix = 2;
  594. while (hasConfigurationNamed (name))
  595. nm = nameRoot + " " + String (suffix++);
  596. return nm;
  597. }
  598. void ProjectExporter::addNewConfigurationFromExisting (const BuildConfiguration& configToCopy)
  599. {
  600. auto configs = getConfigurations();
  601. if (! configs.isValid())
  602. {
  603. settings.addChild (ValueTree (Ids::CONFIGURATIONS), 0, project.getUndoManagerFor (settings));
  604. configs = getConfigurations();
  605. }
  606. ValueTree newConfig (Ids::CONFIGURATION);
  607. newConfig = configToCopy.config.createCopy();
  608. newConfig.setProperty (Ids::name, configToCopy.getName(), nullptr);
  609. configs.appendChild (newConfig, project.getUndoManagerFor (configs));
  610. }
  611. void ProjectExporter::addNewConfiguration (bool isDebugConfig)
  612. {
  613. auto configs = getConfigurations();
  614. if (! configs.isValid())
  615. {
  616. settings.addChild (ValueTree (Ids::CONFIGURATIONS), 0, project.getUndoManagerFor (settings));
  617. configs = getConfigurations();
  618. }
  619. ValueTree newConfig (Ids::CONFIGURATION);
  620. newConfig.setProperty (Ids::isDebug, isDebugConfig, project.getUndoManagerFor (settings));
  621. configs.appendChild (newConfig, project.getUndoManagerFor (settings));
  622. }
  623. void ProjectExporter::BuildConfiguration::removeFromExporter()
  624. {
  625. ValueTree configs (config.getParent());
  626. configs.removeChild (config, project.getUndoManagerFor (configs));
  627. }
  628. void ProjectExporter::createDefaultConfigs()
  629. {
  630. settings.getOrCreateChildWithName (Ids::CONFIGURATIONS, nullptr);
  631. for (int i = 0; i < 2; ++i)
  632. {
  633. auto isDebug = i == 0;
  634. addNewConfiguration (isDebug);
  635. BuildConfiguration::Ptr config (getConfiguration (i));
  636. config->getValue (Ids::name) = (isDebug ? "Debug" : "Release");
  637. }
  638. }
  639. std::unique_ptr<Drawable> ProjectExporter::getBigIcon() const
  640. {
  641. return project.getMainGroup().findItemWithID (settings [Ids::bigIcon]).loadAsImageFile();
  642. }
  643. std::unique_ptr<Drawable> ProjectExporter::getSmallIcon() const
  644. {
  645. return project.getMainGroup().findItemWithID (settings [Ids::smallIcon]).loadAsImageFile();
  646. }
  647. //==============================================================================
  648. ProjectExporter::ConfigIterator::ConfigIterator (ProjectExporter& e)
  649. : index (-1), exporter (e)
  650. {
  651. }
  652. bool ProjectExporter::ConfigIterator::next()
  653. {
  654. if (++index >= exporter.getNumConfigurations())
  655. return false;
  656. config = exporter.getConfiguration (index);
  657. return true;
  658. }
  659. ProjectExporter::ConstConfigIterator::ConstConfigIterator (const ProjectExporter& exporter_)
  660. : index (-1), exporter (exporter_)
  661. {
  662. }
  663. bool ProjectExporter::ConstConfigIterator::next()
  664. {
  665. if (++index >= exporter.getNumConfigurations())
  666. return false;
  667. config = exporter.getConfiguration (index);
  668. return true;
  669. }
  670. //==============================================================================
  671. ProjectExporter::BuildConfiguration::BuildConfiguration (Project& p, const ValueTree& configNode, const ProjectExporter& e)
  672. : config (configNode), project (p), exporter (e),
  673. isDebugValue (config, Ids::isDebug, getUndoManager(), getValue (Ids::isDebug)),
  674. configNameValue (config, Ids::name, getUndoManager(), "Build Configuration"),
  675. targetNameValue (config, Ids::targetName, getUndoManager(), project.getProjectFilenameRootString()),
  676. targetBinaryPathValue (config, Ids::binaryPath, getUndoManager()),
  677. recommendedWarningsValue (config, Ids::recommendedWarnings, getUndoManager()),
  678. optimisationLevelValue (config, Ids::optimisation, getUndoManager()),
  679. linkTimeOptimisationValue (config, Ids::linkTimeOptimisation, getUndoManager(), ! isDebug()),
  680. ppDefinesValue (config, Ids::defines, getUndoManager()),
  681. headerSearchPathValue (config, Ids::headerPath, getUndoManager()),
  682. librarySearchPathValue (config, Ids::libraryPath, getUndoManager()),
  683. userNotesValue (config, Ids::userNotes, getUndoManager()),
  684. usePrecompiledHeaderFileValue (config, Ids::usePrecompiledHeaderFile, getUndoManager(), false),
  685. precompiledHeaderFileValue (config, Ids::precompiledHeaderFile, getUndoManager())
  686. {
  687. auto& llvmFlags = recommendedCompilerWarningFlags[CompilerNames::llvm] = BuildConfiguration::CompilerWarningFlags::getRecommendedForGCCAndLLVM();
  688. llvmFlags.common.addArray ({
  689. "-Wshorten-64-to-32", "-Wconversion", "-Wint-conversion",
  690. "-Wconditional-uninitialized", "-Wconstant-conversion", "-Wbool-conversion",
  691. "-Wextra-semi", "-Wshift-sign-overflow", "-Wno-missing-field-initializers",
  692. "-Wshadow-all", "-Wnullable-to-nonnull-conversion"
  693. });
  694. llvmFlags.cpp.addArray ({
  695. "-Wunused-private-field", "-Winconsistent-missing-destructor-override"
  696. });
  697. auto& gccFlags = recommendedCompilerWarningFlags[CompilerNames::gcc] = BuildConfiguration::CompilerWarningFlags::getRecommendedForGCCAndLLVM();
  698. gccFlags.common.addArray ({
  699. "-Wextra", "-Wsign-compare", "-Wno-implicit-fallthrough", "-Wno-maybe-uninitialized",
  700. "-Wno-missing-field-initializers", "-Wredundant-decls", "-Wno-strict-overflow",
  701. "-Wshadow"
  702. });
  703. }
  704. ProjectExporter::BuildConfiguration::~BuildConfiguration()
  705. {
  706. }
  707. String ProjectExporter::BuildConfiguration::getGCCOptimisationFlag() const
  708. {
  709. switch (getOptimisationLevelInt())
  710. {
  711. case gccO0: return "0";
  712. case gccO1: return "1";
  713. case gccO2: return "2";
  714. case gccO3: return "3";
  715. case gccOs: return "s";
  716. case gccOfast: return "fast";
  717. default: break;
  718. }
  719. return "0";
  720. }
  721. void ProjectExporter::BuildConfiguration::addGCCOptimisationProperty (PropertyListBuilder& props)
  722. {
  723. props.add (new ChoicePropertyComponent (optimisationLevelValue, "Optimisation",
  724. { "-O0 (no optimisation)", "-Os (minimise code size)", "-O1 (fast)", "-O2 (faster)",
  725. "-O3 (fastest with safe optimisations)", "-Ofast (uses aggressive optimisations)" },
  726. { gccO0, gccOs, gccO1, gccO2, gccO3, gccOfast }),
  727. "The optimisation level for this configuration");
  728. }
  729. void ProjectExporter::BuildConfiguration::addRecommendedLinuxCompilerWarningsProperty (PropertyListBuilder& props)
  730. {
  731. props.add (new ChoicePropertyComponent (recommendedWarningsValue, "Add Recommended Compiler Warning Flags",
  732. { CompilerNames::gcc, CompilerNames::llvm, "Disabled" },
  733. { CompilerNames::gcc, CompilerNames::llvm, "" }),
  734. "Enable this to add a set of recommended compiler warning flags.");
  735. recommendedWarningsValue.setDefault ("");
  736. }
  737. void ProjectExporter::BuildConfiguration::addRecommendedLLVMCompilerWarningsProperty (PropertyListBuilder& props)
  738. {
  739. props.add (new ChoicePropertyComponent (recommendedWarningsValue, "Add Recommended Compiler Warning Flags",
  740. { "Enabled", "Disabled" },
  741. { CompilerNames::llvm, "" }),
  742. "Enable this to add a set of recommended compiler warning flags.");
  743. recommendedWarningsValue.setDefault ("");
  744. }
  745. ProjectExporter::BuildConfiguration::CompilerWarningFlags ProjectExporter::BuildConfiguration::getRecommendedCompilerWarningFlags() const
  746. {
  747. auto label = recommendedWarningsValue.get().toString();
  748. if (label == "GCC-7")
  749. label = CompilerNames::gcc;
  750. auto it = recommendedCompilerWarningFlags.find (label);
  751. if (it != recommendedCompilerWarningFlags.end())
  752. return it->second;
  753. return {};
  754. }
  755. void ProjectExporter::BuildConfiguration::createPropertyEditors (PropertyListBuilder& props)
  756. {
  757. if (exporter.supportsUserDefinedConfigurations())
  758. props.add (new TextPropertyComponent (configNameValue, "Name", 96, false),
  759. "The name of this configuration.");
  760. props.add (new ChoicePropertyComponent (isDebugValue, "Debug Mode"),
  761. "If enabled, this means that the configuration should be built with debug symbols.");
  762. props.add (new TextPropertyComponent (targetNameValue, "Binary Name", 256, false),
  763. "The filename to use for the destination binary executable file. If you don't add a suffix to this name, "
  764. "a suitable platform-specific suffix will be added automatically.");
  765. props.add (new TextPropertyComponent (targetBinaryPathValue, "Binary Location", 1024, false),
  766. "The folder in which the finished binary should be placed. Leave this blank to cause the binary to be placed "
  767. "in its default location in the build folder.");
  768. props.addSearchPathProperty (headerSearchPathValue, "Header Search Paths", "Extra header search paths.");
  769. props.addSearchPathProperty (librarySearchPathValue, "Extra Library Search Paths", "Extra library search paths.");
  770. props.add (new TextPropertyComponent (ppDefinesValue, "Preprocessor Definitions", 32768, true),
  771. "Extra preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  772. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  773. props.add (new ChoicePropertyComponent (linkTimeOptimisationValue, "Link-Time Optimisation"),
  774. "Enable this to perform link-time code optimisation. This is recommended for release builds.");
  775. if (exporter.supportsPrecompiledHeaders())
  776. {
  777. props.add (new ChoicePropertyComponent (usePrecompiledHeaderFileValue, "Use Precompiled Header"),
  778. "Enable this to turn on precompiled header support for this configuration. Use the setting "
  779. "below to specify the header file to use.");
  780. auto quotedHeaderFileName = (getPrecompiledHeaderFilename() + ".h").quoted();
  781. props.add (new FilePathPropertyComponentWithEnablement (precompiledHeaderFileValue, usePrecompiledHeaderFileValue,
  782. "Precompiled Header File", false, true, "*", project.getProjectFolder()),
  783. "Specify an input header file that will be used to generate a file named " + quotedHeaderFileName + " which is used to generate the "
  784. "PCH file artefact for this exporter configuration. This file can be an absolute path, or relative to the jucer project folder. "
  785. "The " + quotedHeaderFileName + " file will be force included to all source files unless the \"Skip PCH\" setting has been enabled. "
  786. "The generated header will be written on project save and placed in the target folder for this exporter.");
  787. }
  788. createConfigProperties (props);
  789. props.add (new TextPropertyComponent (userNotesValue, "Notes", 32768, true),
  790. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  791. }
  792. StringPairArray ProjectExporter::BuildConfiguration::getAllPreprocessorDefs() const
  793. {
  794. return mergePreprocessorDefs (project.getPreprocessorDefs(),
  795. parsePreprocessorDefs (getBuildConfigPreprocessorDefsString()));
  796. }
  797. StringPairArray ProjectExporter::BuildConfiguration::getUniquePreprocessorDefs() const
  798. {
  799. auto perConfigurationDefs = parsePreprocessorDefs (getBuildConfigPreprocessorDefsString());
  800. auto globalDefs = project.getPreprocessorDefs();
  801. for (int i = 0; i < globalDefs.size(); ++i)
  802. {
  803. auto globalKey = globalDefs.getAllKeys()[i];
  804. int idx = perConfigurationDefs.getAllKeys().indexOf (globalKey);
  805. if (idx >= 0)
  806. {
  807. auto globalValue = globalDefs.getAllValues()[i];
  808. if (globalValue == perConfigurationDefs.getAllValues()[idx])
  809. perConfigurationDefs.remove (idx);
  810. }
  811. }
  812. return perConfigurationDefs;
  813. }
  814. StringArray ProjectExporter::BuildConfiguration::getHeaderSearchPaths() const
  815. {
  816. return getSearchPathsFromString (getHeaderSearchPathString() + ';' + project.getHeaderSearchPathsString());
  817. }
  818. StringArray ProjectExporter::BuildConfiguration::getLibrarySearchPaths() const
  819. {
  820. auto separator = exporter.isVisualStudio() ? "\\" : "/";
  821. auto s = getSearchPathsFromString (getLibrarySearchPathString());
  822. for (auto path : exporter.moduleLibSearchPaths)
  823. {
  824. if (exporter.isXcode())
  825. s.add (path);
  826. s.add (path + separator + getModuleLibraryArchName());
  827. }
  828. return s;
  829. }
  830. String ProjectExporter::BuildConfiguration::getPrecompiledHeaderFileContent() const
  831. {
  832. if (shouldUsePrecompiledHeaderFile())
  833. {
  834. auto f = project.getProjectFolder().getChildFile (precompiledHeaderFileValue.get().toString());
  835. if (f.existsAsFile() && f.hasFileExtension (headerFileExtensions))
  836. {
  837. MemoryOutputStream content;
  838. content.setNewLineString (exporter.getNewLineString());
  839. writeAutoGenWarningComment (content);
  840. content << "*/" << newLine << newLine
  841. << "#ifndef " << getSkipPrecompiledHeaderDefine() << newLine << newLine
  842. << f.loadFileAsString() << newLine
  843. << "#endif" << newLine;
  844. return content.toString();
  845. }
  846. }
  847. return {};
  848. }
  849. String ProjectExporter::getExternalLibraryFlags (const BuildConfiguration& config) const
  850. {
  851. auto libraries = StringArray::fromTokens (getExternalLibrariesString(), ";\n", "\"'");
  852. libraries.removeEmptyStrings (true);
  853. if (libraries.size() != 0)
  854. return replacePreprocessorTokens (config, "-l" + libraries.joinIntoString (" -l")).trim();
  855. return {};
  856. }