ENH: Make install on windows seems to work now

This commit is contained in:
Andy Cedilnik 2004-01-27 12:37:30 -05:00
parent 127872e820
commit d13e30f3ae
6 changed files with 131 additions and 41 deletions

View File

@ -1,12 +1,12 @@
SET( SRCS SET( SRCS
CMakeSetup.cpp CMakeSetup.cpp
MakeHelp.cpp MakeHelp.cpp
CMakeSetup.rc CMakeSetup.rc
CMakeSetupDialog.cpp CMakeSetupDialog.cpp
PathDialog.cpp PathDialog.cpp
PropertyList.cpp PropertyList.cpp
StdAfx.cpp StdAfx.cpp
CMakeCommandLineInfo.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)

View File

@ -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]);
std::string ctarget = files[i].c_str();
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;
}
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 )
if ( !cmSystemTools::SetPermissions(destfile.c_str(),
#if defined( _MSC_VER ) || defined( __MINGW32__ )
S_IREAD | S_IWRITE | S_IEXEC
#elif defined( __BORLANDC__ )
S_IRUSR | S_IWUSR | S_IXUSR
#else
S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IXGRP |
S_IROTH | S_IXOTH
#endif
) )
{ {
perror("problem doing chmod."); 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 defined( _MSC_VER ) || defined( __MINGW32__ )
S_IREAD | S_IWRITE | S_IEXEC
#elif defined( __BORLANDC__ )
S_IRUSR | S_IWUSR | S_IXUSR
#else
S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IXGRP |
S_IROTH | S_IXOTH
#endif
) )
{
perror("problem doing chmod.");
}
}
}
else
{
if ( !optional )
{
std::string errstring = "cannot find file: " + ctarget + " to install.";
this->SetError(errstring.c_str());
return false;
} }
} }
} }

View File

@ -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());
} }
} }

View File

@ -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)

View File

@ -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;

View File

@ -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;