Commit 8a6255d2 authored by Thiago Macieira's avatar Thiago Macieira Committed by Oswald Buddenhagen
Browse files

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: default avatarOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
(cherry picked from qtbase/d7795559a7b80d3ec0a1eb86d29deaca6074f4ed)
parent e5616a80
......@@ -55,6 +55,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
......@@ -67,6 +70,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)
......@@ -960,6 +996,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");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment