From 549d8ffea1193b8f410ec76fac6439b64a77cffc Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Sat, 25 Mar 2023 14:56:23 -0700 Subject: [PATCH] fix windows io headers --- CMakeLists.txt | 20 ++++++++++++++++---- cmake/GenerateConfigH.cmake | 2 ++ src/BufferedFile.cc | 2 +- src/Context.cc | 3 ++- src/File.cc | 9 +++++++++ src/a2io.h | 3 +++ 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9aa6a1af..3946711f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,12 +11,13 @@ project( set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/") # ####### Set compiler flags ######## -set(CMAKE_CXX_STANDARD_REQUIRED true) -set(CMAKE_C_STANDARD_REQUIRED true) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_C_EXTENSIONS OFF) -#include(GenerateExportHeader) include(GenerateConfigH) config_h_add_compile_definitions(PACKAGE="${PROJECT_NAME}") @@ -83,6 +84,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") add_compile_definitions(NOMINMAX) config_h_add_compile_macro("__restrict__ __restrict") config_h_add_compile_macro("__attribute__(unused) /*Empty*/") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus") endif() if(WIN32 AND NOT MINGW) @@ -262,9 +264,10 @@ if(WIN32) ws2tcpip.h mmsystem.h io.h - iphlpapi. + iphlpapi.h winioctl.h share.h + sys/utime.h ) foreach(header ${_check_headers}) @@ -283,6 +286,15 @@ if(WIN32) unset(_check_headers) + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # Cake can't find them but they absolutly exist + set(HAVE_IPHLPAPI_H true) + set(HAVE_WINIOCTL_H true) + config_h_add_compile_definitions(HAVE_IPHLPAPI_H) + config_h_add_compile_definitions(HAVE_WINIOCTL_H) + + endif() + else() set(WIN_BUILD no) endif() diff --git a/cmake/GenerateConfigH.cmake b/cmake/GenerateConfigH.cmake index e73f8db9..09795a7b 100644 --- a/cmake/GenerateConfigH.cmake +++ b/cmake/GenerateConfigH.cmake @@ -18,7 +18,9 @@ function(config_h_generate_header name) set(${def_name}_config_h_val "${${def_name}}") string(REPLACE "yes" "1" ${def_name}_config_h_val ${${def_name}_config_h_val}) string(REPLACE "ON" "1" ${def_name}_config_h_val ${${def_name}_config_h_val}) + string(REPLACE "on" "1" ${def_name}_config_h_val ${${def_name}_config_h_val}) string(REPLACE "TRUE" "1" ${def_name}_config_h_val ${${def_name}_config_h_val}) + string(REPLACE "true" "1" ${def_name}_config_h_val ${${def_name}_config_h_val}) endif() write_file(${CMAKE_CURRENT_BINARY_DIR}/${name}.h.cmake.in "#define ${def_name} @${def_name}_config_h_val@\n" APPEND) endforeach() diff --git a/src/BufferedFile.cc b/src/BufferedFile.cc index 6384eb8f..bd5af484 100644 --- a/src/BufferedFile.cc +++ b/src/BufferedFile.cc @@ -81,7 +81,7 @@ int BufferedFile::onClose() int rv = 0; if (fp_) { fflush(fp_); -#if defined(__MINGW32__) || defined(_MSC_VER) +#if defined(__MINGW32__) fsync(fileno(fp_)); #else // __MINGW32__ _commit(fileno(fp_)); diff --git a/src/Context.cc b/src/Context.cc index ffa8f5b7..5d3c022f 100644 --- a/src/Context.cc +++ b/src/Context.cc @@ -36,8 +36,9 @@ #ifndef NO_UNIX # include +# include #endif -#include + #ifdef HAVE_SYS_RESOURCE_H # include diff --git a/src/File.cc b/src/File.cc index 4faf8cae..a9670634 100644 --- a/src/File.cc +++ b/src/File.cc @@ -54,6 +54,15 @@ #include "LogFactory.h" #include "fmt.h" +#if defined(_MSC_VER) +# if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG) +# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +# endif +# if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR) +# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +# endif +#endif + namespace aria2 { File::File(const std::string& name) : name_(name) {} diff --git a/src/a2io.h b/src/a2io.h index a8bbe7c4..70a031c3 100644 --- a/src/a2io.h +++ b/src/a2io.h @@ -54,6 +54,9 @@ #ifdef HAVE_SHARE_H # include #endif // HAVE_SHARE_H +#ifdef HAVE_SYS_UTIME_H +# include +#endif // in some platforms following definitions are missing: #ifndef EINPROGRESS