From 89729b4790d39f6b9e83ae551e9d73cf2ff0b60a Mon Sep 17 00:00:00 2001 From: Mathieu Westphal <mathieu.westphal@kitware.com> Date: Thu, 27 Feb 2025 13:21:21 +0100 Subject: [PATCH 1/6] Windows: Add _USE_MATH_DEFINES for M_PI --- src/gaussian_latitudes.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/gaussian_latitudes.c b/src/gaussian_latitudes.c index 7196999fc..f62954c31 100644 --- a/src/gaussian_latitudes.c +++ b/src/gaussian_latitudes.c @@ -14,6 +14,9 @@ #include <stdlib.h> #include <stdbool.h> #include <float.h> + +// Required on windows to be able to use M_PI +#define _USE_MATH_DEFINES #include <math.h> #ifndef M_SQRT2 -- GitLab From 082fa31119cdea91fd9c1589241519765f79b9e4 Mon Sep 17 00:00:00 2001 From: Mathieu Westphal <mathieu.westphal@kitware.com> Date: Thu, 27 Feb 2025 13:30:37 +0100 Subject: [PATCH 2/6] Windows: Fix includes in lib in order to support compilation on Windows --- src/file.c | 16 +++++++++++----- src/input_file.c | 8 ++++++++ src/iterator_fallback.c | 6 ++++++ src/stream_cdf_i.c | 8 +++++++- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/file.c b/src/file.c index 2086da8a5..bd602ef2b 100644 --- a/src/file.c +++ b/src/file.c @@ -10,19 +10,25 @@ #include "config.h" #endif -#include <unistd.h> - #include <assert.h> #include <ctype.h> #include <errno.h> #include <fcntl.h> +#include <io.h> #include <limits.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> -#include <stdbool.h> #include <string.h> -#include <sys/types.h> #include <sys/stat.h> +#include <sys/types.h> + +// On Windows, define ssize_t manually +#ifdef _WIN32 +#define ssize_t __int64 +#else +#include <unistd.h> +#endif #ifdef HAVE_SYS_TIME_H #include <sys/time.h> // gettimeofday() @@ -392,7 +398,7 @@ fileFlush(int fileID) { FILE *fp = fileptr->fp; retval = fflush(fp); - if (retval == 0) retval = fsync(fileno(fp)); + if (retval == 0) retval = fflush(fp); if (retval != 0) retval = errno; } diff --git a/src/input_file.c b/src/input_file.c index f34d24c48..4c920efa2 100644 --- a/src/input_file.c +++ b/src/input_file.c @@ -18,8 +18,16 @@ #include <errno.h> #include <fcntl.h> +#include <io.h> #include <string.h> + +// On Windows, define ssize_t and pread manually +#ifdef _WIN32 +#define ssize_t __int64 +#define pread read +#else #include <unistd.h> +#endif #if HAVE_PTHREAD #include <pthread.h> diff --git a/src/iterator_fallback.c b/src/iterator_fallback.c index a2252bd8a..fd7bc6db7 100644 --- a/src/iterator_fallback.c +++ b/src/iterator_fallback.c @@ -19,7 +19,13 @@ #include <assert.h> #include <limits.h> #include <stdlib.h> + +// On Windows, define ssize_t manually +#ifdef _WIN32 +#define ssize_t __int64 +#else #include <unistd.h> +#endif struct CdiFallbackIterator { diff --git a/src/stream_cdf_i.c b/src/stream_cdf_i.c index 708565eca..3096c518c 100644 --- a/src/stream_cdf_i.c +++ b/src/stream_cdf_i.c @@ -6,7 +6,6 @@ #include <ctype.h> #include <limits.h> -#include <unistd.h> #include "dmemory.h" #include "cdi_int.h" @@ -19,6 +18,13 @@ #include "cdf_lazy_grid.h" #include "cdf_filter.h" +// On Windows, define strcasecmp manually +#ifdef _WIN32 +#define strcasecmp _stricmp +#else +#include <unistd.h> +#endif + enum VarStatus { UndefVar = -1, -- GitLab From d6fbc4d69adc228239d3eba4de7268d00c6020f8 Mon Sep 17 00:00:00 2001 From: Mathieu Westphal <mathieu.westphal@kitware.com> Date: Thu, 27 Feb 2025 13:35:12 +0100 Subject: [PATCH 3/6] Windows: Remove cdiCreateUUID on Windows --- src/cdi_uuid.h | 2 ++ src/util.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/cdi_uuid.h b/src/cdi_uuid.h index e55d3a895..cbb307189 100644 --- a/src/cdi_uuid.h +++ b/src/cdi_uuid.h @@ -24,7 +24,9 @@ int cdiUUIDIsNull(const unsigned char uuid[]) return isNull; } +#ifndef _WIN32 void cdiCreateUUID(unsigned char uuid[CDI_UUID_SIZE]); +#endif int cdiUUID2Str(const unsigned char uuid[], char uuidstr[]); int cdiStr2UUID(const char *uuidstr, unsigned char uuid[]); diff --git a/src/util.c b/src/util.c index 7eada35c9..df97d6a0c 100644 --- a/src/util.c +++ b/src/util.c @@ -100,6 +100,7 @@ cdiUnescapeSpaces(const char *string, const char **outStringEnd) return result; } +#ifndef _WIN32 #if defined(HAVE_DECL_UUID_GENERATE) && defined(HAVE_UUID_UUID_H) #ifdef HAVE_SYS_TIME_H #include <sys/time.h> @@ -252,6 +253,7 @@ cdiCreateUUID(unsigned char *uuid) #endif } #endif +#endif /* * Local Variables: -- GitLab From 3d9fade324dcd5dff06fafaa537a907772341c6a Mon Sep 17 00:00:00 2001 From: Mathieu Westphal <mathieu.westphal@kitware.com> Date: Thu, 27 Feb 2025 13:36:33 +0100 Subject: [PATCH 4/6] Windows: Add symbol export using CMake --- src/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b7dde6384..8328f34e5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -190,6 +190,9 @@ list( APPEND cdi_unknown resource_unpack.h ) +# Support exporting all symbolds on Windows +set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) + add_library(cdilib ${cdi_src_files} ${cdi_unknown} # INSTALL_HEADERS_LIST cdi.h -- GitLab From ef897ee999d981ee08326cfcada6b3aec50a9a0f Mon Sep 17 00:00:00 2001 From: Uwe Schulzweida <uwe.schulzweida@mpimet.mpg.de> Date: Thu, 27 Feb 2025 18:07:54 +0000 Subject: [PATCH 5/6] Moved include of io.h to windows branch --- src/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file.c b/src/file.c index bd602ef2b..d38c5a251 100644 --- a/src/file.c +++ b/src/file.c @@ -14,7 +14,6 @@ #include <ctype.h> #include <errno.h> #include <fcntl.h> -#include <io.h> #include <limits.h> #include <stdbool.h> #include <stdio.h> @@ -26,6 +25,7 @@ // On Windows, define ssize_t manually #ifdef _WIN32 #define ssize_t __int64 +#include <io.h> #else #include <unistd.h> #endif -- GitLab From 010129d30602eb55919a69b2764e411fe98f328a Mon Sep 17 00:00:00 2001 From: Uwe Schulzweida <uwe.schulzweida@mpimet.mpg.de> Date: Thu, 27 Feb 2025 18:09:37 +0000 Subject: [PATCH 6/6] Moved include of io.h to windows branch --- src/input_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input_file.c b/src/input_file.c index 4c920efa2..11df000c9 100644 --- a/src/input_file.c +++ b/src/input_file.c @@ -18,13 +18,13 @@ #include <errno.h> #include <fcntl.h> -#include <io.h> #include <string.h> // On Windows, define ssize_t and pread manually #ifdef _WIN32 #define ssize_t __int64 #define pread read +#include <io.h> #else #include <unistd.h> #endif -- GitLab