-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystempaths.cpp
More file actions
100 lines (87 loc) · 3.08 KB
/
systempaths.cpp
File metadata and controls
100 lines (87 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "systempaths.h"
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QSettings>
#if defined(Q_OS_MAC)
#include <sys/sysctl.h>
#include <mach/machine.h>
#endif
QDir SystemPaths::scriptDir()
{
//return QDir(QCoreApplication::applicationDirPath() + "/scripts/").absolutePath();
#if defined(Q_OS_MAC)
return QDir(QCoreApplication::applicationDirPath() + "/../Resources/share/scripts/");
#else
return QDir::cleanPath(QCoreApplication::applicationDirPath() + QString("/../" DATA_PREFIX "/./scripts/"));
#if !defined(DATA_PREFIX)
#error DATA_PREFIX not defined
#endif
#endif
}
QString SystemPaths::script(QString name)
{
return QDir::toNativeSeparators(scriptDir().filePath(name));
}
QString SystemPaths::nwchemBinDefault()
{
return QStringLiteral("mpirun nwchem");
}
QString SystemPaths::nwchemBin()
{
QString command = QSettings().value("NWChemPath").toString();
if (command.isEmpty())
return nwchemBinDefault();
return command;
}
QProcessEnvironment SystemPaths::setupNWChemEnvironment()
{
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
#if defined(Q_OS_MAC)
env.insert("NWCHEM_BASIS_LIBRARY", QCoreApplication::applicationDirPath() + "/../Resources/share/nwchem/libraries/");
env.insert("OMP_NUM_THREADS", "1");
#endif
return env;
}
void SystemPaths::setupEnviroment()
{
#if defined(Q_OS_MAC)
// Detect ARM/x86
// https://stackoverflow.com/questions/63214720/determine-cpu-type-architecture-in-macos
bool isARM = false;
{
uint32_t cputype = 0;
size_t size = sizeof (cputype);
if(0 == sysctlbyname ("hw.cputype", &cputype, &size, NULL, 0))
{
isARM = (cputype & 0xFF) == CPU_TYPE_ARM;
}
else
{
qWarning() << "Error detecting CPU type, defaulting to x86";
}
qDebug() << "CPU type:" << (isARM ? "ARM" : "x86");
}
QByteArray path = qgetenv("PATH");
QDir prefixDir;
QDir binDir;
QDir babelLibDir;
if (isARM)
{
prefixDir = QDir(QCoreApplication::applicationDirPath() + "/../Resources/arm/");
binDir = QDir(QCoreApplication::applicationDirPath() + "/../Resources/arm/bin/");
babelLibDir = QDir(QCoreApplication::applicationDirPath() + "/../Resources/arm/lib/openbabel/3.1.0/");
}
else
{
prefixDir = QDir(QCoreApplication::applicationDirPath() + "/../Resources/x86/");
binDir = QDir(QCoreApplication::applicationDirPath() + "/../Resources/x86/bin/");
babelLibDir = QDir(QCoreApplication::applicationDirPath() + "/../Resources/x86/lib/openbabel/3.1.0/");
}
QDir babelDataDir = QDir(QCoreApplication::applicationDirPath() + "/../Resources/share/openbabel/3.1.0/");
qputenv("OPAL_PREFIX", QDir::toNativeSeparators(prefixDir.absolutePath()).toUtf8());
qputenv("BABEL_LIBDIR", QDir::toNativeSeparators(babelLibDir.absolutePath()).toUtf8());
qputenv("BABEL_DATADIR", QDir::toNativeSeparators(babelDataDir.absolutePath()).toUtf8());
qputenv("PATH", QDir::toNativeSeparators(binDir.absolutePath()).toUtf8() + ":" + path);
#endif
}