GenerateMappings.cmake 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. # Usage:
  2. # cmake -P GenerateMappings.cmake <path/to/mappings.h.in> <path/to/mappings.h>
  3. set(source_url "https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt")
  4. set(source_path "${CMAKE_CURRENT_BINARY_DIR}/gamecontrollerdb.txt")
  5. set(template_path "${CMAKE_ARGV3}")
  6. set(target_path "${CMAKE_ARGV4}")
  7. if (NOT EXISTS "${template_path}")
  8. message(FATAL_ERROR "Failed to find template file ${template_path}")
  9. endif()
  10. file(DOWNLOAD "${source_url}" "${source_path}"
  11. STATUS download_status
  12. TLS_VERIFY on)
  13. list(GET download_status 0 status_code)
  14. list(GET download_status 1 status_message)
  15. if (status_code)
  16. message(FATAL_ERROR "Failed to download ${source_url}: ${status_message}")
  17. endif()
  18. file(STRINGS "${source_path}" lines)
  19. foreach(line ${lines})
  20. if ("${line}" MATCHES "^[0-9a-fA-F].*$")
  21. set(GLFW_GAMEPAD_MAPPINGS "${GLFW_GAMEPAD_MAPPINGS}\"${line}\",\n")
  22. endif()
  23. endforeach()
  24. configure_file("${template_path}" "${target_path}" @ONLY NEWLINE_STYLE UNIX)
  25. file(REMOVE "${source_path}")