logic: added include path detector for visual studio
This commit is contained in:
@@ -117,8 +117,8 @@ void QtProjectWizzardContentPaths::setHelpString(const QString& help)
|
||||
void QtProjectWizzardContentPaths::addDetection(QString name, QGridLayout* layout, int row)
|
||||
{
|
||||
StandardHeaderDetection detection;
|
||||
std::vector<std::string> compilers = detection.getDetectedCompilers();
|
||||
if (!compilers.size())
|
||||
std::vector<std::string> detectorNames = detection.getWorkingDetectorNames();
|
||||
if (!detectorNames.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -127,9 +127,9 @@ void QtProjectWizzardContentPaths::addDetection(QString name, QGridLayout* layou
|
||||
|
||||
m_detectorBox = new QComboBox();
|
||||
|
||||
for (const std::string& compiler : compilers)
|
||||
for (const std::string& detectorName: detectorNames)
|
||||
{
|
||||
m_detectorBox->addItem(compiler.c_str());
|
||||
m_detectorBox->addItem(detectorName.c_str());
|
||||
}
|
||||
|
||||
QPushButton* button = new QPushButton("detect");
|
||||
|
||||
@@ -12,25 +12,6 @@ CompilerDetector::~CompilerDetector()
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<std::string> CompilerDetector::getHeaderPaths()
|
||||
{
|
||||
std::string command = m_name + " -x c++ -v -E /dev/null";
|
||||
std::string clangOutput = utility::executeProcess(command.c_str());
|
||||
std::string standardHeaders =
|
||||
utility::substrBetween(clangOutput, "#include <...> search starts here:\n","\nEnd of search list");
|
||||
std::vector<std::string> paths;
|
||||
|
||||
if (!standardHeaders.empty())
|
||||
{
|
||||
for (std::string s : utility::splitToVector(standardHeaders, '\n'))
|
||||
{
|
||||
paths.push_back(utility::trim(s));
|
||||
}
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
std::vector<FilePath> CompilerDetector::getStandardHeaderPaths()
|
||||
{
|
||||
std::vector<std::string> paths = getHeaderPaths();
|
||||
@@ -60,3 +41,22 @@ std::vector<FilePath> CompilerDetector::getStandardFrameworkPaths()
|
||||
|
||||
return frameworkPaths;
|
||||
}
|
||||
|
||||
std::vector<std::string> CompilerDetector::getHeaderPaths()
|
||||
{
|
||||
std::string command = m_name + " -x c++ -v -E /dev/null";
|
||||
std::string clangOutput = utility::executeProcess(command.c_str());
|
||||
std::string standardHeaders =
|
||||
utility::substrBetween(clangOutput, "#include <...> search starts here:\n","\nEnd of search list");
|
||||
std::vector<std::string> paths;
|
||||
|
||||
if (!standardHeaders.empty())
|
||||
{
|
||||
for (std::string s : utility::splitToVector(standardHeaders, '\n'))
|
||||
{
|
||||
paths.push_back(utility::trim(s));
|
||||
}
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
@@ -11,10 +11,11 @@ public:
|
||||
|
||||
virtual ~CompilerDetector();
|
||||
|
||||
std::vector<std::string> getHeaderPaths();
|
||||
|
||||
virtual std::vector<FilePath> getStandardHeaderPaths();
|
||||
virtual std::vector<FilePath> getStandardFrameworkPaths();
|
||||
|
||||
private:
|
||||
std::vector<std::string> getHeaderPaths();
|
||||
};
|
||||
|
||||
#endif // COMPILER_DETECTOR_H
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
#include "utility/headerSearch/DetectorBase.h"
|
||||
|
||||
DetectorBase::DetectorBase(const std::string name)
|
||||
: m_name(name)
|
||||
{
|
||||
setName(name);
|
||||
}
|
||||
|
||||
bool DetectorBase::detect()
|
||||
DetectorBase::~DetectorBase()
|
||||
{
|
||||
return !getStandardHeaderPaths().empty();
|
||||
}
|
||||
|
||||
std::vector<FilePath> DetectorBase::getStandardFrameworkPaths()
|
||||
{
|
||||
return std::vector<FilePath>();
|
||||
}
|
||||
|
||||
std::string DetectorBase::getName() const
|
||||
@@ -20,10 +14,7 @@ std::string DetectorBase::getName() const
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void DetectorBase::setName(const std::string& name)
|
||||
bool DetectorBase::isWorking()
|
||||
{
|
||||
if (!name.empty())
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
return !getStandardHeaderPaths().empty();
|
||||
}
|
||||
|
||||
@@ -9,12 +9,14 @@ class DetectorBase
|
||||
{
|
||||
public:
|
||||
DetectorBase(const std::string name);
|
||||
virtual ~DetectorBase(){};
|
||||
virtual bool detect();
|
||||
virtual ~DetectorBase();
|
||||
|
||||
std::string getName() const;
|
||||
bool isWorking();
|
||||
|
||||
virtual std::vector<FilePath> getStandardHeaderPaths() = 0;
|
||||
virtual std::vector<FilePath> getStandardFrameworkPaths();
|
||||
virtual std::string getName() const;
|
||||
virtual void setName(const std::string& name);
|
||||
virtual std::vector<FilePath> getStandardFrameworkPaths() = 0;
|
||||
|
||||
protected:
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
@@ -2,20 +2,14 @@
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/headerSearch/CompilerDetector.h"
|
||||
#include "utility/headerSearch/VisualStudioDetector.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/utilityApp.h"
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
StandardHeaderDetection::DetectorMap StandardHeaderDetection::s_availableDetectors;
|
||||
StandardHeaderDetection::DetectorMap StandardHeaderDetection::s_detectedCompilers;
|
||||
StandardHeaderDetection::DetectorMap StandardHeaderDetection::s_workingDetectors;
|
||||
|
||||
StandardHeaderDetection::StandardHeaderDetection()
|
||||
{
|
||||
@@ -23,11 +17,14 @@ StandardHeaderDetection::StandardHeaderDetection()
|
||||
{
|
||||
addDetector(std::make_shared<CompilerDetector>("gcc"));
|
||||
addDetector(std::make_shared<CompilerDetector>("clang"));
|
||||
|
||||
addDetector(std::make_shared<VisualStudioDetector>("14"));
|
||||
addDetector(std::make_shared<VisualStudioDetector>("12"));
|
||||
addDetector(std::make_shared<VisualStudioDetector>("11"));
|
||||
addDetector(std::make_shared<VisualStudioDetector>("9"));
|
||||
addDetector(std::make_shared<VisualStudioDetector>("Visual Studio 2010", 9, false));
|
||||
addDetector(std::make_shared<VisualStudioDetector>("Visual Studio 2010 Express", 9, true));
|
||||
addDetector(std::make_shared<VisualStudioDetector>("Visual Studio 2012", 11, false));
|
||||
addDetector(std::make_shared<VisualStudioDetector>("Visual Studio 2012 Express", 11, true));
|
||||
addDetector(std::make_shared<VisualStudioDetector>("Visual Studio 2013", 12, false));
|
||||
addDetector(std::make_shared<VisualStudioDetector>("Visual Studio 2013 Express", 12, true));
|
||||
addDetector(std::make_shared<VisualStudioDetector>("Visual Studio 2015", 14, false));
|
||||
addDetector(std::make_shared<VisualStudioDetector>("Visual Studio 2015 Express", 14, true));
|
||||
|
||||
detectHeaders();
|
||||
}
|
||||
@@ -44,63 +41,62 @@ void StandardHeaderDetection::addDetector(std::shared_ptr<DetectorBase> detector
|
||||
|
||||
void StandardHeaderDetection::detectHeaders()
|
||||
{
|
||||
for ( DetectorPair detector : s_availableDetectors)
|
||||
for (DetectorPair detector: s_availableDetectors)
|
||||
{
|
||||
if ( detector.second->detect() )
|
||||
if (detector.second->isWorking())
|
||||
{
|
||||
s_detectedCompilers.insert(detector);
|
||||
s_workingDetectors.insert(detector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> StandardHeaderDetection::getDetectedCompilers()
|
||||
std::vector<std::string> StandardHeaderDetection::getWorkingDetectorNames()
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
for ( DetectorPair detector : s_detectedCompilers)
|
||||
std::vector<std::string> detectorNames;
|
||||
for (DetectorPair detector: s_workingDetectors)
|
||||
{
|
||||
v.push_back(detector.first);
|
||||
detectorNames.push_back(detector.first);
|
||||
}
|
||||
return v;
|
||||
return detectorNames;
|
||||
}
|
||||
|
||||
std::vector<FilePath> StandardHeaderDetection::getStandardHeaderPaths(std::string compiler)
|
||||
std::vector<FilePath> StandardHeaderDetection::getStandardHeaderPaths(std::string detectorName)
|
||||
{
|
||||
auto it = s_detectedCompilers.find(compiler);
|
||||
if (it != s_detectedCompilers.end())
|
||||
DetectorMap::const_iterator it = s_workingDetectors.find(detectorName);
|
||||
if (it != s_workingDetectors.end())
|
||||
{
|
||||
return it->second->getStandardHeaderPaths();
|
||||
}
|
||||
return std::vector<FilePath>();
|
||||
}
|
||||
|
||||
std::vector<FilePath> StandardHeaderDetection::getStandardFrameworkPaths(std::string compiler)
|
||||
std::vector<FilePath> StandardHeaderDetection::getStandardFrameworkPaths(std::string detectorName)
|
||||
{
|
||||
auto it = s_detectedCompilers.find(compiler);
|
||||
if (it != s_detectedCompilers.end())
|
||||
DetectorMap::const_iterator it = s_workingDetectors.find(detectorName);
|
||||
if (it != s_workingDetectors.end())
|
||||
{
|
||||
return it->second->getStandardFrameworkPaths();
|
||||
}
|
||||
return std::vector<FilePath>();
|
||||
}
|
||||
|
||||
void StandardHeaderDetection::printDetectedCompilers()
|
||||
void StandardHeaderDetection::logAvailableDetectors()
|
||||
{
|
||||
std::cout << "Detected Compilers: " << std::endl;
|
||||
LOG_INFO("Available Header Detectors:");
|
||||
|
||||
std::vector<std::string> compilers = getDetectedCompilers();
|
||||
for ( std::string compiler : compilers)
|
||||
for (DetectorPair detector: s_availableDetectors)
|
||||
{
|
||||
std::cout << compiler << std::endl;
|
||||
LOG_INFO("Detector: " + detector.first);
|
||||
}
|
||||
}
|
||||
|
||||
void StandardHeaderDetection::printAvailableDetectors()
|
||||
void StandardHeaderDetection::logWorkingDetectors()
|
||||
{
|
||||
std::cout << "Available Detectors: " << std::endl;
|
||||
LOG_INFO("Working Header Detectors:");
|
||||
|
||||
for ( DetectorPair detector : s_availableDetectors)
|
||||
for (std::string detectorName: getWorkingDetectorNames())
|
||||
{
|
||||
std::cout << detector.first << std::endl;
|
||||
LOG_INFO("Detector: " + detectorName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/headerSearch/DetectorBase.h"
|
||||
|
||||
@@ -21,23 +21,22 @@ public:
|
||||
/// Checks all availabe detectors and saves found Compilers
|
||||
void detectHeaders();
|
||||
|
||||
/// Returns alls found compilers
|
||||
std::vector<std::string> getDetectedCompilers();
|
||||
std::vector<std::string> getWorkingDetectorNames();
|
||||
|
||||
/// Returns the headerpaths from a found compiler
|
||||
std::vector<FilePath> getStandardHeaderPaths(std::string compiler);
|
||||
std::vector<FilePath> getStandardFrameworkPaths(std::string compiler);
|
||||
std::vector<FilePath> getStandardHeaderPaths(std::string detectorName);
|
||||
std::vector<FilePath> getStandardFrameworkPaths(std::string detectorName);
|
||||
|
||||
/// Debugging Output
|
||||
void printAvailableDetectors();
|
||||
void printDetectedCompilers();
|
||||
void logAvailableDetectors();
|
||||
void logWorkingDetectors();
|
||||
|
||||
private:
|
||||
typedef std::map<std::string, std::shared_ptr<DetectorBase>> DetectorMap;
|
||||
typedef std::pair<std::string, std::shared_ptr<DetectorBase>> DetectorPair;
|
||||
|
||||
static DetectorMap s_availableDetectors;
|
||||
static DetectorMap s_detectedCompilers;
|
||||
static DetectorMap s_workingDetectors;
|
||||
};
|
||||
|
||||
#endif // STANDARD_HEADER_DETECTION_H
|
||||
|
||||
@@ -4,93 +4,94 @@
|
||||
|
||||
#include <QSettings>
|
||||
#include <QSysInfo>
|
||||
#include <QDir>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
VisualStudioDetector::VisualStudioDetector(const std::string name)
|
||||
: DetectorBase("")
|
||||
, m_isExpress(false)
|
||||
VisualStudioDetector::VisualStudioDetector(const std::string name, int version, bool isExpress)
|
||||
: DetectorBase(name)
|
||||
, m_version(version)
|
||||
, m_isExpress(isExpress)
|
||||
{
|
||||
setName(name);
|
||||
}
|
||||
|
||||
VisualStudioDetector::~VisualStudioDetector()
|
||||
{
|
||||
}
|
||||
|
||||
void VisualStudioDetector::setName(const std::string& version)
|
||||
{
|
||||
m_versionNumber = std::stoi(version);
|
||||
if (m_versionNumber > 8 && m_versionNumber < 15)
|
||||
{
|
||||
DetectorBase::setName("VS" + version + "0");
|
||||
}
|
||||
else
|
||||
{
|
||||
// unsupported Visual Studio version
|
||||
}
|
||||
}
|
||||
|
||||
std::string VisualStudioDetector::getFullName()
|
||||
{
|
||||
return "Visual Studio " + std::to_string(m_versionNumber + 1) + (m_isExpress ? " Express" : "");
|
||||
}
|
||||
|
||||
std::vector<FilePath> VisualStudioDetector::getStandardHeaderPaths()
|
||||
{
|
||||
std::vector<FilePath> headerPaths;
|
||||
FilePath vsInstallPath = getVsInstallPathUsingRegistry();
|
||||
|
||||
// vc++ headers
|
||||
if ( !getStanardHeaderPathsUsingEnvironmentVariable(headerPaths) )
|
||||
std::vector<FilePath> headerPaths;
|
||||
if (vsInstallPath.exists())
|
||||
{
|
||||
if ( !getStanardHeaderPathsUsingRegistry(headerPaths) )
|
||||
std::vector<std::string> subdirectories;
|
||||
subdirectories.push_back("vc/include");
|
||||
subdirectories.push_back("vc/atlmfc/include");
|
||||
|
||||
for (size_t i = 0; i < subdirectories.size(); i++)
|
||||
{
|
||||
if ( !getStanardHeaderPathsUsingRegistry(headerPaths, true) )
|
||||
FilePath headerSearchPath = vsInstallPath.concat(subdirectories[i]);
|
||||
if (headerSearchPath.exists())
|
||||
{
|
||||
return headerPaths;
|
||||
headerPaths.push_back(headerSearchPath.canonical().str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//windows sdk
|
||||
//TODO
|
||||
if (headerPaths.size() > 0)
|
||||
{
|
||||
//windows sdk
|
||||
std::vector<std::string> windowsSdkVersions;
|
||||
windowsSdkVersions.push_back("v8.1A");
|
||||
windowsSdkVersions.push_back("v8.0A");
|
||||
windowsSdkVersions.push_back("v7.1A");
|
||||
windowsSdkVersions.push_back("v7.0A");
|
||||
|
||||
for (size_t i = 0; i < windowsSdkVersions.size(); i++)
|
||||
{
|
||||
FilePath sdkPath = getWindowsSdkPathUsingRegistry(windowsSdkVersions[i]);
|
||||
if (sdkPath.exists())
|
||||
{
|
||||
FilePath sdkIncludePath = sdkPath.concat("include/");
|
||||
if (sdkIncludePath.exists())
|
||||
{
|
||||
std::vector<std::string> subdirectories;
|
||||
subdirectories.push_back("shared");
|
||||
subdirectories.push_back("um");
|
||||
subdirectories.push_back("winrt");
|
||||
|
||||
bool usingSubdirectories = false;
|
||||
for (size_t j = 0; j < subdirectories.size(); j++)
|
||||
{
|
||||
FilePath sdkSubdirectory = sdkPath.concat(subdirectories[j]);
|
||||
if (sdkSubdirectory.exists())
|
||||
{
|
||||
headerPaths.push_back(sdkSubdirectory);
|
||||
usingSubdirectories = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!usingSubdirectories)
|
||||
{
|
||||
headerPaths.push_back(sdkIncludePath);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return headerPaths;
|
||||
}
|
||||
|
||||
std::string getInstallDir(const std::string RegistryKey)
|
||||
std::vector<FilePath> VisualStudioDetector::getStandardFrameworkPaths()
|
||||
{
|
||||
return "";
|
||||
return std::vector<FilePath>();
|
||||
}
|
||||
|
||||
std::string getWindowsSDKDir()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
bool VisualStudioDetector::getStanardHeaderPathsUsingEnvironmentVariable(std::vector<FilePath>& paths)
|
||||
{
|
||||
std::string VSToolstring = m_name + "comntools";
|
||||
std::vector<FilePath> path;
|
||||
|
||||
if ( const char* vs_env = std::getenv(VSToolstring.c_str()))
|
||||
{
|
||||
FilePath VSHeaderpath(vs_env);
|
||||
VSHeaderpath = VSHeaderpath.concat("../vc/include");
|
||||
if (VSHeaderpath.exists())
|
||||
{
|
||||
LOG_INFO_STREAM(<< getFullName() << " includes detected");
|
||||
path.push_back(VSHeaderpath.str());
|
||||
paths = std::move(path);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VisualStudioDetector::getStanardHeaderPathsUsingRegistry(std::vector<FilePath>& paths, bool lookForExpressVersion)
|
||||
FilePath VisualStudioDetector::getVsInstallPathUsingRegistry()
|
||||
{
|
||||
QString key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\";
|
||||
if (QSysInfo::currentCpuArchitecture() == "x86_64")
|
||||
@@ -98,20 +99,33 @@ bool VisualStudioDetector::getStanardHeaderPathsUsingRegistry(std::vector<FilePa
|
||||
key += "Wow6432Node\\";
|
||||
}
|
||||
key += "Microsoft\\";
|
||||
key += ( lookForExpressVersion ? "VCExpress" : "VisualStudio" );
|
||||
key += "\\" + QString::number(m_versionNumber) + ".0";
|
||||
key += (m_isExpress ? "VCExpress" : "VisualStudio");
|
||||
key += "\\" + QString::number(m_version) + ".0";
|
||||
|
||||
QSettings expressKey(key, QSettings::NativeFormat);
|
||||
QString value = expressKey.value("InstallDir").toString() + "../VC/include";
|
||||
QDir dir(value);
|
||||
if ( dir.exists())
|
||||
QSettings expressKey(key, QSettings::NativeFormat); // NativeFormat means from Registry on Windows.
|
||||
QString value = expressKey.value("InstallDir").toString() + "../../";
|
||||
|
||||
FilePath path(value.toStdString());
|
||||
if (path.exists())
|
||||
{
|
||||
if ( lookForExpressVersion )
|
||||
{
|
||||
m_isExpress = true;
|
||||
}
|
||||
return true;
|
||||
return path;
|
||||
}
|
||||
|
||||
return false;
|
||||
return FilePath();
|
||||
}
|
||||
|
||||
FilePath VisualStudioDetector::getWindowsSdkPathUsingRegistry(const std::string& version)
|
||||
{
|
||||
QString key(("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\" + version).c_str());
|
||||
|
||||
QSettings expressKey(key, QSettings::NativeFormat); // NativeFormat means from Registry on Windows.
|
||||
QString value = expressKey.value("InstallationFolder").toString();
|
||||
|
||||
FilePath path(value.toStdString());
|
||||
if (path.exists())
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
return FilePath();
|
||||
}
|
||||
|
||||
@@ -7,19 +7,20 @@
|
||||
|
||||
class FilePath;
|
||||
|
||||
class VisualStudioDetector : public DetectorBase
|
||||
class VisualStudioDetector: public DetectorBase
|
||||
{
|
||||
public:
|
||||
VisualStudioDetector(const std::string name = "14");
|
||||
VisualStudioDetector(const std::string name, int version, bool isExpress);
|
||||
virtual ~VisualStudioDetector();
|
||||
virtual std::vector<FilePath> getStandardHeaderPaths();
|
||||
private:
|
||||
std::string getFullName();
|
||||
bool getStanardHeaderPathsUsingEnvironmentVariable(std::vector<FilePath>& paths);
|
||||
bool getStanardHeaderPathsUsingRegistry(std::vector<FilePath>& paths, bool lookForExpressVersion = false);
|
||||
|
||||
void setName(const std::string& version);
|
||||
int m_versionNumber;
|
||||
virtual std::vector<FilePath> getStandardHeaderPaths();
|
||||
virtual std::vector<FilePath> getStandardFrameworkPaths();
|
||||
|
||||
private:
|
||||
FilePath getVsInstallPathUsingRegistry();
|
||||
FilePath getWindowsSdkPathUsingRegistry(const std::string& version);
|
||||
|
||||
int m_version;
|
||||
bool m_isExpress;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user