From c1beb3b141e470e95d46ba58f22f005544d984dc Mon Sep 17 00:00:00 2001 From: Alexander Neundorf Date: Wed, 23 Dec 2009 13:56:01 -0500 Subject: fix the way the PATH and other related env.vars are stored in the eclipse project file when using MSVC Before this commit, the value of PATH at cmake time was put into the eclipse project file. The problem with this is that this will be lost the first time cmake is rerun from an build inside eclipse which was started without the environment externally already set. This patch now: -adds the env.var to the cache if it is not already in the cache -reuses the variable from the cache if it is in the cache, but not in the env. -uses the variable from the cache if it contains the whole content of the current env.var (e.g. if it is the full PATH plus the MSVC dirs) Also store INTEL_LICENSE_FILE in the project file if an Intel compiler is used. Alex --- Source/cmExtraEclipseCDT4Generator.cxx | 100 ++++++++++++++++++++++++++------- Source/cmExtraEclipseCDT4Generator.h | 3 + 2 files changed, 82 insertions(+), 21 deletions(-) diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index 244f8ca..57ff255 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -124,10 +124,72 @@ void cmExtraEclipseCDT4Generator::CreateSourceProjectFile() const ; } + +//---------------------------------------------------------------------------- +void cmExtraEclipseCDT4Generator::AddEnvVar(cmGeneratedFileStream& fout, + const char* envVar, cmMakefile* mf) +{ + // get the variables from the environment and from the cache and then + // figure out which one to use: + + const char* envVarValue = getenv(envVar); + + std::string cacheEntryName = "CMAKE_ECLIPSE_ENVVAR_"; + cacheEntryName += envVar; + const char* cacheValue = mf->GetCacheManager()->GetCacheValue( + cacheEntryName.c_str()); + + // now we have both, decide which one to use + std::string valueToUse; + if (envVarValue==0 && cacheValue==0) + { + // nothing known, do nothing + valueToUse = ""; + } + else if (envVarValue!=0 && cacheValue==0) + { + // The variable is in the env, but not in the cache. Use it and put it + // in the cache + valueToUse = envVarValue; + mf->AddCacheDefinition(cacheEntryName.c_str(), valueToUse.c_str(), + cacheEntryName.c_str(), cmCacheManager::STRING, + true); + mf->GetCacheManager()->SaveCache(mf->GetHomeOutputDirectory()); + } + else if (envVarValue==0 && cacheValue!=0) + { + // It is already in the cache, but not in the env, so use it from the cache + valueToUse = cacheValue; + } + else + { + // It is both in the cache and in the env. + // Use the version from the env. except if the value from the env is + // completely contained in the value from the cache (for the case that we + // now have a PATH without MSVC dirs in the env. but had the full PATH with + // all MSVC dirs during the cmake run which stored the var in the cache: + valueToUse = cacheValue; + if (valueToUse.find(envVarValue) == std::string::npos) + { + valueToUse = envVarValue; + mf->AddCacheDefinition(cacheEntryName.c_str(), valueToUse.c_str(), + cacheEntryName.c_str(), cmCacheManager::STRING, + true); + mf->GetCacheManager()->SaveCache(mf->GetHomeOutputDirectory()); + } + } + + if (!valueToUse.empty()) + { + fout << envVar << "=" << valueToUse << "|"; + } +} + + //---------------------------------------------------------------------------- void cmExtraEclipseCDT4Generator::CreateProjectFile() { - const cmMakefile* mf + cmMakefile* mf = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile(); const std::string filename = this->HomeOutputDirectory + "/.project"; @@ -138,6 +200,12 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() return; } + std::string compilerId = mf->GetSafeDefinition("CMAKE_C_COMPILER_ID"); + if (compilerId.empty()) // no C compiler, try the C++ compiler: + { + compilerId = mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID"); + } + fout << "\n" "\n" @@ -218,24 +286,19 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() ; // set vsvars32.bat environment available at CMake time, // but not necessarily when eclipse is open - if (make.find("nmake") != std::string::npos) - { - if (getenv("PATH")) + if (compilerId == "MSVC") { - fout << "PATH=" << getenv("PATH") << "|"; + AddEnvVar(fout, "PATH", mf); + AddEnvVar(fout, "INCLUDE", mf); + AddEnvVar(fout, "LIB", mf); + AddEnvVar(fout, "LIBPATH", mf); + AddEnvVar(fout, "INCLUDE", mf); } - if (getenv("INCLUDE")) - { - fout << "INCLUDE=" << getenv("INCLUDE") << "|"; - } - if (getenv("LIB")) + else if (compilerId == "Intel") { - fout << "LIB=" << getenv("LIB") << "|"; - } - if (getenv("LIBPATH")) - { - fout << "LIBPATH=" << getenv("LIBPATH") << "|"; - } + // if the env.var is set, use this one and put it in the cache + // if the env.var is not set, but the value is in the cache, use it from the cache: + AddEnvVar(fout, "INTEL_LICENSE_FILE", mf); } fout << "\n" @@ -284,11 +347,6 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() "\t\t\t\t\torg.eclipse.cdt.core.errorOutputParser\n" "\t\t\t\t\t" ; - std::string compilerId = mf->GetSafeDefinition("CMAKE_C_COMPILER_ID"); - if (compilerId.empty()) // no C compiler, try the C++ compiler: - { - compilerId = mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID"); - } if (compilerId == "MSVC") { fout << "org.eclipse.cdt.core.VCErrorParser;"; diff --git a/Source/cmExtraEclipseCDT4Generator.h b/Source/cmExtraEclipseCDT4Generator.h index f7ddad9..143b7fa 100644 --- a/Source/cmExtraEclipseCDT4Generator.h +++ b/Source/cmExtraEclipseCDT4Generator.h @@ -100,6 +100,9 @@ private: const std::vector& includeDirs, std::set& emittedDirs); + static void AddEnvVar(cmGeneratedFileStream& fout, const char* envVar, + cmMakefile* mf); + std::vector SrcLinkedResources; std::vector OutLinkedResources; std::string HomeDirectory; -- cgit v0.12