Proper support for BUILD_SHARED_LIBS on Windows
Describe the feature or improvement you're requesting
It would be great if you could add proper support for the compilation of the library as DLL on Windows via the BUILD_SHARED_LIBS CMake variable. Currently the __declspec(dllexport) attribute is applied to many methods in the codebase. If there is no intention to support DLL compilation, please remove the __declspec(dllexport) attribute since it is not required for static libraries. I would even consider this an error as it is applied now. To support DLL compilation, something like this has to be implemented:
liboai\include\core\response.h:
#if defined(__linux__) || defined(__APPLE__)
#define LIBOAI_EXPORT
#else
#ifdef LIBOAI_DLL
#ifdef LIBOAI_BUILD
#define LIBOAI_EXPORT __declspec(dllexport)
#else
#define LIBOAI_EXPORT __declspec(dllimport)
#endif
#else
#define LIBOAI_EXPORT
#endif
#endif
liboai\CMakeLists.txt:
if(BUILD_SHARED_LIBS)
target_compile_definitions(${PROJECT_NAME}
PRIVATE
LIBOAI_BUILD
PUBLIC
LIBOAI_DLL
)
endif()
Furthermore, the LIBOAI_EXPORT macro has to be applied to all methods that are used by a client.
Additional context
No response
I'm not sure if this fixes your specific issue, but after fixing the MSVC/vcpkg build configuration in https://github.com/D7EAD/liboai/pull/84 I tried
cmake .. -DBUILD_SHARED_LIBS:BOOL=ON
and was able to build DLLs. There may be some extra exports there, but its usable.
I'm not sure if this fixes your specific issue, but after fixing the MSVC/vcpkg build configuration in #84
Unfortunately, it doesn't. Also, if you compile with the -DBUILD_EXAMPLES:BOOL=ON option in addition to -DBUILD_SHARED_LIBS:BOOL=ON, you will get multiple linker errors due to missing exports. Since with #84 find_package is only done for WIN32, will this not interfere with the build on other platforms?