This commit is contained in:
Jack Humbert 2023-04-04 14:19:52 -04:00
parent c9ca9b9875
commit 7093a41c6c
4 changed files with 43 additions and 46 deletions

View File

@ -5,7 +5,7 @@
// Configure glob patterns for excluding files and folders.
"files.exclude": {
"**/.build": true,
"**/*.hex": true,
// "**/*.hex": true,
"**/*.bin": true,
"**/*.uf2": true
},

View File

@ -8,10 +8,6 @@ include(ValidateJSON)
set(QMK_KEYBOARDS_FOLDER "${CMAKE_SOURCE_DIR}/keyboards")
# early declaration of macro defined in toolchain
# macro(add_qmk_executable _)
# endmacro(add_qmk_executable)
function (_get_all_cmake_targets out_var current_dir)
get_property(targets DIRECTORY ${current_dir} PROPERTY BUILDSYSTEM_TARGETS)
get_property(subdirs DIRECTORY ${current_dir} PROPERTY SUBDIRECTORIES)
@ -32,12 +28,6 @@ project(qmk_firmware)
add_subdirectory(keyboards)
# Run at end of top-level CMakeLists
# _get_all_cmake_targets(all_targets ${CMAKE_SOURCE_DIR})
# message(STATUS "All: ${all_targets}")
# list(JOIN all_targets "\n" TARGET_FILE)
# file(WRITE "${CMAKE_SOURCE_DIR}/build/targets" ${TARGET_FILE})
else()
# build step
@ -93,15 +83,15 @@ add_compile_definitions(
PRODUCT="${KEYBOARD_NAME}"
)
if(EXISTS ${QMK_KEYBOARD_FOLDER_ABS}/CMakeLists.txt)
add_subdirectory(${QMK_KEYBOARD_FOLDER_ABS})
else()
# if(EXISTS ${QMK_KEYBOARD_FOLDER_ABS}/CMakeLists.txt)
# add_subdirectory(${QMK_KEYBOARD_FOLDER_ABS})
# else()
file(GLOB KEYBOARD_SRC "${QMK_KEYBOARD_FOLDER_ABS}/*.c")
list(REMOVE_ITEM KEYBOARD_SRC "${QMK_KEYBOARD_KEYMAP}")
add_qmk_executable(${QMK_KEYBOARD} ${KEYBOARD_SRC})
endif()
add_qmk_executable(${TARGET_NAME} ${KEYBOARD_SRC})
# endif()
# add_library(qmk)
add_library(qmk)
resolve_keyboard_includes(${QMK_KEYBOARD_FOLDER_ABS})

View File

