WindowsDllCopy.cmake 999 B

12345678910111213141516171819202122232425262728293031
  1. # In Windows we need to find dependency DLLs and install them along with our
  2. # binaries. This script uses the following variables:
  3. #
  4. # - BINARY: The binary file whose dependencies need to be installed
  5. # - DST: The destination path
  6. # - CMAKE_PREFIX_PATH: A list of directories to search for dependencies
  7. if(NOT DEFINED BINARY)
  8. message(FATAL_ERROR "Missing required argument -DBINARY=")
  9. endif()
  10. if(NOT DEFINED DST)
  11. message(FATAL_ERROR "Missing required arguments -DDST=")
  12. endif()
  13. if(NOT DEFINED CMAKE_PREFIX_PATH)
  14. message(FATAL_ERROR "Missing required arguments -DCMAKE_PREFIX_PATH=")
  15. endif()
  16. include(GetPrerequisites)
  17. get_prerequisites(${BINARY} DLLS 1 1 "" "${CMAKE_PREFIX_PATH}")
  18. foreach(DLL_NAME ${DLLS})
  19. find_program(DLL_PATH ${DLL_NAME})
  20. if(NOT DLL_PATH)
  21. message(FATAL_ERROR "Unable to find dependency ${DLL_NAME}")
  22. endif()
  23. message("Copying ${DLL_NAME} to ${DST}")
  24. execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${DLL_PATH} ${DST})
  25. unset(DLL_PATH CACHE)
  26. endforeach()