WindowsDllCopy.cmake 1.0 KB

1234567891011121314151617181920212223242526272829303132
  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 -D BINARY=")
  9. endif()
  10. if(NOT DEFINED DST)
  11. message(FATAL_ERROR "Missing required arguments -D DST=")
  12. endif()
  13. if(NOT DEFINED CMAKE_PREFIX_PATH)
  14. message(FATAL_ERROR "Missing required arguments -D CMAKE_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. if(CI_BUILD)
  24. message("Copying ${DLL_NAME} to ${DST}")
  25. endif()
  26. execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${DLL_PATH} ${DST})
  27. unset(DLL_PATH CACHE)
  28. endforeach()