RunPzip.cmake 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. function(run_pzip target_name source destination glob)
  2. file(GLOB_RECURSE files RELATIVE "${source}" "${source}/${glob}")
  3. if(CMAKE_CROSSCOMPILING)
  4. add_executable(host_pzip ALIAS Panda3D::Tools::pzip)
  5. else()
  6. add_executable(host_pzip ALIAS pzip)
  7. endif()
  8. set(dstfiles "")
  9. foreach(filename ${files})
  10. string(REGEX REPLACE "^/" "" filename "${filename}")
  11. get_filename_component(dstdir "${destination}/${filename}" DIRECTORY)
  12. if(TARGET host_pzip)
  13. set(dstfile "${filename}.pz")
  14. list(APPEND dstfiles "${destination}/${dstfile}")
  15. add_custom_command(OUTPUT "${destination}/${dstfile}"
  16. COMMAND ${CMAKE_COMMAND} -E make_directory "${dstdir}"
  17. COMMAND host_pzip -o "${destination}/${dstfile}" "${source}/${filename}"
  18. DEPENDS host_pzip
  19. COMMENT "")
  20. else()
  21. # If pzip isn't built, we just copy instead.
  22. list(APPEND dstfiles "${destination}/${filename}")
  23. add_custom_command(OUTPUT "${destination}/${filename}"
  24. COMMAND ${CMAKE_COMMAND} -E
  25. copy_if_different "${source}/${filename}" "${destination}/${filename}"
  26. COMMENT "")
  27. endif()
  28. endforeach(filename)
  29. add_custom_target(${target_name} ALL
  30. DEPENDS ${dstfiles}
  31. WORKING_DIRECTORY "${destination}")
  32. endfunction(run_pzip)