Let qmake find the number of processors online
Instead of trying to load in ltcg.prf and cache the value. Change-Id: If485ff68fc6ff9d9cf7009cd72d5e702d0199c7f Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
This commit is contained in:
parent
62b752b3a2
commit
d7795559a7
@ -15,16 +15,10 @@ CONFIG(release, debug|release) {
|
||||
QMAKE_CFLAGS_LTCG += -fno-fat-lto-objects
|
||||
QMAKE_CXXFLAGS_LTCG += -fno-fat-lto-objects
|
||||
}
|
||||
linux {
|
||||
# Get the number of online processors, like _SC_NPROCESSORS_ONLN
|
||||
isEmpty(QMAKE_NPROCESSORS_ONLN) {
|
||||
QMAKE_NPROCESSORS_ONLN = $$system("grep -c '^processor' /proc/cpuinfo 2>/dev/null || echo 1")
|
||||
cache(QMAKE_NPROCESSORS_ONLN, set stash)
|
||||
}
|
||||
|
||||
greaterThan(QMAKE_HOST.cpu_count, 1) {
|
||||
# Override LTO number of jobs
|
||||
QMAKE_LFLAGS_LTCG -= -flto
|
||||
QMAKE_LFLAGS_LTCG += -flto=$$QMAKE_NPROCESSORS_ONLN
|
||||
QMAKE_LFLAGS_LTCG += -flto=$$QMAKE_HOST.cpu_count
|
||||
}
|
||||
} else: static {
|
||||
QMAKE_CFLAGS_LTCG =
|
||||
|
@ -58,6 +58,9 @@
|
||||
#ifdef Q_OS_UNIX
|
||||
#include <unistd.h>
|
||||
#include <sys/utsname.h>
|
||||
# ifdef Q_OS_BSD4
|
||||
# include <sys/sysctl.h>
|
||||
# endif
|
||||
#else
|
||||
#include <windows.h>
|
||||
#endif
|
||||
@ -70,6 +73,39 @@ QT_BEGIN_NAMESPACE
|
||||
|
||||
#define fL1S(s) QString::fromLatin1(s)
|
||||
|
||||
// we can't use QThread in qmake
|
||||
// this function is a merger of QThread::idealThreadCount from qthread_win.cpp and qthread_unix.cpp
|
||||
static int idealThreadCount()
|
||||
{
|
||||
#ifdef PROEVALUATOR_THREAD_SAFE
|
||||
return QThread::idealThreadCount();
|
||||
#elif defined(Q_OS_WIN)
|
||||
SYSTEM_INFO sysinfo;
|
||||
GetSystemInfo(&sysinfo);
|
||||
return sysinfo.dwNumberOfProcessors;
|
||||
#else
|
||||
// there are a couple more definitions in the Unix QThread::idealThreadCount, but
|
||||
// we don't need them all here
|
||||
int cores = 1;
|
||||
# if defined(Q_OS_BSD4)
|
||||
// FreeBSD, OpenBSD, NetBSD, BSD/OS, Mac OS X
|
||||
size_t len = sizeof(cores);
|
||||
int mib[2];
|
||||
mib[0] = CTL_HW;
|
||||
mib[1] = HW_NCPU;
|
||||
if (sysctl(mib, 2, &cores, &len, NULL, 0) != 0) {
|
||||
perror("sysctl");
|
||||
}
|
||||
# elif defined(_SC_NPROCESSORS_ONLN)
|
||||
// the rest: Linux, Solaris, AIX, Tru64
|
||||
cores = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
||||
if (cores == -1)
|
||||
return 1;
|
||||
# endif
|
||||
return cores;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
QMakeBaseKey::QMakeBaseKey(const QString &_root, const QString &_stash, bool _hostBuild)
|
||||
: root(_root), stash(_stash), hostBuild(_hostBuild)
|
||||
@ -955,6 +991,7 @@ void QMakeEvaluator::loadDefaults()
|
||||
vars[ProKey("QMAKE_QMAKE")] << ProString(m_option->qmake_abslocation);
|
||||
if (!m_option->qmake_args.isEmpty())
|
||||
vars[ProKey("QMAKE_ARGS")] = ProStringList(m_option->qmake_args);
|
||||
vars[ProKey("QMAKE_HOST.cpu_count")] = ProString(QString::number(idealThreadCount()));
|
||||
#if defined(Q_OS_WIN32)
|
||||
vars[ProKey("QMAKE_HOST.os")] << ProString("Windows");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user