diff --git a/CMakeLists.txt b/CMakeLists.txt
index 43d7dee70..b5f7cdec2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,6 +42,21 @@ message("PATH: $ENV{PATH}")
message("PERL5LIB: $ENV{PERL5LIB}")
find_package(Perl REQUIRED)
+# CMAKE_PREFIX_PATH is used to point CMake to the remaining dependencies (Boost, TBB, ...)
+# We pick it from environment if it is not defined in another way
+if(NOT DEFINED CMAKE_PREFIX_PATH)
+ if(DEFINED ENV{CMAKE_PREFIX_PATH})
+ set(CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}")
+ endif()
+endif()
+
+if (MSVC)
+ # By default the startup project in MSVC is the 'ALL_BUILD' cmake-created project,
+ # but we want 'slic3r' as the startup one because debugging run command is associated with it.
+ # (Unfortunatelly it cannot be associated with ALL_BUILD using CMake.)
+ set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT slic3r)
+endif ()
+
add_subdirectory(xs)
enable_testing ()
diff --git a/cmake/msvc/slic3r.wperl64d.props b/cmake/msvc/slic3r.wperl64d.props
new file mode 100644
index 000000000..68dac2085
--- /dev/null
+++ b/cmake/msvc/slic3r.wperl64d.props
@@ -0,0 +1,9 @@
+
+
+
+ C:\wperl64d\bin\perl.exe
+ slic3r.pl
+ WindowsLocalDebugger
+ ..\..
+
+
diff --git a/cmake/msvc/xs.wperl64d.props b/cmake/msvc/xs.wperl64d.props
new file mode 100644
index 000000000..101923581
--- /dev/null
+++ b/cmake/msvc/xs.wperl64d.props
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+ $(VC_ExecutablePath_x64);$(WindowsSDK_ExecutablePath);$(VS_ExecutablePath);$(MSBuild_ExecutablePath);$(FxCopDir);$(PATH);c:\wperl64d\bin\;
+
+
+
+
diff --git a/xs/CMakeLists.txt b/xs/CMakeLists.txt
index d2f252030..e4e0e1c6c 100644
--- a/xs/CMakeLists.txt
+++ b/xs/CMakeLists.txt
@@ -603,6 +603,17 @@ elseif (NOT MSVC)
target_link_libraries(slic3r -lstdc++)
endif ()
+if (MSVC)
+ # Here we associate some additional properties with the MSVC projects to enable compilation and debugging out of the box.
+ # It seems a props file needs to be copied to the same dir as the proj file, otherwise MSVC doesn't load it up.
+ # For copying, the configure_file() function seems to work much better than the file() function.
+ configure_file("${PROJECT_SOURCE_DIR}/cmake/msvc/xs.wperl64d.props" ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
+ set_target_properties(XS PROPERTIES VS_USER_PROPS "xs.wperl64d.props")
+ configure_file("${PROJECT_SOURCE_DIR}/cmake/msvc/slic3r.wperl64d.props" ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
+ set_target_properties(slic3r PROPERTIES VS_USER_PROPS "slic3r.wperl64d.props")
+endif ()
+
+
# Installation
install(TARGETS XS DESTINATION lib/slic3r-prusa3d/auto/Slic3r/XS)
install(FILES lib/Slic3r/XS.pm DESTINATION lib/slic3r-prusa3d/Slic3r)
diff --git a/xs/src/xsinit.h b/xs/src/xsinit.h
index 49981b74b..96c4b74d7 100644
--- a/xs/src/xsinit.h
+++ b/xs/src/xsinit.h
@@ -59,6 +59,15 @@ extern "C" {
#undef seek
#undef send
#undef write
+ #undef open
+ #undef close
+ #undef seekdir
+ #undef setbuf
+ #undef fread
+ #undef fseek
+ #undef fputc
+ #undef fwrite
+ #undef fclose
#endif /* _MSC_VER */
}
#endif