diff options
author | Alexander Neundorf <neundorf@kde.org> | 2009-12-23 18:56:01 (GMT) |
---|---|---|
committer | Alexander Neundorf <neundorf@kde.org> | 2009-12-23 18:56:01 (GMT) |
commit | c1beb3b141e470e95d46ba58f22f005544d984dc (patch) | |
tree | b57d75cceb0d23ecce4d93d0e812e2cceca3cf40 /Source | |
parent | a1614caf37e907183fe831b6b7ecb96cdb21bfbe (diff) | |
download | CMake-c1beb3b141e470e95d46ba58f22f005544d984dc.zip CMake-c1beb3b141e470e95d46ba58f22f005544d984dc.tar.gz CMake-c1beb3b141e470e95d46ba58f22f005544d984dc.tar.bz2 |
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
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmExtraEclipseCDT4Generator.cxx | 100 | ||||
-rw-r--r-- | 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 << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<projectDescription>\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 << "</value>\n" @@ -284,11 +347,6 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() "\t\t\t\t\t<key>org.eclipse.cdt.core.errorOutputParser</key>\n" "\t\t\t\t\t<value>" ; - 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<std::string>& includeDirs, std::set<std::string>& emittedDirs); + static void AddEnvVar(cmGeneratedFileStream& fout, const char* envVar, + cmMakefile* mf); + std::vector<std::string> SrcLinkedResources; std::vector<std::string> OutLinkedResources; std::string HomeDirectory; |