@ -7,6 +7,9 @@
@@ -7,6 +7,9 @@
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 } ) # E i t h e r n e w o r o l d
@ -57,9 +60,29 @@ if (ZMK_CONFIG)
@@ -57,9 +60,29 @@ if (ZMK_CONFIG)
endif ( )
endif ( )
if ( DEFINED SHIELD )
string ( REPLACE " " ";" SHIELD_AS_LIST "${SHIELD}" )
endif ( )
foreach ( root ${ BOARD_ROOT } )
set ( shield_dir ${ root } /boards/shields )
# M a t c h t h e K c o n f i g . s h i e l d f i l e s i n t h e s h i e l d d i r e c t o r i e s t o m a k e s u r e w e a r e
# f i n d i n g s h i e l d s , e . g . x _ n u c l e o _ i k s 0 1 a 1 / K c o n f i g . s h i e l d
file ( GLOB_RECURSE shields_refs_list ${ shield_dir } /*/Kconfig.shield )
unset ( SHIELD_LIST )
foreach ( shields_refs ${ shields_refs_list } )
get_filename_component ( shield_path ${ shields_refs } DIRECTORY )
file ( GLOB shield_overlays RELATIVE ${ shield_path } ${ shield_path } /*.overlay )
foreach ( overlay ${ shield_overlays } )
get_filename_component ( shield ${ overlay } NAME_WE )
list ( APPEND SHIELD_LIST ${ shield } )
set ( SHIELD_DIR_ ${ shield } ${ shield_path } )
endforeach ( )
endforeach ( )
if ( EXISTS "${root}/boards/${BOARD}.overlay" )
list ( APPEND ZMK_DTC_FILES "${root}/boards/${BOARD}.overlay" )
list ( APPEND shield_dts_files "${root}/boards/${BOARD}.overlay" )
endif ( )
if ( NOT DEFINED BOARD_DIR_NAME )
find_path ( BOARD_DIR
@ -74,17 +97,37 @@ foreach(root ${BOARD_ROOT})
@@ -74,17 +97,37 @@ foreach(root ${BOARD_ROOT})
endif ( )
if ( DEFINED SHIELD )
find_path ( shields_refs_list
N A M E S $ { S H I E L D } . o v e r l a y
P A T H S $ { r o o t } / b o a r d s / s h i e l d s / *
N O _ D E F A U L T _ P A T H
)
foreach ( shield_path ${ shields_refs_list } )
get_filename_component ( SHIELD_DIR ${ shield_path } NAME )
list ( APPEND KEYMAP_DIRS ${ shield_path } )
foreach ( s ${ SHIELD_AS_LIST } )
if ( NOT ${ s } IN_LIST SHIELD_LIST )
message ( WARNING "Didn't find ${s}" )
continue ( )
endif ( )
message ( STATUS "Adding ${SHIELD_DIR_${s}}" )
list ( APPEND KEYMAP_DIRS ${ SHIELD_DIR_${s } } )
get_filename_component ( shield_dir_name ${ SHIELD_DIR_${s } } NAME )
list ( APPEND SHIELD_DIR ${ shield_dir_name } )
endforeach ( )
endif ( )
endforeach ( )
# G i v e a s h i e l d l i k e ` k y r i a _ r e v 2 _ l e f t ` w e w a n t t o u s e ` k y r i a _ r e v 2 ` a n d ` k y r i a ` a s c a n d i d a t e n a m e s f o r
# o v e r l a y / c o n f / k e y m a p f i l e s .
if ( DEFINED SHIELD )
foreach ( s ${ SHIELD_AS_LIST } )
message ( STATUS ${ SHIELD_DIR_${s } } )
get_filename_component ( shield_dir_name ${ SHIELD_DIR_${s } } NAME )
string ( REPLACE "_" ";" S_PIECES ${ s } )
list ( LENGTH S_PIECES S_PIECES_LEN )
while ( NOT S_PIECES STREQUAL "" )
list ( POP_BACK S_PIECES )
list ( JOIN S_PIECES "_" S_SUBSTR )
if ( S_SUBSTR STREQUAL ${ shield_dir_name } )
break ( )
endif ( )
list ( APPEND shield_candidate_names ${ S_SUBSTR } )
endwhile ( )
endforeach ( )
endif ( )
if ( ZMK_CONFIG )
if ( EXISTS ${ ZMK_CONFIG } )
@ -92,16 +135,20 @@ if (ZMK_CONFIG)
@@ -92,16 +135,20 @@ if (ZMK_CONFIG)
list ( APPEND DTS_ROOT ${ ZMK_CONFIG } )
list ( PREPEND KEYMAP_DIRS "${ZMK_CONFIG}" )
if ( SHIELD )
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" )
list ( APPEND overlay_candidates "${ZMK_CONFIG}/${SHIELD}_${BOARD}.overlay" )
list ( APPEND overlay_candidates "${ZMK_CONFIG}/${SHIELD}.overlay" )
list ( APPEND config_candidates "${ZMK_CONFIG}/${SHIELD_DIR}.conf" )
list ( APPEND config_candidates "${ZMK_CONFIG}/${SHIELD_DIR}_${BOARD}.conf" )
list ( APPEND config_candidates "${ZMK_CONFIG}/${SHIELD}_${BOARD}.conf" )
list ( APPEND config_candidates "${ZMK_CONFIG}/${SHIELD}.conf" )
if ( DEFINED SHIELD )
foreach ( s ${ shield_candidate_names } )
if ( DEFINED $ SHIELD_DIR_ ${ s } )
get_filename_component ( shield_dir_name ${ SHIELD_DIR_${s } } NAME )
endif ( )
list ( APPEND overlay_candidates "${ZMK_CONFIG}/${s}_${BOARD}.overlay" )
list ( APPEND overlay_candidates "${ZMK_CONFIG}/${s}.overlay" )
if ( NOT "${shield_dir_name}" STREQUAL "${s}" )
list ( APPEND config_candidates "${ZMK_CONFIG}/${shield_dir_name}_${BOARD}.conf" )
list ( APPEND config_candidates "${ZMK_CONFIG}/${shield_dir_name}.conf" )
endif ( )
list ( APPEND config_candidates "${ZMK_CONFIG}/${s}_${BOARD}.conf" )
list ( APPEND config_candidates "${ZMK_CONFIG}/${s}.conf" )
endforeach ( )
endif ( )
# T O D O : B o a r d r e v i s i o n s ?
@ -115,7 +162,7 @@ if (ZMK_CONFIG)
@@ -115,7 +162,7 @@ if (ZMK_CONFIG)
foreach ( overlay ${ overlay_candidates } )
if ( EXISTS "${overlay}" )
message ( STATUS "ZMK Config devicetree overlay: ${overlay}" )
list ( APPEND ZMK_DTC_FILES "${overlay}" )
list ( APPEND shield_dts_files "${overlay}" )
break ( )
endif ( )
endforeach ( )
@ -123,8 +170,7 @@ if (ZMK_CONFIG)
@@ -123,8 +170,7 @@ if (ZMK_CONFIG)
foreach ( conf ${ config_candidates } )
if ( EXISTS "${conf}" )
message ( STATUS "ZMK Config Kconfig: ${conf}" )
set ( CONF_FILE "${conf}" )
break ( )
list ( APPEND shield_conf_files "${conf}" )
endif ( )
endforeach ( )
else ( )
@ -135,22 +181,20 @@ endif()
@@ -135,22 +181,20 @@ endif()
if ( NOT KEYMAP_FILE )
foreach ( keymap_dir ${ KEYMAP_DIRS } )
foreach ( keymap_prefix ${ SHIELD } ${ SHIELD_DIR } ${ BOARD } ${ BOARD_DIR_NAME } )
foreach ( keymap_prefix ${ shield_candidate_names } ${ SHIELD_AS_LIST } ${ SHIELD_DIR } ${ BOARD } ${ 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 } )
break ( )
endif ( )
endforeach ( )
endforeach ( )
else ( )
message ( STATUS "Using keymap file: ${KEYMAP_FILE}" )
set ( DTC_OVERLAY_FILE ${ KEYMAP_FILE } )
endif ( )
if ( NOT KEYMAP_FILE )
message ( FATAL_ERROR "Failed to locate keymap file!" )
endif ( )
list ( APPEND ZMK_DTC_FILES ${ KEYMAP_FILE } )
if ( ZMK_DTC_FILES )
string ( REPLACE ";" " " DTC_OVERLAY_FILE "${ZMK_DTC_FILES}" )
message ( WARNING "Failed to locate keymap file!" )
endif ( )