MSVC: POSIX compatibility files

There's a bunch of packages on vcpkg, let's use them this way. I wasn't
able to find anything for <unistd.h>, so I took that from
https://stackoverflow.com/a/826027/2245623 .
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1764a5f..9a6bad1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -343,10 +343,32 @@
     target_compile_definitions(yangobj PRIVATE LIBYANG_BUILD)
     add_library(yang SHARED $<TARGET_OBJECTS:yangobj>)
 
+    if(WIN32)
+        find_package(dlfcn-win32 REQUIRED)
+        set(CMAKE_DL_LIBS dlfcn-win32::dl)
+    endif()
+
     #link dl
     target_link_libraries(yang ${CMAKE_DL_LIBS})
 endif()
 
+if(WIN32)
+    find_path(DIRENT_INCLUDE_DIR NAMES dirent.h REQUIRED)
+    message(STATUS "Found <dirent.h> at ${DIRENT_INCLUDE_DIR}")
+
+    set(COMPAT_POSIX_INCLUDES
+        ${CMAKE_CURRENT_SOURCE_DIR}/compat/posix-shims
+        ${DIRENT_INCLUDE_DIR})
+
+    if(TARGET yangobj)
+        target_include_directories(yangobj PRIVATE ${COMPAT_POSIX_INCLUDES})
+    endif()
+    target_include_directories(yang PRIVATE ${COMPAT_POSIX_INCLUDES})
+
+    find_package(pthreads REQUIRED)
+    target_link_libraries(yang PThreads4W::PThreads4W)
+endif()
+
 set_target_properties(yang PROPERTIES VERSION ${LIBYANG_SOVERSION_FULL} SOVERSION ${LIBYANG_SOVERSION})
 
 # link math