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.

1053 lines
45KB

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