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.

818 lines
29KB

  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. #pragma once
  20. //==============================================================================
  21. class CodeBlocksProjectExporter : public ProjectExporter
  22. {
  23. public:
  24. enum CodeBlocksOS
  25. {
  26. windowsTarget,
  27. linuxTarget
  28. };
  29. //==============================================================================
  30. static const char* getNameWindows() noexcept { return "Code::Blocks (Windows)"; }
  31. static const char* getNameLinux() noexcept { return "Code::Blocks (Linux)"; }
  32. static const char* getName (CodeBlocksOS os) noexcept
  33. {
  34. if (os == windowsTarget) return getNameWindows();
  35. if (os == linuxTarget) return getNameLinux();
  36. // currently no other OSes supported by Codeblocks exporter!
  37. jassertfalse;
  38. return "Code::Blocks (Unknown OS)";
  39. }
  40. //==============================================================================
  41. static const char* getValueTreeTypeName (CodeBlocksOS os)
  42. {
  43. if (os == windowsTarget) return "CODEBLOCKS_WINDOWS";
  44. if (os == linuxTarget) return "CODEBLOCKS_LINUX";
  45. // currently no other OSes supported by Codeblocks exporter!
  46. jassertfalse;
  47. return "CODEBLOCKS_UNKNOWN_OS";
  48. }
  49. //==============================================================================
  50. static CodeBlocksProjectExporter* createForSettings (Project& project, const ValueTree& settings)
  51. {
  52. // this will also import legacy jucer files where CodeBlocks only worked for Windows,
  53. // had valueTreetTypeName "CODEBLOCKS", and there was no OS distinction
  54. if (settings.hasType (getValueTreeTypeName (windowsTarget)) || settings.hasType ("CODEBLOCKS"))
  55. return new CodeBlocksProjectExporter (project, settings, windowsTarget);
  56. if (settings.hasType (getValueTreeTypeName (linuxTarget)))
  57. return new CodeBlocksProjectExporter (project, settings, linuxTarget);
  58. return nullptr;
  59. }
  60. //==============================================================================
  61. CodeBlocksProjectExporter (Project& p, const ValueTree& t, CodeBlocksOS codeBlocksOs)
  62. : ProjectExporter (p, t), os (codeBlocksOs)
  63. {
  64. name = getName (os);
  65. targetLocationValue.setDefault (getDefaultBuildsRootFolder() + getTargetFolderForExporter (getValueTreeTypeName (os)));
  66. if (isWindows())
  67. targetPlatformValue.referTo (settings, Ids::codeBlocksWindowsTarget, getUndoManager());
  68. }
  69. //==============================================================================
  70. bool canLaunchProject() override { return false; }
  71. bool launchProject() override { return false; }
  72. bool usesMMFiles() const override { return false; }
  73. bool canCopeWithDuplicateFiles() override { return false; }
  74. bool supportsUserDefinedConfigurations() const override { return true; }
  75. bool isXcode() const override { return false; }
  76. bool isVisualStudio() const override { return false; }
  77. bool isCodeBlocks() const override { return true; }
  78. bool isMakefile() const override { return false; }
  79. bool isAndroidStudio() const override { return false; }
  80. bool isCLion() const override { return false; }
  81. bool isAndroid() const override { return false; }
  82. bool isWindows() const override { return os == windowsTarget; }
  83. bool isLinux() const override { return os == linuxTarget; }
  84. bool isOSX() const override { return false; }
  85. bool isiOS() const override { return false; }
  86. bool supportsTargetType (ProjectType::Target::Type type) const override
  87. {
  88. switch (type)
  89. {
  90. case ProjectType::Target::StandalonePlugIn:
  91. case ProjectType::Target::GUIApp:
  92. case ProjectType::Target::ConsoleApp:
  93. case ProjectType::Target::StaticLibrary:
  94. case ProjectType::Target::SharedCodeTarget:
  95. case ProjectType::Target::AggregateTarget:
  96. case ProjectType::Target::VSTPlugIn:
  97. case ProjectType::Target::DynamicLibrary:
  98. return true;
  99. default:
  100. break;
  101. }
  102. return false;
  103. }
  104. void createExporterProperties (PropertyListBuilder& props) override
  105. {
  106. if (isWindows())
  107. {
  108. props.add (new ChoicePropertyComponent (targetPlatformValue, "Target platform",
  109. { "Windows NT 4.0", "Windows 2000", "Windows XP", "Windows Server 2003", "Windows Vista", "Windows Server 2008",
  110. "Windows 7", "Windows 8", "Windows 8.1", "Windows 10" },
  111. { "0x0400", "0x0500", "0x0501", "0x0502", "0x0600", "0x0600",
  112. "0x0601", "0x0602", "0x0603", "0x0A00" }),
  113. "This sets the preprocessor macro WINVER to an appropriate value for the corresponding platform.");
  114. }
  115. }
  116. //==============================================================================
  117. void create (const OwnedArray<LibraryModule>&) const override
  118. {
  119. auto cbpFile = getTargetFolder().getChildFile (project.getProjectFilenameRootString())
  120. .withFileExtension (".cbp");
  121. XmlElement xml ("CodeBlocks_project_file");
  122. addVersion (xml);
  123. createProject (*xml.createNewChildElement ("Project"));
  124. writeXmlOrThrow (xml, cbpFile, "UTF-8", 10);
  125. }
  126. //==============================================================================
  127. void addPlatformSpecificSettingsForProjectType (const ProjectType&) override
  128. {
  129. // add shared code target first as order matters for Codeblocks
  130. if (shouldBuildTargetType (ProjectType::Target::SharedCodeTarget))
  131. targets.add (new CodeBlocksTarget (*this, ProjectType::Target::SharedCodeTarget));
  132. //ProjectType::Target::SharedCodeTarget
  133. callForAllSupportedTargets ([this] (ProjectType::Target::Type targetType)
  134. {
  135. if (targetType == ProjectType::Target::SharedCodeTarget)
  136. return;
  137. if (auto* target = new CodeBlocksTarget (*this, targetType))
  138. {
  139. if (targetType == ProjectType::Target::AggregateTarget)
  140. targets.insert (0, target);
  141. else
  142. targets.add (target);
  143. }
  144. });
  145. // If you hit this assert, you tried to generate a project for an exporter
  146. // that does not support any of your targets!
  147. jassert (targets.size() > 0);
  148. }
  149. //==============================================================================
  150. void initialiseDependencyPathValues() override {}
  151. private:
  152. ValueWithDefault targetPlatformValue;
  153. String getTargetPlatformString() const { return targetPlatformValue.get(); }
  154. //==============================================================================
  155. class CodeBlocksBuildConfiguration : public BuildConfiguration
  156. {
  157. public:
  158. CodeBlocksBuildConfiguration (Project& p, const ValueTree& settings, const ProjectExporter& e)
  159. : BuildConfiguration (p, settings, e),
  160. architectureTypeValue (config, exporter.isWindows() ? Ids::windowsCodeBlocksArchitecture
  161. : Ids::linuxCodeBlocksArchitecture, getUndoManager(), "-m64")
  162. {
  163. linkTimeOptimisationValue.setDefault (false);
  164. optimisationLevelValue.setDefault (isDebug() ? gccO0 : gccO3);
  165. }
  166. void createConfigProperties (PropertyListBuilder& props) override
  167. {
  168. addGCCOptimisationProperty (props);
  169. props.add (new ChoicePropertyComponent (architectureTypeValue, "Architecture",
  170. { "32-bit (-m32)", "64-bit (-m64)", "ARM v6", "ARM v7" },
  171. { "-m32", "-m64", "-march=armv6", "-march=armv7" }),
  172. "Specifies the 32/64-bit architecture to use.");
  173. }
  174. String getModuleLibraryArchName() const override
  175. {
  176. auto archFlag = getArchitectureTypeString();
  177. String prefix ("-march=");
  178. if (archFlag.startsWith (prefix))
  179. return archFlag.substring (prefix.length());
  180. else if (archFlag == "-m64")
  181. return "x86_64";
  182. else if (archFlag == "-m32")
  183. return "i386";
  184. jassertfalse;
  185. return {};
  186. }
  187. String getArchitectureTypeString() const { return architectureTypeValue.get(); }
  188. //==============================================================================
  189. ValueWithDefault architectureTypeValue;
  190. };
  191. BuildConfiguration::Ptr createBuildConfig (const ValueTree& tree) const override
  192. {
  193. return new CodeBlocksBuildConfiguration (project, tree, *this);
  194. }
  195. //==============================================================================
  196. class CodeBlocksTarget : public ProjectType::Target
  197. {
  198. public:
  199. CodeBlocksTarget (const CodeBlocksProjectExporter& e, ProjectType::Target::Type typeToUse)
  200. : ProjectType::Target (typeToUse),
  201. exporter (e)
  202. {}
  203. String getTargetNameForConfiguration (const BuildConfiguration& config) const
  204. {
  205. if (type == ProjectType::Target::AggregateTarget)
  206. return config.getName();
  207. return getName() + String (" | ") + config.getName();
  208. }
  209. String getTargetSuffix() const
  210. {
  211. auto fileType = getTargetFileType();
  212. if (exporter.isWindows())
  213. {
  214. switch (fileType)
  215. {
  216. case executable: return ".exe";
  217. case staticLibrary: return ".lib";
  218. case sharedLibraryOrDLL:
  219. case pluginBundle: return ".dll";
  220. default:
  221. break;
  222. }
  223. }
  224. else
  225. {
  226. switch (fileType)
  227. {
  228. case executable: return {};
  229. case staticLibrary: return ".a";
  230. case sharedLibraryOrDLL: return ".so";
  231. case pluginBundle:
  232. switch (type)
  233. {
  234. case VSTPlugIn: return ".so";
  235. default: break;
  236. }
  237. return ".so";
  238. default:
  239. break;
  240. }
  241. }
  242. return {};
  243. }
  244. bool isDynamicLibrary() const
  245. {
  246. return (type == DynamicLibrary || type == VSTPlugIn);
  247. }
  248. const CodeBlocksProjectExporter& exporter;
  249. };
  250. //==============================================================================
  251. StringArray getPackages() const
  252. {
  253. auto result = linuxPackages;
  254. static String guiExtrasModule ("juce_gui_extra");
  255. if (project.getModules().isModuleEnabled (guiExtrasModule)
  256. && project.isConfigFlagEnabled ("JUCE_WEB_BROWSER", true))
  257. {
  258. result.add ("webkit2gtk-4.0");
  259. result.add ("gtk+-x11-3.0");
  260. }
  261. result.removeDuplicates (false);
  262. return result;
  263. }
  264. void addVersion (XmlElement& xml) const
  265. {
  266. auto* fileVersion = xml.createNewChildElement ("FileVersion");
  267. fileVersion->setAttribute ("major", 1);
  268. fileVersion->setAttribute ("minor", 6);
  269. }
  270. void addOptions (XmlElement& xml) const
  271. {
  272. xml.createNewChildElement ("Option")->setAttribute ("title", project.getProjectNameString());
  273. xml.createNewChildElement ("Option")->setAttribute ("pch_mode", 2);
  274. xml.createNewChildElement ("Option")->setAttribute ("compiler", "gcc");
  275. }
  276. StringArray getDefines (const BuildConfiguration& config, CodeBlocksTarget& target) const
  277. {
  278. StringPairArray defines;
  279. if (isWindows())
  280. {
  281. defines.set ("__MINGW__", "1");
  282. defines.set ("__MINGW_EXTENSION", {});
  283. auto targetPlatform = getTargetPlatformString();
  284. if (targetPlatform.isNotEmpty())
  285. defines.set ("WINVER", targetPlatform);
  286. }
  287. else
  288. {
  289. defines.set ("LINUX", "1");
  290. }
  291. if (config.isDebug())
  292. {
  293. defines.set ("DEBUG", "1");
  294. defines.set ("_DEBUG", "1");
  295. }
  296. else
  297. {
  298. defines.set ("NDEBUG", "1");
  299. }
  300. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config, target.type));
  301. StringArray defs;
  302. auto keys = defines.getAllKeys();
  303. auto values = defines.getAllValues();
  304. for (int i = 0; i < defines.size(); ++i)
  305. {
  306. auto result = keys[i];
  307. if (values[i].isNotEmpty())
  308. result += "=" + values[i];
  309. defs.add (result);
  310. }
  311. return getCleanedStringArray (defs);
  312. }
  313. StringArray getCompilerFlags (const BuildConfiguration& config, CodeBlocksTarget& target) const
  314. {
  315. StringArray flags;
  316. if (auto* codeBlocksConfig = dynamic_cast<const CodeBlocksBuildConfiguration*> (&config))
  317. flags.add (codeBlocksConfig->getArchitectureTypeString());
  318. flags.add ("-O" + config.getGCCOptimisationFlag());
  319. if (config.isLinkTimeOptimisationEnabled())
  320. flags.add ("-flto");
  321. {
  322. auto cppStandard = config.project.getCppStandardString();
  323. if (cppStandard == "latest")
  324. cppStandard = "17";
  325. cppStandard = "-std=" + String (shouldUseGNUExtensions() ? "gnu++" : "c++") + cppStandard;
  326. flags.add (cppStandard);
  327. }
  328. flags.add ("-mstackrealign");
  329. if (config.isDebug())
  330. flags.add ("-g");
  331. flags.addTokens (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim(),
  332. " \n", "\"'");
  333. if (config.exporter.isLinux())
  334. {
  335. if (target.isDynamicLibrary() || getProject().getProjectType().isAudioPlugin())
  336. flags.add ("-fPIC");
  337. auto packages = getPackages();
  338. if (packages.size() > 0)
  339. {
  340. auto pkgconfigFlags = String ("`pkg-config --cflags");
  341. for (auto p : packages)
  342. pkgconfigFlags << " " << p;
  343. pkgconfigFlags << "`";
  344. flags.add (pkgconfigFlags);
  345. }
  346. if (linuxLibs.contains("pthread"))
  347. flags.add ("-pthread");
  348. }
  349. return getCleanedStringArray (flags);
  350. }
  351. StringArray getLinkerFlags (const BuildConfiguration& config, CodeBlocksTarget& target) const
  352. {
  353. auto flags = makefileExtraLinkerFlags;
  354. if (auto* codeBlocksConfig = dynamic_cast<const CodeBlocksBuildConfiguration*> (&config))
  355. flags.add (codeBlocksConfig->getArchitectureTypeString());
  356. if (! config.isDebug())
  357. flags.add ("-s");
  358. if (config.isLinkTimeOptimisationEnabled())
  359. flags.add ("-flto");
  360. flags.addTokens (replacePreprocessorTokens (config, getExtraLinkerFlagsString()).trim(), " \n", "\"'");
  361. auto packages = getPackages();
  362. if (config.exporter.isLinux())
  363. {
  364. if (target.isDynamicLibrary())
  365. flags.add ("-shared");
  366. if (packages.size() > 0)
  367. {
  368. String pkgconfigLibs ("`pkg-config --libs");
  369. for (auto& p : packages)
  370. pkgconfigLibs << " " << p;
  371. pkgconfigLibs << "`";
  372. flags.add (pkgconfigLibs);
  373. }
  374. }
  375. return getCleanedStringArray (flags);
  376. }
  377. StringArray getLinkerSearchPaths (const BuildConfiguration& config, CodeBlocksTarget& target) const
  378. {
  379. auto librarySearchPaths = config.getLibrarySearchPaths();
  380. if (getProject().getProjectType().isAudioPlugin() && target.type != ProjectType::Target::SharedCodeTarget)
  381. librarySearchPaths.add (RelativePath (getSharedCodePath (config), RelativePath::buildTargetFolder).getParentDirectory().toUnixStyle());
  382. return librarySearchPaths;
  383. }
  384. StringArray getIncludePaths (const BuildConfiguration& config) const
  385. {
  386. StringArray paths;
  387. paths.add (".");
  388. paths.addArray (extraSearchPaths);
  389. paths.addArray (config.getHeaderSearchPaths());
  390. if (! isWindows())
  391. {
  392. paths.add ("/usr/include/freetype2");
  393. // Replace ~ character with $(HOME) environment variable
  394. for (auto& path : paths)
  395. path = path.replace ("~", "$(HOME)");
  396. }
  397. return getCleanedStringArray (paths);
  398. }
  399. static int getTypeIndex (const ProjectType::Target::Type& type)
  400. {
  401. switch (type)
  402. {
  403. case ProjectType::Target::GUIApp:
  404. case ProjectType::Target::StandalonePlugIn:
  405. return 0;
  406. case ProjectType::Target::ConsoleApp:
  407. return 1;
  408. case ProjectType::Target::StaticLibrary:
  409. case ProjectType::Target::SharedCodeTarget:
  410. return 2;
  411. case ProjectType::Target::DynamicLibrary:
  412. case ProjectType::Target::VSTPlugIn:
  413. return 3;
  414. default:
  415. break;
  416. }
  417. return 0;
  418. }
  419. String getOutputPathForTarget (CodeBlocksTarget& target, const BuildConfiguration& config) const
  420. {
  421. String outputPath;
  422. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  423. {
  424. RelativePath binaryPath (config.getTargetBinaryRelativePathString(), RelativePath::projectFolder);
  425. binaryPath = binaryPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder);
  426. outputPath = config.getTargetBinaryRelativePathString();
  427. }
  428. else
  429. {
  430. outputPath ="bin/" + File::createLegalFileName (config.getName().trim());
  431. }
  432. return outputPath + "/" + replacePreprocessorTokens (config, config.getTargetBinaryNameString() + target.getTargetSuffix());
  433. }
  434. String getSharedCodePath (const BuildConfiguration& config) const
  435. {
  436. auto outputPath = getOutputPathForTarget (getTargetWithType (ProjectType::Target::SharedCodeTarget), config);
  437. RelativePath path (outputPath, RelativePath::buildTargetFolder);
  438. auto filename = path.getFileName();
  439. if (isLinux())
  440. filename = "lib" + filename;
  441. return path.getParentDirectory().getChildFile (filename).toUnixStyle();
  442. }
  443. void createBuildTarget (XmlElement& xml, CodeBlocksTarget& target, const BuildConfiguration& config) const
  444. {
  445. xml.setAttribute ("title", target.getTargetNameForConfiguration (config));
  446. {
  447. auto* output = xml.createNewChildElement ("Option");
  448. output->setAttribute ("output", getOutputPathForTarget (target, config));
  449. if (isLinux())
  450. {
  451. bool keepPrefix = (target.type == ProjectType::Target::VSTPlugIn);
  452. output->setAttribute ("prefix_auto", keepPrefix ? 0 : 1);
  453. }
  454. else
  455. {
  456. output->setAttribute ("prefix_auto", 0);
  457. }
  458. output->setAttribute ("extension_auto", 0);
  459. }
  460. xml.createNewChildElement ("Option")
  461. ->setAttribute ("object_output", "obj/" + File::createLegalFileName (config.getName().trim()));
  462. xml.createNewChildElement ("Option")->setAttribute ("type", getTypeIndex (target.type));
  463. xml.createNewChildElement ("Option")->setAttribute ("compiler", "gcc");
  464. if (getProject().getProjectType().isAudioPlugin() && target.type != ProjectType::Target::SharedCodeTarget)
  465. xml.createNewChildElement ("Option")->setAttribute ("external_deps", getSharedCodePath (config));
  466. {
  467. auto* compiler = xml.createNewChildElement ("Compiler");
  468. {
  469. StringArray flags;
  470. for (auto& def : getDefines (config, target))
  471. {
  472. if (! def.containsChar ('='))
  473. def << '=';
  474. flags.add ("-D" + def);
  475. }
  476. flags.addArray (getCompilerFlags (config, target));
  477. for (auto flag : flags)
  478. setAddOption (*compiler, "option", flag);
  479. }
  480. {
  481. auto includePaths = getIncludePaths (config);
  482. for (auto path : includePaths)
  483. setAddOption (*compiler, "directory", path);
  484. }
  485. }
  486. {
  487. auto* linker = xml.createNewChildElement ("Linker");
  488. if (getProject().getProjectType().isAudioPlugin() && target.type != ProjectType::Target::SharedCodeTarget)
  489. setAddOption (*linker, "option", getSharedCodePath (config));
  490. for (auto& flag : getLinkerFlags (config, target))
  491. setAddOption (*linker, "option", flag);
  492. const StringArray& libs = isWindows() ? mingwLibs : linuxLibs;
  493. for (auto lib : libs)
  494. setAddOption (*linker, "library", lib);
  495. for (auto& path : getLinkerSearchPaths (config, target))
  496. setAddOption (*linker, "directory", replacePreprocessorDefs (getAllPreprocessorDefs(), path));
  497. }
  498. }
  499. void addBuild (XmlElement& xml) const
  500. {
  501. auto* build = xml.createNewChildElement ("Build");
  502. for (ConstConfigIterator config (*this); config.next();)
  503. for (auto target : targets)
  504. if (target->type != ProjectType::Target::AggregateTarget)
  505. createBuildTarget (*build->createNewChildElement ("Target"), *target, *config);
  506. }
  507. void addVirtualTargets (XmlElement& xml) const
  508. {
  509. auto* virtualTargets = xml.createNewChildElement ("VirtualTargets");
  510. for (ConstConfigIterator config (*this); config.next();)
  511. {
  512. StringArray allTargets;
  513. for (auto target : targets)
  514. if (target->type != ProjectType::Target::AggregateTarget)
  515. allTargets.add (target->getTargetNameForConfiguration (*config));
  516. for (auto target : targets)
  517. {
  518. if (target->type == ProjectType::Target::AggregateTarget)
  519. {
  520. auto* configTarget = virtualTargets->createNewChildElement ("Add");
  521. configTarget->setAttribute ("alias", config->getName());
  522. configTarget->setAttribute ("targets", allTargets.joinIntoString (";"));
  523. }
  524. }
  525. }
  526. }
  527. StringArray getProjectCompilerOptions() const
  528. {
  529. return { "-Wall", "-Wno-strict-aliasing", "-Wno-strict-overflow" };
  530. }
  531. void addProjectCompilerOptions (XmlElement& xml) const
  532. {
  533. auto* compiler = xml.createNewChildElement ("Compiler");
  534. for (auto& option : getProjectCompilerOptions())
  535. setAddOption (*compiler, "option", option);
  536. }
  537. StringArray getProjectLinkerLibs() const
  538. {
  539. StringArray result;
  540. if (isWindows())
  541. result.addArray ({ "gdi32", "user32", "kernel32", "comctl32" });
  542. result.addTokens (getExternalLibrariesString(), ";\n", "\"'");
  543. result = getCleanedStringArray (result);
  544. for (auto& option : result)
  545. option = replacePreprocessorDefs (getAllPreprocessorDefs(), option);
  546. return result;
  547. }
  548. void addProjectLinkerOptions (XmlElement& xml) const
  549. {
  550. auto* linker = xml.createNewChildElement ("Linker");
  551. for (auto& lib : getProjectLinkerLibs())
  552. setAddOption (*linker, "library", lib);
  553. }
  554. CodeBlocksTarget& getTargetWithType (ProjectType::Target::Type type) const
  555. {
  556. CodeBlocksTarget* nonAggregrateTarget = nullptr;
  557. for (auto* target : targets)
  558. {
  559. if (target->type == type)
  560. return *target;
  561. if (target->type != ProjectType::Target::AggregateTarget)
  562. nonAggregrateTarget = target;
  563. }
  564. // this project has no valid targets
  565. jassert (nonAggregrateTarget != nullptr);
  566. return *nonAggregrateTarget;
  567. }
  568. // Returns SharedCode target for multi-target projects, otherwise it returns
  569. // the single target
  570. CodeBlocksTarget& getMainTarget() const
  571. {
  572. if (getProject().getProjectType().isAudioPlugin())
  573. return getTargetWithType (ProjectType::Target::SharedCodeTarget);
  574. for (auto* target : targets)
  575. if (target->type != ProjectType::Target::AggregateTarget)
  576. return *target;
  577. jassertfalse;
  578. return *targets[0];
  579. }
  580. CodeBlocksTarget& getTargetForProjectItem (const Project::Item& projectItem) const
  581. {
  582. if (getProject().getProjectType().isAudioPlugin())
  583. {
  584. if (! projectItem.shouldBeCompiled())
  585. return getTargetWithType (ProjectType::Target::SharedCodeTarget);
  586. return getTargetWithType (getProject().getTargetTypeFromFilePath (projectItem.getFile(), true));
  587. }
  588. return getMainTarget();
  589. }
  590. void addCompileUnits (const Project::Item& projectItem, XmlElement& xml) const
  591. {
  592. if (projectItem.isGroup())
  593. {
  594. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  595. addCompileUnits (projectItem.getChild(i), xml);
  596. }
  597. else if (projectItem.shouldBeAddedToTargetProject())
  598. {
  599. RelativePath file (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  600. auto* unit = xml.createNewChildElement ("Unit");
  601. unit->setAttribute ("filename", file.toUnixStyle());
  602. for (ConstConfigIterator config (*this); config.next();)
  603. {
  604. auto targetName = getTargetForProjectItem (projectItem).getTargetNameForConfiguration (*config);
  605. unit->createNewChildElement ("Option")->setAttribute ("target", targetName);
  606. }
  607. if (! projectItem.shouldBeCompiled())
  608. {
  609. unit->createNewChildElement ("Option")->setAttribute ("compile", 0);
  610. unit->createNewChildElement ("Option")->setAttribute ("link", 0);
  611. }
  612. }
  613. }
  614. void addCompileUnits (XmlElement& xml) const
  615. {
  616. for (int i = 0; i < getAllGroups().size(); ++i)
  617. addCompileUnits (getAllGroups().getReference(i), xml);
  618. }
  619. void createProject (XmlElement& xml) const
  620. {
  621. addOptions (xml);
  622. addBuild (xml);
  623. addVirtualTargets (xml);
  624. addProjectCompilerOptions (xml);
  625. addProjectLinkerOptions (xml);
  626. addCompileUnits (xml);
  627. }
  628. void setAddOption (XmlElement& xml, const String& nm, const String& value) const
  629. {
  630. xml.createNewChildElement ("Add")->setAttribute (nm, value);
  631. }
  632. CodeBlocksOS os;
  633. OwnedArray<CodeBlocksTarget> targets;
  634. friend class CLionProjectExporter;
  635. JUCE_DECLARE_NON_COPYABLE (CodeBlocksProjectExporter)
  636. };