]> git.sesse.net Git - pistorm/blob - raylib/external/glfw/CMake/GenerateMappings.cmake
[MEGA-WIP] Raylib-based RTG output
[pistorm] / raylib / external / glfw / CMake / GenerateMappings.cmake
1 # Usage:
2 # cmake -P GenerateMappings.cmake <path/to/mappings.h.in> <path/to/mappings.h>
3
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
9 if (NOT EXISTS "${template_path}")
10     message(FATAL_ERROR "Failed to find template file ${template_path}")
11 endif()
12
13 file(DOWNLOAD "${source_url}" "${source_path}"
14      STATUS download_status
15      TLS_VERIFY on)
16
17 list(GET download_status 0 status_code)
18 list(GET download_status 1 status_message)
19
20 if (status_code)
21     message(FATAL_ERROR "Failed to download ${source_url}: ${status_message}")
22 endif()
23
24 file(STRINGS "${source_path}" lines)
25 foreach(line ${lines})
26     if ("${line}" MATCHES "^[0-9a-fA-F].*$")
27         set(GLFW_GAMEPAD_MAPPINGS "${GLFW_GAMEPAD_MAPPINGS}\"${line}\",\n")
28     endif()
29 endforeach()
30
31 configure_file("${template_path}" "${target_path}" @ONLY NEWLINE_STYLE UNIX)
32 file(REMOVE "${source_path}")
33