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.

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