File indexing completed on 2024-05-12 04:39:39
0001 /* 0002 SPDX-FileCopyrightText: 2010 Patrick Spendrin <ps_ml@gmx.de> 0003 SPDX-FileCopyrightText: 2013 Kevin Funk <kfunk@kde.org> 0004 SPDX-FileCopyrightText: 2014 Sergey Kalinichev <kalinichev.so.0@gmail.com> 0005 0006 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0007 */ 0008 0009 #include "msvccompiler.h" 0010 0011 #include <QDir> 0012 #include <QProcessEnvironment> 0013 0014 #include <KProcess> 0015 0016 #include <debug.h> 0017 0018 using namespace KDevelop; 0019 0020 Defines MsvcCompiler::defines(Utils::LanguageType, const QString&) const 0021 { 0022 Defines ret; 0023 //Get standard macros from kdevmsvcdefinehelpers 0024 KProcess proc; 0025 proc.setOutputChannelMode( KProcess::MergedChannels ); 0026 proc.setTextModeEnabled( true ); 0027 0028 // we want to use kdevmsvcdefinehelper as a pseudo compiler backend which 0029 // returns the defines used in msvc. there is no such thing as -dM with cl.exe 0030 proc << path() << QStringLiteral("/nologo") << QStringLiteral("/Bxkdevmsvcdefinehelper") << QStringLiteral("empty.cpp"); 0031 0032 // this will fail, so check on that as well 0033 if ( proc.execute( 5000 ) == 2 ) { 0034 QString line; 0035 proc.readLine(); // read the filename 0036 0037 while ( proc.canReadLine() ) { 0038 QByteArray buff = proc.readLine(); 0039 qCDebug(DEFINESANDINCLUDES) << "msvcstandardmacros:" << buff; 0040 if ( !buff.isEmpty() ) { 0041 line = QString::fromUtf8(buff); 0042 if ( line.startsWith( QLatin1String("#define ") ) ) { 0043 line = line.midRef(8).trimmed().toString(); 0044 int pos = line.indexOf(QLatin1Char(' ')); 0045 0046 if ( pos != -1 ) { 0047 ret[line.left(pos)] = line.mid(pos + 1); 0048 } else { 0049 ret[line] = QLatin1String(""); 0050 } 0051 } 0052 } 0053 } 0054 } else { 0055 qCDebug(DEFINESANDINCLUDES) << QLatin1String("Unable to read standard c++ macro definitions from ") + path(); 0056 while ( proc.canReadLine() ){ 0057 qCDebug(DEFINESANDINCLUDES) << proc.readLine(); 0058 } 0059 qCDebug(DEFINESANDINCLUDES) << proc.exitCode(); 0060 } 0061 0062 // MSVC builtin attributes 0063 { 0064 ret[QStringLiteral("__cdecl")] = QLatin1String(""); 0065 ret[QStringLiteral("__fastcall")] = QLatin1String(""); 0066 ret[QStringLiteral("__stdcall")] = QLatin1String(""); 0067 ret[QStringLiteral("__thiscall")] = QLatin1String(""); 0068 } 0069 0070 // MSVC builtin types 0071 // see http://msdn.microsoft.com/en-us/library/cc953fe1.aspx 0072 { 0073 ret[QStringLiteral("__int8")] = QStringLiteral("char"); 0074 ret[QStringLiteral("__int16")] = QStringLiteral("short"); 0075 ret[QStringLiteral("__int32")] = QStringLiteral("int"); 0076 ret[QStringLiteral("__int64")] = QStringLiteral("long long"); 0077 ret[QStringLiteral("__int16")] = QStringLiteral("short"); 0078 ret[QStringLiteral("__ptr32")] = QLatin1String(""); 0079 ret[QStringLiteral("__ptr64")] = QLatin1String(""); 0080 } 0081 0082 // MSVC specific modifiers 0083 // see http://msdn.microsoft.com/en-us/library/vstudio/s04b5w00.aspx 0084 { 0085 ret[QStringLiteral("__sptr")] = QLatin1String(""); 0086 ret[QStringLiteral("__uptr")] = QLatin1String(""); 0087 ret[QStringLiteral("__unaligned")] = QLatin1String(""); 0088 ret[QStringLiteral("__w64")] = QLatin1String(""); 0089 } 0090 0091 // MSVC function specifiers 0092 // see http://msdn.microsoft.com/de-de/library/z8y1yy88.aspx 0093 { 0094 ret[QStringLiteral("__inline")] = QLatin1String(""); 0095 ret[QStringLiteral("__forceinline")] = QLatin1String(""); 0096 } 0097 0098 return ret; 0099 } 0100 0101 Path::List MsvcCompiler::includes(Utils::LanguageType, const QString&) const 0102 { 0103 const QStringList _includePaths = QProcessEnvironment::systemEnvironment() 0104 .value(QStringLiteral("INCLUDE")) 0105 .split(QLatin1Char(';'), Qt::SkipEmptyParts); 0106 Path::List includePaths; 0107 includePaths.reserve(_includePaths.size()); 0108 for (const QString& include : _includePaths) { 0109 includePaths.append( Path( QDir::fromNativeSeparators( include ) ) ); 0110 } 0111 return includePaths; 0112 } 0113 0114 MsvcCompiler::MsvcCompiler(const QString& name, const QString& path, bool editable, const QString& factoryName): 0115 ICompiler(name, path, factoryName, editable) 0116 {}