BUG: fix SameFile function for windows, and compare source directories
This commit is contained in:
parent
dd7ab1f577
commit
75f9434374
@ -487,6 +487,47 @@ std::string cmSystemTools::EscapeQuotes(const char* str)
|
|||||||
|
|
||||||
bool cmSystemTools::SameFile(const char* file1, const char* file2)
|
bool cmSystemTools::SameFile(const char* file1, const char* file2)
|
||||||
{
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
HANDLE hFile1, hFile2;
|
||||||
|
|
||||||
|
hFile1 = CreateFile( file1,
|
||||||
|
GENERIC_READ,
|
||||||
|
FILE_SHARE_READ ,
|
||||||
|
NULL,
|
||||||
|
OPEN_EXISTING,
|
||||||
|
FILE_FLAG_BACKUP_SEMANTICS,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
hFile2 = CreateFile( file2,
|
||||||
|
GENERIC_READ,
|
||||||
|
FILE_SHARE_READ,
|
||||||
|
NULL,
|
||||||
|
OPEN_EXISTING,
|
||||||
|
FILE_FLAG_BACKUP_SEMANTICS,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
if( hFile1 == INVALID_HANDLE_VALUE || hFile2 == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
if(hFile1 != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
CloseHandle(hFile1);
|
||||||
|
}
|
||||||
|
if(hFile2 != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
CloseHandle(hFile2);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
BY_HANDLE_FILE_INFORMATION fiBuf1;
|
||||||
|
BY_HANDLE_FILE_INFORMATION fiBuf2;
|
||||||
|
GetFileInformationByHandle( hFile1, &fiBuf1 );
|
||||||
|
GetFileInformationByHandle( hFile2, &fiBuf2 );
|
||||||
|
CloseHandle(hFile1);
|
||||||
|
CloseHandle(hFile2);
|
||||||
|
return (fiBuf1.nFileIndexHigh == fiBuf2.nFileIndexHigh &&
|
||||||
|
fiBuf1.nFileIndexLow == fiBuf2.nFileIndexLow);
|
||||||
|
#else
|
||||||
struct stat fileStat1, fileStat2;
|
struct stat fileStat1, fileStat2;
|
||||||
if (stat(file1, &fileStat1) == 0 && stat(file2, &fileStat2) == 0)
|
if (stat(file1, &fileStat1) == 0 && stat(file2, &fileStat2) == 0)
|
||||||
{
|
{
|
||||||
@ -501,6 +542,7 @@ bool cmSystemTools::SameFile(const char* file1, const char* file2)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -358,19 +358,15 @@ int cmake::Generate(const std::vector<std::string>& args, bool buildMakefiles)
|
|||||||
cmCacheManager::GetInstance()->LoadCache(&mf);
|
cmCacheManager::GetInstance()->LoadCache(&mf);
|
||||||
if(mf.GetDefinition("CMAKE_HOME_DIRECTORY"))
|
if(mf.GetDefinition("CMAKE_HOME_DIRECTORY"))
|
||||||
{
|
{
|
||||||
std::string cacheStart =
|
std::string cacheStart = mf.GetDefinition("CMAKE_HOME_DIRECTORY");
|
||||||
cmSystemTools::CollapseFullPath(mf.GetDefinition("CMAKE_HOME_DIRECTORY"));
|
cacheStart += "/CMakeLists.txt";
|
||||||
std::string currentStart =
|
std::string currentStart = mf.GetHomeDirectory();
|
||||||
cmSystemTools::CollapseFullPath(mf.GetHomeDirectory());
|
currentStart += "/CMakeLists.txt";
|
||||||
#ifdef _WIN32
|
if(!cmSystemTools::SameFile(cacheStart.c_str(), currentStart.c_str()))
|
||||||
cacheStart = cmSystemTools::LowerCase(cacheStart);
|
|
||||||
currentStart = cmSystemTools::LowerCase(currentStart);
|
|
||||||
#endif
|
|
||||||
if(cacheStart != currentStart)
|
|
||||||
{
|
{
|
||||||
std::string message = "Error: source directory: ";
|
std::string message = "Error: source : ";
|
||||||
message += currentStart;
|
message += currentStart;
|
||||||
message += "\nDoes not match source directory used to generate cache: ";
|
message += "\nDoes not match source used to generate cache: ";
|
||||||
message += cacheStart;
|
message += cacheStart;
|
||||||
message += "\nRe-run cmake with a different source directory.";
|
message += "\nRe-run cmake with a different source directory.";
|
||||||
cmSystemTools::Error(message.c_str());
|
cmSystemTools::Error(message.c_str());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user