[Cmake-commits] [cmake-commits] king committed cmTarget.cxx 1.246 1.247 cmTarget.h 1.126 1.127

cmake-commits at cmake.org cmake-commits at cmake.org
Fri Jul 3 10:34:03 EDT 2009


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

Modified Files:
	cmTarget.cxx cmTarget.h 
Log Message:
ENH: Refactor target output dir computation

This creates cmTarget::GetOutputInfo to compute, cache, and lookup
target output directory information on a per-configuration basis.  It
avoids re-computing the information every time it is needed.


Index: cmTarget.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTarget.h,v
retrieving revision 1.126
retrieving revision 1.127
diff -C 2 -d -r1.126 -r1.127
*** cmTarget.h	1 May 2009 14:39:44 -0000	1.126
--- cmTarget.h	3 Jul 2009 14:33:59 -0000	1.127
***************
*** 463,470 ****
    const char* GetOutputTargetType(bool implib);
  
-   // Get the full path to the target output directory.
-   std::string GetOutputDir(bool implib);
-   std::string const& ComputeBaseOutputDir(bool implib);
- 
    // Get the target base name.
    std::string GetOutputName(const char* config, bool implib);
--- 463,466 ----
***************
*** 501,506 ****
    std::string InstallPath;
    std::string RuntimeInstallPath;
-   std::string BaseOutputDir;
-   std::string BaseOutputDirImplib;
    std::string Location;
    std::string ExportMacro;
--- 497,500 ----
***************
*** 512,515 ****
--- 506,520 ----
    bool IsImportedTarget;
  
+   // Cache target output paths for each configuration.
+   struct OutputInfo
+   {
+     std::string OutDir;
+     std::string ImpDir;
+   };
+   typedef std::map<cmStdString, OutputInfo> OutputInfoMapType;
+   OutputInfoMapType OutputInfoMap;
+   OutputInfo const* GetOutputInfo(const char* config);
+   void ComputeOutputDir(const char* config, bool implib, std::string& out);
+ 
    // Cache import information from properties for each configuration.
    struct ImportInfo

Index: cmTarget.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTarget.cxx,v
retrieving revision 1.246
retrieving revision 1.247
diff -C 2 -d -r1.246 -r1.247
*** cmTarget.cxx	24 Jun 2009 13:36:29 -0000	1.246
--- cmTarget.cxx	3 Jul 2009 14:33:57 -0000	1.247
***************
*** 1938,1941 ****
--- 1938,1983 ----
  
  //----------------------------------------------------------------------------
+ cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config)
+ {
+   // There is no output information for imported targets.
+   if(this->IsImported())
+     {
+     return 0;
+     }
+ 
+   // Only libraries and executables have well-defined output files.
+   if(this->GetType() != cmTarget::STATIC_LIBRARY &&
+      this->GetType() != cmTarget::SHARED_LIBRARY &&
+      this->GetType() != cmTarget::MODULE_LIBRARY &&
+      this->GetType() != cmTarget::EXECUTABLE)
+     {
+     std::string msg = "cmTarget::GetOutputInfo called for ";
+     msg += this->GetName();
+     msg += " which has type ";
+     msg += cmTarget::TargetTypeNames[this->GetType()];
+     this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
+     return 0;
+     }
+ 
+   // Lookup/compute/cache the output information for this configuration.
+   std::string config_upper;
+   if(config && *config)
+     {
+     config_upper = cmSystemTools::UpperCase(config);
+     }
+   OutputInfoMapType::const_iterator i =
+     this->OutputInfoMap.find(config_upper);
+   if(i == this->OutputInfoMap.end())
+     {
+     OutputInfo info;
+     this->ComputeOutputDir(config, false, info.OutDir);
+     this->ComputeOutputDir(config, true, info.ImpDir);
+     OutputInfoMapType::value_type entry(config_upper, info);
+     i = this->OutputInfoMap.insert(entry).first;
+     }
+   return &i->second;
+ }
+ 
+ //----------------------------------------------------------------------------
  std::string cmTarget::GetDirectory(const char* config, bool implib)
  {
***************
*** 1947,1966 ****
        this->ImportedGetFullPath(config, implib));
      }
!   else
      {
      // Return the directory in which the target will be built.
!     if(config && *config)
!       {
!       // Add the configuration's subdirectory.
!       std::string dir = this->GetOutputDir(implib);
!       this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
!         AppendDirectoryForConfig("/", config, "", dir);
!       return dir;
!       }
!     else
!       {
!       return this->GetOutputDir(implib);
!       }
      }
  }
  
--- 1989,1998 ----
        this->ImportedGetFullPath(config, implib));
      }
!   else if(OutputInfo const* info = this->GetOutputInfo(config))
      {
      // Return the directory in which the target will be built.
!     return implib? info->ImpDir : info->OutDir;
      }
+   return "";
  }
  
***************
*** 3154,3207 ****
  
  //----------------------------------------------------------------------------
! std::string cmTarget::GetOutputDir(bool implib)
! {
!   // The implib option is only allowed for shared libraries, module
!   // libraries, and executables.
!   if(this->GetType() != cmTarget::SHARED_LIBRARY &&
!      this->GetType() != cmTarget::MODULE_LIBRARY &&
!      this->GetType() != cmTarget::EXECUTABLE)
!     {
!     implib = false;
!     }
! 
!   // Sanity check.  Only generators on platforms supporting import
!   // libraries should be asking for the import library output
!   // directory.
!   if(implib &&
!      !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
!     {
!     std::string msg =  "GetOutputDir, imlib set but there is no "
!       "CMAKE_IMPORT_LIBRARY_SUFFIX for target: ";
!     msg += this->GetName();
!     this->GetMakefile()->
!       IssueMessage(cmake::INTERNAL_ERROR,
!                    msg.c_str());
!     }
!   if(implib && !this->DLLPlatform)
!     {
!     std::string msg =  "implib set for platform that does not "
!       " support DLL's for target: ";
!     msg += this->GetName();
!     this->GetMakefile()->
!       IssueMessage(cmake::INTERNAL_ERROR,
!                    msg.c_str());
!     }
! 
!   return this->ComputeBaseOutputDir(implib);
! }
! 
! //----------------------------------------------------------------------------
! std::string const& cmTarget::ComputeBaseOutputDir(bool implib)
  {
-   // Select whether we are constructing the directory for the main
-   // target or the import library.
-   std::string& out = implib? this->BaseOutputDirImplib : this->BaseOutputDir;
- 
-   // Return immediately if the directory has already been computed.
-   if(!out.empty())
-     {
-     return out;
-     }
- 
    // Look for a target property defining the target output directory
    // based on the target type.
--- 3186,3192 ----
  
  //----------------------------------------------------------------------------
! void cmTarget::ComputeOutputDir(const char* config,
!                                 bool implib, std::string& out)
  {
    // Look for a target property defining the target output directory
    // based on the target type.
***************
*** 3243,3247 ****
    out = (cmSystemTools::CollapseFullPath
           (out.c_str(), this->Makefile->GetStartOutputDirectory()));
!   return out;
  }
  
--- 3228,3238 ----
    out = (cmSystemTools::CollapseFullPath
           (out.c_str(), this->Makefile->GetStartOutputDirectory()));
! 
!   // The generator may add the configuration's subdirectory.
!   if(config && *config)
!     {
!     this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
!       AppendDirectoryForConfig("/", config, "", out);
!     }
  }
  



More information about the Cmake-commits mailing list