diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp index 301dbf01..90deb4ef 100644 --- a/src/Parser/Parser.cpp +++ b/src/Parser/Parser.cpp @@ -60,111 +60,12 @@ static std::string GetClangBuiltinIncludeDir() } //-----------------------------------// -#ifdef _WIN32 -#include -#include -#include - -static std::string exec(const char* cmd) -{ - FILE* pipe = _popen(cmd, "r"); - if (!pipe) return "ERROR"; - char buffer[128]; - std::string result = ""; - while(!feof(pipe)) { - if(fgets(buffer, 128, pipe) != NULL) - result += buffer; - } - _pclose(pipe); - return result; -} - -#pragma comment(lib, "shlwapi.lib") //_popen, _pclose -#include - - -// -// Returns true if got settings, false if not. -// -bool GetVisualStudioEnv( - const char* envVar, // [in] "INCLUDE" / "LIBPATH" - std::vector& vecPathes, - int iProbeFrom = 0, int iProbeTo = 0 // 2005 - 8, 2008 - 9, 2010 - 10 -) -{ - std::string s; - - if( iProbeFrom == 0 && iProbeTo == 0 ) - { - // Environment variable specifies which VS to use. - if( getenv("VSENV") != NULL ) - { - int iVer = atoi( getenv("VSENV") ); - - if( iVer == 0 ) - return false; - - return GetVisualStudioEnv(envVar, vecPathes, iVer, iVer ); - } - - iProbeFrom = 20; - iProbeTo = 9; - } //if - - - for( int iProbeVer = iProbeFrom; iProbeVer >= iProbeTo; iProbeVer-- ) - { - char envvar[64]; - sprintf(envvar, "VS%d0COMNTOOLS", iProbeVer); - - // Not defined - if( getenv(envvar) == NULL ) - continue; - - std::string cmd = getenv(envvar); - cmd += "\\..\\..\\vc\\vcvarsall.bat"; - - if( !PathFileExistsA( cmd.c_str() ) ) - continue; - - //printf("Located: %s", envvar); - - cmd = "cmd /C \"" + cmd + "\" ^>nul ^& set"; - s = exec(cmd.c_str()); - break; - } - - if( s.length() == 0 ) - return false; - - char* envline; - - vecPathes.clear(); - - for (envline = strtok( &s[0], "\n" ); envline; envline = strtok( NULL, "\n" )) - { - char* varend = strchr( envline, '='); - if( !varend ) - continue; - - *varend = 0; - - if( strcmp(envline,envVar) == 0 ) - { - char* val; - for (val = strtok( varend + 1, ";" ); val; val = strtok( NULL, ";" )) - { - vecPathes.push_back(val); - } - } - *varend = '='; - } //for - - return true; -} //GetVisualStudioEnv - -#endif //_WIN32 +#ifdef _MSC_VER +bool GetVisualStudioEnv(const char* env, + std::vector& pathes, + int probeFrom = 0, int probeTo = 0); +#endif void Parser::Setup(ParserOptions^ Opts) { @@ -232,9 +133,8 @@ void Parser::Setup(ParserOptions^ Opts) } #endif -#ifdef _WIN32 +#ifdef _MSC_VER std::vector SystemDirs; - if( GetVisualStudioEnv("INCLUDE", SystemDirs, Opts->toolSetToUse, Opts->toolSetToUse ) ) { clang::HeaderSearchOptions& HSOpts = C->getHeaderSearchOpts(); @@ -243,7 +143,7 @@ void Parser::Setup(ParserOptions^ Opts) { HSOpts.AddPath(SystemDirs[i], frontend::System, false, false, true); } - } //if + } #endif C->createPreprocessor(); diff --git a/src/Parser/VSLookup.cpp b/src/Parser/VSLookup.cpp new file mode 100644 index 00000000..6d344ff6 --- /dev/null +++ b/src/Parser/VSLookup.cpp @@ -0,0 +1,110 @@ +/************************************************************************ +* +* Cxxi +* Licensed under the simplified BSD license. All rights reserved. +* +************************************************************************/ + +#ifdef _MSC_VER + +#include +#include +#include + +static std::string exec(const char* cmd) +{ + FILE* pipe = _popen(cmd, "r"); + if (!pipe) return "ERROR"; + char buffer[128]; + std::string result = ""; + while(!feof(pipe)) { + if(fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + _pclose(pipe); + return result; +} + +#pragma comment(lib, "shlwapi.lib") //_popen, _pclose +#include + +// +// Returns true if got settings, false if not. +// +bool GetVisualStudioEnv( + const char* envVar, // [in] "INCLUDE" / "LIBPATH" + std::vector& vecPathes, + int iProbeFrom = 0, int iProbeTo = 0 // 2005 - 8, 2008 - 9, 2010 - 10 +) +{ + std::string s; + + if( iProbeFrom == 0 && iProbeTo == 0 ) + { + // Environment variable specifies which VS to use. + if( getenv("VSENV") != NULL ) + { + int iVer = atoi( getenv("VSENV") ); + + if( iVer == 0 ) + return false; + + return GetVisualStudioEnv(envVar, vecPathes, iVer, iVer ); + } + + iProbeFrom = 20; + iProbeTo = 9; + } + + for( int iProbeVer = iProbeFrom; iProbeVer >= iProbeTo; iProbeVer-- ) + { + char envvar[64]; + sprintf(envvar, "VS%d0COMNTOOLS", iProbeVer); + + // Not defined + if( getenv(envvar) == NULL ) + continue; + + std::string cmd = getenv(envvar); + cmd += "\\..\\..\\vc\\vcvarsall.bat"; + + if( !PathFileExistsA( cmd.c_str() ) ) + continue; + + //printf("Located: %s", envvar); + + cmd = "cmd /C \"" + cmd + "\" ^>nul ^& set"; + s = exec(cmd.c_str()); + break; + } + + if( s.length() == 0 ) + return false; + + char* envline; + + vecPathes.clear(); + + for (envline = strtok( &s[0], "\n" ); envline; envline = strtok( NULL, "\n" )) + { + char* varend = strchr( envline, '='); + if( !varend ) + continue; + + *varend = 0; + + if( strcmp(envline,envVar) == 0 ) + { + char* val; + for (val = strtok( varend + 1, ";" ); val; val = strtok( NULL, ";" )) + { + vecPathes.push_back(val); + } + } + *varend = '='; + } + + return true; +} + +#endif \ No newline at end of file