Skip to content

Commit ca6f0da

Browse files
committed
Windows compatibility
1 parent 8627996 commit ca6f0da

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,11 @@ target_include_directories(openPMD PUBLIC
421421
$<INSTALL_INTERFACE:include>
422422
)
423423

424+
# Winsock library for gethostname() function on Windows
425+
if(WIN32)
426+
target_link_libraries(openPMD PRIVATE ws2_32)
427+
endif()
428+
424429
# C++11 std::variant (C++17 stdlib preview)
425430
# TODO not needed with C++17 compiler
426431
add_library(openPMD::thirdparty::mpark_variant INTERFACE IMPORTED)

src/ChunkInfo.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@
2626
#include <iostream>
2727
#include <list>
2828
#include <map>
29-
#include <unistd.h>
3029
#include <utility>
3130

31+
#ifdef _WIN32
32+
#include <windows.h>
33+
#else
34+
#include <unistd.h>
35+
#endif
36+
3237
namespace openPMD
3338
{
3439
ChunkInfo::ChunkInfo( Offset offset_in, Extent extent_in )
@@ -569,7 +574,10 @@ chunk_assignment::RankMeta byMethodCollective( MPI_Comm comm, Method method )
569574
std::string hostname()
570575
{
571576
char hostname[ MAX_HOSTNAME_LENGTH ];
572-
gethostname( hostname, MAX_HOSTNAME_LENGTH );
577+
if( gethostname( hostname, MAX_HOSTNAME_LENGTH ) )
578+
{
579+
throw std::runtime_error( "[gethostname] Could not inquire hostname." );
580+
}
573581
std::string res( hostname );
574582
return res;
575583
}

0 commit comments

Comments
 (0)