From 01778329ec0ccc485eab2a90cc42d3ff88624c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 28 Jun 2021 23:52:07 +0200 Subject: [PATCH] Add custom target for updating gamepad mappings --- docs/input.dox | 5 +++++ src/CMakeLists.txt | 9 +++++++++ src/mappings.h | 2 +- src/mappings.h.in | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/input.dox b/docs/input.dox index 5c6bbf03..dcd8f670 100644 --- a/docs/input.dox +++ b/docs/input.dox @@ -797,6 +797,11 @@ glfwUpdateGamepadMappings(mappings); This function supports everything from single lines up to and including the unmodified contents of the whole `gamecontrollerdb.txt` file. +If you are compiling GLFW from source with CMake you can update the built-in mappings by +building the _update_mappings_ target. This runs the `GenerateMappings.cmake` CMake +script, which downloads `gamecontrollerdb.txt` and regenerates the `mappings.h` header +file. + Below is a description of the mapping format. Please keep in mind that __this description is not authoritative__. The format is defined by the SDL and SDL_GameControllerDB projects and their documentation and code takes precedence. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f6e404f2..fab20ddb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,6 +4,15 @@ add_library(glfw "${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h" internal.h mappings.h context.c init.c input.c monitor.c vulkan.c window.c) +add_custom_target(update_mappings + COMMAND "${CMAKE_COMMAND}" -P "${GLFW_SOURCE_DIR}/CMake/GenerateMappings.cmake" mappings.h.in mappings.h + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMENT "Updating gamepad mappings from upstream repository" + SOURCES mappings.h.in "${GLFW_SOURCE_DIR}/CMake/GenerateMappings.cmake" + VERBATIM) + +set_target_properties(update_mappings PROPERTIES FOLDER "GLFW3") + if (_GLFW_COCOA) target_sources(glfw PRIVATE cocoa_platform.h cocoa_joystick.h posix_thread.h nsgl_context.h egl_context.h osmesa_context.h diff --git a/src/mappings.h b/src/mappings.h index eda9a549..03bc7f3d 100644 --- a/src/mappings.h +++ b/src/mappings.h @@ -31,7 +31,7 @@ // all available in SDL_GameControllerDB. Do not edit this file. Any gamepad // mappings not specific to GLFW should be submitted to SDL_GameControllerDB. // This file can be re-generated from mappings.h.in and the upstream -// gamecontrollerdb.txt with the GenerateMappings.cmake script. +// gamecontrollerdb.txt with the 'update_mappings' CMake target. //======================================================================== // All gamepad mappings not labeled GLFW are copied from the diff --git a/src/mappings.h.in b/src/mappings.h.in index 583e98b2..6717f3c1 100644 --- a/src/mappings.h.in +++ b/src/mappings.h.in @@ -31,7 +31,7 @@ // all available in SDL_GameControllerDB. Do not edit this file. Any gamepad // mappings not specific to GLFW should be submitted to SDL_GameControllerDB. // This file can be re-generated from mappings.h.in and the upstream -// gamecontrollerdb.txt with the GenerateMappings.cmake script. +// gamecontrollerdb.txt with the 'update_mappings' CMake target. //======================================================================== // All gamepad mappings not labeled GLFW are copied from the