Fix MinGW cross-build with precompiled headers on Linux

We need localtime_r() in several places. To have this function
declared when including time.h, _POSIX_THREAD_SAFE_FUNCTIONS must be
defined. E.g. qdatetime.cpp includes unistd.h before time.h to define
said macro.

However, this falls apart when precompiled headers are used, because
of the following include chain in qt_pch.h:
qcoreapplication.h -> qobject.h -> chrono -> time.h

This patch ensures that _POSIX_THREAD_SAFE_FUNCTIONS is defined before
including time.h in qt_pch.h by including unistd.h early.

Fixes: QTBUG-76680
Change-Id: I3875072edf37f45492f29d84fc297a9682e11db4
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Joerg Bornemann 2019-07-10 08:16:56 +02:00
parent f4b5fa76d7
commit 605062b21f

View File

@ -55,6 +55,10 @@
#include <stdlib.h>
#include <qglobal.h>
#ifdef Q_OS_WIN
# ifdef Q_CC_MINGW
// <unistd.h> must be included before any other header pulls in <time.h>.
# include <unistd.h> // Define _POSIX_THREAD_SAFE_FUNCTIONS to obtain localtime_r()
# endif
# define _POSIX_
# include <limits.h>
# undef _POSIX_