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.

971 lines
41KB

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