GenerateMappings.cmake 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. if (line MATCHES "platform:Windows")
  22. if (GLFW_WIN32_MAPPINGS)
  23. set(GLFW_WIN32_MAPPINGS "${GLFW_WIN32_MAPPINGS}\n")
  24. endif()
  25. set(GLFW_WIN32_MAPPINGS "${GLFW_WIN32_MAPPINGS}\"${line}\",")
  26. elseif (line MATCHES "platform:Mac OS X")
  27. if (GLFW_COCOA_MAPPINGS)
  28. set(GLFW_COCOA_MAPPINGS "${GLFW_COCOA_MAPPINGS}\n")
  29. endif()
  30. set(GLFW_COCOA_MAPPINGS "${GLFW_COCOA_MAPPINGS}\"${line}\",")
  31. elseif (line MATCHES "platform:Linux")
  32. if (GLFW_LINUX_MAPPINGS)
  33. set(GLFW_LINUX_MAPPINGS "${GLFW_LINUX_MAPPINGS}\n")
  34. endif()
  35. set(GLFW_LINUX_MAPPINGS "${GLFW_LINUX_MAPPINGS}\"${line}\",")
  36. endif()
  37. endif()
  38. endforeach()
  39. configure_file("${template_path}" "${target_path}" @ONLY NEWLINE_STYLE UNIX)
  40. file(REMOVE "${source_path}")