2020-06-14 06:37:31 +10:00
|
|
|
# TODO: Check for env or command line "ZMK_CONFIG" setting.
|
|
|
|
# * That directory should load
|
|
|
|
# * defconfigs,
|
|
|
|
# * .conf file,
|
|
|
|
# * single overlay,
|
|
|
|
# * or per board/shield.
|
|
|
|
|
2020-11-19 23:01:13 +11:00
|
|
|
cmake_minimum_required(VERSION 3.15)
|
|
|
|
|
2020-06-14 06:37:31 +10:00
|
|
|
get_property(cached_user_config_value CACHE ZMK_CONFIG PROPERTY VALUE)
|
|
|
|
|
|
|
|
set(user_config_cli_argument ${cached_user_config_value}) # Either new or old
|
|
|
|
if(user_config_cli_argument STREQUAL CACHED_ZMK_CONFIG)
|
|
|
|
# We already have a CACHED_ZMK_CONFIG so there is no new input on the CLI
|
|
|
|
unset(user_config_cli_argument)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(user_config_app_cmake_lists ${ZMK_CONFIG})
|
|
|
|
if(cached_user_config_value STREQUAL ZMK_CONFIG)
|
|
|
|
# The app build scripts did not set a default, The ZMK_CONFIG we are
|
|
|
|
# reading is the cached value from the CLI
|
|
|
|
unset(user_config_app_cmake_lists)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CACHED_ZMK_CONFIG)
|
|
|
|
# Warn the user if it looks like he is trying to change the user_config
|
|
|
|
# without cleaning first
|
|
|
|
if(user_config_cli_argument)
|
|
|
|
if(NOT (CACHED_ZMK_CONFIG STREQUAL user_config_cli_argument))
|
|
|
|
message(WARNING "The build directory must be cleaned pristinely when changing user ZMK config")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(ZMK_CONFIG ${CACHED_ZMK_CONFIG})
|
|
|
|
elseif(user_config_cli_argument)
|
|
|
|
set(ZMK_CONFIG ${user_config_cli_argument})
|
|
|
|
|
|
|
|
elseif(DEFINED ENV{ZMK_CONFIG})
|
|
|
|
set(ZMK_CONFIG $ENV{ZMK_CONFIG})
|
|
|
|
|
|
|
|
elseif(user_config_app_cmake_lists)
|
|
|
|
set(ZMK_CONFIG ${user_config_app_cmake_lists})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Store the selected user_config in the cache
|
|
|
|
set(CACHED_ZMK_CONFIG ${ZMK_CONFIG} CACHE STRING "Selected user ZMK config")
|
|
|
|
|
2020-07-23 09:42:05 +10:00
|
|
|
if (ZMK_CONFIG)
|
2020-08-21 00:51:35 +10:00
|
|
|
set(ENV{ZMK_CONFIG} "${ZMK_CONFIG}")
|
2020-07-25 14:13:40 +10:00
|
|
|
if(EXISTS ${ZMK_CONFIG}/boards)
|
2020-07-24 13:01:47 +10:00
|
|
|
message(STATUS "Adding ZMK config directory as board root: ${ZMK_CONFIG}")
|
2020-07-25 14:13:40 +10:00
|
|
|
list(APPEND BOARD_ROOT ${ZMK_CONFIG})
|
2020-07-23 09:42:05 +10:00
|
|
|
endif()
|
2020-07-25 14:13:40 +10:00
|
|
|
if(EXISTS ${ZMK_CONFIG}/dts)
|
2020-07-24 13:01:47 +10:00
|
|
|
message(STATUS "Adding ZMK config directory as DTS root: ${ZMK_CONFIG}")
|
2020-07-25 14:13:40 +10:00
|
|
|
list(APPEND DTS_ROOT ${ZMK_CONFIG})
|
2020-07-23 09:42:05 +10:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2020-06-14 06:37:31 +10:00
|
|
|
foreach(root ${BOARD_ROOT})
|
2020-07-02 12:58:30 +10:00
|
|
|
if (EXISTS "${root}/boards/${BOARD}.overlay")
|
|
|
|
list(APPEND ZMK_DTC_FILES "${root}/boards/${BOARD}.overlay")
|
|
|
|
endif()
|
2020-06-14 06:37:31 +10:00
|
|
|
find_path(BOARD_DIR
|
|
|
|
NAMES ${BOARD}_defconfig
|
|
|
|
PATHS ${root}/boards/*/*
|
|
|
|
NO_DEFAULT_PATH
|
2020-08-07 00:32:06 +10:00
|
|
|
)
|
|
|
|
if(BOARD_DIR)
|
|
|
|
list(APPEND KEYMAP_DIRS ${BOARD_DIR})
|
2020-06-14 06:37:31 +10:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(DEFINED SHIELD)
|
|
|
|
find_path(shields_refs_list
|
|
|
|
NAMES ${SHIELD}.overlay
|
|
|
|
PATHS ${root}/boards/shields/*
|
|
|
|
NO_DEFAULT_PATH
|
|
|
|
)
|
|
|
|
foreach(shield_path ${shields_refs_list})
|
2020-07-25 14:13:40 +10:00
|
|
|
get_filename_component(SHIELD_DIR ${shield_path} NAME)
|
2020-08-07 00:32:06 +10:00
|
|
|
list(APPEND KEYMAP_DIRS ${shield_path})
|
2020-06-14 06:37:31 +10:00
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if (ZMK_CONFIG)
|
2020-07-25 14:13:40 +10:00
|
|
|
if (EXISTS ${ZMK_CONFIG})
|
2020-06-14 06:37:31 +10:00
|
|
|
message(STATUS "ZMK Config directory: ${ZMK_CONFIG}")
|
|
|
|
list(APPEND DTS_ROOT ${ZMK_CONFIG})
|
2020-08-07 00:32:06 +10:00
|
|
|
list(PREPEND KEYMAP_DIRS "${ZMK_CONFIG}")
|
2020-06-14 06:37:31 +10:00
|
|
|
|
|
|
|
if (SHIELD)
|
2020-07-25 14:13:40 +10:00
|
|
|
message(STATUS "Board: ${BOARD}, ${BOARD_DIR}, ${SHIELD}, ${SHIELD_DIR}")
|
|
|
|
list(APPEND overlay_candidates "${ZMK_CONFIG}/${SHIELD_DIR}.overlay")
|
|
|
|
list(APPEND overlay_candidates "${ZMK_CONFIG}/${SHIELD_DIR}_${BOARD}.overlay")
|
2020-06-14 06:37:31 +10:00
|
|
|
list(APPEND overlay_candidates "${ZMK_CONFIG}/${SHIELD}_${BOARD}.overlay")
|
|
|
|
list(APPEND overlay_candidates "${ZMK_CONFIG}/${SHIELD}.overlay")
|
2020-07-25 14:13:40 +10:00
|
|
|
list(APPEND config_candidates "${ZMK_CONFIG}/${SHIELD_DIR}.conf")
|
|
|
|
list(APPEND config_candidates "${ZMK_CONFIG}/${SHIELD_DIR}_${BOARD}.conf")
|
2020-06-14 06:37:31 +10:00
|
|
|
list(APPEND config_candidates "${ZMK_CONFIG}/${SHIELD}_${BOARD}.conf")
|
|
|
|
list(APPEND config_candidates "${ZMK_CONFIG}/${SHIELD}.conf")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# TODO: Board revisions?
|
|
|
|
list(APPEND overlay_candidates "${ZMK_CONFIG}/${BOARD}.overlay")
|
|
|
|
list(APPEND overlay_candidates "${ZMK_CONFIG}/default.overlay")
|
|
|
|
list(APPEND config_candidates "${ZMK_CONFIG}/${BOARD}.conf")
|
|
|
|
list(APPEND config_candidates "${ZMK_CONFIG}/default.conf")
|
|
|
|
|
|
|
|
foreach(overlay ${overlay_candidates})
|
|
|
|
if (EXISTS "${overlay}")
|
|
|
|
message(STATUS "ZMK Config devicetree overlay: ${overlay}")
|
|
|
|
list(APPEND ZMK_DTC_FILES "${overlay}")
|
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
foreach(conf ${config_candidates})
|
|
|
|
if (EXISTS "${conf}")
|
2020-08-07 00:32:06 +10:00
|
|
|
message(STATUS "ZMK Config Kconfig: ${conf}")
|
2020-06-14 06:37:31 +10:00
|
|
|
set(CONF_FILE "${conf}")
|
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
else()
|
|
|
|
message(WARNING "Unable to locate ZMK config at: ${ZMK_CONFIG}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2020-08-07 00:32:06 +10:00
|
|
|
|
|
|
|
if(NOT KEYMAP_FILE)
|
|
|
|
foreach(keymap_dir ${KEYMAP_DIRS})
|
|
|
|
foreach(keymap_prefix ${SHIELD} ${SHIELD_DIR} ${BOARD} ${BOARD_DIR})
|
|
|
|
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}")
|
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (NOT KEYMAP_FILE)
|
|
|
|
message(FATAL_ERROR "Failed to locate keymap file!")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
list(APPEND ZMK_DTC_FILES ${KEYMAP_FILE})
|
|
|
|
|
2020-06-14 06:37:31 +10:00
|
|
|
if (ZMK_DTC_FILES)
|
|
|
|
string(REPLACE ";" " " DTC_OVERLAY_FILE "${ZMK_DTC_FILES}")
|
|
|
|
endif()
|