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.

1190 lines
55KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  19. #include "jucer_ProjectExport_CodeBlocks.h"
  20. #include "jucer_ProjectExport_Make.h"
  21. #include "jucer_ProjectExport_Xcode.h"
  22. //==============================================================================
  23. class CLionProjectExporter : public ProjectExporter
  24. {
  25. protected:
  26. //==============================================================================
  27. class CLionBuildConfiguration : public BuildConfiguration
  28. {
  29. public:
  30. CLionBuildConfiguration (Project& p, const ValueTree& settings, const ProjectExporter& e)
  31. : BuildConfiguration (p, settings, e)
  32. {
  33. }
  34. void createConfigProperties (PropertyListBuilder&) override {}
  35. String getModuleLibraryArchName() const override { return {}; }
  36. };
  37. BuildConfiguration::Ptr createBuildConfig (const ValueTree& tree) const override
  38. {
  39. return *new CLionBuildConfiguration (project, tree, *this);
  40. }
  41. public:
  42. //==============================================================================
  43. static String getDisplayName() { return "CLion (beta)"; }
  44. static String getValueTreeTypeName() { return "CLION"; }
  45. static String getTargetFolderName() { return "CLion"; }
  46. static CLionProjectExporter* createForSettings (Project& projectToUse, const ValueTree& settingsToUse)
  47. {
  48. if (settingsToUse.hasType (getValueTreeTypeName()))
  49. return new CLionProjectExporter (projectToUse, settingsToUse);
  50. return nullptr;
  51. }
  52. static bool isExporterSupported (const ProjectExporter& exporter)
  53. {
  54. return exporter.isMakefile()
  55. || (exporter.isXcode() && ! exporter.isiOS())
  56. || (exporter.isCodeBlocks() && exporter.isWindows());
  57. }
  58. //==============================================================================
  59. CLionProjectExporter (Project& p, const ValueTree& t) : ProjectExporter (p, t)
  60. {
  61. name = getDisplayName();
  62. targetLocationValue.setDefault (getDefaultBuildsRootFolder() + getTargetFolderName());
  63. }
  64. //==============================================================================
  65. bool usesMMFiles() const override { return false; }
  66. bool canCopeWithDuplicateFiles() override { return false; }
  67. bool supportsUserDefinedConfigurations() const override { return false; }
  68. bool isXcode() const override { return false; }
  69. bool isVisualStudio() const override { return false; }
  70. bool isCodeBlocks() const override { return false; }
  71. bool isMakefile() const override { return false; }
  72. bool isAndroidStudio() const override { return false; }
  73. bool isCLion() const override { return true; }
  74. bool isAndroid() const override { return false; }
  75. bool isWindows() const override { return false; }
  76. bool isLinux() const override { return false; }
  77. bool isOSX() const override { return false; }
  78. bool isiOS() const override { return false; }
  79. bool supportsTargetType (build_tools::ProjectType::Target::Type) const override { return true; }
  80. void addPlatformSpecificSettingsForProjectType (const build_tools::ProjectType&) override {}
  81. //==============================================================================
  82. bool canLaunchProject() override
  83. {
  84. #if JUCE_MAC
  85. static Identifier exporterName (XcodeProjectExporter::getValueTreeTypeNameMac());
  86. #elif JUCE_WINDOWS
  87. static Identifier exporterName (CodeBlocksProjectExporter::getValueTreeTypeNameWindows());
  88. #elif JUCE_LINUX
  89. static Identifier exporterName (MakefileProjectExporter::getValueTreeTypeName());
  90. #else
  91. static Identifier exporterName;
  92. #endif
  93. if (getProject().getExporters().getChildWithName (exporterName).isValid())
  94. return getCLionExecutableOrApp().exists();
  95. return false;
  96. }
  97. bool launchProject() override
  98. {
  99. return getCLionExecutableOrApp().startAsProcess (getTargetFolder().getFullPathName().quoted());
  100. }
  101. String getDescription() override
  102. {
  103. String description;
  104. description << "The " << getDisplayName() << " exporter produces a single CMakeLists.txt file with "
  105. << "multiple platform dependent sections, where the configuration for each section "
  106. << "is inherited from other exporters added to this project." << newLine
  107. << newLine
  108. << "The exporters which provide the CLion configuration for the corresponding platform are:" << newLine
  109. << newLine;
  110. for (auto& exporterInfo : getExporterTypeInfos())
  111. {
  112. std::unique_ptr<ProjectExporter> exporter (createNewExporter (getProject(), exporterInfo.identifier));
  113. if (isExporterSupported (*exporter))
  114. description << exporterInfo.displayName << newLine;
  115. }
  116. description << newLine
  117. << "Add these exporters to the project to enable CLion builds." << newLine
  118. << newLine
  119. << "Not all features of all the exporters are currently supported. Notable omissions are AUv3 "
  120. << "plug-ins, embedding resources and fat binaries on MacOS. On Windows the CLion exporter "
  121. << "requires a GCC-based compiler like MinGW.";
  122. return description;
  123. }
  124. void createExporterProperties (PropertyListBuilder& properties) override
  125. {
  126. for (Project::ExporterIterator exporter (getProject()); exporter.next();)
  127. if (isExporterSupported (*exporter))
  128. properties.add (new BooleanPropertyComponent (getExporterEnabledValue (*exporter), "Import settings from exporter", exporter->getUniqueName()),
  129. "If this is enabled then settings from the corresponding exporter will "
  130. "be used in the generated CMakeLists.txt");
  131. }
  132. void createDefaultConfigs() override {}
  133. void create (const OwnedArray<LibraryModule>&) const override
  134. {
  135. // We'll append to this later.
  136. build_tools::writeStreamToFile (getTargetFolder().getChildFile ("CMakeLists.txt"), [] (MemoryOutputStream& mo)
  137. {
  138. mo.setNewLineString ("\n");
  139. mo << "# Automatically generated CMakeLists, created by the Projucer" << newLine
  140. << "# Do not edit this file! Your changes will be overwritten when you re-save the Projucer project!" << newLine
  141. << newLine;
  142. mo << "cmake_minimum_required (VERSION 3.4.1)" << newLine
  143. << newLine;
  144. mo << "if (NOT CMAKE_BUILD_TYPE)" << newLine
  145. << " set (CMAKE_BUILD_TYPE \"Debug\" CACHE STRING \"Choose the type of build.\" FORCE)" << newLine
  146. << "endif (NOT CMAKE_BUILD_TYPE)" << newLine
  147. << newLine;
  148. });
  149. // CMake has stopped adding PkgInfo files to bundles, so we need to do it manually
  150. build_tools::writeStreamToFile (getTargetFolder().getChildFile ("PkgInfo"),
  151. [] (MemoryOutputStream& mo) { mo << "BNDL????"; });
  152. }
  153. void writeCMakeListsExporterSection (ProjectExporter* exporter) const
  154. {
  155. if (! (isExporterSupported (*exporter) && isExporterEnabled (*exporter)))
  156. return;
  157. MemoryBlock existingContent;
  158. getTargetFolder().getChildFile ("CMakeLists.txt").loadFileAsData (existingContent);
  159. MemoryOutputStream out (existingContent, true);
  160. out.setNewLineString ("\n");
  161. out << "###############################################################################" << newLine
  162. << "# " << exporter->getUniqueName() << newLine
  163. << "###############################################################################" << newLine
  164. << newLine;
  165. if (auto* makefileExporter = dynamic_cast<MakefileProjectExporter*> (exporter))
  166. {
  167. out << "if (UNIX AND NOT APPLE)" << newLine << newLine;
  168. writeCMakeListsMakefileSection (out, *makefileExporter);
  169. }
  170. else if (auto* xcodeExporter = dynamic_cast<XcodeProjectExporter*> (exporter))
  171. {
  172. out << "if (APPLE)" << newLine << newLine;
  173. writeCMakeListsXcodeSection (out, *xcodeExporter);
  174. }
  175. else if (auto* codeBlocksExporter = dynamic_cast<CodeBlocksProjectExporter*> (exporter))
  176. {
  177. out << "if (WIN32)" << newLine << newLine;
  178. writeCMakeListsCodeBlocksSection (out, *codeBlocksExporter);
  179. }
  180. out << "endif()" << newLine << newLine;
  181. build_tools::overwriteFileIfDifferentOrThrow (getTargetFolder().getChildFile ("CMakeLists.txt"), out);
  182. }
  183. private:
  184. //==============================================================================
  185. static File getCLionExecutableOrApp()
  186. {
  187. File clionExeOrApp (getAppSettings()
  188. .getStoredPath (Ids::clionExePath, TargetOS::getThisOS()).get()
  189. .toString()
  190. .replace ("${user.home}", File::getSpecialLocation (File::userHomeDirectory).getFullPathName()));
  191. #if JUCE_MAC
  192. if (clionExeOrApp.getFullPathName().endsWith ("/Contents/MacOS/clion"))
  193. clionExeOrApp = clionExeOrApp.getParentDirectory()
  194. .getParentDirectory()
  195. .getParentDirectory();
  196. #endif
  197. return clionExeOrApp;
  198. }
  199. //==============================================================================
  200. Identifier getExporterEnabledId (const ProjectExporter& exporter) const
  201. {
  202. jassert (isExporterSupported (exporter));
  203. if (exporter.isMakefile()) return Ids::clionMakefileEnabled;
  204. else if (exporter.isXcode()) return Ids::clionXcodeEnabled;
  205. else if (exporter.isCodeBlocks()) return Ids::clionCodeBlocksEnabled;
  206. jassertfalse;
  207. return {};
  208. }
  209. bool isExporterEnabled (const ProjectExporter& exporter) const
  210. {
  211. auto setting = settings[getExporterEnabledId (exporter)];
  212. return setting.isVoid() || setting;
  213. }
  214. Value getExporterEnabledValue (const ProjectExporter& exporter)
  215. {
  216. auto enabledID = getExporterEnabledId (exporter);
  217. getSetting (enabledID) = isExporterEnabled (exporter);
  218. return getSetting (enabledID);
  219. }
  220. //==============================================================================
  221. static bool isWindowsAbsolutePath (const String& path)
  222. {
  223. return path.length() > 1 && path[1] == ':';
  224. }
  225. static bool isUnixAbsolutePath (const String& path)
  226. {
  227. return path.isNotEmpty() && (path[0] == '/' || path[0] == '~' || path.startsWith ("$ENV{HOME}"));
  228. }
  229. //==============================================================================
  230. static String setCMakeVariable (const String& variableName, const String& value)
  231. {
  232. return "set (" + variableName + " \"" + value + "\")";
  233. }
  234. static String addToCMakeVariable (const String& variableName, const String& value)
  235. {
  236. return setCMakeVariable (variableName, "${" + variableName + "} " + value);
  237. }
  238. static String getTargetVarName (build_tools::ProjectType::Target& target)
  239. {
  240. return String (target.getName()).toUpperCase().replaceCharacter (L' ', L'_');
  241. }
  242. template <class Target, class Exporter>
  243. void getFileInfoList (Target& target, Exporter& exporter, const Project::Item& projectItem, std::vector<std::tuple<String, bool, String>>& fileInfoList) const
  244. {
  245. auto targetType = (getProject().isAudioPluginProject() ? target.type : Target::Type::SharedCodeTarget);
  246. if (projectItem.isGroup())
  247. {
  248. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  249. getFileInfoList (target, exporter, projectItem.getChild(i), fileInfoList);
  250. }
  251. else if (projectItem.shouldBeAddedToTargetProject() && projectItem.shouldBeAddedToTargetExporter (*this)
  252. && getProject().getTargetTypeFromFilePath (projectItem.getFile(), true) == targetType )
  253. {
  254. auto path = build_tools::RelativePath (projectItem.getFile(), exporter.getTargetFolder(), build_tools::RelativePath::buildTargetFolder).toUnixStyle();
  255. fileInfoList.push_back (std::make_tuple (path, projectItem.shouldBeCompiled(),
  256. exporter.compilerFlagSchemesMap[projectItem.getCompilerFlagSchemeString()].get().toString()));
  257. }
  258. }
  259. template <class Exporter>
  260. void writeCMakeTargets (OutputStream& out, Exporter& exporter) const
  261. {
  262. for (auto* target : exporter.targets)
  263. {
  264. if (target->type == build_tools::ProjectType::Target::Type::AggregateTarget
  265. || target->type == build_tools::ProjectType::Target::Type::AudioUnitv3PlugIn)
  266. continue;
  267. String functionName;
  268. StringArray properties;
  269. switch (target->getTargetFileType())
  270. {
  271. case build_tools::ProjectType::Target::TargetFileType::executable:
  272. functionName = "add_executable";
  273. if (exporter.isCodeBlocks() && exporter.isWindows()
  274. && target->type !=
  275. build_tools::ProjectType::Target::Type::ConsoleApp)
  276. properties.add ("WIN32");
  277. break;
  278. case build_tools::ProjectType::Target::TargetFileType::staticLibrary:
  279. case build_tools::ProjectType::Target::TargetFileType::sharedLibraryOrDLL:
  280. case build_tools::ProjectType::Target::TargetFileType::pluginBundle:
  281. functionName = "add_library";
  282. if (target->getTargetFileType() ==
  283. build_tools::ProjectType::Target::TargetFileType::staticLibrary)
  284. properties.add ("STATIC");
  285. else if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::sharedLibraryOrDLL)
  286. properties.add ("SHARED");
  287. else
  288. properties.add ("MODULE");
  289. break;
  290. case build_tools::ProjectType::Target::TargetFileType::macOSAppex:
  291. case build_tools::ProjectType::Target::TargetFileType::unknown:
  292. default:
  293. continue;
  294. }
  295. out << functionName << " (" << getTargetVarName (*target);
  296. if (! properties.isEmpty())
  297. out << " " << properties.joinIntoString (" ");
  298. out << newLine;
  299. std::vector<std::tuple<String, bool, String>> fileInfoList;
  300. for (auto& group : exporter.getAllGroups())
  301. getFileInfoList (*target, exporter, group, fileInfoList);
  302. for (auto& fileInfo : fileInfoList)
  303. out << " " << std::get<0> (fileInfo).quoted() << newLine;
  304. auto isCMakeBundle = exporter.isXcode()
  305. && target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle;
  306. auto pkgInfoPath = String ("PkgInfo").quoted();
  307. if (isCMakeBundle)
  308. out << " " << pkgInfoPath << newLine;
  309. auto xcodeIcnsFilePath = [&]() -> String
  310. {
  311. if (exporter.isXcode()
  312. && target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::executable)
  313. {
  314. StringArray pathComponents = { "..", "MacOSX", "Icon.icns" };
  315. auto xcodeIcnsFile = getTargetFolder();
  316. for (auto& comp : pathComponents)
  317. xcodeIcnsFile = xcodeIcnsFile.getChildFile (comp);
  318. if (xcodeIcnsFile.existsAsFile())
  319. return pathComponents.joinIntoString ("/").quoted();
  320. }
  321. return {};
  322. }();
  323. if (xcodeIcnsFilePath.isNotEmpty())
  324. out << " " << xcodeIcnsFilePath << newLine;
  325. if (exporter.isCodeBlocks()
  326. && target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::executable)
  327. {
  328. StringArray pathComponents = { "..", "CodeBlocksWindows", "resources.rc" };
  329. auto windowsRcFile = getTargetFolder();
  330. for (auto& comp : pathComponents)
  331. windowsRcFile = windowsRcFile.getChildFile (comp);
  332. if (windowsRcFile.existsAsFile())
  333. out << " " << pathComponents.joinIntoString ("/").quoted() << newLine;
  334. }
  335. out << ")" << newLine << newLine;
  336. if (isCMakeBundle)
  337. out << "set_source_files_properties (" << pkgInfoPath << " PROPERTIES MACOSX_PACKAGE_LOCATION .)" << newLine;
  338. if (xcodeIcnsFilePath.isNotEmpty())
  339. out << "set_source_files_properties (" << xcodeIcnsFilePath << " PROPERTIES MACOSX_PACKAGE_LOCATION \"Resources\")" << newLine;
  340. for (auto& fileInfo : fileInfoList)
  341. {
  342. if (std::get<1> (fileInfo))
  343. {
  344. auto extraCompilerFlags = std::get<2> (fileInfo);
  345. if (extraCompilerFlags.isNotEmpty())
  346. out << "set_source_files_properties(" << std::get<0> (fileInfo).quoted() << " PROPERTIES COMPILE_FLAGS " << extraCompilerFlags << " )" << newLine;
  347. }
  348. else
  349. {
  350. out << "set_source_files_properties (" << std::get<0> (fileInfo).quoted() << " PROPERTIES HEADER_FILE_ONLY TRUE)" << newLine;
  351. }
  352. }
  353. out << newLine;
  354. }
  355. }
  356. //==============================================================================
  357. void writeCMakeListsMakefileSection (OutputStream& out, MakefileProjectExporter& exporter) const
  358. {
  359. out << "project (" << getProject().getProjectNameString().quoted() << " C CXX)" << newLine
  360. << newLine;
  361. out << "find_package (PkgConfig REQUIRED)" << newLine;
  362. StringArray cmakePkgconfigPackages;
  363. for (auto& package : exporter.getPackages())
  364. {
  365. cmakePkgconfigPackages.add (package.toUpperCase());
  366. out << "pkg_search_module (" << cmakePkgconfigPackages.strings.getLast() << " REQUIRED " << package << ")" << newLine;
  367. }
  368. out << newLine;
  369. writeCMakeTargets (out, exporter);
  370. for (auto* target : exporter.targets)
  371. {
  372. if (target->type == build_tools::ProjectType::Target::Type::AggregateTarget)
  373. continue;
  374. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle)
  375. out << "set_target_properties (" << getTargetVarName (*target) << " PROPERTIES PREFIX \"\")" << newLine;
  376. out << "set_target_properties (" << getTargetVarName (*target) << " PROPERTIES SUFFIX \"" << target->getTargetFileSuffix() << "\")" << newLine
  377. << newLine;
  378. }
  379. for (ProjectExporter::ConstConfigIterator c (exporter); c.next();)
  380. {
  381. auto& config = dynamic_cast<const MakefileProjectExporter::MakeBuildConfiguration&> (*c);
  382. out << "#------------------------------------------------------------------------------" << newLine
  383. << "# Config: " << config.getName() << newLine
  384. << "#------------------------------------------------------------------------------" << newLine
  385. << newLine;
  386. auto buildTypeCondition = String ("CMAKE_BUILD_TYPE STREQUAL " + config.getName());
  387. out << "if (" << buildTypeCondition << ")" << newLine
  388. << newLine;
  389. out << "execute_process (COMMAND uname -m OUTPUT_VARIABLE JUCE_ARCH_LABEL OUTPUT_STRIP_TRAILING_WHITESPACE)" << newLine
  390. << newLine;
  391. out << "include_directories (" << newLine;
  392. for (auto& path : exporter.getHeaderSearchPaths (config))
  393. out << " " << path.quoted() << newLine;
  394. for (auto& package : cmakePkgconfigPackages)
  395. out << " ${" << package << "_INCLUDE_DIRS}" << newLine;
  396. out << ")" << newLine << newLine;
  397. StringArray cmakeFoundLibraries;
  398. for (auto& library : exporter.getLibraryNames (config))
  399. {
  400. String cmakeLibraryID (library.toUpperCase());
  401. cmakeFoundLibraries.add (String ("${") + cmakeLibraryID + "}");
  402. out << "find_library (" << cmakeLibraryID << " " << library << newLine;
  403. for (auto& path : exporter.getLibrarySearchPaths (config))
  404. out << " " << path.quoted() << newLine;
  405. out << ")" << newLine
  406. << newLine;
  407. }
  408. for (auto* target : exporter.targets)
  409. {
  410. if (target->type == build_tools::ProjectType::Target::Type::AggregateTarget)
  411. continue;
  412. auto targetVarName = getTargetVarName (*target);
  413. out << "set_target_properties (" << targetVarName << " PROPERTIES" << newLine
  414. << " OUTPUT_NAME " << config.getTargetBinaryNameString().quoted() << newLine;
  415. auto cxxStandard = project.getCppStandardString();
  416. if (cxxStandard == "latest")
  417. cxxStandard = "17";
  418. out << " CXX_STANDARD " << cxxStandard << newLine;
  419. if (! shouldUseGNUExtensions())
  420. out << " CXX_EXTENSIONS OFF" << newLine;
  421. out << ")" << newLine << newLine;
  422. auto defines = exporter.getDefines (config);
  423. defines.addArray (target->getDefines (config));
  424. out << "target_compile_definitions (" << targetVarName << " PRIVATE" << newLine;
  425. for (auto& key : defines.getAllKeys())
  426. out << " " << key << "=" << defines[key] << newLine;
  427. out << ")" << newLine << newLine;
  428. auto targetFlags = target->getCompilerFlags();
  429. if (! targetFlags.isEmpty())
  430. {
  431. out << "target_compile_options (" << targetVarName << " PRIVATE" << newLine;
  432. for (auto& flag : targetFlags)
  433. out << " " << flag << newLine;
  434. out << ")" << newLine << newLine;
  435. }
  436. out << "target_link_libraries (" << targetVarName << " PRIVATE" << newLine;
  437. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle
  438. || target->type == build_tools::ProjectType::Target::Type::StandalonePlugIn)
  439. out << " SHARED_CODE" << newLine;
  440. out << " " << exporter.getArchFlags (config) << newLine;
  441. for (auto& flag : target->getLinkerFlags())
  442. out << " " << flag << newLine;
  443. for (auto& flag : exporter.getLinkerFlags (config))
  444. out << " " << flag << newLine;
  445. for (auto& lib : cmakeFoundLibraries)
  446. out << " " << lib << newLine;
  447. for (auto& package : cmakePkgconfigPackages)
  448. out << " ${" << package << "_LIBRARIES}" << newLine;
  449. out << ")" << newLine << newLine;
  450. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle
  451. || target->type == build_tools::ProjectType::Target::Type::StandalonePlugIn)
  452. out << "add_dependencies (" << targetVarName << " " << "SHARED_CODE)" << newLine << newLine;
  453. }
  454. StringArray cFlags;
  455. cFlags.add (exporter.getArchFlags (config));
  456. cFlags.addArray (exporter.getCPreprocessorFlags (config));
  457. cFlags.addArray (exporter.getCFlags (config));
  458. out << addToCMakeVariable ("CMAKE_C_FLAGS", cFlags.joinIntoString (" ")) << newLine;
  459. String cxxFlags;
  460. for (auto& flag : exporter.getCXXFlags())
  461. if (! flag.startsWith ("-std="))
  462. cxxFlags += " " + flag;
  463. out << addToCMakeVariable ("CMAKE_CXX_FLAGS", "${CMAKE_C_FLAGS} " + cxxFlags) << newLine
  464. << newLine;
  465. out << "endif (" << buildTypeCondition << ")" << newLine
  466. << newLine;
  467. }
  468. }
  469. //==============================================================================
  470. void writeCMakeListsCodeBlocksSection (OutputStream& out, CodeBlocksProjectExporter& exporter) const
  471. {
  472. out << "project (" << getProject().getProjectNameString().quoted() << " C CXX)" << newLine
  473. << newLine;
  474. writeCMakeTargets (out, exporter);
  475. for (auto* target : exporter.targets)
  476. {
  477. if (target->type == build_tools::ProjectType::Target::Type::AggregateTarget)
  478. continue;
  479. out << "set_target_properties (" << getTargetVarName (*target) << " PROPERTIES PREFIX \"\")" << newLine
  480. << "set_target_properties (" << getTargetVarName (*target) << " PROPERTIES SUFFIX " << target->getTargetSuffix().quoted() << ")" << newLine
  481. << newLine;
  482. }
  483. for (ProjectExporter::ConstConfigIterator c (exporter); c.next();)
  484. {
  485. auto& config = dynamic_cast<const CodeBlocksProjectExporter::CodeBlocksBuildConfiguration&> (*c);
  486. out << "#------------------------------------------------------------------------------" << newLine
  487. << "# Config: " << config.getName() << newLine
  488. << "#------------------------------------------------------------------------------" << newLine
  489. << newLine;
  490. auto buildTypeCondition = String ("CMAKE_BUILD_TYPE STREQUAL " + config.getName());
  491. out << "if (" << buildTypeCondition << ")" << newLine
  492. << newLine;
  493. out << "include_directories (" << newLine;
  494. for (auto& path : exporter.getIncludePaths (config))
  495. out << " " << path.replace ("\\", "/").quoted() << newLine;
  496. out << ")" << newLine << newLine;
  497. for (auto* target : exporter.targets)
  498. {
  499. if (target->type == build_tools::ProjectType::Target::Type::AggregateTarget)
  500. continue;
  501. auto targetVarName = getTargetVarName (*target);
  502. out << "set_target_properties (" << targetVarName << " PROPERTIES" << newLine
  503. << " OUTPUT_NAME " << config.getTargetBinaryNameString().quoted() << newLine;
  504. auto cxxStandard = project.getCppStandardString();
  505. if (cxxStandard == "latest")
  506. cxxStandard = "17";
  507. out << " CXX_STANDARD " << cxxStandard << newLine;
  508. if (! shouldUseGNUExtensions())
  509. out << " CXX_EXTENSIONS OFF" << newLine;
  510. out << ")" << newLine << newLine;
  511. out << "target_compile_definitions (" << targetVarName << " PRIVATE" << newLine;
  512. for (auto& def : exporter.getDefines (config, *target))
  513. out << " " << def << newLine;
  514. out << ")" << newLine << newLine;
  515. out << "target_compile_options (" << targetVarName << " PRIVATE" << newLine;
  516. for (auto& option : exporter.getCompilerFlags (config, *target))
  517. if (! option.startsWith ("-std="))
  518. out << " " << option.quoted() << newLine;
  519. out << ")" << newLine << newLine;
  520. out << "target_link_libraries (" << targetVarName << " PRIVATE" << newLine;
  521. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle
  522. || target->type == build_tools::ProjectType::Target::Type::StandalonePlugIn)
  523. out << " SHARED_CODE" << newLine
  524. << " -L." << newLine;
  525. for (auto& path : exporter.getLinkerSearchPaths (config, *target))
  526. {
  527. out << " \"-L\\\"";
  528. if (! isWindowsAbsolutePath (path))
  529. out << "${CMAKE_CURRENT_SOURCE_DIR}/";
  530. out << path.replace ("\\", "/").unquoted() << "\\\"\"" << newLine;
  531. }
  532. for (auto& flag : exporter.getLinkerFlags (config, *target))
  533. out << " " << flag << newLine;
  534. for (auto& flag : exporter.getProjectLinkerLibs())
  535. out << " -l" << flag << newLine;
  536. for (auto& lib : exporter.mingwLibs)
  537. out << " -l" << lib << newLine;
  538. out << ")" << newLine << newLine;
  539. }
  540. out << addToCMakeVariable ("CMAKE_CXX_FLAGS", exporter.getProjectCompilerOptions().joinIntoString (" ")) << newLine
  541. << addToCMakeVariable ("CMAKE_C_FLAGS", "${CMAKE_CXX_FLAGS}") << newLine
  542. << newLine;
  543. out << "endif (" << buildTypeCondition << ")" << newLine
  544. << newLine;
  545. }
  546. }
  547. //==============================================================================
  548. void writeCMakeListsXcodeSection (OutputStream& out, XcodeProjectExporter& exporter) const
  549. {
  550. // We need to find out the SDK root before defining the project. Unfortunately this is
  551. // set per-target in the Xcode project, but we want it per-configuration.
  552. for (ProjectExporter::ConstConfigIterator c (exporter); c.next();)
  553. {
  554. auto& config = dynamic_cast<const XcodeProjectExporter::XcodeBuildConfiguration&> (*c);
  555. for (auto* target : exporter.targets)
  556. {
  557. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::macOSAppex
  558. || target->type == build_tools::ProjectType::Target::Type::AggregateTarget
  559. || target->type == build_tools::ProjectType::Target::Type::AudioUnitv3PlugIn)
  560. continue;
  561. auto targetAttributes = target->getTargetSettings (config);
  562. auto targetAttributeKeys = targetAttributes.getAllKeys();
  563. if (targetAttributes.getAllKeys().contains ("SDKROOT"))
  564. {
  565. out << "if (CMAKE_BUILD_TYPE STREQUAL " + config.getName() << ")" << newLine
  566. << " set (CMAKE_OSX_SYSROOT " << targetAttributes["SDKROOT"] << ")" << newLine
  567. << "endif()" << newLine << newLine;
  568. break;
  569. }
  570. }
  571. }
  572. out << "project (" << getProject().getProjectNameString().quoted() << " C CXX)" << newLine << newLine;
  573. writeCMakeTargets (out, exporter);
  574. for (auto* target : exporter.targets)
  575. {
  576. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::macOSAppex
  577. || target->type == build_tools::ProjectType::Target::Type::AggregateTarget
  578. || target->type == build_tools::ProjectType::Target::Type::AudioUnitv3PlugIn)
  579. continue;
  580. if (target->type == build_tools::ProjectType::Target::Type::AudioUnitPlugIn)
  581. out << "find_program (RC_COMPILER Rez NO_DEFAULT_PATHS PATHS \"/Applications/Xcode.app/Contents/Developer/usr/bin\")" << newLine
  582. << "if (NOT RC_COMPILER)" << newLine
  583. << " message (WARNING \"failed to find Rez; older resource-based AU plug-ins may not work correctly\")" << newLine
  584. << "endif (NOT RC_COMPILER)" << newLine << newLine;
  585. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::staticLibrary
  586. || target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::sharedLibraryOrDLL)
  587. out << "set_target_properties (" << getTargetVarName (*target) << " PROPERTIES SUFFIX \"" << target->xcodeBundleExtension << "\")" << newLine
  588. << newLine;
  589. }
  590. for (ProjectExporter::ConstConfigIterator c (exporter); c.next();)
  591. {
  592. auto& config = dynamic_cast<const XcodeProjectExporter::XcodeBuildConfiguration&> (*c);
  593. out << "#------------------------------------------------------------------------------" << newLine
  594. << "# Config: " << config.getName() << newLine
  595. << "#------------------------------------------------------------------------------" << newLine
  596. << newLine;
  597. auto buildTypeCondition = String ("CMAKE_BUILD_TYPE STREQUAL " + config.getName());
  598. out << "if (" << buildTypeCondition << ")" << newLine
  599. << newLine;
  600. out << "execute_process (COMMAND uname -m OUTPUT_VARIABLE JUCE_ARCH_LABEL OUTPUT_STRIP_TRAILING_WHITESPACE)" << newLine
  601. << newLine;
  602. auto configSettings = exporter.getProjectSettings (config);
  603. auto configSettingsKeys = configSettings.getAllKeys();
  604. auto binaryName = config.getTargetBinaryNameString();
  605. if (configSettingsKeys.contains ("PRODUCT_NAME"))
  606. binaryName = configSettings["PRODUCT_NAME"].unquoted();
  607. for (auto* target : exporter.targets)
  608. {
  609. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::macOSAppex
  610. || target->type == build_tools::ProjectType::Target::Type::AggregateTarget
  611. || target->type == build_tools::ProjectType::Target::Type::AudioUnitv3PlugIn)
  612. continue;
  613. auto targetVarName = getTargetVarName (*target);
  614. auto targetAttributes = target->getTargetSettings (config);
  615. auto targetAttributeKeys = targetAttributes.getAllKeys();
  616. StringArray headerSearchPaths;
  617. if (targetAttributeKeys.contains ("HEADER_SEARCH_PATHS"))
  618. {
  619. auto paths = targetAttributes["HEADER_SEARCH_PATHS"].trim().substring (1).dropLastCharacters (1);
  620. paths = paths.replace ("\"$(inherited)\"", {})
  621. .replace ("$(HOME)", "$ENV{HOME}")
  622. .replace ("~", "$ENV{HOME}");
  623. headerSearchPaths.addTokens (paths, ",\"\t\\", {});
  624. headerSearchPaths.removeEmptyStrings();
  625. targetAttributeKeys.removeString ("HEADER_SEARCH_PATHS");
  626. }
  627. out << "target_include_directories (" << targetVarName << " PRIVATE" << newLine;
  628. for (auto& path : headerSearchPaths)
  629. out << " " << path.quoted() << newLine;
  630. out << ")" << newLine << newLine;
  631. StringArray defines;
  632. if (targetAttributeKeys.contains ("GCC_PREPROCESSOR_DEFINITIONS"))
  633. {
  634. defines.addTokens (targetAttributes["GCC_PREPROCESSOR_DEFINITIONS"], "(),\t", {});
  635. defines.removeEmptyStrings();
  636. targetAttributeKeys.removeString ("GCC_PREPROCESSOR_DEFINITIONS");
  637. }
  638. out << "target_compile_definitions (" << targetVarName << " PRIVATE" << newLine;
  639. for (auto& def : defines)
  640. out << " " << def.replace ("\\\\\\\"", "\\\"").replace ("\\\\ ", " ") << newLine;
  641. out << ")" << newLine << newLine;
  642. StringArray cppFlags;
  643. String archLabel ("${JUCE_ARCH_LABEL}");
  644. // Fat binaries are not supported.
  645. if (targetAttributeKeys.contains ("ARCHS"))
  646. {
  647. auto value = targetAttributes["ARCHS"].unquoted();
  648. if (value.contains ("NATIVE_ARCH_ACTUAL"))
  649. {
  650. cppFlags.add ("-march=native");
  651. }
  652. else if (value.contains ("ARCHS_STANDARD_32_BIT"))
  653. {
  654. archLabel = "i386";
  655. cppFlags.add ("-arch x86");
  656. }
  657. else if (value.contains ("ARCHS_STANDARD_32_64_BIT")
  658. || value.contains ("ARCHS_STANDARD_64_BIT"))
  659. {
  660. archLabel = "x86_64";
  661. cppFlags.add ("-arch x86_64");
  662. }
  663. targetAttributeKeys.removeString ("ARCHS");
  664. }
  665. if (targetAttributeKeys.contains ("MACOSX_DEPLOYMENT_TARGET"))
  666. {
  667. cppFlags.add ("-mmacosx-version-min=" + targetAttributes["MACOSX_DEPLOYMENT_TARGET"]);
  668. targetAttributeKeys.removeString ("MACOSX_DEPLOYMENT_TARGET");
  669. }
  670. if (targetAttributeKeys.contains ("OTHER_CPLUSPLUSFLAGS"))
  671. {
  672. cppFlags.add (targetAttributes["OTHER_CPLUSPLUSFLAGS"].unquoted());
  673. targetAttributeKeys.removeString ("OTHER_CPLUSPLUSFLAGS");
  674. }
  675. if (targetAttributeKeys.contains ("GCC_OPTIMIZATION_LEVEL"))
  676. {
  677. cppFlags.add ("-O" + targetAttributes["GCC_OPTIMIZATION_LEVEL"]);
  678. targetAttributeKeys.removeString ("GCC_OPTIMIZATION_LEVEL");
  679. }
  680. if (targetAttributeKeys.contains ("LLVM_LTO"))
  681. {
  682. cppFlags.add ("-flto");
  683. targetAttributeKeys.removeString ("LLVM_LTO");
  684. }
  685. if (targetAttributeKeys.contains ("GCC_FAST_MATH"))
  686. {
  687. cppFlags.add ("-ffast-math");
  688. targetAttributeKeys.removeString ("GCC_FAST_MATH");
  689. }
  690. // We'll take this setting from the project
  691. targetAttributeKeys.removeString ("CLANG_CXX_LANGUAGE_STANDARD");
  692. if (targetAttributeKeys.contains ("CLANG_CXX_LIBRARY"))
  693. {
  694. cppFlags.add ("-stdlib=" + targetAttributes["CLANG_CXX_LIBRARY"].unquoted());
  695. targetAttributeKeys.removeString ("CLANG_CXX_LIBRARY");
  696. }
  697. out << "target_compile_options (" << targetVarName << " PRIVATE" << newLine;
  698. for (auto& flag : cppFlags)
  699. out << " " << flag << newLine;
  700. out << ")" << newLine << newLine;
  701. StringArray libSearchPaths;
  702. if (targetAttributeKeys.contains ("LIBRARY_SEARCH_PATHS"))
  703. {
  704. auto paths = targetAttributes["LIBRARY_SEARCH_PATHS"].trim().substring (1).dropLastCharacters (1);
  705. paths = paths.replace ("\"$(inherited)\"", {});
  706. paths = paths.replace ("$(HOME)", "$ENV{HOME}");
  707. libSearchPaths.addTokens (paths, ",\"\t\\", {});
  708. libSearchPaths.removeEmptyStrings();
  709. for (auto& libPath : libSearchPaths)
  710. {
  711. libPath = libPath.replace ("${CURRENT_ARCH}", archLabel);
  712. if (! isUnixAbsolutePath (libPath))
  713. libPath = "${CMAKE_CURRENT_SOURCE_DIR}/" + libPath;
  714. }
  715. targetAttributeKeys.removeString ("LIBRARY_SEARCH_PATHS");
  716. }
  717. StringArray linkerFlags;
  718. if (targetAttributeKeys.contains ("OTHER_LDFLAGS"))
  719. {
  720. // CMake adds its own SHARED_CODE library linking flags
  721. auto flagsWithReplacedSpaces = targetAttributes["OTHER_LDFLAGS"].unquoted().replace ("\\\\ ", "^^%%^^");
  722. linkerFlags.addTokens (flagsWithReplacedSpaces, true);
  723. linkerFlags.removeString ("-bundle");
  724. linkerFlags.removeString ("-l" + binaryName.replace (" ", "^^%%^^"));
  725. for (auto& flag : linkerFlags)
  726. flag = flag.replace ("^^%%^^", " ");
  727. targetAttributeKeys.removeString ("OTHER_LDFLAGS");
  728. }
  729. if (target->type == build_tools::ProjectType::Target::Type::AudioUnitPlugIn)
  730. {
  731. String rezFlags;
  732. if (targetAttributeKeys.contains ("OTHER_REZFLAGS"))
  733. {
  734. rezFlags = targetAttributes["OTHER_REZFLAGS"];
  735. targetAttributeKeys.removeString ("OTHER_REZFLAGS");
  736. }
  737. for (auto& item : exporter.getAllGroups())
  738. {
  739. if (item.getName() == ProjectSaver::getJuceCodeGroupName())
  740. {
  741. auto resSourcesVar = targetVarName + "_REZ_SOURCES";
  742. auto resOutputVar = targetVarName + "_REZ_OUTPUT";
  743. auto sdkVersion = config.getOSXSDKVersionString().upToFirstOccurrenceOf (" ", false, false);
  744. auto sysroot = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" + sdkVersion + ".sdk";
  745. build_tools::RelativePath rFile ("JuceLibraryCode/include_juce_audio_plugin_client_AU.r", build_tools::RelativePath::projectFolder);
  746. rFile = rebaseFromProjectFolderToBuildTarget (rFile);
  747. out << "if (RC_COMPILER)" << newLine
  748. << " set (" << resSourcesVar << newLine
  749. << " " << ("${CMAKE_CURRENT_SOURCE_DIR}/" + rFile.toUnixStyle()).quoted() << newLine
  750. << " )" << newLine
  751. << " set (" << resOutputVar << " " << ("${CMAKE_CURRENT_BINARY_DIR}/" + binaryName + ".rsrc").quoted() << ")" << newLine
  752. << " target_sources (" << targetVarName << " PRIVATE" << newLine
  753. << " ${" << resSourcesVar << "}" << newLine
  754. << " ${" << resOutputVar << "}" << newLine
  755. << " )" << newLine
  756. << " execute_process (COMMAND" << newLine
  757. << " ${RC_COMPILER}" << newLine
  758. << " " << rezFlags.unquoted().removeCharacters ("\\") << newLine
  759. << " -isysroot " << sysroot.quoted() << newLine;
  760. for (auto& path : headerSearchPaths)
  761. {
  762. out << " -I \"";
  763. if (! isUnixAbsolutePath (path))
  764. out << "${PROJECT_SOURCE_DIR}/";
  765. out << path << "\"" << newLine;
  766. }
  767. out << " ${" << resSourcesVar << "}" << newLine
  768. << " -o ${" << resOutputVar << "}" << newLine
  769. << " )" << newLine
  770. << " set_source_files_properties (${" << resOutputVar << "} PROPERTIES" << newLine
  771. << " GENERATED TRUE" << newLine
  772. << " MACOSX_PACKAGE_LOCATION Resources" << newLine
  773. << " )" << newLine
  774. << "endif (RC_COMPILER)" << newLine << newLine;
  775. break;
  776. }
  777. }
  778. }
  779. if (targetAttributeKeys.contains ("INFOPLIST_FILE"))
  780. {
  781. auto plistFile = exporter.getTargetFolder().getChildFile (targetAttributes["INFOPLIST_FILE"]);
  782. if (auto plist = parseXML (plistFile))
  783. {
  784. if (auto* dict = plist->getChildByName ("dict"))
  785. {
  786. if (auto* entry = dict->getChildByName ("key"))
  787. {
  788. while (entry != nullptr)
  789. {
  790. if (entry->getAllSubText() == "CFBundleExecutable")
  791. {
  792. if (auto* bundleName = entry->getNextElementWithTagName ("string"))
  793. {
  794. bundleName->deleteAllTextElements();
  795. bundleName->addTextElement (binaryName);
  796. }
  797. }
  798. entry = entry->getNextElementWithTagName ("key");
  799. }
  800. }
  801. }
  802. auto updatedPlist = getTargetFolder().getChildFile (config.getName() + "-" + plistFile.getFileName());
  803. XmlElement::TextFormat format;
  804. format.dtd = "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">";
  805. plist->writeTo (updatedPlist, format);
  806. targetAttributes.set ("INFOPLIST_FILE", ("${CMAKE_CURRENT_SOURCE_DIR}/" + updatedPlist.getFileName()).quoted());
  807. }
  808. else
  809. {
  810. targetAttributeKeys.removeString ("INFOPLIST_FILE");
  811. }
  812. }
  813. targetAttributeKeys.sort (false);
  814. out << "set_target_properties (" << targetVarName << " PROPERTIES" << newLine
  815. << " OUTPUT_NAME " << binaryName.quoted() << newLine;
  816. auto cxxStandard = project.getCppStandardString();
  817. if (cxxStandard == "latest")
  818. cxxStandard = "17";
  819. out << " CXX_STANDARD " << cxxStandard << newLine;
  820. if (! shouldUseGNUExtensions())
  821. out << " CXX_EXTENSIONS OFF" << newLine;
  822. for (auto& key : targetAttributeKeys)
  823. out << " XCODE_ATTRIBUTE_" << key << " " << targetAttributes[key] << newLine;
  824. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::executable
  825. || target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle)
  826. {
  827. out << " MACOSX_BUNDLE_INFO_PLIST " << targetAttributes.getValue ("INFOPLIST_FILE", "\"\"") << newLine
  828. << " XCODE_ATTRIBUTE_PRODUCT_NAME " << binaryName.quoted() << newLine;
  829. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::executable)
  830. {
  831. out << " MACOSX_BUNDLE TRUE" << newLine;
  832. }
  833. else
  834. {
  835. out << " BUNDLE TRUE" << newLine
  836. << " BUNDLE_EXTENSION " << targetAttributes.getValue ("WRAPPER_EXTENSION", "\"\"") << newLine
  837. << " XCODE_ATTRIBUTE_MACH_O_TYPE \"mh_bundle\"" << newLine;
  838. }
  839. }
  840. out << ")" << newLine << newLine;
  841. out << "target_link_libraries (" << targetVarName << " PRIVATE" << newLine;
  842. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle
  843. || target->type == build_tools::ProjectType::Target::Type::StandalonePlugIn)
  844. out << " SHARED_CODE" << newLine;
  845. for (auto& path : libSearchPaths)
  846. out << " \"-L\\\"" << path << "\\\"\"" << newLine;
  847. for (auto& flag : linkerFlags)
  848. out << " " << flag.quoted() << newLine;
  849. for (auto& framework : target->frameworkNames)
  850. out << " \"-framework " << framework << "\"" << newLine;
  851. out << ")" << newLine << newLine;
  852. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle
  853. || target->type == build_tools::ProjectType::Target::Type::StandalonePlugIn)
  854. {
  855. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle
  856. && targetAttributeKeys.contains("INSTALL_PATH"))
  857. {
  858. auto installPath = targetAttributes["INSTALL_PATH"].unquoted().replace ("$(HOME)", "$ENV{HOME}");
  859. auto productFilename = binaryName + (targetAttributeKeys.contains ("WRAPPER_EXTENSION") ? "." + targetAttributes["WRAPPER_EXTENSION"] : String());
  860. auto productPath = (installPath + productFilename).quoted();
  861. out << "add_custom_command (TARGET " << targetVarName << " POST_BUILD" << newLine
  862. << " COMMAND ${CMAKE_COMMAND} -E remove_directory " << productPath << newLine
  863. << " COMMAND ${CMAKE_COMMAND} -E copy_directory \"${CMAKE_BINARY_DIR}/" << productFilename << "\" " << productPath << newLine
  864. << " COMMENT \"Copying \\\"" << productFilename << "\\\" to \\\"" << installPath.unquoted() << "\\\"\"" << newLine
  865. << ")" << newLine << newLine;
  866. }
  867. }
  868. }
  869. std::map<String, String> basicWarnings
  870. {
  871. { "CLANG_WARN_BOOL_CONVERSION", "bool-conversion" },
  872. { "CLANG_WARN_COMMA", "comma" },
  873. { "CLANG_WARN_CONSTANT_CONVERSION", "constant-conversion" },
  874. { "CLANG_WARN_EMPTY_BODY", "empty-body" },
  875. { "CLANG_WARN_ENUM_CONVERSION", "enum-conversion" },
  876. { "CLANG_WARN_INFINITE_RECURSION", "infinite-recursion" },
  877. { "CLANG_WARN_INT_CONVERSION", "int-conversion" },
  878. { "CLANG_WARN_RANGE_LOOP_ANALYSIS", "range-loop-analysis" },
  879. { "CLANG_WARN_STRICT_PROTOTYPES", "strict-prototypes" },
  880. { "GCC_WARN_CHECK_SWITCH_STATEMENTS", "switch" },
  881. { "GCC_WARN_UNUSED_VARIABLE", "unused-variable" },
  882. { "GCC_WARN_MISSING_PARENTHESES", "parentheses" },
  883. { "GCC_WARN_NON_VIRTUAL_DESTRUCTOR", "non-virtual-dtor" },
  884. { "GCC_WARN_64_TO_32_BIT_CONVERSION", "shorten-64-to-32" },
  885. { "GCC_WARN_UNDECLARED_SELECTOR", "undeclared-selector" },
  886. { "GCC_WARN_UNUSED_FUNCTION", "unused-function" }
  887. };
  888. StringArray compilerFlags;
  889. for (auto& key : configSettingsKeys)
  890. {
  891. auto basicWarning = basicWarnings.find (key);
  892. if (basicWarning != basicWarnings.end())
  893. {
  894. compilerFlags.add (configSettings[key] == "YES" ? "-W" + basicWarning->second : "-Wno-" + basicWarning->second);
  895. }
  896. else if (key == "CLANG_WARN_SUSPICIOUS_MOVE" && configSettings[key] == "YES") compilerFlags.add ("-Wmove");
  897. else if (key == "CLANG_WARN_UNREACHABLE_CODE" && configSettings[key] == "YES") compilerFlags.add ("-Wunreachable-code");
  898. else if (key == "CLANG_WARN__DUPLICATE_METHOD_MATCH" && configSettings[key] == "YES") compilerFlags.add ("-Wduplicate-method-match");
  899. else if (key == "GCC_INLINES_ARE_PRIVATE_EXTERN" && configSettings[key] == "YES") compilerFlags.add ("-fvisibility-inlines-hidden");
  900. else if (key == "GCC_NO_COMMON_BLOCKS" && configSettings[key] == "YES") compilerFlags.add ("-fno-common");
  901. else if (key == "GCC_WARN_ABOUT_RETURN_TYPE" && configSettings[key] != "YES") compilerFlags.add (configSettings[key] == "YES_ERROR" ? "-Werror=return-type" : "-Wno-return-type");
  902. else if (key == "GCC_WARN_TYPECHECK_CALLS_TO_PRINTF" && configSettings[key] != "YES") compilerFlags.add ("-Wno-format");
  903. else if (key == "GCC_WARN_UNINITIALIZED_AUTOS")
  904. {
  905. if (configSettings[key] == "YES") compilerFlags.add ("-Wuninitialized");
  906. else if (configSettings[key] == "YES_AGGRESSIVE") compilerFlags.add ("--Wconditional-uninitialized");
  907. else compilerFlags.add (")-Wno-uninitialized");
  908. }
  909. else if (key == "WARNING_CFLAGS") compilerFlags.add (configSettings[key].unquoted());
  910. }
  911. out << addToCMakeVariable ("CMAKE_CXX_FLAGS", compilerFlags.joinIntoString (" ")) << newLine
  912. << addToCMakeVariable ("CMAKE_C_FLAGS", "${CMAKE_CXX_FLAGS}") << newLine
  913. << newLine;
  914. out << "endif (" << buildTypeCondition << ")" << newLine
  915. << newLine;
  916. }
  917. }
  918. //==============================================================================
  919. JUCE_DECLARE_NON_COPYABLE (CLionProjectExporter)
  920. };