[Cmake-commits] [cmake-commits] king committed cmFindBase.cxx 1.45 1.46 cmFindBase.h 1.14 1.15 cmFindLibraryCommand.cxx 1.59 1.60 cmFindLibraryCommand.h 1.27 1.28 cmFindPathCommand.cxx 1.42 1.43 cmFindPathCommand.h 1.18 1.19 cmFindProgramCommand.cxx 1.42 1.43

cmake-commits at cmake.org cmake-commits at cmake.org
Mon Jun 9 11:58:32 EDT 2008


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

Modified Files:
	cmFindBase.cxx cmFindBase.h cmFindLibraryCommand.cxx 
	cmFindLibraryCommand.h cmFindPathCommand.cxx 
	cmFindPathCommand.h cmFindProgramCommand.cxx 
Log Message:
ENH: Refactor find_* command framework/appbundle search order impl.

  - CMAKE_FIND_FRAMEWORK and CMAKE_FIND_APPBUNDLE are supposed to specify
    whether to find frameworks/appbundles FIRST, LAST, ONLY, or NEVER.
  - Previously this affected only the placement of CMAKE_FRAMEWORK_PATH
    and CMAKE_APPBUNDLE_PATH with respect to the other path specifiers.
  - Now it behaves as documented.  The entire search path is inspected for
    each kind of program, library, or header before trying the next kind.
  - Additionally the ONLY mode is now honored for headers so that users
    do not end up with a library in framework and a header from elsewhere.


