Fix export macros on non-Linux systems
Needs ReviewPublic

Authored by rakuco on Sep 13 2016, 10:59 AM.

Details

Summary

At the moment, building any application that links against libkolab on
FreeBSD fails because of missing symbols. For example, building
kolabformatchecker throws the following error messages:

CMakeFiles/kolabformatchecker.dir/kolabformatchecker.cpp.o: In function `main':
/tmp/libkolab/utils/kolabformatchecker.cpp:95: undefined reference to `Kolab::KolabObjectReader::KolabObjectReader(boost::shared_ptr<KMime::Message> const&)'
/tmp/libkolab/utils/kolabformatchecker.cpp:105: undefined reference to `Kolab::KolabObjectReader::~KolabObjectReader()'
/tmp/libkolab/utils/kolabformatchecker.cpp:105: undefined reference to `Kolab::KolabObjectReader::~KolabObjectReader()'
CMakeFiles/kolabformatchecker.dir/kolabformatchecker.cpp.o: In function `Kolab::ErrorHandler::instance()':
/tmp/libkolab/./kolabformat/errorhandler.h:64: undefined reference to `Kolab::ErrorHandler::ErrorHandler()'
CMakeFiles/kolabformatchecker.dir/kolabformatchecker.cpp.o: In function `Kolab::ErrorHandler::errorOccured()':
/tmp/libkolab/./kolabformat/errorhandler.h:86: undefined reference to `Kolab::ErrorHandler::error() const'

The direct cause for the issue is the fact that Q_DECL_IMPORT is an
empty macro on most non-Windows compilers in Qt4 (this has been fixed in
Qt5), and the workaround in kolab_export.h was only defined for Linux.

Using a broader #ifdef check does fix the issue, but there is one other
things we can improve: nothing in the code defines MAKE_KOLAB_LIB, so
KOLAB_EXPORT was never set to Q_DECL_EXPORT (which is also likely why
the Q_DECL_IMPORT workaround was added in the first place). We can check
for kolab_EXPORTS instead: it's a macro defined by CMake itself when a
shared library is being built, which is exactly what we want.

The Q_DECL_IMPORT hack is still useful though, as omitting it can cause
problems with dynamic_cast, exceptions and anything that requires a
typeinfo lookup.

Test Plan

Building libkolab's utils/ on FreeBSD works, and so does kdepim-runtime.

Diff Detail

Repository
rLK libkolab
Lint
Lint Skipped
Unit
Unit Tests Skipped
rakuco retitled this revision from to Fix export macros on non-Linux systems.Sep 13 2016, 10:59 AM
rakuco updated this object.
rakuco edited the test plan for this revision. (Show Details)
rakuco added reviewers: mollekopf, vanmeeuwen.
rakuco set the repository for this revision to rLK libkolab.