@ -51,16 +51,16 @@ macro(add_keyboard KEYBOARD_FOLDER KEYMAP_FOLDER)
string(MAKE_C_IDENTIFIER ${KEYBOARD_NAME} KEYBOARD_SLUG)
endif()
string(JSON MANUFACTURER GET ${JSON_STRING} manufacturer)
ExternalProject_Add(${KEYBOARD_SLUG}_${KEYMAP_NAME}
set(TARGET_NAME "${KEYBOARD_SLUG}_${KEYMAP_NAME}")
ExternalProject_Add(${TARGET_NAME}
SOURCE_DIR ${CMAKE_SOURCE_DIR}
# PREFIX ${CMAKE_SOURCE_DIR}/build/keyboards/${KEYBOARD_FOLDER}
TMP_DIR ${CMAKE_SOURCE_DIR}/build/keyboards/${KEYBOARD_FOLDER}/tmp
DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/build/keyboards/${KEYBOARD_FOLDER}/Download
BINARY_DIR ${CMAKE_SOURCE_DIR}/build/keyboards/${KEYBOARD_FOLDER}/Build
STAMP_DIR ${CMAKE_SOURCE_DIR}/build/keyboards/${KEYBOARD_FOLDER}/Stamp
LOG_DIR ${CMAKE_SOURCE_DIR}/build/keyboards/${KEYBOARD_FOLDER}/Log
INSTALL_DIR ${CMAKE_SOURCE_DIR}/build/keyboards/${KEYBOARD_FOLDER}/Install
TMP_DIR ${CMAKE_SOURCE_DIR}/build/tmp
DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/build/download
BINARY_DIR ${CMAKE_SOURCE_DIR}/build/keyboards/${TARGET_NAME}
STAMP_DIR ${CMAKE_SOURCE_DIR}/build/stamp
LOG_DIR ${CMAKE_SOURCE_DIR}/build/log
INSTALL_DIR ${CMAKE_SOURCE_DIR}/build/install
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "nothing to install" #copy ${CMAKE_SOURCE_DIR}/build/keyboards/${KEYBOARD_FOLDER}/Build/* ${CMAKE_SOURCE_DIR}/build/keyboards/${KEYBOARD_FOLDER}/Install/
# this seems to work well for all systems so far - not sure if it'd be useful to customize
CMAKE_GENERATOR "Unix Makefiles"
@ -69,7 +69,8 @@ macro(add_keyboard KEYBOARD_FOLDER KEYMAP_FOLDER)
-DQMK_KEYBOARD=${KEYBOARD_SLUG}
-DQMK_KEYBOARD_FOLDER=${KEYBOARD_FOLDER}
-DQMK_KEYMAP_FOLDER=${KEYMAP_FOLDER}
-DTARGET_NAME=${TARGET_NAME}
)
file(APPEND "${CMAKE_SOURCE_DIR}/build/targets" "${KEYBOARD_SLUG}_${KEYMAP_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)

View File

@ -99,10 +99,10 @@ add_link_options(
macro(add_qmk_executable target_name)
set(QMK_TARGET ${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)
set(elf_file ${target_name}.elf)
set(map_file ${target_name}.map)
set(hex_file ${target_name}.hex)
set(lst_file ${target_name}.lst)
add_compile_options(
-mmcu=${QMK_MCU}
@ -114,15 +114,16 @@ macro(add_qmk_executable target_name)
)
# create elf file
add_executable(qmk ${ARGN})
add_executable(${elf_file} ${ARGN})
set_target_properties(qmk
PROPERTIES OUTPUT_NAME ${QMK_TARGET}
)
# add_executable(qmk ${ARGN})
# set_target_properties(qmk
# PROPERTIES OUTPUT_NAME ${elf_file}
# )
# target_link_libraries(${QMK_TARGET} qmk)
target_link_libraries(${elf_file} qmk)
# set_target_properties(${QMK_TARGET}
# set_target_properties(${elf_file}
# PROPERTIES
# COMPILE_FLAGS "-mmcu=${QMK_MCU} ${COMPILE_OPTIONS}"
# LINK_FLAGS "-mmcu=${QMK_MCU} ${LINK_OPTIONS}"
@ -131,22 +132,22 @@ macro(add_qmk_executable target_name)
# generate the lst file
add_custom_command(
OUTPUT ${lst_file}
COMMAND ${CMAKE_OBJDUMP} -h -S ${QMK_TARGET} > ${lst_file}
DEPENDS ${QMK_TARGET}
COMMAND ${CMAKE_OBJDUMP} -h -S ${elf_file} > ${lst_file}
DEPENDS ${elf_file}
)
# create hex file
add_custom_command(
OUTPUT ${hex_file}
# COMMAND ${CMAKE_OBJCOPY} -j .text -j .data -O ihex ${QMK_TARGET} ${hex_file}
COMMAND ${CMAKE_OBJCOPY} -O ihex -R .eeprom -R .fuse -R .lock -R .signature ${QMK_TARGET} ${hex_file}
DEPENDS ${QMK_TARGET}
# COMMAND ${CMAKE_OBJCOPY} -j .text -j .data -O ihex ${elf_file} ${hex_file}
COMMAND ${CMAKE_OBJCOPY} -O ihex -R .eeprom -R .fuse -R .lock -R .signature ${elf_file} ${hex_file}
DEPENDS ${elf_file}
)
add_custom_command(
OUTPUT "print-size-${QMK_TARGET}"
COMMAND ${AVR_SIZE} ${QMK_TARGET}
DEPENDS ${QMK_TARGET}
OUTPUT "print-size-${elf_file}"
COMMAND ${AVR_SIZE} ${elf_file}
DEPENDS ${elf_file}
)
add_custom_command(
@ -155,12 +156,17 @@ macro(add_qmk_executable target_name)
DEPENDS ${hex_file}
)
add_custom_target(copy_hex
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${elf_file}> ${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-${QMK_TARGET}" "print-size-${hex_file}"
DEPENDS ${hex_file} ${lst_file} "print-size-${elf_file}" "print-size-${hex_file}" copy_hex
)
set_target_properties(${target_name}
PROPERTIES OUTPUT_NAME ${QMK_TARGET}
PROPERTIES OUTPUT_NAME ${elf_file}
)
endmacro(add_qmk_executable)