Skip to content

Commit

Permalink
Fix mingw build (#610)
Browse files Browse the repository at this point in the history
* fix compilation for mingw
* add *.user to ignor
  • Loading branch information
slyshykO authored and xor-gate committed Jun 29, 2017
1 parent dc8eb3e commit bf58700
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
obj-*
*.user*
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 ()

###
Expand Down
4 changes: 2 additions & 2 deletions src/mingw/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -290,7 +290,6 @@ void usleep(DWORD waitTime)
CloseHandle(timer);
return;
}
#endif
LARGE_INTEGER perf_cnt, start, now;

QueryPerformanceFrequency(&perf_cnt);
Expand All @@ -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

Expand Down
6 changes: 5 additions & 1 deletion src/mingw/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

#include <io.h>
#include <WinSock2.h>
#if defined(_MSC_VER)
#pragma comment(lib, "ws2_32.lib")
#endif
#include <unistd.h>

#if defined(_MSC_VER)
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <sys/time.h>
#endif
#include <sys/types.h>
#if defined(_MSC_VER)
#include <mingw.h>
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4200 4255 4668 4820)
#include <libusb.h>
Expand Down

0 comments on commit bf58700

Please sign in to comment.