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.

978 lines
41KB

  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 (defs, project.getAppConfigDefs());
  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,
  377. build_tools::ProjectType::Target::unspecified), 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. void ProjectExporter::addProjectPathToBuildPathList (StringArray& pathList,
  395. const build_tools::RelativePath& pathFromProjectFolder,
  396. int index) const
  397. {
  398. auto localPath = build_tools::RelativePath (rebaseFromProjectFolderToBuildTarget (pathFromProjectFolder));
  399. auto path = isVisualStudio() ? localPath.toWindowsStyle() : localPath.toUnixStyle();
  400. if (! pathList.contains (path))
  401. pathList.insert (index, path);
  402. }
  403. void ProjectExporter::addToModuleLibPaths (const build_tools::RelativePath& pathFromProjectFolder)
  404. {
  405. addProjectPathToBuildPathList (moduleLibSearchPaths, pathFromProjectFolder);
  406. }
  407. void ProjectExporter::addToExtraSearchPaths (const build_tools::RelativePath& pathFromProjectFolder, int index)
  408. {
  409. addProjectPathToBuildPathList (extraSearchPaths, pathFromProjectFolder, index);
  410. }
  411. static var getStoredPathForModule (const String& id, const ProjectExporter& exp)
  412. {
  413. return getAppSettings().getStoredPath (isJUCEModule (id) ? Ids::defaultJuceModulePath : Ids::defaultUserModulePath,
  414. exp.getTargetOSForExporter()).get();
  415. }
  416. ValueWithDefault ProjectExporter::getPathForModuleValue (const String& moduleID)
  417. {
  418. auto* um = getUndoManager();
  419. auto paths = settings.getOrCreateChildWithName (Ids::MODULEPATHS, um);
  420. auto m = paths.getChildWithProperty (Ids::ID, moduleID);
  421. if (! m.isValid())
  422. {
  423. m = ValueTree (Ids::MODULEPATH);
  424. m.setProperty (Ids::ID, moduleID, um);
  425. paths.appendChild (m, um);
  426. }
  427. return { m, Ids::path, um, getStoredPathForModule (moduleID, *this) };
  428. }
  429. String ProjectExporter::getPathForModuleString (const String& moduleID) const
  430. {
  431. auto exporterPath = settings.getChildWithName (Ids::MODULEPATHS)
  432. .getChildWithProperty (Ids::ID, moduleID) [Ids::path].toString();
  433. if (exporterPath.isEmpty() || project.getEnabledModules().shouldUseGlobalPath (moduleID))
  434. return getStoredPathForModule (moduleID, *this);
  435. return exporterPath;
  436. }
  437. void ProjectExporter::removePathForModule (const String& moduleID)
  438. {
  439. auto paths = settings.getChildWithName (Ids::MODULEPATHS);
  440. auto m = paths.getChildWithProperty (Ids::ID, moduleID);
  441. paths.removeChild (m, project.getUndoManagerFor (settings));
  442. }
  443. TargetOS::OS ProjectExporter::getTargetOSForExporter() const
  444. {
  445. auto targetOS = TargetOS::unknown;
  446. if (isWindows()) targetOS = TargetOS::windows;
  447. else if (isOSX() || isiOS()) targetOS = TargetOS::osx;
  448. else if (isLinux()) targetOS = TargetOS::linux;
  449. else if (isAndroid() || isCLion()) targetOS = TargetOS::getThisOS();
  450. return targetOS;
  451. }
  452. build_tools::RelativePath ProjectExporter::getModuleFolderRelativeToProject (const String& moduleID) const
  453. {
  454. if (project.getEnabledModules().shouldCopyModuleFilesLocally (moduleID))
  455. return build_tools::RelativePath (project.getRelativePathForFile (project.getLocalModuleFolder (moduleID)),
  456. build_tools::RelativePath::projectFolder);
  457. auto path = getPathForModuleString (moduleID);
  458. if (path.isEmpty())
  459. return getLegacyModulePath (moduleID).getChildFile (moduleID);
  460. return build_tools::RelativePath (path, build_tools::RelativePath::projectFolder).getChildFile (moduleID);
  461. }
  462. String ProjectExporter::getLegacyModulePath() const
  463. {
  464. return getSettingString ("juceFolder");
  465. }
  466. build_tools::RelativePath ProjectExporter::getLegacyModulePath (const String& moduleID) const
  467. {
  468. if (project.getEnabledModules().shouldCopyModuleFilesLocally (moduleID))
  469. return build_tools::RelativePath (project.getRelativePathForFile (project.getGeneratedCodeFolder()
  470. .getChildFile ("modules")
  471. .getChildFile (moduleID)), build_tools::RelativePath::projectFolder);
  472. auto oldJucePath = getLegacyModulePath();
  473. if (oldJucePath.isEmpty())
  474. return build_tools::RelativePath();
  475. build_tools::RelativePath p (oldJucePath, build_tools::RelativePath::projectFolder);
  476. if (p.getFileName() != "modules")
  477. p = p.getChildFile ("modules");
  478. return p.getChildFile (moduleID);
  479. }
  480. void ProjectExporter::updateOldModulePaths()
  481. {
  482. auto oldPath = getLegacyModulePath();
  483. if (oldPath.isNotEmpty())
  484. {
  485. for (int i = project.getEnabledModules().getNumModules(); --i >= 0;)
  486. {
  487. auto modID = project.getEnabledModules().getModuleID (i);
  488. getPathForModuleValue (modID) = getLegacyModulePath (modID).getParentDirectory().toUnixStyle();
  489. }
  490. settings.removeProperty ("juceFolder", nullptr);
  491. }
  492. }
  493. static bool areCompatibleExporters (const ProjectExporter& p1, const ProjectExporter& p2)
  494. {
  495. return (p1.isVisualStudio() && p2.isVisualStudio())
  496. || (p1.isXcode() && p2.isXcode())
  497. || (p1.isMakefile() && p2.isMakefile())
  498. || (p1.isAndroidStudio() && p2.isAndroidStudio())
  499. || (p1.isCodeBlocks() && p2.isCodeBlocks() && p1.isWindows() != p2.isLinux());
  500. }
  501. void ProjectExporter::createDefaultModulePaths()
  502. {
  503. for (Project::ExporterIterator exporter (project); exporter.next();)
  504. {
  505. if (areCompatibleExporters (*this, *exporter))
  506. {
  507. for (int i = project.getEnabledModules().getNumModules(); --i >= 0;)
  508. {
  509. auto modID = project.getEnabledModules().getModuleID (i);
  510. getPathForModuleValue (modID) = exporter->getPathForModuleValue (modID);
  511. }
  512. return;
  513. }
  514. }
  515. for (Project::ExporterIterator exporter (project); exporter.next();)
  516. {
  517. if (exporter->canLaunchProject())
  518. {
  519. for (int i = project.getEnabledModules().getNumModules(); --i >= 0;)
  520. {
  521. auto modID = project.getEnabledModules().getModuleID (i);
  522. getPathForModuleValue (modID) = exporter->getPathForModuleValue (modID);
  523. }
  524. return;
  525. }
  526. }
  527. for (int i = project.getEnabledModules().getNumModules(); --i >= 0;)
  528. {
  529. auto modID = project.getEnabledModules().getModuleID (i);
  530. getPathForModuleValue (modID) = "../../juce";
  531. }
  532. }
  533. //==============================================================================
  534. ValueTree ProjectExporter::getConfigurations() const
  535. {
  536. return settings.getChildWithName (Ids::CONFIGURATIONS);
  537. }
  538. int ProjectExporter::getNumConfigurations() const
  539. {
  540. return getConfigurations().getNumChildren();
  541. }
  542. ProjectExporter::BuildConfiguration::Ptr ProjectExporter::getConfiguration (int index) const
  543. {
  544. return createBuildConfig (getConfigurations().getChild (index));
  545. }
  546. bool ProjectExporter::hasConfigurationNamed (const String& nameToFind) const
  547. {
  548. auto configs = getConfigurations();
  549. for (int i = configs.getNumChildren(); --i >= 0;)
  550. if (configs.getChild(i) [Ids::name].toString() == nameToFind)
  551. return true;
  552. return false;
  553. }
  554. String ProjectExporter::getUniqueConfigName (String nm) const
  555. {
  556. auto nameRoot = nm;
  557. while (CharacterFunctions::isDigit (nameRoot.getLastCharacter()))
  558. nameRoot = nameRoot.dropLastCharacters (1);
  559. nameRoot = nameRoot.trim();
  560. int suffix = 2;
  561. while (hasConfigurationNamed (name))
  562. nm = nameRoot + " " + String (suffix++);
  563. return nm;
  564. }
  565. void ProjectExporter::addNewConfigurationFromExisting (const BuildConfiguration& configToCopy)
  566. {
  567. auto configs = getConfigurations();
  568. if (! configs.isValid())
  569. {
  570. settings.addChild (ValueTree (Ids::CONFIGURATIONS), 0, project.getUndoManagerFor (settings));
  571. configs = getConfigurations();
  572. }
  573. ValueTree newConfig (Ids::CONFIGURATION);
  574. newConfig = configToCopy.config.createCopy();
  575. newConfig.setProperty (Ids::name, configToCopy.getName(), nullptr);
  576. configs.appendChild (newConfig, project.getUndoManagerFor (configs));
  577. }
  578. void ProjectExporter::addNewConfiguration (bool isDebugConfig)
  579. {
  580. auto configs = getConfigurations();
  581. if (! configs.isValid())
  582. {
  583. settings.addChild (ValueTree (Ids::CONFIGURATIONS), 0, project.getUndoManagerFor (settings));
  584. configs = getConfigurations();
  585. }
  586. ValueTree newConfig (Ids::CONFIGURATION);
  587. newConfig.setProperty (Ids::isDebug, isDebugConfig, project.getUndoManagerFor (settings));
  588. configs.appendChild (newConfig, project.getUndoManagerFor (settings));
  589. }
  590. void ProjectExporter::BuildConfiguration::removeFromExporter()
  591. {
  592. ValueTree configs (config.getParent());
  593. configs.removeChild (config, project.getUndoManagerFor (configs));
  594. }
  595. void ProjectExporter::createDefaultConfigs()
  596. {
  597. settings.getOrCreateChildWithName (Ids::CONFIGURATIONS, nullptr);
  598. for (int i = 0; i < 2; ++i)
  599. {
  600. auto isDebug = i == 0;
  601. addNewConfiguration (isDebug);
  602. BuildConfiguration::Ptr config (getConfiguration (i));
  603. config->getValue (Ids::name) = (isDebug ? "Debug" : "Release");
  604. }
  605. }
  606. std::unique_ptr<Drawable> ProjectExporter::getBigIcon() const
  607. {
  608. return project.getMainGroup().findItemWithID (settings [Ids::bigIcon]).loadAsImageFile();
  609. }
  610. std::unique_ptr<Drawable> ProjectExporter::getSmallIcon() const
  611. {
  612. return project.getMainGroup().findItemWithID (settings [Ids::smallIcon]).loadAsImageFile();
  613. }
  614. //==============================================================================
  615. ProjectExporter::ConfigIterator::ConfigIterator (ProjectExporter& e)
  616. : index (-1), exporter (e)
  617. {
  618. }
  619. bool ProjectExporter::ConfigIterator::next()
  620. {
  621. if (++index >= exporter.getNumConfigurations())
  622. return false;
  623. config = exporter.getConfiguration (index);
  624. return true;
  625. }
  626. ProjectExporter::ConstConfigIterator::ConstConfigIterator (const ProjectExporter& exporter_)
  627. : index (-1), exporter (exporter_)
  628. {
  629. }
  630. bool ProjectExporter::ConstConfigIterator::next()
  631. {
  632. if (++index >= exporter.getNumConfigurations())
  633. return false;
  634. config = exporter.getConfiguration (index);
  635. return true;
  636. }
  637. //==============================================================================
  638. ProjectExporter::BuildConfiguration::BuildConfiguration (Project& p, const ValueTree& configNode, const ProjectExporter& e)
  639. : config (configNode), project (p), exporter (e),
  640. isDebugValue (config, Ids::isDebug, getUndoManager(), getValue (Ids::isDebug)),
  641. configNameValue (config, Ids::name, getUndoManager(), "Build Configuration"),
  642. targetNameValue (config, Ids::targetName, getUndoManager(), project.getProjectFilenameRootString()),
  643. targetBinaryPathValue (config, Ids::binaryPath, getUndoManager()),
  644. recommendedWarningsValue (config, Ids::recommendedWarnings, getUndoManager()),
  645. optimisationLevelValue (config, Ids::optimisation, getUndoManager()),
  646. linkTimeOptimisationValue (config, Ids::linkTimeOptimisation, getUndoManager(), ! isDebug()),
  647. ppDefinesValue (config, Ids::defines, getUndoManager()),
  648. headerSearchPathValue (config, Ids::headerPath, getUndoManager()),
  649. librarySearchPathValue (config, Ids::libraryPath, getUndoManager()),
  650. userNotesValue (config, Ids::userNotes, getUndoManager())
  651. {
  652. recommendedCompilerWarningFlags["LLVM"] = { "-Wall", "-Wshadow-all", "-Wshorten-64-to-32", "-Wstrict-aliasing", "-Wuninitialized", "-Wunused-parameter",
  653. "-Wconversion", "-Wsign-compare", "-Wint-conversion", "-Wconditional-uninitialized", "-Woverloaded-virtual",
  654. "-Wreorder", "-Wconstant-conversion", "-Wsign-conversion", "-Wunused-private-field", "-Wbool-conversion",
  655. "-Wextra-semi", "-Wunreachable-code", "-Wzero-as-null-pointer-constant", "-Wcast-align",
  656. "-Winconsistent-missing-destructor-override", "-Wshift-sign-overflow", "-Wnullable-to-nonnull-conversion",
  657. "-Wno-missing-field-initializers", "-Wno-ignored-qualifiers",
  658. "-Wswitch-enum"
  659. };
  660. recommendedCompilerWarningFlags["GCC"] = { "-Wall", "-Wextra", "-Wstrict-aliasing", "-Wuninitialized", "-Wunused-parameter", "-Wsign-compare",
  661. "-Woverloaded-virtual", "-Wreorder", "-Wsign-conversion", "-Wunreachable-code",
  662. "-Wzero-as-null-pointer-constant", "-Wcast-align", "-Wno-implicit-fallthrough",
  663. "-Wno-maybe-uninitialized", "-Wno-missing-field-initializers", "-Wno-ignored-qualifiers",
  664. "-Wswitch-enum", "-Wredundant-decls"
  665. };
  666. recommendedCompilerWarningFlags["GCC-7"] = recommendedCompilerWarningFlags["GCC"];
  667. recommendedCompilerWarningFlags["GCC-7"].add ("-Wno-strict-overflow");
  668. }
  669. ProjectExporter::BuildConfiguration::~BuildConfiguration()
  670. {
  671. }
  672. String ProjectExporter::BuildConfiguration::getGCCOptimisationFlag() const
  673. {
  674. switch (getOptimisationLevelInt())
  675. {
  676. case gccO0: return "0";
  677. case gccO1: return "1";
  678. case gccO2: return "2";
  679. case gccO3: return "3";
  680. case gccOs: return "s";
  681. case gccOfast: return "fast";
  682. default: break;
  683. }
  684. return "0";
  685. }
  686. void ProjectExporter::BuildConfiguration::addGCCOptimisationProperty (PropertyListBuilder& props)
  687. {
  688. props.add (new ChoicePropertyComponent (optimisationLevelValue, "Optimisation",
  689. { "-O0 (no optimisation)", "-Os (minimise code size)", "-O1 (fast)", "-O2 (faster)",
  690. "-O3 (fastest with safe optimisations)", "-Ofast (uses aggressive optimisations)" },
  691. { gccO0, gccOs, gccO1, gccO2, gccO3, gccOfast }),
  692. "The optimisation level for this configuration");
  693. }
  694. void ProjectExporter::BuildConfiguration::addRecommendedLinuxCompilerWarningsProperty (PropertyListBuilder& props)
  695. {
  696. props.add (new ChoicePropertyComponent (recommendedWarningsValue, "Add Recommended Compiler Warning Flags",
  697. { "GCC", "GCC 7 and below", "LLVM", "Disabled" },
  698. { "GCC", "GCC-7", "LLVM", "" }),
  699. "Enable this to add a set of recommended compiler warning flags.");
  700. recommendedWarningsValue.setDefault ("");
  701. }
  702. void ProjectExporter::BuildConfiguration::addRecommendedLLVMCompilerWarningsProperty (PropertyListBuilder& props)
  703. {
  704. props.add (new ChoicePropertyComponent (recommendedWarningsValue, "Add Recommended Compiler Warning Flags",
  705. { "Enabled", "Disabled" },
  706. { "LLVM", "" }),
  707. "Enable this to add a set of recommended compiler warning flags.");
  708. recommendedWarningsValue.setDefault ("");
  709. }
  710. StringArray ProjectExporter::BuildConfiguration::getRecommendedCompilerWarningFlags() const
  711. {
  712. auto label = recommendedWarningsValue.get().toString();
  713. auto it = recommendedCompilerWarningFlags.find (label);
  714. if (it != recommendedCompilerWarningFlags.end())
  715. return it->second;
  716. return {};
  717. }
  718. void ProjectExporter::BuildConfiguration::createPropertyEditors (PropertyListBuilder& props)
  719. {
  720. if (exporter.supportsUserDefinedConfigurations())
  721. props.add (new TextPropertyComponent (configNameValue, "Name", 96, false),
  722. "The name of this configuration.");
  723. props.add (new ChoicePropertyComponent (isDebugValue, "Debug Mode"),
  724. "If enabled, this means that the configuration should be built with debug symbols.");
  725. props.add (new TextPropertyComponent (targetNameValue, "Binary Name", 256, false),
  726. "The filename to use for the destination binary executable file. If you don't add a suffix to this name, "
  727. "a suitable platform-specific suffix will be added automatically.");
  728. props.add (new TextPropertyComponent (targetBinaryPathValue, "Binary Location", 1024, false),
  729. "The folder in which the finished binary should be placed. Leave this blank to cause the binary to be placed "
  730. "in its default location in the build folder.");
  731. props.addSearchPathProperty (headerSearchPathValue, "Header Search Paths", "Extra header search paths.");
  732. props.addSearchPathProperty (librarySearchPathValue, "Extra Library Search Paths", "Extra library search paths.");
  733. props.add (new TextPropertyComponent (ppDefinesValue, "Preprocessor Definitions", 32768, true),
  734. "Extra preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  735. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  736. props.add (new ChoicePropertyComponent (linkTimeOptimisationValue, "Link-Time Optimisation"),
  737. "Enable this to perform link-time code optimisation. This is recommended for release builds.");
  738. createConfigProperties (props);
  739. props.add (new TextPropertyComponent (userNotesValue, "Notes", 32768, true),
  740. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  741. }
  742. StringPairArray ProjectExporter::BuildConfiguration::getAllPreprocessorDefs() const
  743. {
  744. return mergePreprocessorDefs (project.getPreprocessorDefs(),
  745. parsePreprocessorDefs (getBuildConfigPreprocessorDefsString()));
  746. }
  747. StringPairArray ProjectExporter::BuildConfiguration::getUniquePreprocessorDefs() const
  748. {
  749. auto perConfigurationDefs = parsePreprocessorDefs (getBuildConfigPreprocessorDefsString());
  750. auto globalDefs = project.getPreprocessorDefs();
  751. for (int i = 0; i < globalDefs.size(); ++i)
  752. {
  753. auto globalKey = globalDefs.getAllKeys()[i];
  754. int idx = perConfigurationDefs.getAllKeys().indexOf (globalKey);
  755. if (idx >= 0)
  756. {
  757. auto globalValue = globalDefs.getAllValues()[i];
  758. if (globalValue == perConfigurationDefs.getAllValues()[idx])
  759. perConfigurationDefs.remove (idx);
  760. }
  761. }
  762. return perConfigurationDefs;
  763. }
  764. StringArray ProjectExporter::BuildConfiguration::getHeaderSearchPaths() const
  765. {
  766. return getSearchPathsFromString (getHeaderSearchPathString() + ';' + project.getHeaderSearchPathsString());
  767. }
  768. StringArray ProjectExporter::BuildConfiguration::getLibrarySearchPaths() const
  769. {
  770. auto separator = exporter.isVisualStudio() ? "\\" : "/";
  771. auto s = getSearchPathsFromString (getLibrarySearchPathString());
  772. for (auto path : exporter.moduleLibSearchPaths)
  773. s.add (path + separator + getModuleLibraryArchName());
  774. return s;
  775. }
  776. String ProjectExporter::getExternalLibraryFlags (const BuildConfiguration& config) const
  777. {
  778. auto libraries = StringArray::fromTokens (getExternalLibrariesString(), ";\n", "\"'");
  779. libraries.removeEmptyStrings (true);
  780. if (libraries.size() != 0)
  781. return replacePreprocessorTokens (config, "-l" + libraries.joinIntoString (" -l")).trim();
  782. return {};
  783. }