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.

815 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. private:
  150. ValueWithDefault targetPlatformValue;
  151. String getTargetPlatformString() const { return targetPlatformValue.get(); }
  152. //==============================================================================
  153. class CodeBlocksBuildConfiguration : public BuildConfiguration
  154. {
  155. public:
  156. CodeBlocksBuildConfiguration (Project& p, const ValueTree& settings, const ProjectExporter& e)
  157. : BuildConfiguration (p, settings, e),
  158. architectureTypeValue (config, exporter.isWindows() ? Ids::windowsCodeBlocksArchitecture
  159. : Ids::linuxCodeBlocksArchitecture, getUndoManager(), "-m64")
  160. {
  161. linkTimeOptimisationValue.setDefault (false);
  162. optimisationLevelValue.setDefault (isDebug() ? gccO0 : gccO3);
  163. }
  164. void createConfigProperties (PropertyListBuilder& props) override
  165. {
  166. addGCCOptimisationProperty (props);
  167. props.add (new ChoicePropertyComponent (architectureTypeValue, "Architecture",
  168. { "32-bit (-m32)", "64-bit (-m64)", "ARM v6", "ARM v7" },
  169. { "-m32", "-m64", "-march=armv6", "-march=armv7" }),
  170. "Specifies the 32/64-bit architecture to use.");
  171. }
  172. String getModuleLibraryArchName() const override
  173. {
  174. auto archFlag = getArchitectureTypeString();
  175. String prefix ("-march=");
  176. if (archFlag.startsWith (prefix))
  177. return archFlag.substring (prefix.length());
  178. else if (archFlag == "-m64")
  179. return "x86_64";
  180. else if (archFlag == "-m32")
  181. return "i386";
  182. jassertfalse;
  183. return {};
  184. }
  185. String getArchitectureTypeString() const { return architectureTypeValue.get(); }
  186. //==============================================================================
  187. ValueWithDefault architectureTypeValue;
  188. };
  189. BuildConfiguration::Ptr createBuildConfig (const ValueTree& tree) const override
  190. {
  191. return *new CodeBlocksBuildConfiguration (project, tree, *this);
  192. }
  193. //==============================================================================
  194. class CodeBlocksTarget : public ProjectType::Target
  195. {
  196. public:
  197. CodeBlocksTarget (const CodeBlocksProjectExporter& e, ProjectType::Target::Type typeToUse)
  198. : ProjectType::Target (typeToUse),
  199. exporter (e)
  200. {}
  201. String getTargetNameForConfiguration (const BuildConfiguration& config) const
  202. {
  203. if (type == ProjectType::Target::AggregateTarget)
  204. return config.getName();
  205. return getName() + String (" | ") + config.getName();
  206. }
  207. String getTargetSuffix() const
  208. {
  209. auto fileType = getTargetFileType();
  210. if (exporter.isWindows())
  211. {
  212. switch (fileType)
  213. {
  214. case executable: return ".exe";
  215. case staticLibrary: return ".lib";
  216. case sharedLibraryOrDLL:
  217. case pluginBundle: return ".dll";
  218. default:
  219. break;
  220. }
  221. }
  222. else
  223. {
  224. switch (fileType)
  225. {
  226. case executable: return {};
  227. case staticLibrary: return ".a";
  228. case sharedLibraryOrDLL: return ".so";
  229. case pluginBundle:
  230. switch (type)
  231. {
  232. case VSTPlugIn: return ".so";
  233. default: break;
  234. }
  235. return ".so";
  236. default:
  237. break;
  238. }
  239. }
  240. return {};
  241. }
  242. bool isDynamicLibrary() const
  243. {
  244. return (type == DynamicLibrary || type == VSTPlugIn);
  245. }
  246. const CodeBlocksProjectExporter& exporter;
  247. };
  248. //==============================================================================
  249. StringArray getPackages() const
  250. {
  251. auto result = linuxPackages;
  252. static String guiExtrasModule ("juce_gui_extra");
  253. if (project.getEnabledModules().isModuleEnabled (guiExtrasModule)
  254. && project.isConfigFlagEnabled ("JUCE_WEB_BROWSER", true))
  255. {
  256. result.add ("webkit2gtk-4.0");
  257. result.add ("gtk+-x11-3.0");
  258. }
  259. result.removeDuplicates (false);
  260. return result;
  261. }
  262. void addVersion (XmlElement& xml) const
  263. {
  264. auto* fileVersion = xml.createNewChildElement ("FileVersion");
  265. fileVersion->setAttribute ("major", 1);
  266. fileVersion->setAttribute ("minor", 6);
  267. }
  268. void addOptions (XmlElement& xml) const
  269. {
  270. xml.createNewChildElement ("Option")->setAttribute ("title", project.getProjectNameString());
  271. xml.createNewChildElement ("Option")->setAttribute ("pch_mode", 2);
  272. xml.createNewChildElement ("Option")->setAttribute ("compiler", "gcc");
  273. }
  274. StringArray getDefines (const BuildConfiguration& config, CodeBlocksTarget& target) const
  275. {
  276. StringPairArray defines;
  277. if (isWindows())
  278. {
  279. defines.set ("__MINGW__", "1");
  280. defines.set ("__MINGW_EXTENSION", {});
  281. auto targetPlatform = getTargetPlatformString();
  282. if (targetPlatform.isNotEmpty())
  283. defines.set ("WINVER", targetPlatform);
  284. }
  285. else
  286. {
  287. defines.set ("LINUX", "1");
  288. }
  289. if (config.isDebug())
  290. {
  291. defines.set ("DEBUG", "1");
  292. defines.set ("_DEBUG", "1");
  293. }
  294. else
  295. {
  296. defines.set ("NDEBUG", "1");
  297. }
  298. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config, target.type));
  299. StringArray defs;
  300. auto keys = defines.getAllKeys();
  301. auto values = defines.getAllValues();
  302. for (int i = 0; i < defines.size(); ++i)
  303. {
  304. auto result = keys[i];
  305. if (values[i].isNotEmpty())
  306. result += "=" + values[i];
  307. defs.add (result);
  308. }
  309. return getCleanedStringArray (defs);
  310. }
  311. StringArray getCompilerFlags (const BuildConfiguration& config, CodeBlocksTarget& target) const
  312. {
  313. StringArray flags;
  314. if (auto* codeBlocksConfig = dynamic_cast<const CodeBlocksBuildConfiguration*> (&config))
  315. flags.add (codeBlocksConfig->getArchitectureTypeString());
  316. flags.add ("-O" + config.getGCCOptimisationFlag());
  317. if (config.isLinkTimeOptimisationEnabled())
  318. flags.add ("-flto");
  319. {
  320. auto cppStandard = config.project.getCppStandardString();
  321. if (cppStandard == "latest")
  322. cppStandard = "17";
  323. cppStandard = "-std=" + String (shouldUseGNUExtensions() ? "gnu++" : "c++") + cppStandard;
  324. flags.add (cppStandard);
  325. }
  326. flags.add ("-mstackrealign");
  327. if (config.isDebug())
  328. flags.add ("-g");
  329. flags.addTokens (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim(),
  330. " \n", "\"'");
  331. if (config.exporter.isLinux())
  332. {
  333. if (target.isDynamicLibrary() || getProject().getProjectType().isAudioPlugin())
  334. flags.add ("-fPIC");
  335. auto packages = getPackages();
  336. if (packages.size() > 0)
  337. {
  338. auto pkgconfigFlags = String ("`pkg-config --cflags");
  339. for (auto p : packages)
  340. pkgconfigFlags << " " << p;
  341. pkgconfigFlags << "`";
  342. flags.add (pkgconfigFlags);
  343. }
  344. if (linuxLibs.contains("pthread"))
  345. flags.add ("-pthread");
  346. }
  347. return getCleanedStringArray (flags);
  348. }
  349. StringArray getLinkerFlags (const BuildConfiguration& config, CodeBlocksTarget& target) const
  350. {
  351. auto flags = makefileExtraLinkerFlags;
  352. if (auto* codeBlocksConfig = dynamic_cast<const CodeBlocksBuildConfiguration*> (&config))
  353. flags.add (codeBlocksConfig->getArchitectureTypeString());
  354. if (! config.isDebug())
  355. flags.add ("-s");
  356. if (config.isLinkTimeOptimisationEnabled())
  357. flags.add ("-flto");
  358. flags.addTokens (replacePreprocessorTokens (config, getExtraLinkerFlagsString()).trim(), " \n", "\"'");
  359. auto packages = getPackages();
  360. if (config.exporter.isLinux())
  361. {
  362. if (target.isDynamicLibrary())
  363. flags.add ("-shared");
  364. if (packages.size() > 0)
  365. {
  366. String pkgconfigLibs ("`pkg-config --libs");
  367. for (auto& p : packages)
  368. pkgconfigLibs << " " << p;
  369. pkgconfigLibs << "`";
  370. flags.add (pkgconfigLibs);
  371. }
  372. }
  373. return getCleanedStringArray (flags);
  374. }
  375. StringArray getLinkerSearchPaths (const BuildConfiguration& config, CodeBlocksTarget& target) const
  376. {
  377. auto librarySearchPaths = config.getLibrarySearchPaths();
  378. if (getProject().getProjectType().isAudioPlugin() && target.type != ProjectType::Target::SharedCodeTarget)
  379. librarySearchPaths.add (RelativePath (getSharedCodePath (config), RelativePath::buildTargetFolder).getParentDirectory().toUnixStyle());
  380. return librarySearchPaths;
  381. }
  382. StringArray getIncludePaths (const BuildConfiguration& config) const
  383. {
  384. StringArray paths;
  385. paths.add (".");
  386. paths.addArray (extraSearchPaths);
  387. paths.addArray (config.getHeaderSearchPaths());
  388. if (! isWindows())
  389. {
  390. paths.add ("/usr/include/freetype2");
  391. // Replace ~ character with $(HOME) environment variable
  392. for (auto& path : paths)
  393. path = path.replace ("~", "$(HOME)");
  394. }
  395. return getCleanedStringArray (paths);
  396. }
  397. static int getTypeIndex (const ProjectType::Target::Type& type)
  398. {
  399. switch (type)
  400. {
  401. case ProjectType::Target::GUIApp:
  402. case ProjectType::Target::StandalonePlugIn:
  403. return 0;
  404. case ProjectType::Target::ConsoleApp:
  405. return 1;
  406. case ProjectType::Target::StaticLibrary:
  407. case ProjectType::Target::SharedCodeTarget:
  408. return 2;
  409. case ProjectType::Target::DynamicLibrary:
  410. case ProjectType::Target::VSTPlugIn:
  411. return 3;
  412. default:
  413. break;
  414. }
  415. return 0;
  416. }
  417. String getOutputPathForTarget (CodeBlocksTarget& target, const BuildConfiguration& config) const
  418. {
  419. String outputPath;
  420. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  421. {
  422. RelativePath binaryPath (config.getTargetBinaryRelativePathString(), RelativePath::projectFolder);
  423. binaryPath = binaryPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder);
  424. outputPath = config.getTargetBinaryRelativePathString();
  425. }
  426. else
  427. {
  428. outputPath ="bin/" + File::createLegalFileName (config.getName().trim());
  429. }
  430. return outputPath + "/" + replacePreprocessorTokens (config, config.getTargetBinaryNameString() + target.getTargetSuffix());
  431. }
  432. String getSharedCodePath (const BuildConfiguration& config) const
  433. {
  434. auto outputPath = getOutputPathForTarget (getTargetWithType (ProjectType::Target::SharedCodeTarget), config);
  435. RelativePath path (outputPath, RelativePath::buildTargetFolder);
  436. auto filename = path.getFileName();
  437. if (isLinux())
  438. filename = "lib" + filename;
  439. return path.getParentDirectory().getChildFile (filename).toUnixStyle();
  440. }
  441. void createBuildTarget (XmlElement& xml, CodeBlocksTarget& target, const BuildConfiguration& config) const
  442. {
  443. xml.setAttribute ("title", target.getTargetNameForConfiguration (config));
  444. {
  445. auto* output = xml.createNewChildElement ("Option");
  446. output->setAttribute ("output", getOutputPathForTarget (target, config));
  447. if (isLinux())
  448. {
  449. bool keepPrefix = (target.type == ProjectType::Target::VSTPlugIn);
  450. output->setAttribute ("prefix_auto", keepPrefix ? 0 : 1);
  451. }
  452. else
  453. {
  454. output->setAttribute ("prefix_auto", 0);
  455. }
  456. output->setAttribute ("extension_auto", 0);
  457. }
  458. xml.createNewChildElement ("Option")
  459. ->setAttribute ("object_output", "obj/" + File::createLegalFileName (config.getName().trim()));
  460. xml.createNewChildElement ("Option")->setAttribute ("type", getTypeIndex (target.type));
  461. xml.createNewChildElement ("Option")->setAttribute ("compiler", "gcc");
  462. if (getProject().getProjectType().isAudioPlugin() && target.type != ProjectType::Target::SharedCodeTarget)
  463. xml.createNewChildElement ("Option")->setAttribute ("external_deps", getSharedCodePath (config));
  464. {
  465. auto* compiler = xml.createNewChildElement ("Compiler");
  466. {
  467. StringArray flags;
  468. for (auto& def : getDefines (config, target))
  469. {
  470. if (! def.containsChar ('='))
  471. def << '=';
  472. flags.add ("-D" + def);
  473. }
  474. flags.addArray (getCompilerFlags (config, target));
  475. for (auto flag : flags)
  476. setAddOption (*compiler, "option", flag);
  477. }
  478. {
  479. auto includePaths = getIncludePaths (config);
  480. for (auto path : includePaths)
  481. setAddOption (*compiler, "directory", path);
  482. }
  483. }
  484. {
  485. auto* linker = xml.createNewChildElement ("Linker");
  486. if (getProject().getProjectType().isAudioPlugin() && target.type != ProjectType::Target::SharedCodeTarget)
  487. setAddOption (*linker, "option", getSharedCodePath (config));
  488. for (auto& flag : getLinkerFlags (config, target))
  489. setAddOption (*linker, "option", flag);
  490. const StringArray& libs = isWindows() ? mingwLibs : linuxLibs;
  491. for (auto lib : libs)
  492. setAddOption (*linker, "library", lib);
  493. for (auto& path : getLinkerSearchPaths (config, target))
  494. setAddOption (*linker, "directory", replacePreprocessorDefs (getAllPreprocessorDefs(), path));
  495. }
  496. }
  497. void addBuild (XmlElement& xml) const
  498. {
  499. auto* build = xml.createNewChildElement ("Build");
  500. for (ConstConfigIterator config (*this); config.next();)
  501. for (auto target : targets)
  502. if (target->type != ProjectType::Target::AggregateTarget)
  503. createBuildTarget (*build->createNewChildElement ("Target"), *target, *config);
  504. }
  505. void addVirtualTargets (XmlElement& xml) const
  506. {
  507. auto* virtualTargets = xml.createNewChildElement ("VirtualTargets");
  508. for (ConstConfigIterator config (*this); config.next();)
  509. {
  510. StringArray allTargets;
  511. for (auto target : targets)
  512. if (target->type != ProjectType::Target::AggregateTarget)
  513. allTargets.add (target->getTargetNameForConfiguration (*config));
  514. for (auto target : targets)
  515. {
  516. if (target->type == ProjectType::Target::AggregateTarget)
  517. {
  518. auto* configTarget = virtualTargets->createNewChildElement ("Add");
  519. configTarget->setAttribute ("alias", config->getName());
  520. configTarget->setAttribute ("targets", allTargets.joinIntoString (";"));
  521. }
  522. }
  523. }
  524. }
  525. StringArray getProjectCompilerOptions() const
  526. {
  527. return { "-Wall", "-Wno-strict-aliasing", "-Wno-strict-overflow" };
  528. }
  529. void addProjectCompilerOptions (XmlElement& xml) const
  530. {
  531. auto* compiler = xml.createNewChildElement ("Compiler");
  532. for (auto& option : getProjectCompilerOptions())
  533. setAddOption (*compiler, "option", option);
  534. }
  535. StringArray getProjectLinkerLibs() const
  536. {
  537. StringArray result;
  538. if (isWindows())
  539. result.addArray ({ "gdi32", "user32", "kernel32", "comctl32" });
  540. result.addTokens (getExternalLibrariesString(), ";\n", "\"'");
  541. result = getCleanedStringArray (result);
  542. for (auto& option : result)
  543. option = replacePreprocessorDefs (getAllPreprocessorDefs(), option);
  544. return result;
  545. }
  546. void addProjectLinkerOptions (XmlElement& xml) const
  547. {
  548. auto* linker = xml.createNewChildElement ("Linker");
  549. for (auto& lib : getProjectLinkerLibs())
  550. setAddOption (*linker, "library", lib);
  551. }
  552. CodeBlocksTarget& getTargetWithType (ProjectType::Target::Type type) const
  553. {
  554. CodeBlocksTarget* nonAggregrateTarget = nullptr;
  555. for (auto* target : targets)
  556. {
  557. if (target->type == type)
  558. return *target;
  559. if (target->type != ProjectType::Target::AggregateTarget)
  560. nonAggregrateTarget = target;
  561. }
  562. // this project has no valid targets
  563. jassert (nonAggregrateTarget != nullptr);
  564. return *nonAggregrateTarget;
  565. }
  566. // Returns SharedCode target for multi-target projects, otherwise it returns
  567. // the single target
  568. CodeBlocksTarget& getMainTarget() const
  569. {
  570. if (getProject().getProjectType().isAudioPlugin())
  571. return getTargetWithType (ProjectType::Target::SharedCodeTarget);
  572. for (auto* target : targets)
  573. if (target->type != ProjectType::Target::AggregateTarget)
  574. return *target;
  575. jassertfalse;
  576. return *targets[0];
  577. }
  578. CodeBlocksTarget& getTargetForProjectItem (const Project::Item& projectItem) const
  579. {
  580. if (getProject().getProjectType().isAudioPlugin())
  581. {
  582. if (! projectItem.shouldBeCompiled())
  583. return getTargetWithType (ProjectType::Target::SharedCodeTarget);
  584. return getTargetWithType (getProject().getTargetTypeFromFilePath (projectItem.getFile(), true));
  585. }
  586. return getMainTarget();
  587. }
  588. void addCompileUnits (const Project::Item& projectItem, XmlElement& xml) const
  589. {
  590. if (projectItem.isGroup())
  591. {
  592. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  593. addCompileUnits (projectItem.getChild(i), xml);
  594. }
  595. else if (projectItem.shouldBeAddedToTargetProject())
  596. {
  597. RelativePath file (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  598. auto* unit = xml.createNewChildElement ("Unit");
  599. unit->setAttribute ("filename", file.toUnixStyle());
  600. for (ConstConfigIterator config (*this); config.next();)
  601. {
  602. auto targetName = getTargetForProjectItem (projectItem).getTargetNameForConfiguration (*config);
  603. unit->createNewChildElement ("Option")->setAttribute ("target", targetName);
  604. }
  605. if (! projectItem.shouldBeCompiled())
  606. {
  607. unit->createNewChildElement ("Option")->setAttribute ("compile", 0);
  608. unit->createNewChildElement ("Option")->setAttribute ("link", 0);
  609. }
  610. }
  611. }
  612. void addCompileUnits (XmlElement& xml) const
  613. {
  614. for (int i = 0; i < getAllGroups().size(); ++i)
  615. addCompileUnits (getAllGroups().getReference(i), xml);
  616. }
  617. void createProject (XmlElement& xml) const
  618. {
  619. addOptions (xml);
  620. addBuild (xml);
  621. addVirtualTargets (xml);
  622. addProjectCompilerOptions (xml);
  623. addProjectLinkerOptions (xml);
  624. addCompileUnits (xml);
  625. }
  626. void setAddOption (XmlElement& xml, const String& nm, const String& value) const
  627. {
  628. xml.createNewChildElement ("Add")->setAttribute (nm, value);
  629. }
  630. CodeBlocksOS os;
  631. OwnedArray<CodeBlocksTarget> targets;
  632. friend class CLionProjectExporter;
  633. JUCE_DECLARE_NON_COPYABLE (CodeBlocksProjectExporter)
  634. };