Skip to content

Commit

Permalink
Moved OS-specific shared library name handling to shlibpp
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoferigo committed Jan 29, 2019
1 parent 3f1b197 commit c8adc06
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 23 deletions.
22 changes: 21 additions & 1 deletion deps/sharedlibpp/src/SharedLibraryFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class shlibpp::SharedLibraryFactory::Private
bool isValid() const;
bool useFactoryFunction(void *factory);

static std::string platformSpecificLibName(const std::string& library);
void extendSearchPath(const std::string& path);
void readExtendedPathFromEnvironment();
std::string findLibraryInExtendedPath(const std::string& libraryName);
Expand Down Expand Up @@ -83,6 +84,25 @@ shlibpp::SharedLibraryFactory::Private::Private(int32_t startCheck,
memset(&api, 0, sizeof(SharedLibraryClassApi));
}

std::string shlibpp::SharedLibraryFactory::Private::platformSpecificLibName(const std::string& library)
{
#if defined(_WIN32)
#if _MSC_VER && !__INTEL_COMPILER
#if defined(NDEBUG)
return library + ".dll";
#else
return library + "d.dll";
#endif
#else // Windows with other compilers
return "lib" + library + ".dll";
#endif
#elif defined(__linux__)
return "lib" + library + ".so";
#elif defined(__APPLE__)
return "lib" + library + ".dylib";
#endif
}

std::string shlibpp::SharedLibraryFactory::Private::findLibraryInExtendedPath(const std::string& libraryName)
{
std::size_t found = libraryName.find_first_of("\\/");
Expand All @@ -91,7 +111,7 @@ std::string shlibpp::SharedLibraryFactory::Private::findLibraryInExtendedPath(co
}

for (const auto& path: extendedPath) {
std::string absolutePath = path + PATH_SEPARATOR + libraryName;
std::string absolutePath = path + PATH_SEPARATOR + platformSpecificLibName(libraryName);

if (std::ifstream(absolutePath)) {
return absolutePath;
Expand Down
46 changes: 24 additions & 22 deletions sources/Core/src/FactorySingleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <vector>

using namespace blockfactory::core;
std::string platformSpecificLibName(const std::string& library);
//std::string platformSpecificLibName(const std::string& library);

class ClassFactorySingleton::Impl
{
Expand Down Expand Up @@ -63,7 +63,7 @@ ClassFactorySingleton::getClassFactory(const ClassFactoryData& factorydata)
const ClassFactoryLibrary& libraryName = factorydata.first;
const ClassFactoryName& factoryName = factorydata.second;

std::string fsLibraryName = platformSpecificLibName(libraryName);
// std::string fsLibraryName = platformSpecificLibName(libraryName);

// Clean possible leftovers
if (pImpl->factoryMap.find(factorydata) != pImpl->factoryMap.end()
Expand Down Expand Up @@ -91,7 +91,8 @@ ClassFactorySingleton::getClassFactory(const ClassFactoryData& factorydata)
}

// Open the plugin library
if (!factory->open(fsLibraryName.c_str(), factoryName.c_str()) || !factory->isValid()) {
// if (!factory->open(fsLibraryName.c_str(), factoryName.c_str()) || !factory->isValid()) {
if (!factory->open(libraryName.c_str(), factoryName.c_str()) || !factory->isValid()) {
bfError << "Failed to create factory";
bfError << "Factory error (" << static_cast<std::uint32_t>(factory->getStatus())
<< "): " << factory->getError().c_str();
Expand All @@ -103,7 +104,8 @@ ClassFactorySingleton::getClassFactory(const ClassFactoryData& factorydata)
}

if (!pImpl->factoryMap[factorydata]->isValid()) {
bfError << "The factory " << factoryName << " associated with the plugin " << fsLibraryName
// bfError << "The factory " << factoryName << " associated with the plugin " << fsLibraryName
bfError << "The factory " << factoryName << " associated with the plugin " << libraryName
<< " is not valid";
bfError << "Factory error ("
<< static_cast<std::uint32_t>(pImpl->factoryMap[factorydata]->getStatus())
Expand Down Expand Up @@ -138,21 +140,21 @@ void ClassFactorySingleton::extendPluginSearchPath(const std::string& path)
pImpl->extraPluginPaths.push_back(path);
}

std::string platformSpecificLibName(const std::string& library)
{
#if defined(_WIN32)
#if _MSC_VER && !__INTEL_COMPILER
#if defined(NDEBUG)
return library + ".dll";
#else
return library + "d.dll";
#endif
#else
return "lib" + library + ".dll";
#endif
#elif defined(__linux__)
return "lib" + library + ".so";
#elif defined(__APPLE__)
return "lib" + library + ".dylib";
#endif
}
//std::string platformSpecificLibName(const std::string& library)
//{
//#if defined(_WIN32)
//#if _MSC_VER && !__INTEL_COMPILER
//#if defined(NDEBUG)
// return library + ".dll";
//#else
// return library + "d.dll";
//#endif
//#else
// return "lib" + library + ".dll";
//#endif
//#elif defined(__linux__)
// return "lib" + library + ".so";
//#elif defined(__APPLE__)
// return "lib" + library + ".dylib";
//#endif
//}

0 comments on commit c8adc06

Please sign in to comment.