CMakeLists.txt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
  2. project(cyclegan-jit)
  3. find_package(Torch REQUIRED)
  4. # Explicitly dealing with OpenMP seems to be needed with some C++
  5. # nightlies in March 2020. Probably a bug.
  6. find_package(OpenMP)
  7. if(OPENMP_FOUND)
  8. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
  9. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
  10. endif()
  11. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
  12. add_executable(cyclegan-jit cyclegan_jit.cpp)
  13. target_link_libraries(cyclegan-jit pthread jpeg X11)
  14. target_link_libraries(cyclegan-jit "${TORCH_LIBRARIES}")
  15. set_property(TARGET cyclegan-jit PROPERTY CXX_STANDARD 14)
  16. add_executable(cyclegan-cpp-api cyclegan_cpp_api.cpp)
  17. target_link_libraries(cyclegan-cpp-api pthread jpeg X11)
  18. target_link_libraries(cyclegan-cpp-api "${TORCH_LIBRARIES}")
  19. set_property(TARGET cyclegan-cpp-api PROPERTY CXX_STANDARD 14)
  20. # The following code block is suggested to be used on Windows.
  21. # According to https://github.com/pytorch/pytorch/issues/25457,
  22. # the DLLs need to be copied to avoid memory errors.
  23. if (MSVC)
  24. file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
  25. add_custom_command(TARGET cyclegan-jit
  26. POST_BUILD
  27. COMMAND ${CMAKE_COMMAND} -E copy_if_different
  28. ${TORCH_DLLS}
  29. $<TARGET_FILE_DIR:example-app>)
  30. endif (MSVC)