diff --git a/CMakeLists.txt b/CMakeLists.txt index 149b659..c1d1371 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,10 @@ include(cmake/deps_occ.cmake) # Add an option to enable static builds OPTION(BUILD_STATIC "Build STP2GLB as a static executable." OFF) +if (WIN32 AND DEFINED WIN32_WINNT) + add_compile_definitions(_WIN32_WINNT=${WIN32_WINNT}) +endif () + if (BUILD_STATIC) message(STATUS "Building STP2GLB as a static executable.") diff --git a/src/third_party/httplib.h b/src/third_party/httplib.h index db55d07..b3a2c80 100644 --- a/src/third_party/httplib.h +++ b/src/third_party/httplib.h @@ -32,9 +32,9 @@ #endif #ifdef _WIN32 -#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0A00 +#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0601 #error \ - "cpp-httplib doesn't support Windows 8 or lower. Please use Windows 10 or later." + "cpp-httplib doesn't support platforms older than Windows 7 SP1." #endif #endif @@ -3083,8 +3083,14 @@ inline bool mmap::open(const char *path) { auto wpath = u8string_to_wstring(path); if (wpath.empty()) { return false; } - hFile_ = ::CreateFile2(wpath.c_str(), GENERIC_READ, FILE_SHARE_READ, - OPEN_EXISTING, NULL); + hFile_ = +#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0602 + ::CreateFile2(wpath.c_str(), GENERIC_READ, FILE_SHARE_READ, + OPEN_EXISTING, NULL); +#else + ::CreateFileW(wpath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); +#endif if (hFile_ == INVALID_HANDLE_VALUE) { return false; } @@ -3101,7 +3107,17 @@ inline bool mmap::open(const char *path) { size_ = static_cast(size.QuadPart); hMapping_ = +#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0602 ::CreateFileMappingFromApp(hFile_, NULL, PAGE_READONLY, size_, NULL); +#else + ::CreateFileMappingW( + hFile_, NULL, PAGE_READONLY, + static_cast((static_cast(size_) >> 32) & + 0xffffffffULL), + static_cast(static_cast(size_) & + 0xffffffffULL), + NULL); +#endif // Special treatment for an empty file... if (hMapping_ == NULL && size_ == 0) { @@ -3115,7 +3131,12 @@ inline bool mmap::open(const char *path) { return false; } - addr_ = ::MapViewOfFileFromApp(hMapping_, FILE_MAP_READ, 0, 0); + addr_ = +#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0602 + ::MapViewOfFileFromApp(hMapping_, FILE_MAP_READ, 0, 0); +#else + ::MapViewOfFile(hMapping_, FILE_MAP_READ, 0, 0, 0); +#endif if (addr_ == nullptr) { close();