From 530e20ede6d3488755ced976cc6b91679962c941 Mon Sep 17 00:00:00 2001 From: malte_langkabel Date: Fri, 15 Apr 2016 14:06:17 +0200 Subject: [PATCH] logic: added include path detector for visual studio --- .../QtProjectWizzardContentPaths.cpp | 8 +- .../utility/headerSearch/CompilerDetector.cpp | 38 ++--- .../utility/headerSearch/CompilerDetector.h | 5 +- .../utility/headerSearch/DetectorBase.cpp | 17 +- .../utility/headerSearch/DetectorBase.h | 12 +- .../headerSearch/StandardHeaderDetection.cpp | 66 ++++---- .../headerSearch/StandardHeaderDetection.h | 15 +- .../headerSearch/VisualStudioDetector.cpp | 154 ++++++++++-------- .../headerSearch/VisualStudioDetector.h | 19 ++- 9 files changed, 169 insertions(+), 165 deletions(-) diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp index 8c066789..724028e5 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp @@ -117,8 +117,8 @@ void QtProjectWizzardContentPaths::setHelpString(const QString& help) void QtProjectWizzardContentPaths::addDetection(QString name, QGridLayout* layout, int row) { StandardHeaderDetection detection; - std::vector compilers = detection.getDetectedCompilers(); - if (!compilers.size()) + std::vector 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"); diff --git a/src/lib_gui/utility/headerSearch/CompilerDetector.cpp b/src/lib_gui/utility/headerSearch/CompilerDetector.cpp index 163e3d35..16cef3ca 100644 --- a/src/lib_gui/utility/headerSearch/CompilerDetector.cpp +++ b/src/lib_gui/utility/headerSearch/CompilerDetector.cpp @@ -12,25 +12,6 @@ CompilerDetector::~CompilerDetector() { } -std::vector 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 paths; - - if (!standardHeaders.empty()) - { - for (std::string s : utility::splitToVector(standardHeaders, '\n')) - { - paths.push_back(utility::trim(s)); - } - } - - return paths; -} - std::vector CompilerDetector::getStandardHeaderPaths() { std::vector paths = getHeaderPaths(); @@ -60,3 +41,22 @@ std::vector CompilerDetector::getStandardFrameworkPaths() return frameworkPaths; } + +std::vector 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 paths; + + if (!standardHeaders.empty()) + { + for (std::string s : utility::splitToVector(standardHeaders, '\n')) + { + paths.push_back(utility::trim(s)); + } + } + + return paths; +} diff --git a/src/lib_gui/utility/headerSearch/CompilerDetector.h b/src/lib_gui/utility/headerSearch/CompilerDetector.h index 6ec6113d..7d21b19f 100644 --- a/src/lib_gui/utility/headerSearch/CompilerDetector.h +++ b/src/lib_gui/utility/headerSearch/CompilerDetector.h @@ -11,10 +11,11 @@ public: virtual ~CompilerDetector(); - std::vector getHeaderPaths(); - virtual std::vector getStandardHeaderPaths(); virtual std::vector getStandardFrameworkPaths(); + +private: + std::vector getHeaderPaths(); }; #endif // COMPILER_DETECTOR_H diff --git a/src/lib_gui/utility/headerSearch/DetectorBase.cpp b/src/lib_gui/utility/headerSearch/DetectorBase.cpp index 001318a9..bbc16d77 100644 --- a/src/lib_gui/utility/headerSearch/DetectorBase.cpp +++ b/src/lib_gui/utility/headerSearch/DetectorBase.cpp @@ -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 DetectorBase::getStandardFrameworkPaths() -{ - return std::vector(); } 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(); } diff --git a/src/lib_gui/utility/headerSearch/DetectorBase.h b/src/lib_gui/utility/headerSearch/DetectorBase.h index ca4dd020..358fb88c 100644 --- a/src/lib_gui/utility/headerSearch/DetectorBase.h +++ b/src/lib_gui/utility/headerSearch/DetectorBase.h @@ -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 getStandardHeaderPaths() = 0; - virtual std::vector getStandardFrameworkPaths(); - virtual std::string getName() const; - virtual void setName(const std::string& name); + virtual std::vector getStandardFrameworkPaths() = 0; + protected: std::string m_name; }; diff --git a/src/lib_gui/utility/headerSearch/StandardHeaderDetection.cpp b/src/lib_gui/utility/headerSearch/StandardHeaderDetection.cpp index b72676df..ce5705e2 100644 --- a/src/lib_gui/utility/headerSearch/StandardHeaderDetection.cpp +++ b/src/lib_gui/utility/headerSearch/StandardHeaderDetection.cpp @@ -2,20 +2,14 @@ #include #include -#include -#include #include -#include -#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("gcc")); addDetector(std::make_shared("clang")); - - addDetector(std::make_shared("14")); - addDetector(std::make_shared("12")); - addDetector(std::make_shared("11")); - addDetector(std::make_shared("9")); + addDetector(std::make_shared("Visual Studio 2010", 9, false)); + addDetector(std::make_shared("Visual Studio 2010 Express", 9, true)); + addDetector(std::make_shared("Visual Studio 2012", 11, false)); + addDetector(std::make_shared("Visual Studio 2012 Express", 11, true)); + addDetector(std::make_shared("Visual Studio 2013", 12, false)); + addDetector(std::make_shared("Visual Studio 2013 Express", 12, true)); + addDetector(std::make_shared("Visual Studio 2015", 14, false)); + addDetector(std::make_shared("Visual Studio 2015 Express", 14, true)); detectHeaders(); } @@ -44,63 +41,62 @@ void StandardHeaderDetection::addDetector(std::shared_ptr 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 StandardHeaderDetection::getDetectedCompilers() +std::vector StandardHeaderDetection::getWorkingDetectorNames() { - std::vector v; - for ( DetectorPair detector : s_detectedCompilers) + std::vector detectorNames; + for (DetectorPair detector: s_workingDetectors) { - v.push_back(detector.first); + detectorNames.push_back(detector.first); } - return v; + return detectorNames; } -std::vector StandardHeaderDetection::getStandardHeaderPaths(std::string compiler) +std::vector 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(); } -std::vector StandardHeaderDetection::getStandardFrameworkPaths(std::string compiler) +std::vector 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(); } -void StandardHeaderDetection::printDetectedCompilers() +void StandardHeaderDetection::logAvailableDetectors() { - std::cout << "Detected Compilers: " << std::endl; + LOG_INFO("Available Header Detectors:"); - std::vector 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); } } diff --git a/src/lib_gui/utility/headerSearch/StandardHeaderDetection.h b/src/lib_gui/utility/headerSearch/StandardHeaderDetection.h index e578e447..dce9f60d 100644 --- a/src/lib_gui/utility/headerSearch/StandardHeaderDetection.h +++ b/src/lib_gui/utility/headerSearch/StandardHeaderDetection.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #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 getDetectedCompilers(); + std::vector getWorkingDetectorNames(); /// Returns the headerpaths from a found compiler - std::vector getStandardHeaderPaths(std::string compiler); - std::vector getStandardFrameworkPaths(std::string compiler); + std::vector getStandardHeaderPaths(std::string detectorName); + std::vector getStandardFrameworkPaths(std::string detectorName); /// Debugging Output - void printAvailableDetectors(); - void printDetectedCompilers(); + void logAvailableDetectors(); + void logWorkingDetectors(); private: typedef std::map> DetectorMap; typedef std::pair> DetectorPair; static DetectorMap s_availableDetectors; - static DetectorMap s_detectedCompilers; + static DetectorMap s_workingDetectors; }; #endif // STANDARD_HEADER_DETECTION_H diff --git a/src/lib_gui/utility/headerSearch/VisualStudioDetector.cpp b/src/lib_gui/utility/headerSearch/VisualStudioDetector.cpp index 015ead85..1d1f06d8 100644 --- a/src/lib_gui/utility/headerSearch/VisualStudioDetector.cpp +++ b/src/lib_gui/utility/headerSearch/VisualStudioDetector.cpp @@ -4,93 +4,94 @@ #include #include -#include #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 VisualStudioDetector::getStandardHeaderPaths() { - std::vector headerPaths; + FilePath vsInstallPath = getVsInstallPathUsingRegistry(); + // vc++ headers - if ( !getStanardHeaderPathsUsingEnvironmentVariable(headerPaths) ) + std::vector headerPaths; + if (vsInstallPath.exists()) { - if ( !getStanardHeaderPathsUsingRegistry(headerPaths) ) + std::vector 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 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 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 VisualStudioDetector::getStandardFrameworkPaths() { - return ""; + return std::vector(); } -std::string getWindowsSDKDir() -{ - return ""; -} - -bool VisualStudioDetector::getStanardHeaderPathsUsingEnvironmentVariable(std::vector& paths) -{ - std::string VSToolstring = m_name + "comntools"; - std::vector 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& 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 getStandardHeaderPaths(); -private: - std::string getFullName(); - bool getStanardHeaderPathsUsingEnvironmentVariable(std::vector& paths); - bool getStanardHeaderPathsUsingRegistry(std::vector& paths, bool lookForExpressVersion = false); - void setName(const std::string& version); - int m_versionNumber; + virtual std::vector getStandardHeaderPaths(); + virtual std::vector getStandardFrameworkPaths(); + +private: + FilePath getVsInstallPathUsingRegistry(); + FilePath getWindowsSdkPathUsingRegistry(const std::string& version); + + int m_version; bool m_isExpress; };