diff --git a/CMakeLists.txt b/CMakeLists.txt index 551714d2de..d1ea29616f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -546,7 +546,11 @@ target_include_directories(openPMD PUBLIC # Winsock library for gethostname() function on Windows if(WIN32) - target_link_libraries(openPMD PRIVATE ws2_32) + # need to link this publically as WSAStartup() and WSACleanup() need to be + # called surrounding the gethostname() function on Windows + # and it needs to be done at client site since the winsocks API is + # initialized statically per process.... + target_link_libraries(openPMD PUBLIC ws2_32) endif() # Catch2 for unit tests diff --git a/test/SerialIOTest.cpp b/test/SerialIOTest.cpp index 41d3c823be..80fd638de9 100644 --- a/test/SerialIOTest.cpp +++ b/test/SerialIOTest.cpp @@ -40,6 +40,12 @@ #include #endif +#ifdef _WIN32 +#include +// windows.h defines this macro and it breaks any function with the same name +#undef max +#endif + using namespace openPMD; struct BackendSelection @@ -1512,6 +1518,10 @@ TEST_CASE("dtype_test", "[serial]") inline void write_test(const std::string &backend) { +#ifdef _WIN32 + WSADATA wsaData; + WSAStartup(MAKEWORD(2, 0), &wsaData); +#endif Series o = Series( "../samples/serial_write." + backend, Access::CREATE, @@ -1620,6 +1630,9 @@ inline void write_test(const std::string &backend) REQUIRE( (read.mpiRanksMetaInfo(/* collective = */ false) == chunk_assignment::RankMeta{{0, host_info::hostname()}})); +#ifdef _WIN32 + WSACleanup(); +#endif } TEST_CASE("write_test", "[serial]") @@ -1774,6 +1787,10 @@ fileBased_add_EDpic(ParticleSpecies &e, uint64_t const num_particles) inline void fileBased_write_test(const std::string &backend) { +#ifdef _WIN32 + WSADATA wsaData; + WSAStartup(MAKEWORD(2, 0), &wsaData); +#endif if (auxiliary::directory_exists("../samples/subdir")) auxiliary::remove_directory("../samples/subdir"); @@ -2154,6 +2171,9 @@ inline void fileBased_write_test(const std::string &backend) close(dirfd); } #endif // defined(__unix__) +#ifdef _WIN32 + WSACleanup(); +#endif } TEST_CASE("fileBased_write_test", "[serial]")