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.

1023 lines
42KB

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