Index: cmFindBase.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFindBase.cxx,v
retrieving revision 1.45
retrieving revision 1.46
diff -C 2 -d -r1.45 -r1.46
*** cmFindBase.cxx	9 Jun 2008 15:57:54 -0000	1.45
--- cmFindBase.cxx	9 Jun 2008 15:58:27 -0000	1.46
***************
*** 283,311 ****
  void cmFindBase::ExpandPaths()
  {
!   // if NO Default paths was not specified add the
!   // standard search paths.
!   if(!this->NoDefaultPath)
!     {
!     if(this->SearchFrameworkFirst || this->SearchFrameworkOnly)
!       {
!       this->AddFrameworkPath();
!       }
!     if(this->SearchAppBundleFirst || this->SearchAppBundleOnly)
!       {
!       this->AddAppBundlePath();
!       }
!     this->AddCMakeEnvironmentPath();
!     this->AddCMakeVariablePath();
!     this->AddSystemEnvironmentPath();
!     this->AddCMakeSystemVariablePath();
!     if(this->SearchAppBundleLast)
!       {
!       this->AddAppBundlePath();
!       }
!     if(this->SearchFrameworkLast)
!       {
!       this->AddFrameworkPath();
!       }
!     }
  
    // Add paths specified by the caller.
--- 283,290 ----
  void cmFindBase::ExpandPaths()
  {
!   this->AddCMakeEnvironmentPath();
!   this->AddCMakeVariablePath();
!   this->AddSystemEnvironmentPath();
!   this->AddCMakeSystemVariablePath();
  
    // Add paths specified by the caller.
***************
*** 382,428 ****
  
  //----------------------------------------------------------------------------
- void cmFindBase::AddMacPath(const char* var, const char* sysvar)
- {
-   if(this->NoDefaultPath)
-     {
-     return;
-     }
- 
-   // first environment variables
-   if(!this->NoCMakeEnvironmentPath)
-     {
-     this->AddEnvPath(var);
-     }
- 
-   // add cmake variables
-   if(!this->NoCMakePath)
-     {
-     this->AddCMakePath(var);
-     }
- 
-   // add cmake system variables
-   if(!this->NoCMakeSystemPath)
-     {
-     this->AddCMakePath(sysvar);
-     }
- }
- 
- //----------------------------------------------------------------------------
- void cmFindBase::AddFrameworkPath()
- {
-   this->AddMacPath("CMAKE_FRAMEWORK_PATH", "CMAKE_SYSTEM_FRAMEWORK_PATH");
- }
- 
- //----------------------------------------------------------------------------
- void cmFindBase::AddAppBundlePath()
- {
-   this->AddMacPath("CMAKE_APPBUNDLE_PATH", "CMAKE_SYSTEM_APPBUNDLE_PATH");
- }
- 
- //----------------------------------------------------------------------------
  void cmFindBase::AddCMakeEnvironmentPath()
  {
!   if(!this->NoCMakeEnvironmentPath &&
!      !(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
      {
      // Add CMAKE_*_PATH environment variables
--- 361,367 ----
  
  //----------------------------------------------------------------------------
  void cmFindBase::AddCMakeEnvironmentPath()
  {
!   if(!this->NoCMakeEnvironmentPath && !this->NoDefaultPath)
      {
      // Add CMAKE_*_PATH environment variables
***************
*** 432,435 ****
--- 371,383 ----
      this->AddEnvPrefixPath("CMAKE_PREFIX_PATH");
      this->AddEnvPath(var.c_str());
+ 
+     if(this->CMakePathName == "PROGRAM")
+       {
+       this->AddEnvPath("CMAKE_APPBUNDLE_PATH");
+       }
+     else
+       {
+       this->AddEnvPath("CMAKE_FRAMEWORK_PATH");
+       }
      }
  }
***************
*** 438,443 ****
  void cmFindBase::AddCMakeVariablePath()
  {
!   if(!this->NoCMakePath &&
!      !(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
      {
      // Add CMake varibles of the same name as the previous environment
--- 386,390 ----
  void cmFindBase::AddCMakeVariablePath()
  {
!   if(!this->NoCMakePath && !this->NoDefaultPath)
      {
      // Add CMake varibles of the same name as the previous environment
***************
*** 449,452 ****
--- 396,408 ----
      this->AddCMakePrefixPath("CMAKE_PREFIX_PATH");
      this->AddCMakePath(var.c_str());
+ 
+     if(this->CMakePathName == "PROGRAM")
+       {
+       this->AddCMakePath("CMAKE_APPBUNDLE_PATH");
+       }
+     else
+       {
+       this->AddCMakePath("CMAKE_FRAMEWORK_PATH");
+       }
      }
  }
***************
*** 455,460 ****
  void cmFindBase::AddSystemEnvironmentPath()
  {
!   if(!this->NoSystemEnvironmentPath &&
!      !(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
      {
      // Add LIB or INCLUDE
--- 411,415 ----
  void cmFindBase::AddSystemEnvironmentPath()
  {
!   if(!this->NoSystemEnvironmentPath && !this->NoDefaultPath)
      {
      // Add LIB or INCLUDE
***************
*** 471,476 ****
  void cmFindBase::AddCMakeSystemVariablePath()
  {
!   if(!this->NoCMakeSystemPath &&
!      !(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
      {
      std::string var = "CMAKE_SYSTEM_";
--- 426,430 ----
  void cmFindBase::AddCMakeSystemVariablePath()
  {
!   if(!this->NoCMakeSystemPath && !this->NoDefaultPath)
      {
      std::string var = "CMAKE_SYSTEM_";
***************
*** 479,482 ****
--- 433,445 ----
      this->AddCMakePrefixPath("CMAKE_SYSTEM_PREFIX_PATH");
      this->AddCMakePath(var.c_str());
+ 
+     if(this->CMakePathName == "PROGRAM")
+       {
+       this->AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
+       }
+     else
+       {
+       this->AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
+       }
      }
  }

Index: cmFindProgramCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFindProgramCommand.cxx,v
retrieving revision 1.42
retrieving revision 1.43
diff -C 2 -d -r1.42 -r1.43
*** cmFindProgramCommand.cxx	23 Jan 2008 15:27:59 -0000	1.42
--- cmFindProgramCommand.cxx	9 Jun 2008 15:58:29 -0000	1.43
***************
*** 98,103 ****
    std::string program = "";
  
!   // First/last order taken care of in cmFindBase when the paths are setup.
!   if(this->SearchAppBundleFirst || this->SearchAppBundleLast)
      {
      program = FindAppBundle(names);
--- 98,102 ----
    std::string program = "";
  
!   if(this->SearchAppBundleFirst || this->SearchAppBundleOnly)
      {
      program = FindAppBundle(names);
***************
*** 108,111 ****
--- 107,114 ----
      }
  
+   if(program.empty() && this->SearchAppBundleLast)
+     {
+     program = this->FindAppBundle(names);
+     }
    return program;
  }

Index: cmFindLibraryCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFindLibraryCommand.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -C 2 -d -r1.27 -r1.28
*** cmFindLibraryCommand.h	31 Jan 2008 12:50:40 -0000	1.27
--- cmFindLibraryCommand.h	9 Jun 2008 15:58:29 -0000	1.28
***************
*** 69,73 ****
    void AddArchitecturePaths(const char* suffix);
    void AddLib64Paths();
!   std::string FindLibrary(const char* name);
  };
  
--- 69,76 ----
    void AddArchitecturePaths(const char* suffix);
    void AddLib64Paths();
!   std::string FindLibrary();
! private:
!   std::string FindNormalLibrary();
!   std::string FindFrameworkLibrary();
  };
  

Index: cmFindLibraryCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFindLibraryCommand.cxx,v
retrieving revision 1.59
retrieving revision 1.60
diff -C 2 -d -r1.59 -r1.60
*** cmFindLibraryCommand.cxx	9 Jun 2008 15:57:55 -0000	1.59
--- cmFindLibraryCommand.cxx	9 Jun 2008 15:58:28 -0000	1.60
***************
*** 97,113 ****
      }
  
!   std::string library;
!   for(std::vector<std::string>::iterator i = this->Names.begin();
!       i != this->Names.end() ; ++i)
      {
!     library = this->FindLibrary(i->c_str());
!     if(library != "")
!       {
!       this->Makefile->AddCacheDefinition(this->VariableName.c_str(),
!                                          library.c_str(),
!                                          this->VariableDocumentation.c_str(),
!                                          cmCacheManager::FILEPATH);
!       return true;
!       } 
      }
    std::string notfound = this->VariableName + "-NOTFOUND";
--- 97,109 ----
      }
  
!   std::string library = this->FindLibrary();
!   if(library != "")
      {
!     // Save the value in the cache
!     this->Makefile->AddCacheDefinition(this->VariableName.c_str(),
!                                        library.c_str(),
!                                        this->VariableDocumentation.c_str(),
!                                        cmCacheManager::FILEPATH);
!     return true;
      }
    std::string notfound = this->VariableName + "-NOTFOUND";
***************
*** 212,230 ****
  }
  
! std::string cmFindLibraryCommand::FindLibrary(const char* name)
  {
!   bool supportFrameworks = false;
!   bool onlyFrameworks = false;
!   std::string ff = this->Makefile->GetSafeDefinition("CMAKE_FIND_FRAMEWORK");
!   if(ff == "FIRST" || ff == "LAST")
      {
!     supportFrameworks = true;
      }
!   if(ff == "ONLY")
      {
!     onlyFrameworks = true;
!     supportFrameworks = true;
      }
!   
    const char* prefixes_list =
      this->Makefile->GetRequiredDefinition("CMAKE_FIND_LIBRARY_PREFIXES");
--- 208,234 ----
  }
  
! //----------------------------------------------------------------------------
! std::string cmFindLibraryCommand::FindLibrary()
  {
!   std::string library;
!   if(this->SearchFrameworkFirst || this->SearchFrameworkOnly)
      {
!     library = this->FindFrameworkLibrary();
      }
!   if(library.empty() && !this->SearchFrameworkOnly)
      {
!     library = this->FindNormalLibrary();
      }
!   if(library.empty() && this->SearchFrameworkLast)
!     {
!     library = this->FindFrameworkLibrary();
!     }
!   return library;
! }
! 
! //----------------------------------------------------------------------------
! std::string cmFindLibraryCommand::FindNormalLibrary()
! {
!   // Collect the list of library name prefixes/suffixes to try.
    const char* prefixes_list =
      this->Makefile->GetRequiredDefinition("CMAKE_FIND_LIBRARY_PREFIXES");
***************
*** 236,274 ****
    cmSystemTools::ExpandListArgument(suffixes_list, suffixes, true);
  
!   // If the original library name provided by the user matches one of
!   // the suffixes, try it first.
!   bool tryOrig = false;
!   {
!   std::string nm = name;
!   for(std::vector<std::string>::const_iterator si = suffixes.begin();
!       !tryOrig && si != suffixes.end(); ++si)
!     {
!     std::string const& suffix = *si;
!     if(nm.length() > suffix.length() &&
!        nm.substr(nm.size()-suffix.length()) == suffix)
!       {
!       tryOrig = true;
!       }
!     }
!   }
! 
    std::string tryPath;
!   for(std::vector<std::string>::const_iterator p = this->SearchPaths.begin();
!       p != this->SearchPaths.end(); ++p)
      {
!     if(supportFrameworks)
        {
!       tryPath = *p;
!       tryPath += name;
!       tryPath += ".framework";
!       if(cmSystemTools::FileExists(tryPath.c_str())
!          && cmSystemTools::FileIsDirectory(tryPath.c_str()))
          {
!         tryPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
!         cmSystemTools::ConvertToUnixSlashes(tryPath);
!         return tryPath;
          }
        }
!     if(!onlyFrameworks)
        {
        // Try the original library name as specified by the user.
--- 240,266 ----
    cmSystemTools::ExpandListArgument(suffixes_list, suffixes, true);
  
!   // Search the entire path for each name.
    std::string tryPath;
!   for(std::vector<std::string>::const_iterator ni = this->Names.begin();
!       ni != this->Names.end() ; ++ni)
      {
!     // If the original library name provided by the user matches one of
!     // the suffixes, try it first.
!     bool tryOrig = false;
!     std::string const& name = *ni;
!     for(std::vector<std::string>::const_iterator si = suffixes.begin();
!         !tryOrig && si != suffixes.end(); ++si)
        {
!       std::string const& suffix = *si;
!       if(name.length() > suffix.length() &&
!          name.substr(name.size()-suffix.length()) == suffix)
          {
!         tryOrig = true;
          }
        }
! 
!     for(std::vector<std::string>::const_iterator
!           p = this->SearchPaths.begin();
!         p != this->SearchPaths.end(); ++p)
        {
        // Try the original library name as specified by the user.
***************
*** 310,311 ****
--- 302,326 ----
    return "";
  }
+ 
+ //----------------------------------------------------------------------------
+ std::string cmFindLibraryCommand::FindFrameworkLibrary()
+ {
+   // Search for a framework of each name in the entire search path.
+   for(std::vector<std::string>::const_iterator ni = this->Names.begin();
+       ni != this->Names.end() ; ++ni)
+     {
+     // Search the paths for a framework with this name.
+     std::string fwName = *ni;
+     fwName += ".framework";
+     std::string fwPath = cmSystemTools::FindDirectory(fwName.c_str(),
+                                                       this->SearchPaths,
+                                                       true);
+     if(!fwPath.empty())
+       {
+       return fwPath;
+       }
+     }
+ 
+   // No framework found.
+   return "";
+ }

Index: cmFindBase.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFindBase.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -C 2 -d -r1.14 -r1.15
*** cmFindBase.h	5 Jun 2008 22:20:16 -0000	1.14
--- cmFindBase.h	9 Jun 2008 15:58:28 -0000	1.15
***************
*** 63,68 ****
  private:
    // Add pieces of the search.
-   void AddFrameworkPath();
-   void AddAppBundlePath();
    void AddCMakeEnvironmentPath();
    void AddCMakeVariablePath();
--- 63,66 ----
***************
*** 71,75 ****
  
    // Helpers.
-   void AddMacPath(const char* var, const char* sysvar);
    void AddCMakePrefixPath(const char* variable);
    void AddEnvPrefixPath(const char* variable);
--- 69,72 ----

Index: cmFindPathCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFindPathCommand.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -C 2 -d -r1.18 -r1.19
*** cmFindPathCommand.h	23 Jan 2008 15:27:59 -0000	1.18
--- cmFindPathCommand.h	9 Jun 2008 15:58:29 -0000	1.19
***************
*** 65,74 ****
      }
  
-   std::string FindHeaderInFramework( std::string& file,
-                                      std::string& dir);
    virtual const char* GetFullDocumentation();
    cmTypeMacro(cmFindPathCommand, cmFindBase);
    bool IncludeFileInPath;
    bool ExtraDocAdded;
  };
  
--- 65,78 ----
      }
  
    virtual const char* GetFullDocumentation();
    cmTypeMacro(cmFindPathCommand, cmFindBase);
    bool IncludeFileInPath;
    bool ExtraDocAdded;
+ private:
+   std::string FindHeaderInFramework(std::string const& file,
+                                     std::string const& dir);
+   std::string FindHeader();
+   std::string FindNormalHeader();
+   std::string FindFrameworkHeader();
  };
  

Index: cmFindPathCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFindPathCommand.cxx,v
retrieving revision 1.42
retrieving revision 1.43
diff -C 2 -d -r1.42 -r1.43
*** cmFindPathCommand.cxx	9 Jun 2008 15:57:56 -0000	1.42
--- cmFindPathCommand.cxx	9 Jun 2008 15:58:29 -0000	1.43
***************
*** 96,150 ****
      return true;
      }
!   std::string ff = this->Makefile->GetSafeDefinition("CMAKE_FIND_FRAMEWORK");
!   bool supportFrameworks = true;
!   if( ff.size() == 0 || ff == "NEVER" )
!     {
!     supportFrameworks = false;
!     }
!   std::string framework;
!   // Use the search path to find the file.
!   unsigned int k;
!   std::string result;
!   for(k=0; k < this->SearchPaths.size(); k++)
      {
!     for(unsigned int j =0; j < this->Names.size(); ++j)
!       {
!       // if frameworks are supported try to find the header in a framework
!       std::string tryPath;
!       if(supportFrameworks)
!         {
!         tryPath = this->FindHeaderInFramework(this->Names[j],
!                                               this->SearchPaths[k]);
!         if(tryPath.size())
!           {
!           result = tryPath;
!           }
!         }
!       if(result.size() == 0)
!         {
!         tryPath = this->SearchPaths[k];
!         tryPath += this->Names[j];
!         if(cmSystemTools::FileExists(tryPath.c_str()))
!           {
!           if(this->IncludeFileInPath)
!             {
!             result = tryPath;
!             }
!           else
!             {
!             result = this->SearchPaths[k];
!             }
!           }
!         }
!       if(result.size() != 0)
!         {
!         this->Makefile->AddCacheDefinition
!           (this->VariableName.c_str(), result.c_str(),
!            this->VariableDocumentation.c_str(),
!            (this->IncludeFileInPath) ? 
!            cmCacheManager::FILEPATH :cmCacheManager::PATH);
!         return true;
!         }
!       }
      }
    this->Makefile->AddCacheDefinition
--- 96,109 ----
      return true;
      }
! 
!   std::string result = this->FindHeader();
!   if(result.size() != 0)
      {
!     this->Makefile->AddCacheDefinition
!       (this->VariableName.c_str(), result.c_str(),
!        this->VariableDocumentation.c_str(),
!        (this->IncludeFileInPath) ?
!        cmCacheManager::FILEPATH :cmCacheManager::PATH);
!     return true;
      }
    this->Makefile->AddCacheDefinition
***************
*** 157,162 ****
  }
  
! std::string cmFindPathCommand::FindHeaderInFramework(std::string& file,
!                                                      std::string& dir)
  {
    cmStdString fileName = file;
--- 116,141 ----
  }
  
! //----------------------------------------------------------------------------
! std::string cmFindPathCommand::FindHeader()
! {
!   std::string header;
!   if(this->SearchFrameworkFirst || this->SearchFrameworkOnly)
!     {
!     header = this->FindFrameworkHeader();
!     }
!   if(header.empty() && !this->SearchFrameworkOnly)
!     {
!     header = this->FindNormalHeader();
!     }
!   if(header.empty() && this->SearchFrameworkLast)
!     {
!     header = this->FindFrameworkHeader();
!     }
!   return header;
! }
! 
! std::string
! cmFindPathCommand::FindHeaderInFramework(std::string const& file,
!                                          std::string const& dir)
  {
    cmStdString fileName = file;
***************
*** 218,219 ****
--- 197,246 ----
  }
  
+ //----------------------------------------------------------------------------
+ std::string cmFindPathCommand::FindNormalHeader()
+ {
+   std::string tryPath;
+   for(std::vector<std::string>::const_iterator ni = this->Names.begin();
+       ni != this->Names.end() ; ++ni)
+     {
+     for(std::vector<std::string>::const_iterator
+           p = this->SearchPaths.begin();
+         p != this->SearchPaths.end(); ++p)
+       {
+       tryPath = *p;
+       tryPath += *ni;
+       if(cmSystemTools::FileExists(tryPath.c_str()))
+         {
+         if(this->IncludeFileInPath)
+           {
+           return tryPath;
+           }
+         else
+           {
+           return *p;
+           }
+         }
+       }
+     }
+   return "";
+ }
+ 
+ //----------------------------------------------------------------------------
+ std::string cmFindPathCommand::FindFrameworkHeader()
+ {
+   for(std::vector<std::string>::const_iterator ni = this->Names.begin();
+       ni != this->Names.end() ; ++ni)
+     {
+     for(std::vector<std::string>::const_iterator
+           p = this->SearchPaths.begin();
+         p != this->SearchPaths.end(); ++p)
+       {
+       std::string fwPath = this->FindHeaderInFramework(*ni, *p);
+       if(!fwPath.empty())
+         {
+         return fwPath;
+         }
+       }
+     }
+   return "";
+ }



More information about the Cmake-commits mailing list