GenerateMappings.cmake 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Usage:
  2. # cmake -P GenerateMappings.cmake <path/to/mappings.h.in> <path/to/mappings.h>
  3. cmake_policy(VERSION 3.16)
  4. set(source_url "https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt")
  5. set(source_path "${CMAKE_CURRENT_BINARY_DIR}/gamecontrollerdb.txt")
  6. set(template_path "${CMAKE_ARGV3}")
  7. set(target_path "${CMAKE_ARGV4}")
  8. if (NOT EXISTS "${template_path}")
  9. message(FATAL_ERROR "Failed to find template file ${template_path}")
  10. endif()
  11. file(DOWNLOAD "${source_url}" "${source_path}"
  12. STATUS download_status
  13. TLS_VERIFY on)
  14. list(GET download_status 0 status_code)
  15. list(GET download_status 1 status_message)
  16. if (status_code)
  17. message(FATAL_ERROR "Failed to download ${source_url}: ${status_message}")
  18. endif()
  19. file(STRINGS "${source_path}" lines)
  20. list(FILTER lines INCLUDE REGEX "^[0-9a-fA-F]")
  21. foreach(line IN LISTS lines)
  22. if (line MATCHES "platform:Windows")
  23. if (GLFW_WIN32_MAPPINGS)
  24. string(APPEND GLFW_WIN32_MAPPINGS "\n")
  25. endif()
  26. string(APPEND GLFW_WIN32_MAPPINGS "\"${line}\",")
  27. elseif (line MATCHES "platform:Mac OS X")
  28. if (GLFW_COCOA_MAPPINGS)
  29. string(APPEND GLFW_COCOA_MAPPINGS "\n")
  30. endif()
  31. string(APPEND GLFW_COCOA_MAPPINGS "\"${line}\",")
  32. elseif (line MATCHES "platform:Linux")
  33. if (GLFW_LINUX_MAPPINGS)
  34. string(APPEND GLFW_LINUX_MAPPINGS "\n")
  35. endif()
  36. string(APPEND GLFW_LINUX_MAPPINGS "\"${line}\",")
  37. endif()
  38. endforeach()
  39. configure_file("${template_path}" "${target_path}" @ONLY NEWLINE_STYLE UNIX)
  40. file(REMOVE "${source_path}")