From 74f2f47cb63b02638270beecd20acea1a0f5665e Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 27 Sep 2017 11:17:39 -0700 Subject: First attempt at a Linux build (#193) * First attempt at a Linux build - Fix up places where C++ idioms were written assuming lenient behavior of Microsoft's compiler - Add a few more alternatives for platform-specific behavior where Windows was the only platform accounted for. - Add a basic Makefile that can at least invoke our build, even if it isn't going good dependency tracking, etc. - Build `libslang.so` and `slangc` that depends on it, using a relative `RPATH` to make the binary portable (I hope) - Add an initial `.travis.yml` to see if we can trigger their build process. * Fixup: const bug in `List::Sort` I'm not clear why this gets picked up by the gcc *and* clang that Travis uses, but not the (newer) gcc I'm using on Ubuntu here, but I'm hoping it is just some missing `const` qualifiers. * Fixup: reorder specialization of "class info" Clang complains about things being specialized after being instantiated (implicilty), and I hope it is just the fact that I generate the class info for the roots of the hierarchy after the other cases. We'll see. * Fixup: add `platform.cpp` to unified/lumped build * Fixup: Windows uses `FreeLibrary` and not `UnloadLibrary` * Fixup: fix Windows project file to include new source file This obviously points to the fact that we are going to need to be generating these files sooner or later. --- source/core/platform.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 source/core/platform.cpp (limited to 'source/core/platform.cpp') diff --git a/source/core/platform.cpp b/source/core/platform.cpp new file mode 100644 index 000000000..dbb536b0f --- /dev/null +++ b/source/core/platform.cpp @@ -0,0 +1,74 @@ +// platform.cpp +#include "platform.h" + +#ifdef _WIN32 + #define WIN32_LEAN_AND_MEAN + #define NOMINMAX + #include + #undef WIN32_LEAN_AND_MEAN + #undef NOMINMAX +#else + #include +#endif + +namespace Slang +{ + // SharedLibrary + + SharedLibrary SharedLibrary::load(char const* name) + { + SharedLibrary result; + result.handle = nullptr; + +#ifdef _WIN32 + { + HMODULE h = LoadLibraryA(name); + result.handle = (Handle) h; + } +#else + { + void* h = dlopen(name, RTLD_LOCAL); + result.handle = (Handle) h; + + } +#endif + + return result; + } + + void SharedLibrary::unload() + { +#ifdef _WIN32 + { + FreeLibrary( + (HMODULE) handle); + } +#else + { + dlclose(handle); + } +#endif + + } + + SharedLibrary::FuncPtr SharedLibrary::findFuncByName(char const* name) + { + FuncPtr funcPtr = nullptr; + +#ifdef _WIN32 + { + funcPtr = (FuncPtr) GetProcAddress( + (HMODULE) handle, + name); + } +#else + { + funcPtr = (FuncPtr) dlsym( + (void*) handle, + name); + } +#endif + + return funcPtr; + } +} \ No newline at end of file -- cgit v1.2.3