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.

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