Browse Source

ENH: Make install on windows seems to work now

Andy Cedilnik 22 years ago
parent
commit
d13e30f3ae

+ 9 - 8
Source/MFCDialog/CMakeLists.txt

@@ -1,12 +1,12 @@
 SET( SRCS 
 SET( SRCS 
-CMakeSetup.cpp
-MakeHelp.cpp
-CMakeSetup.rc
-CMakeSetupDialog.cpp
-PathDialog.cpp
-PropertyList.cpp
-StdAfx.cpp
-CMakeCommandLineInfo.cpp
+  CMakeSetup.cpp
+  MakeHelp.cpp
+  CMakeSetup.rc
+  CMakeSetupDialog.cpp
+  PathDialog.cpp
+  PropertyList.cpp
+  StdAfx.cpp
+  CMakeCommandLineInfo.cpp
 )
 )
 
 
 # add stuff to use MFC in this executable
 # add stuff to use MFC in this executable
@@ -16,3 +16,4 @@ SET(CMAKE_MFC_FLAG 6)
 ADD_EXECUTABLE(CMakeSetup WIN32 ${SRCS})
 ADD_EXECUTABLE(CMakeSetup WIN32 ${SRCS})
 TARGET_LINK_LIBRARIES(CMakeSetup CMakeLib)
 TARGET_LINK_LIBRARIES(CMakeSetup CMakeLib)
 ADD_DEPENDENCIES(CMakeSetup cmake)
 ADD_DEPENDENCIES(CMakeSetup cmake)
+INSTALL_TARGETS(/bin CMakeSetup)

+ 63 - 22
Source/cmFileCommand.cxx

@@ -237,6 +237,14 @@ bool cmFileCommand::HandleInstallCommand(std::vector<std::string> const& args)
 
 
   std::string destination = "";
   std::string destination = "";
   std::string stype = "FILES";
   std::string stype = "FILES";
+  const char* build_type = m_Makefile->GetDefinition("BUILD_TYPE");
+  std::string extra_dir = "";
+  if ( build_type )
+    {
+    extra_dir = build_type;
+    }
+
+
   std::vector<std::string> files;
   std::vector<std::string> files;
   int itype = cmTarget::INSTALL_FILES;
   int itype = cmTarget::INSTALL_FILES;
 
 
@@ -245,6 +253,7 @@ bool cmFileCommand::HandleInstallCommand(std::vector<std::string> const& args)
 
 
   std::string expr;
   std::string expr;
   bool in_files = false;
   bool in_files = false;
