From bf5870050fad788822f8ad4b4c55d82722186020 Mon Sep 17 00:00:00 2001 From: Slyshyk Oleksiy Date: Thu, 29 Jun 2017 22:33:31 +0300 Subject: [PATCH] Fix mingw build (#610) * fix compilation for mingw * add *.user to ignor --- .gitignore | 1 + CMakeLists.txt | 13 +++++++++---- src/mingw/mingw.c | 4 ++-- src/mingw/mingw.h | 6 +++++- src/usb.c | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 89cda6d..3a3a5f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build obj-* +*.user* diff --git a/CMakeLists.txt b/CMakeLists.txt index d0660cf..46790de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,11 @@ if (STLINK_HAVE_SYS_MMAN_H) add_definitions(-DSTLINK_HAVE_SYS_MMAN_H) endif() +CHECK_INCLUDE_FILE(unistd.h STLINK_HAVE_UNISTD_H) +if (STLINK_HAVE_UNISTD_H) + add_definitions(-DSTLINK_HAVE_UNISTD_H) +endif() + if (CMAKE_BUILD_TYPE STREQUAL "") set(CMAKE_BUILD_TYPE "Debug") endif() @@ -73,10 +78,10 @@ include_directories(include) include_directories(${PROJECT_BINARY_DIR}/include) include_directories(src/mingw) if (MSVC) - include_directories(src/win32) - include_directories(src/getopt) - # Use string.h rather than strings.h and disable annoying warnings - add_definitions(-DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS /wd4710) + include_directories(src/win32) + include_directories(src/getopt) + # Use string.h rather than strings.h and disable annoying warnings + add_definitions(-DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS /wd4710) endif () ### diff --git a/src/mingw/mingw.c b/src/mingw/mingw.c index b342e7d..8cf289f 100644 --- a/src/mingw/mingw.c +++ b/src/mingw/mingw.c @@ -271,9 +271,9 @@ char *win32_strsep (char **stringp, const char *delim) /* NOTREACHED */ } +#ifdef STLINK_HAVE_SYS_MMAN_H void usleep(DWORD waitTime) { -#ifdef _MSC_VER if (waitTime >= 1000) { // Don't do long busy-waits. @@ -290,7 +290,6 @@ void usleep(DWORD waitTime) CloseHandle(timer); return; } -#endif LARGE_INTEGER perf_cnt, start, now; QueryPerformanceFrequency(&perf_cnt); @@ -300,6 +299,7 @@ void usleep(DWORD waitTime) QueryPerformanceCounter((LARGE_INTEGER*) &now); } while ((now.QuadPart - start.QuadPart) / (float)perf_cnt.QuadPart * 1000 * 1000 < waitTime); } +#endif #endif diff --git a/src/mingw/mingw.h b/src/mingw/mingw.h index 4b5cf53..dd82a8f 100644 --- a/src/mingw/mingw.h +++ b/src/mingw/mingw.h @@ -9,7 +9,9 @@ #include #include +#if defined(_MSC_VER) #pragma comment(lib, "ws2_32.lib") +#endif #include #if defined(_MSC_VER) @@ -69,7 +71,9 @@ char *win32_strsep(char **stringp, const char *delim); ssize_t win32_read_socket(SOCKET fd, void *buf, int n); ssize_t win32_write_socket(SOCKET fd, void *buf, int n); +#ifdef STLINK_HAVE_SYS_MMAN_H static inline void sleep(unsigned ms) { Sleep(ms); } void usleep(DWORD waitTime); - #endif + +#endif //defined(__MINGW32__) || defined(_MSC_VER) diff --git a/src/usb.c b/src/usb.c index 299de87..92a0a6e 100644 --- a/src/usb.c +++ b/src/usb.c @@ -6,8 +6,8 @@ #include #endif #include -#if defined(_MSC_VER) #include +#if defined(_MSC_VER) #pragma warning(push) #pragma warning(disable: 4200 4255 4668 4820) #include