From fe59b4e5d669a3b8513ac32b7f7564a0dc7fcb44 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Tue, 4 Apr 2023 16:26:44 -0400 Subject: [PATCH] load keyboard ui through vscode --- .vscode/tasks.json | 30 +++++++++---------- CMakeLists.txt | 2 +- cmake/AddKeyboard.cmake | 2 +- cmake/ConfigureKeyboard.cmake | 44 ++++++++++++++++++++++++++++ cmake/toolchains/arm-none-eabi.cmake | 42 +++++++++----------------- cmake/toolchains/avr.cmake | 2 -- keyboards/CMakeLists.txt | 38 ++++++++++++++++-------- 7 files changed, 100 insertions(+), 60 deletions(-) create mode 100644 cmake/ConfigureKeyboard.cmake diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 4af654899dd..14618443d53 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,10 +2,10 @@ "version": "2.0.0", "tasks": [ { - "label": "Load Keyboard & Refresh Outline", + "label": "Load Keyboard", "dependsOrder": "sequence", "dependsOn":[ - "Load Keyboard", + "Only Load Keyboard", "Configure CMake" ], "group": { @@ -14,9 +14,9 @@ } }, { - "label": "Load Keyboard", + "label": "Only Load Keyboard", "type": "shell", - "command": "cmake -Bbuild -DQMK_KEYBOARD_FOLDER=${input:all_keyboards}", + "command": "cmake -D QMK_KEYBOARD_FOLDER=\"${input:all_keyboards}\" -D QMK_KEYMAP_FOLDER=\"${input:keymap}\" -P ${workspaceFolder}/cmake/ConfigureKeyboard.cmake", "problemMatcher": [] }, { @@ -72,15 +72,6 @@ // } ], "inputs": [ - { - "id": "keyboard", - "description": "Keyboard:", - "type": "pickString", - "options":[ - "planck/rev5", - "olkb/planck/rev3" - ] - }, { "id": "keyboard_target", "type": "command", @@ -97,8 +88,17 @@ "command": "shellCommand.execute", "args": { "command": "type build\\all_keyboards", - "description": "Keyboard:" + "description": "Keyboard:", + "default": "" }, - } + }, + { + "id": "keymap", + "description": "Keymap:", + "type": "pickString", + "options":[ + "default" + ] + }, ] } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a0e0b99256..1ffd2f24044 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,7 @@ resolve_keymap_c(${QMK_KEYBOARD_FOLDER_ABS} ${QMK_KEYMAP_FOLDER} QMK_KEYMAP_C) message(STATUS "config.h: ${QMK_KEYBOARD_CONFIG_H}") message(STATUS "keyboard.h: ${QMK_KEYBOARD_H}") -message(STATUS "Keymap.c: ${QMK_KEYMAP_C}") +message(STATUS "keymap.c: ${QMK_KEYMAP_C}") validate_json(${QMK_KEYBOARD_FOLDER_ABS}/info.json keyboard QMK_KEYBOARD_INFO_JSON_STRING) diff --git a/cmake/AddKeyboard.cmake b/cmake/AddKeyboard.cmake index f315711d74b..013d8a15b90 100644 --- a/cmake/AddKeyboard.cmake +++ b/cmake/AddKeyboard.cmake @@ -72,5 +72,5 @@ macro(add_keyboard KEYBOARD_FOLDER KEYMAP_FOLDER) -DTARGET_NAME=${TARGET_NAME} ) -file(APPEND "${CMAKE_SOURCE_DIR}/build/targets" "${TARGET_NAME}|${KEYBOARD_NAME} with ${KEYMAP_FOLDER}|${KEYBOARD_FOLDER}|Made by: ${MANUFACTURER}\n") +# file(APPEND "${CMAKE_SOURCE_DIR}/build/targets" "${TARGET_NAME}|${KEYBOARD_NAME} with ${KEYMAP_FOLDER}|${KEYBOARD_FOLDER}|Made by: ${MANUFACTURER}\n") endmacro(add_keyboard) \ No newline at end of file diff --git a/cmake/ConfigureKeyboard.cmake b/cmake/ConfigureKeyboard.cmake new file mode 100644 index 00000000000..f6d084725aa --- /dev/null +++ b/cmake/ConfigureKeyboard.cmake @@ -0,0 +1,44 @@ +cmake_minimum_required(VERSION 3.20) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") + +include(ResolveKeyboard) +include(ValidateJSON) + +resolve_keyboard(${QMK_KEYBOARD_FOLDER} KEYBOARD_FOLDER_ABS) +validate_json(${KEYBOARD_FOLDER_ABS}/info.json keyboard JSON_STRING) + +if(NOT DEFINED QMK_KEYMAP_FOLDER) + set(QMK_KEYMAP_FOLDER default) +endif() + +set(TEMP_PATH ${QMK_KEYBOARD_FOLDER}) +cmake_path(IS_RELATIVE TEMP_PATH IS_KEYBOARD_FOLDER_RELATIVE) + +set(TEMP_PATH ${QMK_KEYMAP_FOLDER}) +cmake_path(IS_RELATIVE TEMP_PATH IS_KEYMAP_FOLDER_RELATIVE) + +if(${IS_KEYMAP_FOLDER_RELATIVE}) + set(KEYMAP_NAME ${QMK_KEYMAP_FOLDER}) +else() + if(WIN32) + set(KEYMAP_NAME $ENV{USERNAME}) + else() + set(KEYMAP_NAME $ENV{USE}) + endif() +endif() + +string(JSON KEYBOARD_NAME GET ${JSON_STRING} keyboard_name) + +if(${IS_KEYBOARD_FOLDER_RELATIVE}) + string(MAKE_C_IDENTIFIER ${QMK_KEYBOARD_FOLDER} KEYBOARD_SLUG) +else() + string(MAKE_C_IDENTIFIER ${KEYBOARD_NAME} KEYBOARD_SLUG) +endif() + +string(JSON MANUFACTURER GET ${JSON_STRING} manufacturer) + +set(TARGET_NAME "${KEYBOARD_SLUG}_${KEYMAP_NAME}") +file(APPEND "${CMAKE_SOURCE_DIR}/build/targets" "${TARGET_NAME}|${KEYBOARD_NAME} with ${QMK_KEYMAP_FOLDER}|${QMK_KEYBOARD_FOLDER}|Made by: ${MANUFACTURER}\n") + +message(STATUS "Added keyboard '${QMK_KEYBOARD_FOLDER}' with keymap '${QMK_KEYMAP_FOLDER}'") diff --git a/cmake/toolchains/arm-none-eabi.cmake b/cmake/toolchains/arm-none-eabi.cmake index cb8333db35f..2af836d0928 100644 --- a/cmake/toolchains/arm-none-eabi.cmake +++ b/cmake/toolchains/arm-none-eabi.cmake @@ -30,8 +30,8 @@ set(AVR_SIZE "${TOOLCHAIN_ROOT}/${QMK_TOOLCHAIN}-size${OS_SUFFIX}" find_program(CMAKE_MAKE_PROGRAM NAME make PATHS - $<$:"${CMAKE_SOURCE_DIR}/toolchains/avr-gcc-12.1.0-x64-windows/bin/"> - $<$UNIX>:"${CMAKE_SOURCE_DIR}/toolchains/avr-gcc-12.1.0-x64-linux/bin/"> + "${CMAKE_SOURCE_DIR}/toolchains/avr-gcc-12.1.0-x64-windows/bin/" + "${CMAKE_SOURCE_DIR}/toolchains/avr-gcc-12.1.0-x64-linux/bin/" /usr/bin/ /usr/local/bin /bin/ @@ -100,36 +100,17 @@ else() ) endif() -# include_directories("C:/Users/Jack/Downloads/avr-gcc-12.1.0-x64-windows/avr/include") - macro(add_qmk_executable target_name) - set(elf_file ${target_name}-${QMK_MCU}.elf) - set(map_file ${target_name}-${QMK_MCU}.map) - set(hex_file ${target_name}-${QMK_MCU}.hex) - set(lst_file ${target_name}-${QMK_MCU}.lst) - - # add_link_options(-Wl,--gc-sections,-nostartfiles) + set(elf_file ${target_name}.elf) + set(map_file ${target_name}.map) + set(hex_file ${target_name}.hex) + set(lst_file ${target_name}.lst) # create elf file - add_executable(${elf_file} - ${ARGN} - ) + add_executable(${elf_file} ${ARGN}) - target_link_libraries(${elf_file} - PUBLIC - quantum - tmk_core_protocol - platforms - ) - - # set_target_properties( - # ${elf_file} - - # PROPERTIES - # COMPILE_FLAGS "-mmcu=${QMK_MCU} -g -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics" - # LINK_FLAGS "-mmcu=${QMK_MCU} -Wl,-Map,${map_file}" - # ) + target_link_libraries(${elf_file} qmk) # generate the lst file add_custom_command( @@ -169,11 +150,16 @@ macro(add_qmk_executable target_name) DEPENDS ${hex_file} ) + add_custom_target(copy_hex + COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_SOURCE_DIR}/build/${target_name}.hex + DEPENDS ${hex_file} + ) + # build the intel hex file for the device add_custom_target( ${target_name} ALL - DEPENDS ${hex_file} ${lst_file} "print-size-${elf_file}" "print-size-${hex_file}" + DEPENDS ${hex_file} ${lst_file} "print-size-${elf_file}" "print-size-${hex_file}" copy_hex ) set_target_properties( diff --git a/cmake/toolchains/avr.cmake b/cmake/toolchains/avr.cmake index 2c72645c802..f8d68c747c2 100644 --- a/cmake/toolchains/avr.cmake +++ b/cmake/toolchains/avr.cmake @@ -95,8 +95,6 @@ add_link_options( -Wl,--gc-sections ) -# include_directories("C:/Users/Jack/Downloads/avr-gcc-12.1.0-x64-windows/avr/include") - macro(add_qmk_executable target_name) set(elf_file ${target_name}.elf) diff --git a/keyboards/CMakeLists.txt b/keyboards/CMakeLists.txt index 77a634b6a46..4e6df9c6f6d 100644 --- a/keyboards/CMakeLists.txt +++ b/keyboards/CMakeLists.txt @@ -1,22 +1,34 @@ include(ExternalProject) include(AddKeyboard) -file(WRITE "${CMAKE_SOURCE_DIR}/build/targets" "") +# file(WRITE "${CMAKE_SOURCE_DIR}/build/targets" "") -if(DEFINED QMK_KEYBOARD_FOLDER) - if(NOT DEFINED QMK_KEYMAP_FOLDER) - set(QMK_KEYMAP_FOLDER "default") - endif() - add_keyboard(${QMK_KEYBOARD_FOLDER} ${QMK_KEYMAP_FOLDER}) -endif() +# if(DEFINED QMK_KEYBOARD_FOLDER) +# if(NOT DEFINED QMK_KEYMAP_FOLDER) +# set(QMK_KEYMAP_FOLDER "default") +# endif() +# add_keyboard(${QMK_KEYBOARD_FOLDER} ${QMK_KEYMAP_FOLDER}) +# endif() -file(GLOB_RECURSE KEYBOARDS **/CMakeLists.txt) +# file(GLOB_RECURSE KEYBOARDS **/CMakeLists.txt) -foreach(KEYBOARD_CMAKE ${KEYBOARDS}) - get_filename_component(KEYBOARD_FOLDER_ABS "${KEYBOARD_CMAKE}" DIRECTORY) - file(RELATIVE_PATH KEYBOARD_FOLDER "${CMAKE_SOURCE_DIR}/keyboards" "${KEYBOARD_FOLDER_ABS}") - add_keyboard(${KEYBOARD_FOLDER} "default") -endforeach() +# foreach(KEYBOARD_CMAKE ${KEYBOARDS}) +# get_filename_component(KEYBOARD_FOLDER_ABS "${KEYBOARD_CMAKE}" DIRECTORY) +# file(RELATIVE_PATH KEYBOARD_FOLDER "${CMAKE_SOURCE_DIR}/keyboards" "${KEYBOARD_FOLDER_ABS}") +# add_keyboard(${KEYBOARD_FOLDER} "default") +# endforeach() + +file(STRINGS "${CMAKE_SOURCE_DIR}/build/targets" TARGETS) + +while(TARGETS) + list(POP_FRONT TARGETS LINE) + if (LINE MATCHES "(.+)\\|(.+)\\|(.+)\\|(.+)") + set(KEYBOARD_FOLDER ${CMAKE_MATCH_3}) + add_keyboard(${KEYBOARD_FOLDER} "default") + endif() +endwhile() + +# list all keyboards in build/all_keyboards file(GLOB_RECURSE POSSIBLE_KEYBOARDS **/info.json)