[Cmake-commits] [cmake-commits] alex committed cmExtraEclipseCDT4Generator.h 1.13 1.14 cmExtraEclipseCDT4Generator.cxx 1.31 1.32

cmake-commits at cmake.org cmake-commits at cmake.org
Wed Dec 23 13:56:03 EST 2009


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv6255

Modified Files:
	cmExtraEclipseCDT4Generator.h cmExtraEclipseCDT4Generator.cxx 
Log Message:
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


Index: cmExtraEclipseCDT4Generator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmExtraEclipseCDT4Generator.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -C 2 -d -r1.13 -r1.14
*** cmExtraEclipseCDT4Generator.h	22 Nov 2009 10:01:04 -0000	1.13
--- cmExtraEclipseCDT4Generator.h	23 Dec 2009 18:56:01 -0000	1.14
***************
*** 101,104 ****
--- 101,107 ----
                                     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;

Index: cmExtraEclipseCDT4Generator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmExtraEclipseCDT4Generator.cxx,v
retrieving revision 1.31
retrieving revision 1.32
diff -C 2 -d -r1.31 -r1.32
*** cmExtraEclipseCDT4Generator.cxx	23 Dec 2009 18:51:45 -0000	1.31
--- cmExtraEclipseCDT4Generator.cxx	23 Dec 2009 18:56:01 -0000	1.32
***************
*** 125,132 ****
  }
  
  //----------------------------------------------------------------------------
  void cmExtraEclipseCDT4Generator::CreateProjectFile()
  {
!   const cmMakefile* mf
      = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
  
--- 125,194 ----
  }
  
+ 
+ //----------------------------------------------------------------------------
+ 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()
  {
!   cmMakefile* mf
      = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
  
***************
*** 139,142 ****
--- 201,210 ----
      }
  
+   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"
***************
*** 219,240 ****
    // 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"))
      {
!       fout << "PATH=" << getenv("PATH") << "|";
      }
!     if (getenv("INCLUDE"))
!       {
!       fout << "INCLUDE=" << getenv("INCLUDE") << "|";
!       }
!     if (getenv("LIB"))
      {
!       fout << "LIB=" << getenv("LIB") << "|";
!       }
!     if (getenv("LIBPATH"))
!       {
!       fout << "LIBPATH=" << getenv("LIBPATH") << "|";
!       }
      }
    fout <<
--- 287,303 ----
    // set vsvars32.bat environment available at CMake time,
    //   but not necessarily when eclipse is open
!   if (compilerId == "MSVC")
      {
!     AddEnvVar(fout, "PATH", mf);
!     AddEnvVar(fout, "INCLUDE", mf);
!     AddEnvVar(fout, "LIB", mf);
!     AddEnvVar(fout, "LIBPATH", mf);
!     AddEnvVar(fout, "INCLUDE", mf);
      }
!   else if (compilerId == "Intel")
      {
!     // 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 <<
***************
*** 285,293 ****
      "\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")
      {
--- 348,351 ----



More information about the Cmake-commits mailing list