2016-01-15 14:58:39 +01:00
|
|
|
/****************************************************************************
|
2013-01-15 13:58:06 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-01-15 13:58:06 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2013-01-15 13:58:06 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2013-01-15 13:58:06 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "hostosinfo.h"
|
|
|
|
|
|
2017-08-18 14:32:39 +02:00
|
|
|
#include <QCoreApplication>
|
|
|
|
|
|
|
|
|
|
#if !defined(QT_NO_OPENGL) && defined(QT_GUI_LIB)
|
2015-09-29 16:43:42 +02:00
|
|
|
#include <QOpenGLContext>
|
2017-08-18 14:32:39 +02:00
|
|
|
#endif
|
2015-09-29 16:43:42 +02:00
|
|
|
|
2013-01-15 13:58:06 +01:00
|
|
|
#ifdef Q_OS_WIN
|
2013-08-12 15:09:57 +02:00
|
|
|
#include <qt_windows.h>
|
2013-01-17 11:56:39 +01:00
|
|
|
#endif
|
2013-01-15 13:58:06 +01:00
|
|
|
|
Add workarounds for running under Rosetta on macOS
When Qt Creator is built as an Intel binary, and runs on
an Apple Silicon (ARM) Mac, it will be run via the Rosetta
translation layer. This means any process spawned by QtC,
including qmake, CMake, and lldb, will launch as x86_64
binaries as well.
For qmake and CMake, this affects their default choice of
build architecture, resulting in x86_64 builds of user
applications. We want to produce native arm64 apps, even
if Qt Creator itself isn't one, so we explicitly detect
the situation, and if Qt has an arm64 slice, we default
to arm64 builds.
The logic of adding CONFIG+=x86_64 to the qmake step has
been disabled, as the assumption that a single qmake run
and build will produce only a single architecture does no
longer hold. The corresponding logic in Qt was removed
in 2015 (qtbase f58e95f098c8d78a5f2db7729606126fe093cbdf).
In the case of lldb, running it as an x86_64 binary fails
to attach to the running application. We work around this
by using the 'arch' tool to explicitly launch it as an
arm64 binary. This works for debugging both arm64 and
x86_64 applications.
Change-Id: I65cc0f600223990f25c76cef18d927895e551260
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2021-06-22 00:11:58 +02:00
|
|
|
#ifdef Q_OS_MACOS
|
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-01-15 13:58:06 +01:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2015-08-12 16:01:19 +02:00
|
|
|
Qt::CaseSensitivity HostOsInfo::m_overrideFileNameCaseSensitivity = Qt::CaseSensitive;
|
|
|
|
|
bool HostOsInfo::m_useOverrideFileNameCaseSensitivity = false;
|
|
|
|
|
|
2013-01-17 11:56:39 +01:00
|
|
|
#ifdef Q_OS_WIN
|
2015-07-22 23:32:12 +03:00
|
|
|
static WORD hostProcessorArchitecture()
|
|
|
|
|
{
|
2013-01-15 13:58:06 +01:00
|
|
|
SYSTEM_INFO info;
|
|
|
|
|
GetNativeSystemInfo(&info);
|
2015-07-22 23:32:12 +03:00
|
|
|
return info.wProcessorArchitecture;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
HostOsInfo::HostArchitecture HostOsInfo::hostArchitecture()
|
|
|
|
|
{
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
static const WORD processorArchitecture = hostProcessorArchitecture();
|
|
|
|
|
switch (processorArchitecture) {
|
2013-01-15 13:58:06 +01:00
|
|
|
case PROCESSOR_ARCHITECTURE_AMD64:
|
|
|
|
|
return HostOsInfo::HostArchitectureAMD64;
|
|
|
|
|
case PROCESSOR_ARCHITECTURE_INTEL:
|
|
|
|
|
return HostOsInfo::HostArchitectureX86;
|
|
|
|
|
case PROCESSOR_ARCHITECTURE_IA64:
|
|
|
|
|
return HostOsInfo::HostArchitectureItanium;
|
|
|
|
|
case PROCESSOR_ARCHITECTURE_ARM:
|
2022-05-23 18:55:37 +02:00
|
|
|
case PROCESSOR_ARCHITECTURE_ARM64:
|
2013-01-15 13:58:06 +01:00
|
|
|
return HostOsInfo::HostArchitectureArm;
|
|
|
|
|
default:
|
2013-01-17 13:41:12 +01:00
|
|
|
return HostOsInfo::HostArchitectureUnknown;
|
2013-01-15 13:58:06 +01:00
|
|
|
}
|
2013-01-17 11:56:39 +01:00
|
|
|
#else
|
|
|
|
|
return HostOsInfo::HostArchitectureUnknown;
|
2013-01-15 13:58:06 +01:00
|
|
|
#endif
|
2013-01-17 11:56:39 +01:00
|
|
|
}
|
2015-08-12 16:01:19 +02:00
|
|
|
|
Add workarounds for running under Rosetta on macOS
When Qt Creator is built as an Intel binary, and runs on
an Apple Silicon (ARM) Mac, it will be run via the Rosetta
translation layer. This means any process spawned by QtC,
including qmake, CMake, and lldb, will launch as x86_64
binaries as well.
For qmake and CMake, this affects their default choice of
build architecture, resulting in x86_64 builds of user
applications. We want to produce native arm64 apps, even
if Qt Creator itself isn't one, so we explicitly detect
the situation, and if Qt has an arm64 slice, we default
to arm64 builds.
The logic of adding CONFIG+=x86_64 to the qmake step has
been disabled, as the assumption that a single qmake run
and build will produce only a single architecture does no
longer hold. The corresponding logic in Qt was removed
in 2015 (qtbase f58e95f098c8d78a5f2db7729606126fe093cbdf).
In the case of lldb, running it as an x86_64 binary fails
to attach to the running application. We work around this
by using the 'arch' tool to explicitly launch it as an
arm64 binary. This works for debugging both arm64 and
x86_64 applications.
Change-Id: I65cc0f600223990f25c76cef18d927895e551260
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2021-06-22 00:11:58 +02:00
|
|
|
bool HostOsInfo::isRunningUnderRosetta()
|
|
|
|
|
{
|
|
|
|
|
#ifdef Q_OS_MACOS
|
|
|
|
|
int translated = 0;
|
|
|
|
|
auto size = sizeof(translated);
|
|
|
|
|
if (sysctlbyname("sysctl.proc_translated", &translated, &size, nullptr, 0) == 0)
|
|
|
|
|
return translated;
|
|
|
|
|
#endif
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-12 16:01:19 +02:00
|
|
|
void HostOsInfo::setOverrideFileNameCaseSensitivity(Qt::CaseSensitivity sensitivity)
|
|
|
|
|
{
|
|
|
|
|
m_useOverrideFileNameCaseSensitivity = true;
|
|
|
|
|
m_overrideFileNameCaseSensitivity = sensitivity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HostOsInfo::unsetOverrideFileNameCaseSensitivity()
|
|
|
|
|
{
|
|
|
|
|
m_useOverrideFileNameCaseSensitivity = false;
|
|
|
|
|
}
|
2015-09-29 16:43:42 +02:00
|
|
|
|
|
|
|
|
bool HostOsInfo::canCreateOpenGLContext(QString *errorMessage)
|
|
|
|
|
{
|
2017-08-18 14:32:39 +02:00
|
|
|
#if defined(QT_NO_OPENGL) || !defined(QT_GUI_LIB)
|
2017-02-10 21:50:37 +01:00
|
|
|
Q_UNUSED(errorMessage)
|
|
|
|
|
return false;
|
|
|
|
|
#else
|
2015-09-29 16:43:42 +02:00
|
|
|
static const bool canCreate = QOpenGLContext().create();
|
|
|
|
|
if (!canCreate)
|
2017-08-18 14:32:39 +02:00
|
|
|
*errorMessage = QCoreApplication::translate("Utils::HostOsInfo",
|
|
|
|
|
"Cannot create OpenGL context.");
|
2015-09-29 16:43:42 +02:00
|
|
|
return canCreate;
|
2017-02-10 21:50:37 +01:00
|
|
|
#endif
|
2015-09-29 16:43:42 +02:00
|
|
|
}
|