diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp index 860b4906..307f7072 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp @@ -42,6 +42,49 @@ #include "Application.h" +namespace +{ + bool applicationSettingsContainVisualStudioHeaderSearchPaths() + { + std::vector expandedPaths; + const std::shared_ptr headerPathDetector = utility::getCxxVsHeaderPathDetector(); + for (const std::string& detectorName : headerPathDetector->getWorkingDetectorNames()) + { + for (const FilePath& path : headerPathDetector->getPaths(detectorName)) + { + utility::append(expandedPaths, path.expandEnvironmentVariables()); + } + } + + std::vector usedExpandedGlobalHeaderSearchPaths = + ApplicationSettings::getInstance()->getHeaderSearchPathsExpanded(); + for (const FilePath& usedExpandedPath : usedExpandedGlobalHeaderSearchPaths) + { + for (const FilePath& expandedPath : expandedPaths) + { + if (expandedPath == usedExpandedPath) + { + return true; + } + } + } + + return false; + } + + void addMsvcCompatibilityFlagsOnDemand(std::shared_ptr settings) + { + if (applicationSettingsContainVisualStudioHeaderSearchPaths()) + { + std::vector flags = settings->getCompilerFlags(); + flags.push_back(L"-fms-extensions"); + flags.push_back(L"-fms-compatibility"); + flags.push_back(L"-fms-compatibility-version=19"); + settings->setCompilerFlags(flags); + } + } +} + QtProjectWizzard::QtProjectWizzard(QWidget* parent) : QtProjectWizzardWindow(parent, false) , m_windowStack(this) @@ -256,34 +299,6 @@ void QtProjectWizzard::handlePrevious() QtWindow::handlePrevious(); } -bool QtProjectWizzard::applicationSettingsContainVisualStudioHeaderSearchPaths() -{ - std::vector expandedPaths; - const std::shared_ptr headerPathDetector = utility::getCxxVsHeaderPathDetector(); - for (const std::string& detectorName : headerPathDetector->getWorkingDetectorNames()) - { - for (const FilePath& path: headerPathDetector->getPaths(detectorName)) - { - utility::append(expandedPaths, path.expandEnvironmentVariables()); - } - } - - std::vector usedExpandedGlobalHeaderSearchPaths = - ApplicationSettings::getInstance()->getHeaderSearchPathsExpanded(); - for (const FilePath& usedExpandedPath: usedExpandedGlobalHeaderSearchPaths) - { - for (const FilePath& expandedPath: expandedPaths) - { - if (expandedPath == usedExpandedPath) - { - return true; - } - } - } - - return false; -} - QtProjectWizzardWindow* QtProjectWizzard::createWindowWithContent( std::function func ){ @@ -748,23 +763,13 @@ void QtProjectWizzard::selectedProjectType(SourceGroupType sourceGroupType) switch (sourceGroupType) { case SOURCE_GROUP_C_EMPTY: + m_newSourceGroupSettings = std::make_shared(sourceGroupId, m_projectSettings.get()); + addMsvcCompatibilityFlagsOnDemand(std::dynamic_pointer_cast(m_newSourceGroupSettings)); + emptySourceGroup(); + break; case SOURCE_GROUP_CPP_EMPTY: - if (sourceGroupType == SOURCE_GROUP_C_EMPTY) - { - m_newSourceGroupSettings = std::make_shared(sourceGroupId, m_projectSettings.get()); - } - else - { - m_newSourceGroupSettings = std::make_shared(sourceGroupId, m_projectSettings.get()); - } - if (applicationSettingsContainVisualStudioHeaderSearchPaths()) - { - std::vector flags; - flags.push_back(L"-fms-extensions"); - flags.push_back(L"-fms-compatibility"); - flags.push_back(L"-fms-compatibility-version=19"); - std::dynamic_pointer_cast(m_newSourceGroupSettings)->setCompilerFlags(flags); - } + m_newSourceGroupSettings = std::make_shared(sourceGroupId, m_projectSettings.get()); + addMsvcCompatibilityFlagsOnDemand(std::dynamic_pointer_cast(m_newSourceGroupSettings)); emptySourceGroup(); break; case SOURCE_GROUP_CXX_CDB: @@ -773,10 +778,12 @@ void QtProjectWizzard::selectedProjectType(SourceGroupType sourceGroupType) break; case SOURCE_GROUP_CXX_CODEBLOCKS: m_newSourceGroupSettings = std::make_shared(sourceGroupId, m_projectSettings.get()); + addMsvcCompatibilityFlagsOnDemand(std::dynamic_pointer_cast(m_newSourceGroupSettings)); emptySourceGroupCxxCodeblocks(); break; case SOURCE_GROUP_CXX_SONARGRAPH: m_newSourceGroupSettings = std::make_shared(sourceGroupId, m_projectSettings.get()); + addMsvcCompatibilityFlagsOnDemand(std::dynamic_pointer_cast(m_newSourceGroupSettings)); emptySourceGroupCxxSonargraph(); break; case SOURCE_GROUP_CXX_VS: diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h index 51dc3764..303558fe 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h @@ -41,8 +41,6 @@ protected: virtual void handlePrevious() override; private: - static bool applicationSettingsContainVisualStudioHeaderSearchPaths(); - QtProjectWizzardWindow* createWindowWithContent( std::function func);