diff --git a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Make.h b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Make.h index d2f5f70856..f506f75021 100644 --- a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Make.h +++ b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Make.h @@ -948,20 +948,20 @@ private: void writeCompilerFlagSchemes (OutputStream& out, const std::vector>& filesToCompile) const { - StringArray schemesToWrite; + std::set schemesToWrite; - for (auto& f : filesToCompile) - if (f.second.isNotEmpty()) - schemesToWrite.addIfNotAlreadyThere (f.second); + for (const auto& pair : filesToCompile) + if (pair.second.isNotEmpty()) + schemesToWrite.insert (pair.second); - if (! schemesToWrite.isEmpty()) - { - for (auto& s : schemesToWrite) - out << getCompilerFlagSchemeVariableName (s) << " := " - << compilerFlagSchemesMap[s].get().toString() << newLine; + if (schemesToWrite.empty()) + return; - out << newLine; - } + for (const auto& s : schemesToWrite) + if (const auto flags = getCompilerFlagsForFileCompilerFlagScheme (s); flags.isNotEmpty()) + out << getCompilerFlagSchemeVariableName (s) << " := " << flags << newLine; + + out << newLine; } void writeMakefile (OutputStream& out) const diff --git a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.cpp b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.cpp index c21e817c85..915e4d5bda 100644 --- a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.cpp +++ b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.cpp @@ -245,7 +245,11 @@ void ProjectExporter::updateCompilerFlagValues() compilerFlagSchemesMap.clear(); for (auto& scheme : project.getCompilerFlagSchemes()) - compilerFlagSchemesMap.set (scheme, { settings, scheme, getUndoManager() }); + { + compilerFlagSchemesMap.emplace (std::piecewise_construct, + std::forward_as_tuple (scheme), + std::forward_as_tuple (settings, scheme, getUndoManager())); + } } //============================================================================== @@ -285,9 +289,11 @@ void ProjectExporter::createPropertyEditors (PropertyListBuilder& props) "Extra command-line flags to be passed to the compiler. This string can contain references to preprocessor definitions in the " "form ${NAME_OF_DEFINITION}, which will be replaced with their values."); - for (HashMap::Iterator i (compilerFlagSchemesMap); i.next();) - props.add (new TextPropertyComponent (compilerFlagSchemesMap.getReference (i.getKey()), "Compiler Flags for " + i.getKey().quoted(), 8192, false), + for (const auto& [key, property] : compilerFlagSchemesMap) + { + props.add (new TextPropertyComponent (property, "Compiler Flags for " + key.quoted(), 8192, false), "The exporter-specific compiler flags that will be added to files using this scheme."); + } props.add (new TextPropertyComponent (extraLinkerFlagsValue, "Extra Linker Flags", 8192, true), "Extra command-line flags to be passed to the linker. You might want to use this for adding additional libraries. " @@ -507,14 +513,19 @@ String ProjectExporter::replacePreprocessorTokens (const ProjectExporter::BuildC sourceString); } -String ProjectExporter::getCompilerFlagsForProjectItem (const Project::Item& projectItem) const +String ProjectExporter::getCompilerFlagsForFileCompilerFlagScheme (StringRef schemeName) const { - if (auto buildConfigurationForFile = getBuildConfigurationWithName (projectItem.getCompilerFlagSchemeString())) - return buildConfigurationForFile->getAllCompilerFlagsString(); + if (const auto iter = compilerFlagSchemesMap.find (schemeName); iter != compilerFlagSchemesMap.cend()) + return iter->second.get().toString(); return {}; } +String ProjectExporter::getCompilerFlagsForProjectItem (const Project::Item& item) const +{ + return getCompilerFlagsForFileCompilerFlagScheme (item.getCompilerFlagSchemeString()); +} + void ProjectExporter::copyMainGroupFromProject() { jassert (itemGroups.size() == 0); @@ -769,43 +780,6 @@ ProjectExporter::BuildConfiguration::Ptr ProjectExporter::getConfiguration (int return createBuildConfig (getConfigurations().getChild (index)); } -std::optional ProjectExporter::getConfigurationWithName (const String& nameToFind) const -{ - auto configs = getConfigurations(); - for (int i = configs.getNumChildren(); --i >= 0;) - { - auto config = configs.getChild (i); - - if (config[Ids::name].toString() == nameToFind) - return config; - } - - return {}; -} - -ProjectExporter::BuildConfiguration::Ptr ProjectExporter::getBuildConfigurationWithName (const String& nameToFind) const -{ - if (auto config = getConfigurationWithName (nameToFind)) - return createBuildConfig (*config); - - return nullptr; -} - -String ProjectExporter::getUniqueConfigName (String nm) const -{ - auto nameRoot = nm; - while (CharacterFunctions::isDigit (nameRoot.getLastCharacter())) - nameRoot = nameRoot.dropLastCharacters (1); - - nameRoot = nameRoot.trim(); - - int suffix = 2; - while (getConfigurationWithName (name).has_value()) - nm = nameRoot + " " + String (suffix++); - - return nm; -} - void ProjectExporter::addNewConfigurationFromExisting (const BuildConfiguration& configToCopy) { auto configs = getConfigurations(); @@ -1053,28 +1027,6 @@ StringPairArray ProjectExporter::BuildConfiguration::getAllPreprocessorDefs() co parsePreprocessorDefs (getBuildConfigPreprocessorDefsString())); } -StringPairArray ProjectExporter::BuildConfiguration::getUniquePreprocessorDefs() const -{ - auto perConfigurationDefs = parsePreprocessorDefs (getBuildConfigPreprocessorDefsString()); - auto globalDefs = project.getPreprocessorDefs(); - - for (int i = 0; i < globalDefs.size(); ++i) - { - auto globalKey = globalDefs.getAllKeys()[i]; - - int idx = perConfigurationDefs.getAllKeys().indexOf (globalKey); - if (idx >= 0) - { - auto globalValue = globalDefs.getAllValues()[i]; - - if (globalValue == perConfigurationDefs.getAllValues()[idx]) - perConfigurationDefs.remove (idx); - } - } - - return perConfigurationDefs; -} - StringArray ProjectExporter::BuildConfiguration::getHeaderSearchPaths() const { return getSearchPathsFromString (getHeaderSearchPathString() + ';' + project.getHeaderSearchPathsString()); diff --git a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.h b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.h index 34d7c9a3a2..a25d1fe86b 100644 --- a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.h +++ b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.h @@ -248,7 +248,6 @@ public: String getBuildConfigPreprocessorDefsString() const { return ppDefinesValue.get(); } StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions - StringPairArray getUniquePreprocessorDefs() const; // returns pre-processor definitions that are not already in the project pre-processor defs String getHeaderSearchPathString() const { return headerSearchPathValue.get(); } StringArray getHeaderSearchPaths() const; @@ -319,7 +318,6 @@ public: void addNewConfigurationFromExisting (const BuildConfiguration& configToCopy); void addNewConfiguration (bool isDebugConfig); - String getUniqueConfigName (String name) const; String getExternalLibraryFlags (const BuildConfiguration& config) const; @@ -360,8 +358,6 @@ public: int getNumConfigurations() const; BuildConfiguration::Ptr getConfiguration (int index) const; - std::optional getConfigurationWithName (const String& nameToFind) const; - BuildConfiguration::Ptr getBuildConfigurationWithName (const String& nameToFind) const; ValueTree getConfigurations() const; virtual void createDefaultConfigs(); @@ -402,7 +398,8 @@ public: return false; } - String getCompilerFlagsForProjectItem (const Project::Item& projectItem) const; + String getCompilerFlagsForFileCompilerFlagScheme (StringRef) const; + String getCompilerFlagsForProjectItem (const Project::Item&) const; protected: //============================================================================== @@ -419,7 +416,6 @@ protected: userNotesValue, gnuExtensionsValue, bigIconValue, smallIconValue, extraPPDefsValue; Value projectCompilerFlagSchemesValue; - HashMap compilerFlagSchemesMap; mutable Array itemGroups; Project::Item* modulesGroup = nullptr; @@ -456,6 +452,9 @@ protected: } private: + //============================================================================== + std::map compilerFlagSchemesMap; + //============================================================================== void valueChanged (Value&) override { updateCompilerFlagValues(); } void updateCompilerFlagValues();