Skip to content

Commit

Permalink
Add copy logic for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjc123 committed Sep 3, 2019
1 parent d3120cd commit ef196d8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cpp/custom-dataset/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@ target_link_libraries(${PROJECT_NAME} "${OpenCV_LIBS}")
target_link_libraries(${PROJECT_NAME} "${TORCH_LIBRARIES}")

configure_file("info.txt" "info.txt" COPYONLY)

# The following code block is suggested to be used on Windows.
# According to https://github.com/pytorch/pytorch/issues/25457,
# the DLLs need to be copied to avoid memory errors.
if (MSVC)
file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${TORCH_DLLS}
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
endif (MSVC)
9 changes: 9 additions & 0 deletions cpp/dcgan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ endif()
add_executable(dcgan dcgan.cpp)
target_link_libraries(dcgan "${TORCH_LIBRARIES}")
set_property(TARGET dcgan PROPERTY CXX_STANDARD 11)

if (MSVC)
file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
add_custom_command(TARGET dcgan
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${TORCH_DLLS}
$<TARGET_FILE_DIR:dcgan>)
endif (MSVC)
9 changes: 9 additions & 0 deletions cpp/mnist/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ endif()
add_executable(mnist mnist.cpp)
target_compile_features(mnist PUBLIC cxx_range_for)
target_link_libraries(mnist ${TORCH_LIBRARIES})

if (MSVC)
file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
add_custom_command(TARGET mnist
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${TORCH_DLLS}
$<TARGET_FILE_DIR:mnist>)
endif (MSVC)
12 changes: 12 additions & 0 deletions cpp/regression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@ find_package(Torch REQUIRED)

add_executable(${PROJECT_NAME} "regression.cpp")
target_link_libraries(${PROJECT_NAME} "${TORCH_LIBRARIES}")

# The following code block is suggested to be used on Windows.
# According to https://github.com/pytorch/pytorch/issues/25457,
# the DLLs need to be copied to avoid memory errors.
if (MSVC)
file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${TORCH_DLLS}
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
endif (MSVC)

0 comments on commit ef196d8

Please sign in to comment.