fix(build): problem with reading LEAN_PATH on cygwin

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-12-30 14:50:40 -08:00
parent cc07c440e1
commit 931e196e83
2 changed files with 53 additions and 9 deletions

View file

@ -30,6 +30,10 @@ if((${CYGWIN} EQUAL "1") OR (${CMAKE_SYSTEM_NAME} MATCHES "Windows"))
set(LEAN_EXTRA_CXX_FLAGS "${LEAN_EXTRA_CXX_FLAGS} -D LEAN_WINDOWS -D LEAN_WIN_STACK_SIZE=${LEAN_WIN_STACK_SIZE}")
endif()
if("${CYGWIN}" EQUAL "1")
set(LEAN_EXTRA_CXX_FLAGS "${LEAN_EXTRA_CXX_FLAGS} -D LEAN_CYGWIN")
endif()
if("${MULTI_THREAD}" MATCHES "OFF")
message(STATUS "Disabled multi-thread support, it will not be safe to run multiple threads in parallel")
else()

View file

@ -66,11 +66,51 @@ static std::string get_exe_location() {
}
#endif
#if defined(LEAN_CYGWIN)
/**
\brief Cleanup path when using cygwin.
This procedure performs two fixes, if the string contains '/'.
1- It replaces '/' with '\\' and ':' with ';'
2- Then, it replaces "\cygdrive\c\" with "c:"
*/
static std::string fix_cygwin_path(std::string f) {
if (f.find('/') != std::string::npos) {
// Step 1.
for (auto & c : f) {
if (c == g_bad_sep)
c = g_sep;
else if (c == ':')
c = g_path_sep;
}
// Step 2.
size_t pos = 0;
size_t matchpos;
std::string cygdrive("\\cygdrive\\");
while ((matchpos = f.find(cygdrive, pos)) != std::string::npos) {
// erase "\cygdrive\"
f = f.replace(matchpos, cygdrive.size(), "");
// replace the next "\" with ":\"
if ((matchpos = f.find("\\", matchpos)) != std::string::npos) {
f.replace(matchpos, 1, ":\\");
}
pos = matchpos;
}
}
return f;
}
#endif
std::string normalize_path(std::string f) {
#if defined(LEAN_CYGWIN)
f = fix_cygwin_path(f);
#else
for (auto & c : f) {
if (c == g_bad_sep)
c = g_sep;
}
#endif
return f;
}