diff --git a/CMakeLists.txt b/CMakeLists.txt index b4e274c..cadf7ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,8 @@ cmake_minimum_required(VERSION 3.15) -# Set the toolchain file for vcpkg on Windows. -if(WIN32) +# Set the toolchain file for vcpkg on Windows (only if VCPKG_ROOT is set; +# on mingw we get libusb from pkg-config directly). +if(WIN32 AND NOT "$ENV{VCPKG_ROOT}" STREQUAL "") set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake") endif() diff --git a/txdemo/stream_duplex_demo/main.cpp b/txdemo/stream_duplex_demo/main.cpp index 400cfe1..d7ff0e2 100644 --- a/txdemo/stream_duplex_demo/main.cpp +++ b/txdemo/stream_duplex_demo/main.cpp @@ -41,6 +41,12 @@ #include typedef int pid_t; #define sleep(seconds) Sleep((seconds)*1000) +#elif defined(__MINGW32__) || defined(__MINGW64__) + // mingw builds: POSIX libusb/unistd PLUS io.h/fcntl.h for binary stdin. + #include + #include + #include + #include #elif defined(__ANDROID__) #include #include @@ -233,7 +239,9 @@ int main(int argc, char **argv) { } } -#if defined(_MSC_VER) +#if defined(_WIN32) + // mingw/GCC defines _WIN32 but not _MSC_VER, yet still has _setmode — make + // stdin binary so a 0x1A/CRLF doesn't corrupt the length-prefixed PSDU stream. _setmode(_fileno(stdin), _O_BINARY); #endif diff --git a/txdemo/stream_tx_demo/main.cpp b/txdemo/stream_tx_demo/main.cpp index 7dc1279..c67d485 100644 --- a/txdemo/stream_tx_demo/main.cpp +++ b/txdemo/stream_tx_demo/main.cpp @@ -46,6 +46,12 @@ #include typedef int pid_t; #define sleep(seconds) Sleep((seconds)*1000) +#elif defined(__MINGW32__) || defined(__MINGW64__) + // mingw builds: POSIX libusb/unistd PLUS io.h/fcntl.h for binary stdin. + #include + #include + #include + #include #elif defined(__ANDROID__) #include #include @@ -134,8 +140,9 @@ int main(int argc, char **argv) { } } -#if defined(_MSC_VER) +#if defined(_WIN32) // Make stdin binary so a 0x1A or CRLF doesn't corrupt PSDU bytes. + // (mingw/GCC defines _WIN32 but not _MSC_VER, yet still has _setmode.) _setmode(_fileno(stdin), _O_BINARY); #endif