From 4965cdf0305ba7b752b400b84b1dd77c73d1764d Mon Sep 17 00:00:00 2001 From: tpoole Date: Thu, 22 Jun 2017 17:50:57 +0100 Subject: [PATCH] Android: Added support for static libraries in modules --- .../Source/Project Saving/jucer_ProjectExport_Android.h | 9 ++++++++- .../Project Saving/jucer_ProjectExport_CodeBlocks.h | 2 +- .../Source/Project Saving/jucer_ProjectExport_MSVC.h | 2 +- .../Source/Project Saving/jucer_ProjectExport_Make.h | 2 +- .../Source/Project Saving/jucer_ProjectExport_XCode.h | 2 +- .../Source/Project Saving/jucer_ProjectExporter.cpp | 5 +++-- .../Source/Project Saving/jucer_ProjectExporter.h | 5 ++++- extras/Projucer/Source/Project/jucer_Module.cpp | 7 ++++++- modules/JUCE Module Format.txt | 4 ++++ 9 files changed, 29 insertions(+), 9 deletions(-) diff --git a/extras/Projucer/Source/Project Saving/jucer_ProjectExport_Android.h b/extras/Projucer/Source/Project Saving/jucer_ProjectExport_Android.h index 7d92cc2269..ee819ce428 100644 --- a/extras/Projucer/Source/Project Saving/jucer_ProjectExport_Android.h +++ b/extras/Projucer/Source/Project Saving/jucer_ProjectExport_Android.h @@ -350,6 +350,11 @@ protected: { return getName().toUpperCase().replaceCharacter (L' ', L'_'); } + + String getModuleLibraryArchName() const override + { + return "${ANDROID_ABI}"; + } }; BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override @@ -396,7 +401,9 @@ private: mo << "SET( CMAKE_SHARED_LINKER_FLAGS \"${CMAKE_EXE_LINKER_FLAGS} ${JUCE_LDFLAGS}\")" << newLine << newLine; } - const StringArray userLibraries = StringArray::fromTokens(getExternalLibrariesString(), ";", ""); + StringArray userLibraries = StringArray::fromTokens(getExternalLibrariesString(), ";", ""); + userLibraries.addArray (androidLibs); + if (getNumConfigurations() > 0) { bool first = true; diff --git a/extras/Projucer/Source/Project Saving/jucer_ProjectExport_CodeBlocks.h b/extras/Projucer/Source/Project Saving/jucer_ProjectExport_CodeBlocks.h index 449604a720..ce5ec7a791 100644 --- a/extras/Projucer/Source/Project Saving/jucer_ProjectExport_CodeBlocks.h +++ b/extras/Projucer/Source/Project Saving/jucer_ProjectExport_CodeBlocks.h @@ -216,7 +216,7 @@ private: Array (archFlags, numElementsInArray (archFlags)))); } - String getLibrarySubdirPath() const override + String getModuleLibraryArchName() const override { const String archFlag = getArchitectureTypeVar(); diff --git a/extras/Projucer/Source/Project Saving/jucer_ProjectExport_MSVC.h b/extras/Projucer/Source/Project Saving/jucer_ProjectExport_MSVC.h index 5657e11331..4618f499f0 100644 --- a/extras/Projucer/Source/Project Saving/jucer_ProjectExport_MSVC.h +++ b/extras/Projucer/Source/Project Saving/jucer_ProjectExport_MSVC.h @@ -165,7 +165,7 @@ public: } } - String getLibrarySubdirPath() const override + String getModuleLibraryArchName() const override { String result ("$(Platform)\\"); result += isUsingRuntimeLibDLL() ? "MD" : "MT"; diff --git a/extras/Projucer/Source/Project Saving/jucer_ProjectExport_Make.h b/extras/Projucer/Source/Project Saving/jucer_ProjectExport_Make.h index c82d178bef..a0d1ebd911 100644 --- a/extras/Projucer/Source/Project Saving/jucer_ProjectExport_Make.h +++ b/extras/Projucer/Source/Project Saving/jucer_ProjectExport_Make.h @@ -53,7 +53,7 @@ protected: Array (archFlags, numElementsInArray (archFlags)))); } - String getLibrarySubdirPath() const override + String getModuleLibraryArchName() const override { String archFlag = getArchitectureTypeVar(); String prefix ("-march="); diff --git a/extras/Projucer/Source/Project Saving/jucer_ProjectExport_XCode.h b/extras/Projucer/Source/Project Saving/jucer_ProjectExport_XCode.h index 5e2f8af7f3..af9cfd0e65 100644 --- a/extras/Projucer/Source/Project Saving/jucer_ProjectExport_XCode.h +++ b/extras/Projucer/Source/Project Saving/jucer_ProjectExport_XCode.h @@ -465,7 +465,7 @@ protected: "will also remove any function names from crash logs. Must be disabled for static library projects."); } - String getLibrarySubdirPath() const override + String getModuleLibraryArchName() const override { return "${CURRENT_ARCH}"; } diff --git a/extras/Projucer/Source/Project Saving/jucer_ProjectExporter.cpp b/extras/Projucer/Source/Project Saving/jucer_ProjectExporter.cpp index 212c2f2c3a..4714228361 100644 --- a/extras/Projucer/Source/Project Saving/jucer_ProjectExporter.cpp +++ b/extras/Projucer/Source/Project Saving/jucer_ProjectExporter.cpp @@ -935,8 +935,9 @@ StringArray ProjectExporter::BuildConfiguration::getLibrarySearchPaths() const { auto separator = exporter.isVisualStudio() ? "\\" : "/"; auto s = getSearchPathsFromString (getLibrarySearchPathString()); + for (auto path : exporter.moduleLibSearchPaths) - s.add (path + separator + getLibrarySubdirPath()); + s.add (path + separator + getModuleLibraryArchName()); return s; } @@ -950,7 +951,7 @@ String ProjectExporter::BuildConfiguration::getGCCLibraryPathFlags() const s << " -L" << escapeSpaces (path).replace ("~", "$(HOME)"); for (auto path : exporter.moduleLibSearchPaths) - s << " -L" << escapeSpaces (path).replace ("~", "$(HOME)") << "/" << getLibrarySubdirPath(); + s << " -L" << escapeSpaces (path).replace ("~", "$(HOME)") << "/" << getModuleLibraryArchName(); return s; } diff --git a/extras/Projucer/Source/Project Saving/jucer_ProjectExporter.h b/extras/Projucer/Source/Project Saving/jucer_ProjectExporter.h index bc97d44d79..e64d2d53c7 100644 --- a/extras/Projucer/Source/Project Saving/jucer_ProjectExporter.h +++ b/extras/Projucer/Source/Project Saving/jucer_ProjectExporter.h @@ -218,6 +218,9 @@ public: String msvcDelayLoadedDLLs; StringArray mingwLibs, windowsLibs; + //============================================================================== + StringArray androidLibs; + //============================================================================== StringArray extraSearchPaths; StringArray moduleLibSearchPaths; @@ -234,7 +237,7 @@ public: //============================================================================== virtual void createConfigProperties (PropertyListBuilder&) = 0; virtual var getDefaultOptimisationLevel() const = 0; - virtual String getLibrarySubdirPath() const { return {}; } + virtual String getModuleLibraryArchName() const = 0; //============================================================================== diff --git a/extras/Projucer/Source/Project/jucer_Module.cpp b/extras/Projucer/Source/Project/jucer_Module.cpp index dad6bd3da1..0587317a40 100644 --- a/extras/Projucer/Source/Project/jucer_Module.cpp +++ b/extras/Projucer/Source/Project/jucer_Module.cpp @@ -356,12 +356,13 @@ void LibraryModule::addSettingsForModuleToExporter (ProjectExporter& exporter, P libDirPlatform = exporter.getTargetFolder().getFileName(); const auto libSubdirPath = String (moduleRelativePath.toUnixStyle() + "/libs/") + libDirPlatform; - const auto moduleLibDir = File (project.getProjectFolder().getFullPathName() + "/" + libSubdirPath); + if (moduleLibDir.exists()) exporter.addToModuleLibPaths (RelativePath (libSubdirPath, moduleRelativePath.getRoot())); const auto extraInternalSearchPaths = moduleInfo.getExtraSearchPaths().trim(); + if (extraInternalSearchPaths.isNotEmpty()) { StringArray paths; @@ -417,6 +418,10 @@ void LibraryModule::addSettingsForModuleToExporter (ProjectExporter& exporter, P else parseAndAddLibs (exporter.windowsLibs, moduleInfo.moduleInfo ["windowsLibs"].toString()); } + else if (exporter.isAndroid()) + { + parseAndAddLibs (exporter.androidLibs, moduleInfo.moduleInfo ["androidLibs"].toString()); + } } void LibraryModule::getConfigFlags (Project& project, OwnedArray& flags) const diff --git a/modules/JUCE Module Format.txt b/modules/JUCE Module Format.txt index 6b068e1e8b..5032dca7e3 100644 --- a/modules/JUCE Module Format.txt +++ b/modules/JUCE Module Format.txt @@ -124,6 +124,10 @@ iOS: libs/iOS/{arch}, where {arch} is the architecture you are targeting in Xcode ("arm64" or "x86_64", for example). +Android: + libs/Android/{arch}, where {arch} is the architecture provided by the Android Studio variable + "${ANDROID_ABI}" ("x86", "armeabi-v7a", "mips", for example). + The BEGIN_JUCE_MODULE_DECLARATION block =======================================