+  bool optional = false;
   for ( ; i != args.size(); ++i )
   for ( ; i != args.size(); ++i )
     {
     {
     const std::string* cstr = &args[i];
     const std::string* cstr = &args[i];
@@ -258,6 +267,11 @@ bool cmFileCommand::HandleInstallCommand(std::vector<std::string> const& args)
       {
       {
       i++;
       i++;
       stype = args[i];
       stype = args[i];
+      if ( args[i+1] == "OPTIONAL" )
+        {
+        i++;
+        optional = true;
+        }
       in_files = false;
       in_files = false;
       }
       }
     else if ( *cstr == "FILES" && !in_files)
     else if ( *cstr == "FILES" && !in_files)
@@ -289,6 +303,10 @@ bool cmFileCommand::HandleInstallCommand(std::vector<std::string> const& args)
     {
     {
     itype = cmTarget::EXECUTABLE;
     itype = cmTarget::EXECUTABLE;
     }
     }
+  else if ( stype == "PROGRAM" ) 
+    {
+    itype = cmTarget::INSTALL_PROGRAMS;
+    }
   else if ( stype == "STATIC_LIBRARY" ) 
   else if ( stype == "STATIC_LIBRARY" ) 
     {
     {
     itype = cmTarget::STATIC_LIBRARY;
     itype = cmTarget::STATIC_LIBRARY;
@@ -302,12 +320,6 @@ bool cmFileCommand::HandleInstallCommand(std::vector<std::string> const& args)
     itype = cmTarget::MODULE_LIBRARY;
     itype = cmTarget::MODULE_LIBRARY;
     }
     }
 
 
-  for ( i = 0; i < files.size(); i ++ )
-    {
-    std::cout << " " << files[i];
-    }
-  std::cout << std::endl;
-
   if ( !cmSystemTools::FileExists(destination.c_str()) )
   if ( !cmSystemTools::FileExists(destination.c_str()) )
     {
     {
     if ( !cmSystemTools::MakeDirectory(destination.c_str()) )
     if ( !cmSystemTools::MakeDirectory(destination.c_str()) )
@@ -329,33 +341,62 @@ bool cmFileCommand::HandleInstallCommand(std::vector<std::string> const& args)
   for ( i = 0; i < files.size(); i ++ )
   for ( i = 0; i < files.size(); i ++ )
     {
     {
     std::string destfile = destination + "/" + cmSystemTools::GetFilenameName(files[i]);
     std::string destfile = destination + "/" + cmSystemTools::GetFilenameName(files[i]);
-
-    if ( !cmSystemTools::CopyFileAlways(files[i].c_str(), destination.c_str()) )
-      {
-      std::string errstring = "cannot copy file: " + files[i] + 
-        " to directory : " + destination + ".";
-      this->SetError(errstring.c_str());
-      return false;
-      }
+    std::string ctarget = files[i].c_str();
     switch( itype )
     switch( itype )
       {
       {
     case cmTarget::MODULE_LIBRARY:
     case cmTarget::MODULE_LIBRARY:
+    case cmTarget::STATIC_LIBRARY:
     case cmTarget::SHARED_LIBRARY:
     case cmTarget::SHARED_LIBRARY:
     case cmTarget::EXECUTABLE:
     case cmTarget::EXECUTABLE:
+      if ( extra_dir.size() > 0 )
+        {
+        cmOStringStream str;
+        str << cmSystemTools::GetFilenamePath(ctarget) << "/" << extra_dir << "/" 
+          << cmSystemTools::GetFilenameName(ctarget);
+        ctarget = str.str();
+        }
+      break;
+      }
+
+    if ( cmSystemTools::FileExists(ctarget.c_str()) )
+      {
+      if ( !cmSystemTools::CopyFileAlways(ctarget.c_str(), destination.c_str()) )
+        {
+        std::string errstring = "cannot copy file: " + ctarget + 
+          " to directory : " + destination + ".";
+        this->SetError(errstring.c_str());
+        return false;
+        }
+      switch( itype )
+        {
+      case cmTarget::MODULE_LIBRARY:
+      case cmTarget::SHARED_LIBRARY:
+      case cmTarget::EXECUTABLE:
+      case cmTarget::INSTALL_PROGRAMS:
 
 
-      if ( !cmSystemTools::SetPermissions(destfile.c_str(), 
+        if ( !cmSystemTools::SetPermissions(destfile.c_str(), 
 #if defined( _MSC_VER ) || defined( __MINGW32__ )
 #if defined( _MSC_VER ) || defined( __MINGW32__ )
-          S_IREAD | S_IWRITE | S_IEXEC
+            S_IREAD | S_IWRITE | S_IEXEC
 #elif defined( __BORLANDC__ )
 #elif defined( __BORLANDC__ )
-          S_IRUSR | S_IWUSR | S_IXUSR
+            S_IRUSR | S_IWUSR | S_IXUSR
 #else
 #else
-          S_IRUSR | S_IWUSR | S_IXUSR | 
-          S_IRGRP | S_IXGRP | 
-          S_IROTH | S_IXOTH 
+            S_IRUSR | S_IWUSR | S_IXUSR | 
+            S_IRGRP | S_IXGRP | 
+            S_IROTH | S_IXOTH 
 #endif
 #endif
-         ) )
+        ) )
+          {
+          perror("problem doing chmod.");
+          }
+        }
+      }
+    else
+      {
+      if ( !optional )
         {
         {
-        perror("problem doing chmod.");
+        std::string errstring = "cannot find file: " + ctarget + " to install.";
+        this->SetError(errstring.c_str());
+        return false;
         }
         }
       }
       }
     }
     }

+ 14 - 1
Source/cmInstallTargetsCommand.cxx

@@ -28,11 +28,24 @@ bool cmInstallTargetsCommand::InitialPass(std::vector<std::string> const& args)
   cmTargets &tgts = m_Makefile->GetTargets();
   cmTargets &tgts = m_Makefile->GetTargets();
   std::vector<std::string>::const_iterator s = args.begin();
   std::vector<std::string>::const_iterator s = args.begin();
   ++s;
   ++s;
+  std::string runtime_dir = "/bin";
   for (;s != args.end(); ++s)
   for (;s != args.end(); ++s)
     {
     {
-    if (tgts.find(*s) != tgts.end())
+    if (*s == "RUNTIME_DIRECTORY")
+      {
+      ++s;
+      if ( s == args.end() )
+        {
+        this->SetError("called with RUNTIME_DIRECTORY but no actual directory");
+        return false;
+        }
+
+      runtime_dir = *s;
+      }
+    else if (tgts.find(*s) != tgts.end())
       {
       {
       tgts[*s].SetInstallPath(args[0].c_str());
       tgts[*s].SetInstallPath(args[0].c_str());
+      tgts[*s].SetRuntimeInstallPath(runtime_dir.c_str());
       }
       }
     }
     }
   
   

+ 31 - 4
Source/cmLocalGenerator.cxx

@@ -127,13 +127,38 @@ void cmLocalGenerator::GenerateInstallRules()
       switch (type)
       switch (type)
         {
         {
       case cmTarget::STATIC_LIBRARY:
       case cmTarget::STATIC_LIBRARY:
-      case cmTarget::SHARED_LIBRARY:
       case cmTarget::MODULE_LIBRARY:
       case cmTarget::MODULE_LIBRARY:
         fname = libOutPath;
         fname = libOutPath;
         fname += this->GetFullTargetName(l->first.c_str(), l->second);
         fname += this->GetFullTargetName(l->first.c_str(), l->second);
         files = fname.c_str();
         files = fname.c_str();
         this->AddInstallRule(fout, dest, type, files);
         this->AddInstallRule(fout, dest, type, files);
         break;
         break;
+      case cmTarget::SHARED_LIBRARY:
+        {
+        // Special code to handle DLL
+        fname = libOutPath;
+        fname += this->GetFullTargetName(l->first.c_str(), l->second);
+        std::string ext = cmSystemTools::GetFilenameExtension(fname);
+        ext = cmSystemTools::LowerCase(ext);
+        if ( ext == ".dll" )
+          {
+          std::string libname = libOutPath;
+          libname += cmSystemTools::GetFilenameWithoutExtension(fname);
+          libname += ".lib";
+          std::cout << "This is dll: " << libname << std::endl;
+          files = libname.c_str();
+          this->AddInstallRule(fout, dest, cmTarget::STATIC_LIBRARY, files, true);
+          std::string dlldest = prefix + l->second.GetRuntimeInstallPath();
+          files = fname.c_str();
+          this->AddInstallRule(fout, dlldest.c_str(), type, files);
+          }
+        else
+          {
+          files = fname.c_str();
+          this->AddInstallRule(fout, dest, type, files);
+          }
+        }
+        break;
       case cmTarget::WIN32_EXECUTABLE:
       case cmTarget::WIN32_EXECUTABLE:
       case cmTarget::EXECUTABLE:
       case cmTarget::EXECUTABLE:
         fname = exeOutPath;
         fname = exeOutPath;
@@ -213,14 +238,15 @@ void cmLocalGenerator::GenerateInstallRules()
     }
     }
 }
 }
 
 
-void cmLocalGenerator::AddInstallRule(std::ostream& fout, const char* dest, int type, const char* files)
+void cmLocalGenerator::AddInstallRule(std::ostream& fout, const char* dest, 
+  int type, const char* files, bool optional)
 {
 {
   std::string sfiles = files;
   std::string sfiles = files;
   std::string destination = dest;
   std::string destination = dest;
   std::string stype;
   std::string stype;
   switch ( type )
   switch ( type )
     {
     {
-  case cmTarget::INSTALL_PROGRAMS: 
+  case cmTarget::INSTALL_PROGRAMS: stype = "PROGRAM"; break;
   case cmTarget::EXECUTABLE:  
   case cmTarget::EXECUTABLE:  
   case cmTarget::WIN32_EXECUTABLE: stype = "EXECUTABLE"; break;
   case cmTarget::WIN32_EXECUTABLE: stype = "EXECUTABLE"; break;
   case cmTarget::STATIC_LIBRARY:   stype = "STATIC_LIBRARY"; break;
   case cmTarget::STATIC_LIBRARY:   stype = "STATIC_LIBRARY"; break;
@@ -232,7 +258,8 @@ void cmLocalGenerator::AddInstallRule(std::ostream& fout, const char* dest, int
   fout 
   fout 
     << "MESSAGE(STATUS \"Install " << stype << ": " << sfiles.c_str() << "\")\n" 
     << "MESSAGE(STATUS \"Install " << stype << ": " << sfiles.c_str() << "\")\n" 
     << "FILE(INSTALL DESTINATION \"" << destination.c_str() 
     << "FILE(INSTALL DESTINATION \"" << destination.c_str() 
-    << "\" TYPE " << stype.c_str() << " FILES \"" << sfiles.c_str() << "\")\n";
+    << "\" TYPE " << stype.c_str() << (optional?" OPTIONAL":"") 
+    << " FILES \"" << sfiles.c_str() << "\")\n";
 }
 }
 
 
 const char* cmLocalGenerator::GetSafeDefinition(const char* def)
 const char* cmLocalGenerator::GetSafeDefinition(const char* def)

+ 2 - 1
Source/cmLocalGenerator.h

@@ -79,7 +79,8 @@ public:
 
 
   std::string ConvertToRelativeOutputPath(const char* p);
   std::string ConvertToRelativeOutputPath(const char* p);
 protected:
 protected:
-  virtual void AddInstallRule(std::ostream& fout, const char* dest, int type, const char* files);
+  virtual void AddInstallRule(std::ostream& fout, const char* dest, int type, 
+    const char* files, bool optional = false);
   
   
   bool m_FromTheTop;
   bool m_FromTheTop;
   cmMakefile *m_Makefile;
   cmMakefile *m_Makefile;

+ 7 - 0
Source/cmTarget.h

@@ -119,6 +119,12 @@ public:
   std::string GetInstallPath() const {return m_InstallPath;}
   std::string GetInstallPath() const {return m_InstallPath;}
   void SetInstallPath(const char *name) {m_InstallPath = name;}
   void SetInstallPath(const char *name) {m_InstallPath = name;}
   
   
+  /**
+   * Set the path where this target (if it has a runtime part) should be
+   * installed. This is relative to INSTALL_PREFIX
+   */
+  std::string GetRuntimeInstallPath() const {return m_RuntimeInstallPath;}
+  void SetRuntimeInstallPath(const char *name) {m_RuntimeInstallPath = name;}
   
   
   /**
   /**
    * Generate the SourceFilesList from the SourceLists. This should only be
    * Generate the SourceFilesList from the SourceLists. This should only be
@@ -213,6 +219,7 @@ private:
   std::vector<std::string> m_LinkDirectories;
   std::vector<std::string> m_LinkDirectories;
   bool m_InAll;
   bool m_InAll;
   std::string m_InstallPath;
   std::string m_InstallPath;
+  std::string m_RuntimeInstallPath;
   std::set<cmStdString> m_Utilities;
   std::set<cmStdString> m_Utilities;
   bool m_RecordDependencies; 
   bool m_RecordDependencies; 
   std::map<cmStdString,cmStdString> m_Properties;
   std::map<cmStdString,cmStdString> m_Properties;