You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
201 lines
6.5 KiB
201 lines
6.5 KiB
5 years ago
|
# TODO: Check for env or command line "ZMK_CONFIG" setting.
|
||
|
# * That directory should load
|
||
|
# * defconfigs,
|
||
|
# * .conf file,
|
||
|
# * single overlay,
|
||
|
# * or per board/shield.
|
||
|
|
||
4 years ago
|
cmake_minimum_required(VERSION 3.15)
|
||
|
|
||
3 years ago
|
list(APPEND BOARD_ROOT ${APPLICATION_SOURCE_DIR})
|
||
|
list(APPEND DTS_ROOT ${APPLICATION_SOURCE_DIR})
|
||
|
|
||
5 years ago
|
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")
|
||
|
|
||
4 years ago
|
if (ZMK_CONFIG)
|
||
4 years ago
|
set(ENV{ZMK_CONFIG} "${ZMK_CONFIG}")
|
||
4 years ago
|
if(EXISTS ${ZMK_CONFIG}/boards)
|
||
4 years ago
|
message(STATUS "Adding ZMK config directory as board root: ${ZMK_CONFIG}")
|
||
4 years ago
|
list(APPEND BOARD_ROOT ${ZMK_CONFIG})
|
||
4 years ago
|
endif()
|
||
4 years ago
|
if(EXISTS ${ZMK_CONFIG}/dts)
|
||
4 years ago
|
message(STATUS "Adding ZMK config directory as DTS root: ${ZMK_CONFIG}")
|
||
4 years ago
|
list(APPEND DTS_ROOT ${ZMK_CONFIG})
|
||
4 years ago
|
endif()
|
||
|
endif()
|
||
|
|
||
3 years ago
|
|
||
|
if(DEFINED SHIELD)
|
||
|
string(REPLACE " " ";" SHIELD_AS_LIST "${SHIELD}")
|
||
|
endif()
|
||
|
|
||
5 years ago
|
foreach(root ${BOARD_ROOT})
|
||
3 years ago
|
set(shield_dir ${root}/boards/shields)
|
||
|
# Match the Kconfig.shield files in the shield directories to make sure we are
|
||
|
# finding shields, e.g. x_nucleo_iks01a1/Kconfig.shield
|
||
|
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()
|
||
|
|
||
4 years ago
|
if (EXISTS "${root}/boards/${BOARD}.overlay")
|
||
3 years ago
|
list(APPEND shield_dts_files "${root}/boards/${BOARD}.overlay")
|
||
4 years ago
|
endif()
|
||
3 years ago
|
if (NOT DEFINED BOARD_DIR_NAME)
|
||
3 years ago
|
find_path(BOARD_DIR
|
||
|
NAMES ${BOARD}_defconfig
|
||
|
PATHS ${root}/boards/*/*
|
||
|
NO_DEFAULT_PATH
|
||
|
)
|
||
|
if(BOARD_DIR)
|
||
|
get_filename_component(BOARD_DIR_NAME ${BOARD_DIR} NAME)
|
||
|
list(APPEND KEYMAP_DIRS ${BOARD_DIR})
|
||
|
endif()
|
||
5 years ago
|
endif()
|
||
|
|
||
|
if(DEFINED SHIELD)
|
||
3 years ago
|
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})
|
||
5 years ago
|
endforeach()
|
||
|
endif()
|
||
|
endforeach()
|
||
|
|
||
3 years ago
|
# Give a shield like `kyria_rev2_left` we want to use `kyria_rev2` and `kyria` as candidate names for
|
||
|
# overlay/conf/keymap files.
|
||
|
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()
|
||
|
|
||
5 years ago
|
if (ZMK_CONFIG)
|
||
4 years ago
|
if (EXISTS ${ZMK_CONFIG})
|
||
5 years ago
|
message(STATUS "ZMK Config directory: ${ZMK_CONFIG}")
|
||
|
list(APPEND DTS_ROOT ${ZMK_CONFIG})
|
||
4 years ago
|
list(PREPEND KEYMAP_DIRS "${ZMK_CONFIG}")
|
||
5 years ago
|
|
||
3 years ago
|
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()
|
||
5 years ago
|
endif()
|
||
|
|
||
|
# TODO: Board revisions?
|
||
3 years ago
|
list(APPEND overlay_candidates "${ZMK_CONFIG}/${BOARD_DIR_NAME}.overlay")
|
||
5 years ago
|
list(APPEND overlay_candidates "${ZMK_CONFIG}/${BOARD}.overlay")
|
||
|
list(APPEND overlay_candidates "${ZMK_CONFIG}/default.overlay")
|
||
3 years ago
|
list(APPEND config_candidates "${ZMK_CONFIG}/${BOARD_DIR_NAME}.conf")
|
||
5 years ago
|
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}")
|
||
3 years ago
|
list(APPEND shield_dts_files "${overlay}")
|
||
5 years ago
|
break()
|
||
|
endif()
|
||
|
endforeach()
|
||
|
|
||
|
foreach(conf ${config_candidates})
|
||
|
if (EXISTS "${conf}")
|
||
4 years ago
|
message(STATUS "ZMK Config Kconfig: ${conf}")
|
||
3 years ago
|
list(APPEND shield_conf_files "${conf}")
|
||
5 years ago
|
endif()
|
||
|
endforeach()
|
||
|
else()
|
||
|
message(WARNING "Unable to locate ZMK config at: ${ZMK_CONFIG}")
|
||
|
endif()
|
||
|
endif()
|
||
|
|
||
4 years ago
|
|
||
|
if(NOT KEYMAP_FILE)
|
||
|
foreach(keymap_dir ${KEYMAP_DIRS})
|
||
3 years ago
|
foreach(keymap_prefix ${shield_candidate_names} ${SHIELD_AS_LIST} ${SHIELD_DIR} ${BOARD} ${BOARD_DIR_NAME})
|
||
4 years ago
|
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}")
|
||
3 years ago
|
set(DTC_OVERLAY_FILE ${KEYMAP_FILE})
|
||
4 years ago
|
break()
|
||
|
endif()
|
||
|
endforeach()
|
||
|
endforeach()
|
||
3 years ago
|
else()
|
||
|
message(STATUS "Using keymap file: ${KEYMAP_FILE}")
|
||
|
set(DTC_OVERLAY_FILE ${KEYMAP_FILE})
|
||
4 years ago
|
endif()
|
||
|
|
||
|
if (NOT KEYMAP_FILE)
|
||
3 years ago
|
message(WARNING "Failed to locate keymap file!")
|
||
5 years ago
|
endif()
|