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.

1215 lines
57KB

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