[PATCH] Support for libraries in IntroJucer


#1

The title says it all, this patch adds support for proper library linker flags in IntroJucer for all exporters, except Android (don’t know if or how to support it)

diff --git a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_MSVC.h b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_MSVC.h
index 695b98a..338ad3f 100644
--- a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_MSVC.h        
+++ b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_MSVC.h        
@@ -802,6 +802,11 @@ protected:
             if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
                 linker->setAttribute ("ModuleDefinitionFile", config.config [Ids::msvcModuleDefinitionFile].toString());
 
+            String externalLibraries (getExternalLibrariesString());
+            
+            if (externalLibraries.isNotEmpty())
+                linker->setAttribute ("AdditionalDependencies", replacePreprocessorTokens (config, externalLibraries).trim());
+            
             String extraLinkerOptions (getExtraLinkerFlagsString());
 
             if (extraLinkerOptions.isNotEmpty())
@@ -817,6 +822,11 @@ protected:
                 extraLinkerOptions << " /IMPLIB:" << getOutDirFile (config.getOutputFilename (".lib", true));
                 linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
 
+                String externalLibraries (getExternalLibrariesString());
+                
+                if (externalLibraries.isNotEmpty())
+                    linker->setAttribute ("AdditionalDependencies", replacePreprocessorTokens (config, externalLibraries).trim());
+                
                 linker->setAttribute ("OutputFile", getOutDirFile (config.getOutputFilename (msvcTargetSuffix, false)));
                 linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
             }
@@ -1188,6 +1198,11 @@ protected:
                     link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
                 }
 
+                String externalLibraries (getExternalLibrariesString());
+                
+                if (externalLibraries.isNotEmpty())
+                    link->createNewChildElement ("AdditionalDependencies")->addTextElement(replacePreprocessorTokens (config, externalLibraries).trim() + ";%(AdditionalDependencies)");
+
                 String extraLinkerOptions (getExtraLinkerFlagsString());
                 if (extraLinkerOptions.isNotEmpty())
                     link->createNewChildElement ("AdditionalOptions")->addTextElement (replacePreprocessorTokens (config, extraLinkerOptions).trim()
diff --git a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Make.h b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Make.h
index 227af49..7d0a794 100644
--- a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Make.h        
+++ b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Make.h        
@@ -167,6 +167,13 @@ private:
         for (int i = 0; i < linuxLibs.size(); ++i)
             out << " -l" << linuxLibs[i];
 
+        StringArray libraries;
+        libraries.addTokens(getExternalLibrariesString(), ";", "\"'");
+        libraries.removeEmptyStrings();
+        if (libraries.size())
+            out << " " << replacePreprocessorTokens (config, "-l" + libraries.joinIntoString(" -l")).trim();
+        
+        
         out << " " << replacePreprocessorTokens (config, getExtraLinkerFlagsString()).trim()
             << newLine;
     }
diff --git a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_XCode.h b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_XCode.h
index d2d3de9..8960d52 100644
--- a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_XCode.h       
+++ b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_XCode.h       
@@ -620,6 +620,13 @@ private:
             getLinkerFlagsForStaticLibrary (extraLibs.getReference(i), flags, librarySearchPaths);
 
         flags.add (replacePreprocessorTokens (config, getExtraLinkerFlagsString()));
+        
+        StringArray libraries;
+        libraries.addTokens(getExternalLibrariesString(), ";", "\"'");
+        libraries.removeEmptyStrings(true);
+        
+        if (libraries.size())
+            flags.add (replacePreprocessorTokens (config, "-l" + libraries.joinIntoString(" -l")).trim());
         flags.removeEmptyStrings (true);
     }
 
diff --git a/extras/Introjucer/Source/Project Saving/jucer_ProjectExporter.cpp b/extras/Introjucer/Source/Project Saving/jucer_ProjectExporter.cpp
index f8054f4..49d98f7 100644
--- a/extras/Introjucer/Source/Project Saving/jucer_ProjectExporter.cpp 
+++ b/extras/Introjucer/Source/Project Saving/jucer_ProjectExporter.cpp 
@@ -223,7 +223,9 @@ void ProjectExporter::createPropertyEditors (PropertyListBuilder& props)
     props.add (new TextPropertyComponent (getExtraCompilerFlags(), "Extra compiler flags", 2048, true),
                "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.");
     props.add (new TextPropertyComponent (getExtraLinkerFlags(), "Extra linker flags", 2048, true),
-               "Extra command-line flags to be passed to the linker. You might want to use this for adding additional libraries. This string can contain references to preprocessor definitions in the form ${NAME_OF_VALUE}, whic
+               "Extra command-line flags to be passed to the linker. You might want to use this for adding linker specific commands. This string can contain references to preprocessor definitions in the form ${NAME_OF_VALUE}, 
+    props.add (new TextPropertyComponent (getExternalLibraries(), "External libraries to link with", 2048, true),
+               "External libraries to link with (one per line). You might want to use this for adding additional libraries. You should not add any platform specific decoration on this list. This string can contain references t
 
     {
         OwnedArray<Project::Item> images;
diff --git a/extras/Introjucer/Source/Project Saving/jucer_ProjectExporter.h b/extras/Introjucer/Source/Project Saving/jucer_ProjectExporter.h
index d340bfe..2291271 100644
--- a/extras/Introjucer/Source/Project Saving/jucer_ProjectExporter.h   
+++ b/extras/Introjucer/Source/Project Saving/jucer_ProjectExporter.h   
@@ -84,6 +84,9 @@ public:
     Value getExtraLinkerFlags()                 { return getSetting (Ids::extraLinkerFlags); }
     String getExtraLinkerFlagsString() const    { return getSettingString (Ids::extraLinkerFlags).replaceCharacters ("\r\n", "  "); }
 
+    Value getExternalLibraries()                { return getSetting (Ids::externalLibraries); }
+    String getExternalLibrariesString() const   { return getSettingString (Ids::externalLibraries).replaceCharacters ("\r\n", " ;"); }
+    
     Value getUserNotes()                        { return getSetting (Ids::userNotes); }
 
     // This adds the quotes, and may return angle-brackets, eg: <foo/bar.h> or normal quotes.
diff --git a/extras/Introjucer/Source/Utility/jucer_PresetIDs.h b/extras/Introjucer/Source/Utility/jucer_PresetIDs.h
index 80ad74a..501e5e4 100644
--- a/extras/Introjucer/Source/Utility/jucer_PresetIDs.h
+++ b/extras/Introjucer/Source/Utility/jucer_PresetIDs.h
@@ -55,6 +55,7 @@ namespace Ids
     DECLARE_ID (time);
     DECLARE_ID (extraCompilerFlags);
     DECLARE_ID (extraLinkerFlags);
+    DECLARE_ID (externalLibraries);
     DECLARE_ID (extraDefs);
     DECLARE_ID (projectType);
     DECLARE_ID (libraryType);

Against the latest git at time of writing


#2

Thank X-Ryl669, for your precious work.

For your patch… I will try and apply it on latest git brach for Juce… And Use it,
but officially When Jules will apply it to the Juce git on sourceforge? We will also wait for that :slight_smile:


#3

Up.


#4

Done. Thanks!


#5

Thanks. Forgot to add that, as usual, I give all rights to this code to Julian Storer, so it can be used in both GPL and commercial version without any requirement on my side (legal terms).


#6

:slight_smile: