generate_export_header does not work with object libraries and always generates empty export macros for static libraries
https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/GenerateExportHeader.cmake#L292 only checks for static libraries and not for object libraries which causes issues on Windows as dllexport/dllimport export macros are generated for object libraries which leads to linker errors as dllexport and dllimport are used in the same binary.
I was planning to simply add an extra object library check to the if statement but I'm not sure if the current behaviour for static libraries is even correct since compiling a static library with __attribute__((visibility("default")))
attributes causes no warnings at all on non-Windows systems so I'm wondering why CMake generates empty export macros for static libraries on non-Windows systems when the compiler supports hidden visibility modifiers.
I'm wondering if:
if((WIN32 OR CYGWIN) AND (NOT ${type} STREQUAL "STATIC_LIBRARY") AND (NOT ${type} STREQUAL "OBJECT_LIBRARY"))
set(DEFINE_EXPORT "__declspec(dllexport)")
set(DEFINE_IMPORT "__declspec(dllimport)")
elseif(COMPILER_HAS_HIDDEN_VISIBILITY)
set(DEFINE_EXPORT "__attribute__((visibility(\"default\")))")
set(DEFINE_IMPORT "__attribute__((visibility(\"default\")))")
set(DEFINE_NO_EXPORT "__attribute__((visibility(\"hidden\")))")
endif()
would be better than the current implementation (supports object libraries and generates non-empty export macros for static and object libraries when the compiler has hidden visibility).