From 0db22dfd7962667058e31fecd747cfbed236d1fc Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 6 Nov 2023 17:59:01 +0000 Subject: [PATCH] refactor: Hook into CMake loading in a better spot. * Shift to using an extra Zephyr module to do keymap location work after all board roots are resolved. This avoids duplicate work and allows us to load custom boards from Zephyr modules as well as user config setups. --- app/CMakeLists.txt | 9 +-------- .../modules/modules.cmake} | 15 ++++++++------- app/keymap-module/zephyr/module.yml | 3 +++ 3 files changed, 12 insertions(+), 15 deletions(-) rename app/{cmake/ZephyrBuildConfig.cmake => keymap-module/modules/modules.cmake} (95%) create mode 100644 app/keymap-module/zephyr/module.yml diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 793f386dbe3..d81da52b291 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -2,14 +2,7 @@ cmake_minimum_required(VERSION 3.13.1) set(CONFIG_APPLICATION_DEFINED_SYSCALL true) -# Add our custom Zephyr module for drivers w/ syscalls, etc. -list(APPEND DTS_ROOT ${CMAKE_SOURCE_DIR}/drivers/zephyr) - -set(ZephyrBuildConfiguration_ROOT ${CMAKE_SOURCE_DIR}/cmake) - -list(APPEND ZEPHYR_EXTRA_MODULES - ${CMAKE_CURRENT_SOURCE_DIR}/module -) +set(ZEPHYR_EXTRA_MODULES "${ZMK_EXTRA_MODULES};${CMAKE_CURRENT_SOURCE_DIR}/module;${CMAKE_CURRENT_SOURCE_DIR}/keymap-module") # Find Zephyr. This also loads Zephyr's build system. find_package(Zephyr REQUIRED HINTS ../zephyr) diff --git a/app/cmake/ZephyrBuildConfig.cmake b/app/keymap-module/modules/modules.cmake similarity index 95% rename from app/cmake/ZephyrBuildConfig.cmake rename to app/keymap-module/modules/modules.cmake index ade341990a0..d125d5e3dca 100644 --- a/app/cmake/ZephyrBuildConfig.cmake +++ b/app/keymap-module/modules/modules.cmake @@ -5,11 +5,6 @@ # * single overlay, # * or per board/shield. -cmake_minimum_required(VERSION 3.15) - -list(APPEND BOARD_ROOT ${APPLICATION_SOURCE_DIR}) -list(APPEND DTS_ROOT ${APPLICATION_SOURCE_DIR}) - get_property(cached_user_config_value CACHE ZMK_CONFIG PROPERTY VALUE) set(user_config_cli_argument ${cached_user_config_value}) # Either new or old @@ -60,7 +55,6 @@ if (ZMK_CONFIG) endif() endif() - if(DEFINED SHIELD) string(REPLACE " " ";" SHIELD_AS_LIST "${SHIELD}") endif() @@ -180,19 +174,26 @@ endif() if(NOT KEYMAP_FILE) + message("Keymap dirs: ${KEYMAP_DIRS}") foreach(keymap_dir ${KEYMAP_DIRS}) foreach(keymap_prefix ${shield_candidate_names} ${SHIELD_AS_LIST} ${SHIELD_DIR} ${BOARD} ${BOARD_DIR_NAME}) + message("Checking ${BOARD_DIR_NAME}") if (EXISTS ${keymap_dir}/${keymap_prefix}.keymap) set(KEYMAP_FILE "${keymap_dir}/${keymap_prefix}.keymap" CACHE STRING "Selected keymap file") message(STATUS "Using keymap file: ${KEYMAP_FILE}") set(DTC_OVERLAY_FILE ${KEYMAP_FILE}) + message("$ENV{DTC_OVERLAY_FILE}") break() endif() endforeach() endforeach() else() message(STATUS "Using keymap file: ${KEYMAP_FILE}") - set(DTC_OVERLAY_FILE ${KEYMAP_FILE}) + message("$ENV{DTC_OVERLAY_FILE}") + message("${DTC_OVERLAY_FILE}") + set(DTC_OVERLAY_FILE "${KEYMAP_FILE}") + message("$ENV{DTC_OVERLAY_FILE}") + message("${DTC_OVERLAY_FILE}") endif() if (NOT KEYMAP_FILE) diff --git a/app/keymap-module/zephyr/module.yml b/app/keymap-module/zephyr/module.yml new file mode 100644 index 00000000000..fc0f4225584 --- /dev/null +++ b/app/keymap-module/zephyr/module.yml @@ -0,0 +1,3 @@ +build: + settings: + module_ext_root: "."