From 43ce64a09934e04b59e6039ed8fb2b3dabbab98d Mon Sep 17 00:00:00 2001 From: jules Date: Fri, 22 May 2015 11:27:01 +0100 Subject: [PATCH] Introjucer: refactored some functions and made it add "--no-undefined" to linux VST makefile linker settings. --- .../audio plugin demo/Builds/Linux/Makefile | 4 ++-- .../ComponentEditor/jucer_GeneratedCode.cpp | 14 ++++------- .../ComponentEditor/jucer_JucerDocument.cpp | 6 +---- .../jucer_ProjectExport_Android.h | 7 +++--- .../jucer_ProjectExport_CodeBlocks.h | 23 +++++++------------ .../Project Saving/jucer_ProjectExport_MSVC.h | 3 +-- .../Project Saving/jucer_ProjectExport_Make.h | 18 +++++++++++---- .../jucer_ProjectExport_XCode.h | 14 ++++------- .../Project Saving/jucer_ProjectExporter.h | 7 +++--- .../Source/Project/jucer_AudioPluginModule.h | 7 ++++-- .../Source/Project/jucer_Module.cpp | 4 ++-- .../Source/Utility/jucer_MiscUtilities.cpp | 10 ++++---- .../Source/Utility/jucer_MiscUtilities.h | 2 ++ 13 files changed, 56 insertions(+), 63 deletions(-) diff --git a/examples/audio plugin demo/Builds/Linux/Makefile b/examples/audio plugin demo/Builds/Linux/Makefile index fff5a2c8a6..5a2b1e84ce 100644 --- a/examples/audio plugin demo/Builds/Linux/Makefile +++ b/examples/audio plugin demo/Builds/Linux/Makefile @@ -21,7 +21,7 @@ ifeq ($(CONFIG),Debug) CPPFLAGS := $(DEPFLAGS) -std=c++11 -D "LINUX=1" -D "DEBUG=1" -D "_DEBUG=1" -D "JUCER_LINUX_MAKE_7346DA2A=1" -D "JUCE_APP_VERSION=1.0.0" -D "JUCE_APP_VERSION_HEX=0x10000" -I /usr/include -I /usr/include/freetype2 -I ~/SDKs/VST3\ SDK -I ~/SDKs/vstsdk2.4 -I ../../JuceLibraryCode -I ../../../../modules CFLAGS += $(CPPFLAGS) $(TARGET_ARCH) -g -ggdb -fPIC -O0 CXXFLAGS += $(CFLAGS) - LDFLAGS += $(TARGET_ARCH) -L$(BINDIR) -L$(LIBDIR) -shared -L/usr/X11R6/lib/ -lX11 -lXext -lXinerama -lasound -ldl -lfreetype -lpthread -lrt + LDFLAGS += $(TARGET_ARCH) -L$(BINDIR) -L$(LIBDIR) --no-undefined -shared -L/usr/X11R6/lib/ -lX11 -lXext -lXinerama -lasound -ldl -lfreetype -lpthread -lrt TARGET := JuceDemoPlugin.so BLDCMD = $(CXX) -o $(OUTDIR)/$(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(TARGET_ARCH) @@ -41,7 +41,7 @@ ifeq ($(CONFIG),Release) CPPFLAGS := $(DEPFLAGS) -std=c++11 -D "LINUX=1" -D "NDEBUG=1" -D "JUCER_LINUX_MAKE_7346DA2A=1" -D "JUCE_APP_VERSION=1.0.0" -D "JUCE_APP_VERSION_HEX=0x10000" -I /usr/include -I /usr/include/freetype2 -I ~/SDKs/VST3\ SDK -I ~/SDKs/vstsdk2.4 -I ../../JuceLibraryCode -I ../../../../modules CFLAGS += $(CPPFLAGS) $(TARGET_ARCH) -fPIC -Os CXXFLAGS += $(CFLAGS) - LDFLAGS += $(TARGET_ARCH) -L$(BINDIR) -L$(LIBDIR) -shared -fvisibility=hidden -L/usr/X11R6/lib/ -lX11 -lXext -lXinerama -lasound -ldl -lfreetype -lpthread -lrt + LDFLAGS += $(TARGET_ARCH) -L$(BINDIR) -L$(LIBDIR) --no-undefined -shared -fvisibility=hidden -L/usr/X11R6/lib/ -lX11 -lXext -lXinerama -lasound -ldl -lfreetype -lpthread -lrt TARGET := JuceDemoPlugin.so BLDCMD = $(CXX) -o $(OUTDIR)/$(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(TARGET_ARCH) diff --git a/extras/Introjucer/Source/ComponentEditor/jucer_GeneratedCode.cpp b/extras/Introjucer/Source/ComponentEditor/jucer_GeneratedCode.cpp index 2bb2854ddf..98bcc972fd 100644 --- a/extras/Introjucer/Source/ComponentEditor/jucer_GeneratedCode.cpp +++ b/extras/Introjucer/Source/ComponentEditor/jucer_GeneratedCode.cpp @@ -164,9 +164,7 @@ String GeneratedCode::getClassDeclaration() const parentClassLines.addTokens (parentClasses, ",", StringRef()); parentClassLines.addArray (getExtraParentClasses()); - parentClassLines.trim(); - parentClassLines.removeEmptyStrings(); - parentClassLines.removeDuplicates (false); + parentClassLines = getCleanedStringArray (parentClassLines); if (parentClassLines.contains ("public Button", false)) parentClassLines.removeString ("public Component", false); @@ -186,9 +184,7 @@ String GeneratedCode::getInitialiserList() const if (parentClassInitialiser.isNotEmpty()) inits.insert (0, parentClassInitialiser); - inits.trim(); - inits.removeEmptyStrings(); - inits.removeDuplicates (false); + inits = getCleanedStringArray (inits); String s; @@ -217,12 +213,10 @@ String GeneratedCode::getInitialiserList() const static String getIncludeFileCode (StringArray files) { - files.trim(); - files.removeEmptyStrings(); - files.removeDuplicates (false); - String s; + files = getCleanedStringArray (files); + for (int i = 0; i < files.size(); ++i) s << "#include \"" << files[i] << "\"\n"; diff --git a/extras/Introjucer/Source/ComponentEditor/jucer_JucerDocument.cpp b/extras/Introjucer/Source/ComponentEditor/jucer_JucerDocument.cpp index 9807b7095e..9d277f5181 100644 --- a/extras/Introjucer/Source/ComponentEditor/jucer_JucerDocument.cpp +++ b/extras/Introjucer/Source/ComponentEditor/jucer_JucerDocument.cpp @@ -158,11 +158,7 @@ void JucerDocument::setParentClasses (const String& classes) { if (classes != parentClasses) { - StringArray parentClassLines; - parentClassLines.addTokens (classes, ",", StringRef()); - parentClassLines.trim(); - parentClassLines.removeEmptyStrings(); - parentClassLines.removeDuplicates (false); + StringArray parentClassLines (getCleanedStringArray (StringArray::fromTokens (classes, ",", StringRef()))); for (int i = parentClassLines.size(); --i >= 0;) { diff --git a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Android.h b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Android.h index 8ae88da17f..ae31498364 100644 --- a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Android.h +++ b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Android.h @@ -336,9 +336,7 @@ private: if (getInternetNeeded()) s.add ("android.permission.INTERNET"); if (getAudioRecordNeeded()) s.add ("android.permission.RECORD_AUDIO"); - s.trim(); - s.removeDuplicates (false); - return s; + return getCleanedStringArray (s); } //============================================================================== @@ -557,7 +555,8 @@ private: String flags; StringArray searchPaths (extraSearchPaths); searchPaths.addArray (config.getHeaderSearchPaths()); - searchPaths.removeDuplicates (false); + + searchPaths = getCleanedStringArray (searchPaths); for (int i = 0; i < searchPaths.size(); ++i) flags << " -I " << FileHelpers::unixStylePath (replacePreprocessorTokens (config, searchPaths[i])).quoted(); diff --git a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_CodeBlocks.h b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_CodeBlocks.h index 7e271025fd..48759a76e1 100644 --- a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_CodeBlocks.h +++ b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_CodeBlocks.h @@ -95,7 +95,8 @@ public: bool canLaunchProject() override { return false; } bool launchProject() override { return false; } bool isCodeBlocksWindows() const override { return os == windowsTarget; } - bool isCodeBlocksLinux() const override { return os == linuxTarget; } + bool isCodeBlocksLinux() const override { return isLinux(); } + bool isLinux() const override { return os == linuxTarget; } bool usesMMFiles() const override { return false; } bool canCopeWithDuplicateFiles() override { return false; } @@ -153,14 +154,6 @@ private: xml.createNewChildElement ("Option")->setAttribute ("compiler", "gcc"); } - static StringArray cleanArray (StringArray s) - { - s.trim(); - s.removeDuplicates (false); - s.removeEmptyStrings (true); - return s; - } - StringArray getDefines (const BuildConfiguration& config) const { StringPairArray defines; @@ -191,7 +184,7 @@ private: for (int i = 0; i < defines.size(); ++i) defs.add (defines.getAllKeys()[i] + "=" + defines.getAllValues()[i]); - return cleanArray (defs); + return getCleanedStringArray (defs); } StringArray getCompilerFlags (const BuildConfiguration& config) const @@ -221,12 +214,12 @@ private: } } - return cleanArray (flags); + return getCleanedStringArray (flags); } StringArray getLinkerFlags (const BuildConfiguration& config) const { - StringArray flags; + StringArray flags (makefileExtraLinkerFlags); if (! config.isDebug()) flags.add ("-s"); @@ -234,7 +227,7 @@ private: flags.addTokens (replacePreprocessorTokens (config, getExtraLinkerFlagsString()).trim(), " \n", "\"'"); - return cleanArray (flags); + return getCleanedStringArray (flags); } StringArray getIncludePaths (const BuildConfiguration& config) const @@ -250,7 +243,7 @@ private: if (! isCodeBlocksWindows()) paths.add ("/usr/include/freetype2"); - return cleanArray (paths); + return getCleanedStringArray (paths); } static int getTypeIndex (const ProjectType& type) @@ -360,7 +353,7 @@ private: libs.addTokens (getExternalLibrariesString(), ";\n", "\"'"); - libs = cleanArray (libs); + libs = getCleanedStringArray (libs); for (int i = 0; i < libs.size(); ++i) setAddOption (*linker, "library", replacePreprocessorDefs (getAllPreprocessorDefs(), libs[i])); diff --git a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_MSVC.h b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_MSVC.h index 813e1630b1..fd9ae0daa2 100644 --- a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_MSVC.h +++ b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_MSVC.h @@ -291,8 +291,7 @@ protected: { StringArray searchPaths (extraSearchPaths); searchPaths.addArray (config.getHeaderSearchPaths()); - searchPaths.removeDuplicates (false); - return searchPaths; + return getCleanedStringArray (searchPaths); } virtual String createConfigName (const BuildConfiguration& config) const diff --git a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Make.h b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Make.h index 5d9a6efc6b..b0ebfda6d9 100644 --- a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Make.h +++ b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Make.h @@ -52,6 +52,7 @@ public: bool launchProject() override { return false; } bool usesMMFiles() const override { return false; } bool isLinuxMakefile() const override { return true; } + bool isLinux() const override { return true; } bool canCopeWithDuplicateFiles() override { return false; } void createExporterProperties (PropertyListBuilder&) override @@ -147,7 +148,7 @@ private: searchPaths.insert (0, "/usr/include/freetype2"); searchPaths.insert (0, "/usr/include"); - searchPaths.removeDuplicates (false); + searchPaths = getCleanedStringArray (searchPaths); for (int i = 0; i < searchPaths.size(); ++i) out << " -I " << escapeSpaces (FileHelpers::unixStylePath (replacePreprocessorTokens (config, searchPaths[i]))); @@ -165,11 +166,18 @@ private: { out << " LDFLAGS += $(TARGET_ARCH) -L$(BINDIR) -L$(LIBDIR)"; - if (makefileIsDLL) - out << " -shared"; + { + StringArray flags (makefileExtraLinkerFlags); + + if (makefileIsDLL) + flags.add ("-shared"); - if (! config.isDebug()) - out << " -fvisibility=hidden"; + if (! config.isDebug()) + flags.add ("-fvisibility=hidden"); + + if (flags.size() > 0) + out << " " << getCleanedStringArray (flags).joinIntoString (" "); + } out << config.getGCCLibraryPathFlags(); diff --git a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_XCode.h b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_XCode.h index 5f17f7854a..2414627a36 100644 --- a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_XCode.h +++ b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_XCode.h @@ -661,8 +661,8 @@ private: StringArray paths (extraSearchPaths); paths.addArray (config.getHeaderSearchPaths()); paths.add ("$(inherited)"); - paths.removeDuplicates (false); - paths.removeEmptyStrings(); + + paths = getCleanedStringArray (paths); for (int i = 0; i < paths.size(); ++i) { @@ -723,8 +723,7 @@ private: for (int i = 0; i < xcodeLibs.size(); ++i) flags.add (getLinkerFlagForLib (xcodeLibs[i])); - flags.removeEmptyStrings (true); - flags.removeDuplicates (false); + flags = getCleanedStringArray (flags); } StringArray getProjectSettings (const XcodeBuildConfiguration& config) const @@ -876,7 +875,7 @@ private: s.add ("OTHER_LDFLAGS = \"" + linkerFlags.joinIntoString (" ") + "\""); librarySearchPaths.addArray (config.getLibrarySearchPaths()); - librarySearchPaths.removeDuplicates (false); + librarySearchPaths = getCleanedStringArray (librarySearchPaths); if (librarySearchPaths.size() > 0) { @@ -926,11 +925,8 @@ private: } s.addTokens (config.getCustomXcodeFlags(), ",", "\"'"); - s.trim(); - s.removeEmptyStrings(); - s.removeDuplicates (false); - return s; + return getCleanedStringArray (s); } void addFrameworks() const diff --git a/extras/Introjucer/Source/Project Saving/jucer_ProjectExporter.h b/extras/Introjucer/Source/Project Saving/jucer_ProjectExporter.h index 3d934e9edd..cf9519f62c 100644 --- a/extras/Introjucer/Source/Project Saving/jucer_ProjectExporter.h +++ b/extras/Introjucer/Source/Project Saving/jucer_ProjectExporter.h @@ -68,10 +68,11 @@ public: virtual int getVisualStudioVersion() const { return 0; } virtual bool isCodeBlocksWindows() const { return false; } virtual bool isCodeBlocksLinux() const { return false; } + virtual bool isLinuxMakefile() const { return false; } virtual bool isAndroid() const { return false; } virtual bool isWindows() const { return false; } - virtual bool isLinuxMakefile() const { return false; } + virtual bool isLinux() const { return false; } virtual bool isOSX() const { return false; } bool mayCompileOnCurrentOS() const @@ -81,7 +82,7 @@ public: #elif JUCE_WINDOWS return isWindows() || isAndroid(); #elif JUCE_LINUX - return isLinuxMakefile() || isCodeBlocksLinux() || isAndroid(); + return isLinux() || isAndroid(); #else #error #endif @@ -173,7 +174,7 @@ public: //============================================================================== String makefileTargetSuffix; bool makefileIsDLL; - StringArray linuxLibs; + StringArray linuxLibs, makefileExtraLinkerFlags; //============================================================================== String msvcTargetSuffix; diff --git a/extras/Introjucer/Source/Project/jucer_AudioPluginModule.h b/extras/Introjucer/Source/Project/jucer_AudioPluginModule.h index 47737685d2..c2dc16b0ed 100644 --- a/extras/Introjucer/Source/Project/jucer_AudioPluginModule.h +++ b/extras/Introjucer/Source/Project/jucer_AudioPluginModule.h @@ -243,7 +243,7 @@ namespace VSTHelpers if (exporter.isVisualStudio()) exporter.extraSearchPaths.add (path.toWindowsStyle()); - else if (exporter.isLinuxMakefile() || exporter.isCodeBlocksLinux() || exporter.isXcode()) + else if (exporter.isLinux() || exporter.isXcode()) exporter.extraSearchPaths.insert (0, path.toUnixStyle()); } } @@ -282,7 +282,7 @@ namespace VSTHelpers if (exporter.isWindows()) exporter.extraSearchPaths.add (juceWrapperFolder.toWindowsStyle()); - else if (exporter.isLinuxMakefile() || exporter.isCodeBlocksLinux() ) + else if (exporter.isLinux()) exporter.extraSearchPaths.add (juceWrapperFolder.toUnixStyle()); if (exporter.isVisualStudio()) @@ -305,6 +305,9 @@ namespace VSTHelpers config->getValue (Ids::postbuildCommand) = "copy /Y \"$(OutDir)\\$(TargetFileName)\" \"$(OutDir)\\$(TargetName).vst3\""; } } + + if (exporter.isLinux()) + exporter.makefileExtraLinkerFlags.add ("--no-undefined"); } static inline void createPropertyEditors (ProjectExporter& exporter, PropertyListBuilder& props, bool isVST3) diff --git a/extras/Introjucer/Source/Project/jucer_Module.cpp b/extras/Introjucer/Source/Project/jucer_Module.cpp index 8d9f5d267d..38830c34bd 100644 --- a/extras/Introjucer/Source/Project/jucer_Module.cpp +++ b/extras/Introjucer/Source/Project/jucer_Module.cpp @@ -370,7 +370,7 @@ void LibraryModule::prepareExporter (ProjectExporter& exporter, ProjectSaver& pr parseAndAddLibs (exporter.xcodeLibs, moduleInfo.moduleInfo [exporter.isOSX() ? "OSXLibs" : "iOSLibs"].toString()); } - else if (exporter.isLinuxMakefile() || exporter.isCodeBlocksLinux()) + else if (exporter.isLinux()) { parseAndAddLibs (exporter.linuxLibs, moduleInfo.moduleInfo ["LinuxLibs"].toString()); } @@ -501,7 +501,7 @@ static bool fileTargetMatches (ProjectExporter& exporter, const String& target) return exporterTargetMatches ("xcode", target); if (exporter.isWindows()) return exporterTargetMatches ("msvc", target); - if (exporter.isLinuxMakefile() || exporter.isCodeBlocksLinux()) + if (exporter.isLinux()) return exporterTargetMatches ("linux", target); if (exporter.isAndroid()) return exporterTargetMatches ("android", target); diff --git a/extras/Introjucer/Source/Utility/jucer_MiscUtilities.cpp b/extras/Introjucer/Source/Utility/jucer_MiscUtilities.cpp index 9cad7bc6ce..3a151982d8 100644 --- a/extras/Introjucer/Source/Utility/jucer_MiscUtilities.cpp +++ b/extras/Introjucer/Source/Utility/jucer_MiscUtilities.cpp @@ -165,16 +165,18 @@ StringArray getSearchPathsFromString (const String& searchPath) { StringArray s; s.addTokens (searchPath, ";\r\n", StringRef()); - s.trim(); - s.removeEmptyStrings(); - s.removeDuplicates (false); - return s; + return getCleanedStringArray (s); } StringArray getCommaOrWhitespaceSeparatedItems (const String& sourceString) { StringArray s; s.addTokens (sourceString, ", \t\r\n", StringRef()); + return getCleanedStringArray (s); +} + +StringArray getCleanedStringArray (StringArray s) +{ s.trim(); s.removeEmptyStrings(); s.removeDuplicates (false); diff --git a/extras/Introjucer/Source/Utility/jucer_MiscUtilities.h b/extras/Introjucer/Source/Utility/jucer_MiscUtilities.h index 893aa12c19..1b0a8355fc 100644 --- a/extras/Introjucer/Source/Utility/jucer_MiscUtilities.h +++ b/extras/Introjucer/Source/Utility/jucer_MiscUtilities.h @@ -56,6 +56,8 @@ void showSVGPathDataToolWindow (ScopedPointer& ownerPointer); bool cancelAnyModalComponents(); bool reinvokeCommandAfterCancellingModalComps (const ApplicationCommandTarget::InvocationInfo&); +StringArray getCleanedStringArray (StringArray); + //============================================================================== class RolloverHelpComp : public Component, private Timer