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.

1068 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 (int i = 0; i < images.size(); ++i)
  270. {
  271. choices.add (images.getUnchecked(i)->getName());
  272. ids.add (images.getUnchecked(i)->getID());
  273. }
  274. props.add (new ChoicePropertyComponent (smallIconValue, "Icon (Small)", choices, ids),
  275. "Sets an icon to use for the executable.");
  276. props.add (new ChoicePropertyComponent (bigIconValue, "Icon (Large)", choices, ids),
  277. "Sets an icon to use for the executable.");
  278. }
  279. //==============================================================================
  280. void ProjectExporter::addSettingsForProjectType (const build_tools::ProjectType& type)
  281. {
  282. addVSTPathsIfPluginOrHost();
  283. if (type.isAudioPlugin())
  284. addCommonAudioPluginSettings();
  285. addPlatformSpecificSettingsForProjectType (type);
  286. }
  287. void ProjectExporter::addVSTPathsIfPluginOrHost()
  288. {
  289. if (((shouldBuildTargetType (build_tools::ProjectType::Target::VSTPlugIn) && project.shouldBuildVST()) || project.isVSTPluginHost())
  290. || ((shouldBuildTargetType (build_tools::ProjectType::Target::VST3PlugIn) && project.shouldBuildVST3()) || project.isVST3PluginHost()))
  291. {
  292. addLegacyVSTFolderToPathIfSpecified();
  293. if (! project.isConfigFlagEnabled ("JUCE_CUSTOM_VST3_SDK"))
  294. addToExtraSearchPaths (getInternalVST3SDKPath(), 0);
  295. }
  296. }
  297. void ProjectExporter::addCommonAudioPluginSettings()
  298. {
  299. if (shouldBuildTargetType (build_tools::ProjectType::Target::AAXPlugIn))
  300. addAAXFoldersToPath();
  301. // Note: RTAS paths are platform-dependent, impl -> addPlatformSpecificSettingsForProjectType
  302. }
  303. void ProjectExporter::addLegacyVSTFolderToPathIfSpecified()
  304. {
  305. auto vstFolder = getVSTLegacyPathString();
  306. if (vstFolder.isNotEmpty())
  307. addToExtraSearchPaths (build_tools::RelativePath (vstFolder, build_tools::RelativePath::projectFolder), 0);
  308. }
  309. build_tools::RelativePath ProjectExporter::getInternalVST3SDKPath()
  310. {
  311. return getModuleFolderRelativeToProject ("juce_audio_processors")
  312. .getChildFile ("format_types")
  313. .getChildFile ("VST3_SDK");
  314. }
  315. void ProjectExporter::addAAXFoldersToPath()
  316. {
  317. auto aaxFolder = getAAXPathString();
  318. if (aaxFolder.isNotEmpty())
  319. {
  320. build_tools::RelativePath aaxFolderPath (aaxFolder, build_tools::RelativePath::projectFolder);
  321. addToExtraSearchPaths (aaxFolderPath);
  322. addToExtraSearchPaths (aaxFolderPath.getChildFile ("Interfaces"));
  323. addToExtraSearchPaths (aaxFolderPath.getChildFile ("Interfaces").getChildFile ("ACF"));
  324. }
  325. }
  326. //==============================================================================
  327. StringPairArray ProjectExporter::getAllPreprocessorDefs (const BuildConfiguration& config, const build_tools::ProjectType::Target::Type targetType) const
  328. {
  329. auto defs = mergePreprocessorDefs (config.getAllPreprocessorDefs(),
  330. parsePreprocessorDefs (getExporterPreprocessorDefsString()));
  331. addDefaultPreprocessorDefs (defs);
  332. addTargetSpecificPreprocessorDefs (defs, targetType);
  333. if (! project.shouldUseAppConfig())
  334. defs = mergePreprocessorDefs (project.getAppConfigDefs(), defs);
  335. return defs;
  336. }
  337. StringPairArray ProjectExporter::getAllPreprocessorDefs() const
  338. {
  339. auto defs = mergePreprocessorDefs (project.getPreprocessorDefs(),
  340. parsePreprocessorDefs (getExporterPreprocessorDefsString()));
  341. addDefaultPreprocessorDefs (defs);
  342. return defs;
  343. }
  344. void ProjectExporter::addTargetSpecificPreprocessorDefs (StringPairArray& defs, const build_tools::ProjectType::Target::Type targetType) const
  345. {
  346. std::pair<String, build_tools::ProjectType::Target::Type> targetFlags[] = {
  347. {"JucePlugin_Build_VST", build_tools::ProjectType::Target::VSTPlugIn},
  348. {"JucePlugin_Build_VST3", build_tools::ProjectType::Target::VST3PlugIn},
  349. {"JucePlugin_Build_AU", build_tools::ProjectType::Target::AudioUnitPlugIn},
  350. {"JucePlugin_Build_AUv3", build_tools::ProjectType::Target::AudioUnitv3PlugIn},
  351. {"JucePlugin_Build_RTAS", build_tools::ProjectType::Target::RTASPlugIn},
  352. {"JucePlugin_Build_AAX", build_tools::ProjectType::Target::AAXPlugIn},
  353. {"JucePlugin_Build_Standalone", build_tools::ProjectType::Target::StandalonePlugIn},
  354. {"JucePlugin_Build_Unity", build_tools::ProjectType::Target::UnityPlugIn}
  355. };
  356. if (targetType == build_tools::ProjectType::Target::SharedCodeTarget)
  357. {
  358. for (auto& flag : targetFlags)
  359. defs.set (flag.first, (shouldBuildTargetType (flag.second) ? "1" : "0"));
  360. defs.set ("JUCE_SHARED_CODE", "1");
  361. }
  362. else if (targetType != build_tools::ProjectType::Target::unspecified)
  363. {
  364. for (auto& flag : targetFlags)
  365. defs.set (flag.first, (targetType == flag.second ? "1" : "0"));
  366. }
  367. }
  368. void ProjectExporter::addDefaultPreprocessorDefs (StringPairArray& defs) const
  369. {
  370. defs.set (getExporterIdentifierMacro(), "1");
  371. defs.set ("JUCE_APP_VERSION", project.getVersionString());
  372. defs.set ("JUCE_APP_VERSION_HEX", project.getVersionAsHex());
  373. }
  374. String ProjectExporter::replacePreprocessorTokens (const ProjectExporter::BuildConfiguration& config,
  375. const String& sourceString) const
  376. {
  377. return build_tools::replacePreprocessorDefs (getAllPreprocessorDefs (config, build_tools::ProjectType::Target::unspecified),
  378. sourceString);
  379. }
  380. void ProjectExporter::copyMainGroupFromProject()
  381. {
  382. jassert (itemGroups.size() == 0);
  383. itemGroups.add (project.getMainGroup().createCopy());
  384. }
  385. Project::Item& ProjectExporter::getModulesGroup()
  386. {
  387. if (modulesGroup == nullptr)
  388. {
  389. jassert (itemGroups.size() > 0); // must call copyMainGroupFromProject before this.
  390. itemGroups.add (Project::Item::createGroup (project, "JUCE Modules", "__modulesgroup__", true));
  391. modulesGroup = &(itemGroups.getReference (itemGroups.size() - 1));
  392. }
  393. return *modulesGroup;
  394. }
  395. //==============================================================================
  396. static bool isWebBrowserComponentEnabled (Project& project)
  397. {
  398. static String guiExtrasModule ("juce_gui_extra");
  399. return (project.getEnabledModules().isModuleEnabled (guiExtrasModule)
  400. && project.isConfigFlagEnabled ("JUCE_WEB_BROWSER", true));
  401. }
  402. static bool isCurlEnabled (Project& project)
  403. {
  404. static String juceCoreModule ("juce_core");
  405. return (project.getEnabledModules().isModuleEnabled (juceCoreModule)
  406. && project.isConfigFlagEnabled ("JUCE_USE_CURL", true));
  407. }
  408. static bool isLoadCurlSymbolsLazilyEnabled (Project& project)
  409. {
  410. static String juceCoreModule ("juce_core");
  411. return (project.getEnabledModules().isModuleEnabled (juceCoreModule)
  412. && project.isConfigFlagEnabled ("JUCE_LOAD_CURL_SYMBOLS_LAZILY", false));
  413. }
  414. StringArray ProjectExporter::getLinuxPackages (PackageDependencyType type) const
  415. {
  416. auto packages = linuxPackages;
  417. // don't add libcurl if curl symbols are loaded at runtime
  418. if (isCurlEnabled (project) && ! isLoadCurlSymbolsLazilyEnabled (project))
  419. packages.add ("libcurl");
  420. if (isWebBrowserComponentEnabled (project) && type == PackageDependencyType::compile)
  421. {
  422. packages.add ("webkit2gtk-4.0");
  423. packages.add ("gtk+-x11-3.0");
  424. }
  425. packages.removeEmptyStrings();
  426. packages.removeDuplicates (false);
  427. return packages;
  428. }
  429. void ProjectExporter::addProjectPathToBuildPathList (StringArray& pathList,
  430. const build_tools::RelativePath& pathFromProjectFolder,
  431. int index) const
  432. {
  433. auto localPath = build_tools::RelativePath (rebaseFromProjectFolderToBuildTarget (pathFromProjectFolder));
  434. auto path = isVisualStudio() ? localPath.toWindowsStyle() : localPath.toUnixStyle();
  435. if (! pathList.contains (path))
  436. pathList.insert (index, path);
  437. }
  438. void ProjectExporter::addToModuleLibPaths (const build_tools::RelativePath& pathFromProjectFolder)
  439. {
  440. addProjectPathToBuildPathList (moduleLibSearchPaths, pathFromProjectFolder);
  441. }
  442. void ProjectExporter::addToExtraSearchPaths (const build_tools::RelativePath& pathFromProjectFolder, int index)
  443. {
  444. addProjectPathToBuildPathList (extraSearchPaths, pathFromProjectFolder, index);
  445. }
  446. static var getStoredPathForModule (const String& id, const ProjectExporter& exp)
  447. {
  448. return getAppSettings().getStoredPath (isJUCEModule (id) ? Ids::defaultJuceModulePath : Ids::defaultUserModulePath,
  449. exp.getTargetOSForExporter()).get();
  450. }
  451. ValueWithDefault ProjectExporter::getPathForModuleValue (const String& moduleID)
  452. {
  453. auto* um = getUndoManager();
  454. auto paths = settings.getOrCreateChildWithName (Ids::MODULEPATHS, um);
  455. auto m = paths.getChildWithProperty (Ids::ID, moduleID);
  456. if (! m.isValid())
  457. {
  458. m = ValueTree (Ids::MODULEPATH);
  459. m.setProperty (Ids::ID, moduleID, um);
  460. paths.appendChild (m, um);
  461. }
  462. return { m, Ids::path, um, getStoredPathForModule (moduleID, *this) };
  463. }
  464. String ProjectExporter::getPathForModuleString (const String& moduleID) const
  465. {
  466. auto exporterPath = settings.getChildWithName (Ids::MODULEPATHS)
  467. .getChildWithProperty (Ids::ID, moduleID) [Ids::path].toString();
  468. if (exporterPath.isEmpty() || project.getEnabledModules().shouldUseGlobalPath (moduleID))
  469. return getStoredPathForModule (moduleID, *this);
  470. return exporterPath;
  471. }
  472. void ProjectExporter::removePathForModule (const String& moduleID)
  473. {
  474. auto paths = settings.getChildWithName (Ids::MODULEPATHS);
  475. auto m = paths.getChildWithProperty (Ids::ID, moduleID);
  476. paths.removeChild (m, project.getUndoManagerFor (settings));
  477. }
  478. TargetOS::OS ProjectExporter::getTargetOSForExporter() const
  479. {
  480. auto targetOS = TargetOS::unknown;
  481. if (isWindows()) targetOS = TargetOS::windows;
  482. else if (isOSX() || isiOS()) targetOS = TargetOS::osx;
  483. else if (isLinux()) targetOS = TargetOS::linux;
  484. else if (isAndroid() || isCLion()) targetOS = TargetOS::getThisOS();
  485. return targetOS;
  486. }
  487. build_tools::RelativePath ProjectExporter::getModuleFolderRelativeToProject (const String& moduleID) const
  488. {
  489. if (project.getEnabledModules().shouldCopyModuleFilesLocally (moduleID))
  490. return build_tools::RelativePath (project.getRelativePathForFile (project.getLocalModuleFolder (moduleID)),
  491. build_tools::RelativePath::projectFolder);
  492. auto path = getPathForModuleString (moduleID);
  493. if (path.isEmpty())
  494. return getLegacyModulePath (moduleID).getChildFile (moduleID);
  495. return build_tools::RelativePath (path, build_tools::RelativePath::projectFolder).getChildFile (moduleID);
  496. }
  497. String ProjectExporter::getLegacyModulePath() const
  498. {
  499. return getSettingString ("juceFolder");
  500. }
  501. build_tools::RelativePath ProjectExporter::getLegacyModulePath (const String& moduleID) const
  502. {
  503. if (project.getEnabledModules().shouldCopyModuleFilesLocally (moduleID))
  504. return build_tools::RelativePath (project.getRelativePathForFile (project.getGeneratedCodeFolder()
  505. .getChildFile ("modules")
  506. .getChildFile (moduleID)), build_tools::RelativePath::projectFolder);
  507. auto oldJucePath = getLegacyModulePath();
  508. if (oldJucePath.isEmpty())
  509. return build_tools::RelativePath();
  510. build_tools::RelativePath p (oldJucePath, build_tools::RelativePath::projectFolder);
  511. if (p.getFileName() != "modules")
  512. p = p.getChildFile ("modules");
  513. return p.getChildFile (moduleID);
  514. }
  515. void ProjectExporter::updateOldModulePaths()
  516. {
  517. auto oldPath = getLegacyModulePath();
  518. if (oldPath.isNotEmpty())
  519. {
  520. for (int i = project.getEnabledModules().getNumModules(); --i >= 0;)
  521. {
  522. auto modID = project.getEnabledModules().getModuleID (i);
  523. getPathForModuleValue (modID) = getLegacyModulePath (modID).getParentDirectory().toUnixStyle();
  524. }
  525. settings.removeProperty ("juceFolder", nullptr);
  526. }
  527. }
  528. static bool areCompatibleExporters (const ProjectExporter& p1, const ProjectExporter& p2)
  529. {
  530. return (p1.isVisualStudio() && p2.isVisualStudio())
  531. || (p1.isXcode() && p2.isXcode())
  532. || (p1.isMakefile() && p2.isMakefile())
  533. || (p1.isAndroidStudio() && p2.isAndroidStudio())
  534. || (p1.isCodeBlocks() && p2.isCodeBlocks() && p1.isWindows() != p2.isLinux());
  535. }
  536. void ProjectExporter::createDefaultModulePaths()
  537. {
  538. for (Project::ExporterIterator exporter (project); exporter.next();)
  539. {
  540. if (areCompatibleExporters (*this, *exporter))
  541. {
  542. for (int i = project.getEnabledModules().getNumModules(); --i >= 0;)
  543. {
  544. auto modID = project.getEnabledModules().getModuleID (i);
  545. getPathForModuleValue (modID) = exporter->getPathForModuleValue (modID);
  546. }
  547. return;
  548. }
  549. }
  550. for (Project::ExporterIterator exporter (project); exporter.next();)
  551. {
  552. if (exporter->canLaunchProject())
  553. {
  554. for (int i = project.getEnabledModules().getNumModules(); --i >= 0;)
  555. {
  556. auto modID = project.getEnabledModules().getModuleID (i);
  557. getPathForModuleValue (modID) = exporter->getPathForModuleValue (modID);
  558. }
  559. return;
  560. }
  561. }
  562. for (int i = project.getEnabledModules().getNumModules(); --i >= 0;)
  563. {
  564. auto modID = project.getEnabledModules().getModuleID (i);
  565. getPathForModuleValue (modID) = "../../juce";
  566. }
  567. }
  568. //==============================================================================
  569. ValueTree ProjectExporter::getConfigurations() const
  570. {
  571. return settings.getChildWithName (Ids::CONFIGURATIONS);
  572. }
  573. int ProjectExporter::getNumConfigurations() const
  574. {
  575. return getConfigurations().getNumChildren();
  576. }
  577. ProjectExporter::BuildConfiguration::Ptr ProjectExporter::getConfiguration (int index) const
  578. {
  579. return createBuildConfig (getConfigurations().getChild (index));
  580. }
  581. bool ProjectExporter::hasConfigurationNamed (const String& nameToFind) const
  582. {
  583. auto configs = getConfigurations();
  584. for (int i = configs.getNumChildren(); --i >= 0;)
  585. if (configs.getChild(i) [Ids::name].toString() == nameToFind)
  586. return true;
  587. return false;
  588. }
  589. String ProjectExporter::getUniqueConfigName (String nm) const
  590. {
  591. auto nameRoot = nm;
  592. while (CharacterFunctions::isDigit (nameRoot.getLastCharacter()))
  593. nameRoot = nameRoot.dropLastCharacters (1);
  594. nameRoot = nameRoot.trim();
  595. int suffix = 2;
  596. while (hasConfigurationNamed (name))
  597. nm = nameRoot + " " + String (suffix++);
  598. return nm;
  599. }
  600. void ProjectExporter::addNewConfigurationFromExisting (const BuildConfiguration& configToCopy)
  601. {
  602. auto configs = getConfigurations();
  603. if (! configs.isValid())
  604. {
  605. settings.addChild (ValueTree (Ids::CONFIGURATIONS), 0, project.getUndoManagerFor (settings));
  606. configs = getConfigurations();
  607. }
  608. ValueTree newConfig (Ids::CONFIGURATION);
  609. newConfig = configToCopy.config.createCopy();
  610. newConfig.setProperty (Ids::name, configToCopy.getName(), nullptr);
  611. configs.appendChild (newConfig, project.getUndoManagerFor (configs));
  612. }
  613. void ProjectExporter::addNewConfiguration (bool isDebugConfig)
  614. {
  615. auto configs = getConfigurations();
  616. if (! configs.isValid())
  617. {
  618. settings.addChild (ValueTree (Ids::CONFIGURATIONS), 0, project.getUndoManagerFor (settings));
  619. configs = getConfigurations();
  620. }
  621. ValueTree newConfig (Ids::CONFIGURATION);
  622. newConfig.setProperty (Ids::isDebug, isDebugConfig, project.getUndoManagerFor (settings));
  623. configs.appendChild (newConfig, project.getUndoManagerFor (settings));
  624. }
  625. void ProjectExporter::BuildConfiguration::removeFromExporter()
  626. {
  627. ValueTree configs (config.getParent());
  628. configs.removeChild (config, project.getUndoManagerFor (configs));
  629. }
  630. void ProjectExporter::createDefaultConfigs()
  631. {
  632. settings.getOrCreateChildWithName (Ids::CONFIGURATIONS, nullptr);
  633. for (int i = 0; i < 2; ++i)
  634. {
  635. auto isDebug = i == 0;
  636. addNewConfiguration (isDebug);
  637. BuildConfiguration::Ptr config (getConfiguration (i));
  638. config->getValue (Ids::name) = (isDebug ? "Debug" : "Release");
  639. }
  640. }
  641. std::unique_ptr<Drawable> ProjectExporter::getBigIcon() const
  642. {
  643. return project.getMainGroup().findItemWithID (settings [Ids::bigIcon]).loadAsImageFile();
  644. }
  645. std::unique_ptr<Drawable> ProjectExporter::getSmallIcon() const
  646. {
  647. return project.getMainGroup().findItemWithID (settings [Ids::smallIcon]).loadAsImageFile();
  648. }
  649. //==============================================================================
  650. ProjectExporter::ConfigIterator::ConfigIterator (ProjectExporter& e)
  651. : index (-1), exporter (e)
  652. {
  653. }
  654. bool ProjectExporter::ConfigIterator::next()
  655. {
  656. if (++index >= exporter.getNumConfigurations())
  657. return false;
  658. config = exporter.getConfiguration (index);
  659. return true;
  660. }
  661. ProjectExporter::ConstConfigIterator::ConstConfigIterator (const ProjectExporter& exporter_)
  662. : index (-1), exporter (exporter_)
  663. {
  664. }
  665. bool ProjectExporter::ConstConfigIterator::next()
  666. {
  667. if (++index >= exporter.getNumConfigurations())
  668. return false;
  669. config = exporter.getConfiguration (index);
  670. return true;
  671. }
  672. //==============================================================================
  673. ProjectExporter::BuildConfiguration::BuildConfiguration (Project& p, const ValueTree& configNode, const ProjectExporter& e)
  674. : config (configNode), project (p), exporter (e),
  675. isDebugValue (config, Ids::isDebug, getUndoManager(), getValue (Ids::isDebug)),
  676. configNameValue (config, Ids::name, getUndoManager(), "Build Configuration"),
  677. targetNameValue (config, Ids::targetName, getUndoManager(), project.getProjectFilenameRootString()),
  678. targetBinaryPathValue (config, Ids::binaryPath, getUndoManager()),
  679. recommendedWarningsValue (config, Ids::recommendedWarnings, getUndoManager()),
  680. optimisationLevelValue (config, Ids::optimisation, getUndoManager()),
  681. linkTimeOptimisationValue (config, Ids::linkTimeOptimisation, getUndoManager(), ! isDebug()),
  682. ppDefinesValue (config, Ids::defines, getUndoManager()),
  683. headerSearchPathValue (config, Ids::headerPath, getUndoManager()),
  684. librarySearchPathValue (config, Ids::libraryPath, getUndoManager()),
  685. userNotesValue (config, Ids::userNotes, getUndoManager()),
  686. usePrecompiledHeaderFileValue (config, Ids::usePrecompiledHeaderFile, getUndoManager(), false),
  687. precompiledHeaderFileValue (config, Ids::precompiledHeaderFile, getUndoManager())
  688. {
  689. recommendedCompilerWarningFlags["LLVM"] = { "-Wall", "-Wshadow-all", "-Wshorten-64-to-32", "-Wstrict-aliasing", "-Wuninitialized", "-Wunused-parameter",
  690. "-Wconversion", "-Wsign-compare", "-Wint-conversion", "-Wconditional-uninitialized", "-Woverloaded-virtual",
  691. "-Wreorder", "-Wconstant-conversion", "-Wsign-conversion", "-Wunused-private-field", "-Wbool-conversion",
  692. "-Wextra-semi", "-Wunreachable-code", "-Wzero-as-null-pointer-constant", "-Wcast-align",
  693. "-Winconsistent-missing-destructor-override", "-Wshift-sign-overflow", "-Wnullable-to-nonnull-conversion",
  694. "-Wno-missing-field-initializers", "-Wno-ignored-qualifiers",
  695. "-Wswitch-enum"
  696. };
  697. recommendedCompilerWarningFlags["GCC"] = { "-Wall", "-Wextra", "-Wstrict-aliasing", "-Wuninitialized", "-Wunused-parameter", "-Wsign-compare",
  698. "-Woverloaded-virtual", "-Wreorder", "-Wsign-conversion", "-Wunreachable-code",
  699. "-Wzero-as-null-pointer-constant", "-Wcast-align", "-Wno-implicit-fallthrough",
  700. "-Wno-maybe-uninitialized", "-Wno-missing-field-initializers", "-Wno-ignored-qualifiers",
  701. "-Wswitch-enum", "-Wredundant-decls"
  702. };
  703. recommendedCompilerWarningFlags["GCC-7"] = recommendedCompilerWarningFlags["GCC"];
  704. recommendedCompilerWarningFlags["GCC-7"].add ("-Wno-strict-overflow");
  705. }
  706. ProjectExporter::BuildConfiguration::~BuildConfiguration()
  707. {
  708. }
  709. String ProjectExporter::BuildConfiguration::getGCCOptimisationFlag() const
  710. {
  711. switch (getOptimisationLevelInt())
  712. {
  713. case gccO0: return "0";
  714. case gccO1: return "1";
  715. case gccO2: return "2";
  716. case gccO3: return "3";
  717. case gccOs: return "s";
  718. case gccOfast: return "fast";
  719. default: break;
  720. }
  721. return "0";
  722. }
  723. void ProjectExporter::BuildConfiguration::addGCCOptimisationProperty (PropertyListBuilder& props)
  724. {
  725. props.add (new ChoicePropertyComponent (optimisationLevelValue, "Optimisation",
  726. { "-O0 (no optimisation)", "-Os (minimise code size)", "-O1 (fast)", "-O2 (faster)",
  727. "-O3 (fastest with safe optimisations)", "-Ofast (uses aggressive optimisations)" },
  728. { gccO0, gccOs, gccO1, gccO2, gccO3, gccOfast }),
  729. "The optimisation level for this configuration");
  730. }
  731. void ProjectExporter::BuildConfiguration::addRecommendedLinuxCompilerWarningsProperty (PropertyListBuilder& props)
  732. {
  733. props.add (new ChoicePropertyComponent (recommendedWarningsValue, "Add Recommended Compiler Warning Flags",
  734. { "GCC", "GCC 7 and below", "LLVM", "Disabled" },
  735. { "GCC", "GCC-7", "LLVM", "" }),
  736. "Enable this to add a set of recommended compiler warning flags.");
  737. recommendedWarningsValue.setDefault ("");
  738. }
  739. void ProjectExporter::BuildConfiguration::addRecommendedLLVMCompilerWarningsProperty (PropertyListBuilder& props)
  740. {
  741. props.add (new ChoicePropertyComponent (recommendedWarningsValue, "Add Recommended Compiler Warning Flags",
  742. { "Enabled", "Disabled" },
  743. { "LLVM", "" }),
  744. "Enable this to add a set of recommended compiler warning flags.");
  745. recommendedWarningsValue.setDefault ("");
  746. }
  747. StringArray ProjectExporter::BuildConfiguration::getRecommendedCompilerWarningFlags() const
  748. {
  749. auto label = recommendedWarningsValue.get().toString();
  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. s.add (path + separator + getModuleLibraryArchName());
  824. return s;
  825. }
  826. String ProjectExporter::BuildConfiguration::getPrecompiledHeaderFileContent() const
  827. {
  828. if (shouldUsePrecompiledHeaderFile())
  829. {
  830. auto f = project.getProjectFolder().getChildFile (precompiledHeaderFileValue.get().toString());
  831. if (f.existsAsFile() && f.hasFileExtension (headerFileExtensions))
  832. {
  833. MemoryOutputStream content;
  834. content.setNewLineString (exporter.getNewLineString());
  835. writeAutoGenWarningComment (content);
  836. content << "*/" << newLine << newLine
  837. << "#ifndef " << getSkipPrecompiledHeaderDefine() << newLine << newLine
  838. << f.loadFileAsString() << newLine
  839. << "#endif" << newLine;
  840. return content.toString();
  841. }
  842. }
  843. return {};
  844. }
  845. String ProjectExporter::getExternalLibraryFlags (const BuildConfiguration& config) const
  846. {
  847. auto libraries = StringArray::fromTokens (getExternalLibrariesString(), ";\n", "\"'");
  848. libraries.removeEmptyStrings (true);
  849. if (libraries.size() != 0)
  850. return replacePreprocessorTokens (config, "-l" + libraries.joinIntoString (" -l")).trim();
  851. return {};
  852. }