Advertisement
Laudanum-user

pytorch cmake

Apr 19th, 2023
2,580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CMake 0.81 KB | None | 0 0
  1. cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
  2. project(example-app)
  3.  
  4. find_package(Torch REQUIRED)
  5. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
  6.  
  7. add_executable(example-app example-app.cpp)
  8. target_link_libraries(example-app "${TORCH_LIBRARIES}")
  9. set_property(TARGET example-app PROPERTY CXX_STANDARD 14)
  10.  
  11. # The following code block is suggested to be used on Windows.
  12. # According to https://github.com/pytorch/pytorch/issues/25457,
  13. # the DLLs need to be copied to avoid memory errors.
  14. if (MSVC)
  15.   file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
  16.   add_custom_command(TARGET example-app
  17.                      POST_BUILD
  18.                      COMMAND ${CMAKE_COMMAND} -E copy_if_different
  19.                      ${TORCH_DLLS}
  20.                      $<TARGET_FILE_DIR:example-app>)
  21. endif (MSVC)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement