2017-09-14 18:16:25 +00:00
|
|
|
# Usage:
|
|
|
|
# cmake -P GenerateMappings.cmake <path/to/mappings.h.in> <path/to/mappings.h>
|
|
|
|
|
2018-02-13 17:57:56 +00:00
|
|
|
set(source_url "https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt")
|
2017-09-14 18:16:25 +00:00
|
|
|
set(source_path "${CMAKE_CURRENT_BINARY_DIR}/gamecontrollerdb.txt")
|
|
|
|
set(template_path "${CMAKE_ARGV3}")
|
|
|
|
set(target_path "${CMAKE_ARGV4}")
|
|
|
|
|
|
|
|
if (NOT EXISTS "${template_path}")
|
|
|
|
message(FATAL_ERROR "Failed to find template file ${template_path}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
file(DOWNLOAD "${source_url}" "${source_path}"
|
|
|
|
STATUS download_status
|
|
|
|
TLS_VERIFY on)
|
|
|
|
|
|
|
|
list(GET download_status 0 status_code)
|
|
|
|
list(GET download_status 1 status_message)
|
|
|
|
|
|
|
|
if (status_code)
|
|
|
|
message(FATAL_ERROR "Failed to download ${source_url}: ${status_message}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
file(STRINGS "${source_path}" lines)
|
|
|
|
foreach(line ${lines})
|
2021-08-25 10:09:21 +00:00
|
|
|
if (line MATCHES "^[0-9a-fA-F]")
|
2021-08-25 10:07:01 +00:00
|
|
|
if (line MATCHES "platform:Windows")
|
2021-06-28 22:42:31 +00:00
|
|
|
if (GLFW_WIN32_MAPPINGS)
|
2021-08-25 10:17:45 +00:00
|
|
|
string(APPEND GLFW_WIN32_MAPPINGS "\n")
|
2021-06-28 22:42:31 +00:00
|
|
|
endif()
|
2021-08-25 10:17:45 +00:00
|
|
|
string(APPEND GLFW_WIN32_MAPPINGS "\"${line}\",")
|
2021-08-25 10:07:01 +00:00
|
|
|
elseif (line MATCHES "platform:Mac OS X")
|
2021-06-28 22:42:31 +00:00
|
|
|
if (GLFW_COCOA_MAPPINGS)
|
2021-08-25 10:17:45 +00:00
|
|
|
string(APPEND GLFW_COCOA_MAPPINGS "\n")
|
2021-06-28 22:42:31 +00:00
|
|
|
endif()
|
2021-08-25 10:17:45 +00:00
|
|
|
string(APPEND GLFW_COCOA_MAPPINGS "\"${line}\",")
|
2021-08-25 10:07:01 +00:00
|
|
|
elseif (line MATCHES "platform:Linux")
|
2021-06-28 22:42:31 +00:00
|
|
|
if (GLFW_LINUX_MAPPINGS)
|
2021-08-25 10:17:45 +00:00
|
|
|
string(APPEND GLFW_LINUX_MAPPINGS "\n")
|
2021-06-28 22:42:31 +00:00
|
|
|
endif()
|
2021-08-25 10:17:45 +00:00
|
|
|
string(APPEND GLFW_LINUX_MAPPINGS "\"${line}\",")
|
2021-06-28 22:42:31 +00:00
|
|
|
endif()
|
2017-09-14 18:16:25 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
configure_file("${template_path}" "${target_path}" @ONLY NEWLINE_STYLE UNIX)
|
|
|
|
file(REMOVE "${source_path}")
|
|
|
|
|