multi folder targets
This commit is contained in:
141
CMakeLists.txt
141
CMakeLists.txt
@ -1,21 +1,140 @@
|
||||
cmake_minimum_required(VERSION 3.3)
|
||||
|
||||
# if(NOT DEFINED QMK_ROOT)
|
||||
macro(add_qmk_executable _)
|
||||
endmacro(add_qmk_executable)
|
||||
|
||||
if(NOT DEFINED QMK_KEYBOARD)
|
||||
|
||||
project(qmk_firmware)
|
||||
|
||||
include(ExternalProject)
|
||||
ExternalProject_Add(mntre
|
||||
SOURCE_DIR ${CMAKE_SOURCE_DIR}/keyboards/mntre
|
||||
TMP_DIR ${CMAKE_SOURCE_DIR}/build
|
||||
CMAKE_GENERATOR "MinGW Makefiles"
|
||||
CMAKE_ARGS
|
||||
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/platforms/avr/toolchain.cmake
|
||||
-DQMK_ROOT=${CMAKE_CURRENT_SOURCE_DIR}
|
||||
|
||||
macro(add_keyboard KEYBOARD_CMAKE)
|
||||
get_filename_component(KEYBOARD_FULL_DIRECTORY "${KEYBOARD_CMAKE}" DIRECTORY)
|
||||
file(RELATIVE_PATH KEYBOARD_FOLDER "${CMAKE_SOURCE_DIR}/keyboards" "${KEYBOARD_FULL_DIRECTORY}")
|
||||
string(REPLACE "/" "." KEYBOARD_NAME ${KEYBOARD_FOLDER})
|
||||
ExternalProject_Add(${KEYBOARD_NAME}
|
||||
SOURCE_DIR ${CMAKE_SOURCE_DIR}
|
||||
TMP_DIR ${CMAKE_SOURCE_DIR}/build
|
||||
INSTALL_COMMAND cmake -E echo "No install needed"
|
||||
CMAKE_GENERATOR "Unix Makefiles"
|
||||
CMAKE_ARGS
|
||||
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/platforms/avr/toolchain.cmake
|
||||
-DQMK_KEYBOARD=${KEYBOARD_NAME}
|
||||
-DQMK_KEYBOARD_FOLDER=${KEYBOARD_FOLDER}
|
||||
)
|
||||
endmacro(add_keyboard)
|
||||
|
||||
if(DEFINED QMK_KEYBOARD_FOLDER)
|
||||
add_keyboard(${CMAKE_SOURCE_DIR}/keyboards/${QMK_KEYBOARD_FOLDER}/CMakeFiles.txt)
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE KEYBOARDS keyboards/**/CMakeLists.txt)
|
||||
|
||||
foreach(KEYBOARD_CMAKE ${KEYBOARDS})
|
||||
add_keyboard(${KEYBOARD_CMAKE})
|
||||
endforeach()
|
||||
|
||||
else()
|
||||
|
||||
set(QMK_KEYBOARD_CURRENT_FOLDER ${QMK_KEYBOARD_FOLDER})
|
||||
set(QMK_KEYBOARD_FOLDERS)
|
||||
set(QMK_KEYBOARD_FOLDER_PARTS)
|
||||
while(NOT ${QMK_KEYBOARD_CURRENT_FOLDER} STREQUAL "")
|
||||
get_filename_component(QMK_KEYBOARD_CURRENT_PART ${QMK_KEYBOARD_CURRENT_FOLDER} NAME)
|
||||
list(PREPEND QMK_KEYBOARD_FOLDER_PARTS ${QMK_KEYBOARD_CURRENT_PART})
|
||||
list(PREPEND QMK_KEYBOARD_FOLDERS ${QMK_KEYBOARD_CURRENT_FOLDER})
|
||||
get_filename_component(QMK_KEYBOARD_CURRENT_FOLDER ${QMK_KEYBOARD_CURRENT_FOLDER} DIRECTORY)
|
||||
endwhile()
|
||||
|
||||
file(READ keyboards/${QMK_KEYBOARD_FOLDER}/info.json JSON_STRING)
|
||||
string(JSON KEYBOARD_NAME GET ${JSON_STRING} keyboard_name)
|
||||
string(JSON MANUFACTURER GET ${JSON_STRING} manufacturer)
|
||||
string(JSON QMK_MCU GET ${JSON_STRING} processor)
|
||||
string(JSON VENDOR_ID GET ${JSON_STRING} usb vid)
|
||||
string(JSON PRODUCT_ID GET ${JSON_STRING} usb pid)
|
||||
string(JSON DEVICE_VER GET ${JSON_STRING} usb device_version)
|
||||
|
||||
foreach(FOLDER ${QMK_KEYBOARD_FOLDERS})
|
||||
include_directories(${CMAKE_SOURCE_DIR}/keyboards/${FOLDER})
|
||||
if(EXISTS ${CMAKE_SOURCE_DIR}/keyboards/${FOLDER}/config.h)
|
||||
list(APPEND QMK_KEYBOARD_CONFIG_HS "${CMAKE_SOURCE_DIR}/keyboards/${FOLDER}/config.h")
|
||||
endif()
|
||||
if(EXISTS ${CMAKE_SOURCE_DIR}/keyboards/${FOLDER}/keymaps/default/keymap.c)
|
||||
list(APPEND QMK_KEYBOARD_KEYMAPS "${CMAKE_SOURCE_DIR}/keyboards/${FOLDER}/keymaps/default/keymap.c")
|
||||
endif()
|
||||
# not sure if merging is needed, since info.json is required iirc
|
||||
# if(EXISTS keyboards/${FOLDER}/info.json)
|
||||
# file(READ keyboards/${FOLDER}/info.json JSON_STRING)
|
||||
# string(JSON KEYBOARD_NAME GET ${JSON_STRING} keyboard_name)
|
||||
# string(JSON MANUFACTURER GET ${JSON_STRING} manufacturer)
|
||||
# string(JSON QMK_MCU GET ${JSON_STRING} processor)
|
||||
# string(JSON VENDOR_ID GET ${JSON_STRING} usb vid)
|
||||
# string(JSON PRODUCT_ID GET ${JSON_STRING} usb pid)
|
||||
# string(JSON DEVICE_VER GET ${JSON_STRING} usb device_version)
|
||||
# endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT DEFINED QMK_KEYBOARD_KEYMAPS)
|
||||
message(FATAL_ERROR "Keymap not found")
|
||||
endif()
|
||||
|
||||
list(GET QMK_KEYBOARD_FOLDERS 0 QMK_KEYBOARD_BASE_FOLDER)
|
||||
list(GET QMK_KEYBOARD_KEYMAPS 0 QMK_KEYBOARD_KEYMAP)
|
||||
list(GET QMK_KEYBOARD_FOLDER_PARTS -1 QMK_KEYBOARD_FOLDER_LAST_PART)
|
||||
|
||||
project(${QMK_KEYBOARD}
|
||||
LANGUAGES C CXX ASM
|
||||
VERSION ${DEVICE_VER})
|
||||
|
||||
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)" VERSION_MATCH ${DEVICE_VER})
|
||||
set(VERSION_MAJOR ${CMAKE_MATCH_1})
|
||||
set(VERSION_MINOR ${CMAKE_MATCH_2})
|
||||
set(VERSION_PATCH ${CMAKE_MATCH_3})
|
||||
math(EXPR VERSION_C_EVAL "${VERSION_MAJOR} * 10000 + ${VERSION_MINOR} * 100 + ${VERSION_PATCH}" OUTPUT_FORMAT HEXADECIMAL)
|
||||
|
||||
|
||||
add_compile_options(
|
||||
-include ${QMK_KEYBOARD_CONFIG_HS}
|
||||
-mmcu=${QMK_MCU}
|
||||
)
|
||||
|
||||
# else()
|
||||
add_link_options(
|
||||
-mmcu=${QMK_MCU}
|
||||
)
|
||||
|
||||
# add_subdirectory()
|
||||
add_compile_definitions(
|
||||
QMK_KEYBOARD_H="${QMK_KEYBOARD_FOLDER_LAST_PART}.h"
|
||||
KEYMAP_C="${QMK_KEYBOARD_KEYMAP}"
|
||||
MATRIX_ROWS=6
|
||||
MATRIX_COLS=15
|
||||
VENDOR_ID=${VENDOR_ID}
|
||||
PRODUCT_ID=${PRODUCT_ID}
|
||||
DEVICE_VER=${VERSION_C_EVAL}
|
||||
MANUFACTURER="${MANUFACTURER}"
|
||||
PRODUCT="${KEYBOARD_NAME}"
|
||||
)
|
||||
|
||||
# endif()
|
||||
add_subdirectory(quantum)
|
||||
add_subdirectory(platforms)
|
||||
add_subdirectory(tmk_core/protocol)
|
||||
|
||||
# option(OLED_ENABLE "" TRUE)
|
||||
# if(${OLED_ENABLE})
|
||||
# target_sources(quantum PUBLIC
|
||||
# ${CMAKE_SOURCE_DIR}/drivers/oled/ssd1306_sh1106.c
|
||||
# ${CMAKE_SOURCE_DIR}/platforms/${CMAKE_SYSTEM_PROCESSOR}/drivers/i2c_master.c)
|
||||
# add_compile_definitions(OLED_ENABLE)
|
||||
# target_include_directories(quantum PUBLIC ${CMAKE_SOURCE_DIR}/drivers)
|
||||
# target_include_directories(quantum PUBLIC ${CMAKE_SOURCE_DIR}/drivers/oled)
|
||||
# target_include_directories(quantum PUBLIC ${CMAKE_SOURCE_DIR}/platforms/${CMAKE_SYSTEM_PROCESSOR}/drivers)
|
||||
# endif()
|
||||
|
||||
if(EXISTS keyboards/${QMK_KEYBOARD_FOLDER}/CMakeLists.txt)
|
||||
add_subdirectory(keyboards/${QMK_KEYBOARD_FOLDER})
|
||||
else()
|
||||
file(GLOB KEYBOARD_SRC "keyboards/${QMK_KEYBOARD_FOLDER}/*.c")
|
||||
add_qmk_executable(${QMK_KEYBOARD} ${KEYBOARD_SRC})
|
||||
endif()
|
||||
|
||||
endif()
|
@ -1,11 +1 @@
|
||||
cmake_minimum_required(VERSION 3.3)
|
||||
|
||||
project(mntre C CXX ASM)
|
||||
|
||||
add_qmk_executable(mntre
|
||||
mntre.c
|
||||
)
|
||||
# set(QMK_INFO_JSON ${CMAKE_CURRENT_SOURCE_DIR}/info.json PARENT_SCOPE)
|
||||
# add_compile_definitions(QMK_KEYMAP_CONFIG_H="${CMAKE_CURRENT_SOURCE_DIR}/config.h")
|
||||
|
||||
# avr_target_link_libraries(mntre qmk)
|
||||
add_qmk_executable(mntre mntre.c)
|
@ -1,3 +1,5 @@
|
||||
add_library(platforms suspend.c synchronization_util.c timer.c)
|
||||
target_include_directories(platforms PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(platforms PUBLIC quantum)
|
||||
target_link_libraries(platforms PUBLIC quantum)
|
||||
|
||||
add_subdirectory(${CMAKE_SYSTEM_PROCESSOR})
|
@ -9,32 +9,26 @@ set(TRIPLE "avr")
|
||||
# find the toolchain root directory
|
||||
|
||||
if(UNIX)
|
||||
|
||||
find_program()
|
||||
set(OS_SUFFIX "")
|
||||
find_path(TOOLCHAIN_ROOT
|
||||
NAMES
|
||||
${TRIPLE}-gcc${OS_SUFFIX}
|
||||
|
||||
PATHS
|
||||
/usr/bin/
|
||||
/usr/local/bin
|
||||
/bin/
|
||||
|
||||
$ENV{AVR_ROOT}
|
||||
)
|
||||
|
||||
elseif(WIN32)
|
||||
|
||||
set(OS_SUFFIX ".exe")
|
||||
find_path(TOOLCHAIN_ROOT
|
||||
NAMES
|
||||
${TRIPLE}-gcc${OS_SUFFIX}
|
||||
|
||||
PATHS
|
||||
"C:/Users/Jack/Downloads/avr-gcc-12.1.0-x64-windows/bin/"
|
||||
$ENV{AVR_ROOT}
|
||||
)
|
||||
|
||||
else(UNIX)
|
||||
message(FATAL_ERROR "toolchain not supported on this OS")
|
||||
endif(UNIX)
|
||||
@ -68,7 +62,6 @@ set(AVR_SIZE "${TOOLCHAIN_ROOT}/${TRIPLE}-size${OS_SUFFIX}" CACHE P
|
||||
find_program(AVR_UPLOAD
|
||||
NAME
|
||||
avrdude
|
||||
|
||||
PATHS
|
||||
/usr/bin/
|
||||
$ENV{AVR_ROOT}
|
||||
@ -78,53 +71,50 @@ find_program(AVR_UPLOAD
|
||||
|
||||
# set(AVR_LINKER_LIBS "-lc -lm -lgcc -Wl,-lprintf_flt -Wl,-u,vfprintf")
|
||||
|
||||
add_compile_options(
|
||||
$<$<COMPILE_LANGUAGE:C>:-std=gnu11>
|
||||
$<$<COMPILE_LANGUAGE:CXX>:-std=gnu++14>
|
||||
# -flto
|
||||
-Os
|
||||
-Wall
|
||||
-Wstrict-prototypes
|
||||
-fcommon
|
||||
# -g
|
||||
--param=min-pagesize=0
|
||||
-funsigned-char
|
||||
-funsigned-bitfields
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
-fpack-struct
|
||||
-fshort-enums
|
||||
-mcall-prologues
|
||||
-fno-builtin-printf
|
||||
$<$<COMPILE_LANGUAGE:C>:-fno-inline-small-functions>
|
||||
$<$<COMPILE_LANGUAGE:C>:-fno-strict-aliasing>
|
||||
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
|
||||
)
|
||||
|
||||
add_compile_definitions(
|
||||
F_CPU=16000000
|
||||
F_USB=16000000UL
|
||||
__AVR_ATmega32U4__
|
||||
# LTO_ENABLE
|
||||
)
|
||||
|
||||
include_directories("C:/Users/Jack/Downloads/avr-gcc-12.1.0-x64-windows/avr/include")
|
||||
|
||||
macro(add_qmk_executable target_name)
|
||||
|
||||
add_compile_options(
|
||||
$<$<COMPILE_LANGUAGE:C>:-std=gnu11>
|
||||
$<$<COMPILE_LANGUAGE:CXX>:-std=gnu++14>
|
||||
# -flto
|
||||
-Os
|
||||
-Wall
|
||||
-Wstrict-prototypes
|
||||
-fcommon
|
||||
# -g
|
||||
--param=min-pagesize=0
|
||||
-funsigned-char
|
||||
-funsigned-bitfields
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
-fpack-struct
|
||||
-fshort-enums
|
||||
-mcall-prologues
|
||||
-fno-builtin-printf
|
||||
$<$<COMPILE_LANGUAGE:C>:-fno-inline-small-functions>
|
||||
$<$<COMPILE_LANGUAGE:C>:-fno-strict-aliasing>
|
||||
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
|
||||
)
|
||||
|
||||
add_compile_definitions(
|
||||
F_CPU=16000000
|
||||
F_USB=16000000UL
|
||||
__AVR_ATmega32U4__
|
||||
# LTO_ENABLE
|
||||
)
|
||||
|
||||
add_link_options(-Wl,--gc-sections,-Map=${map_file})
|
||||
|
||||
include(${QMK_ROOT}/platforms/toolchain.cmake)
|
||||
add_qmk_executable_common(${target_name})
|
||||
|
||||
add_subdirectory(${QMK_ROOT}/platforms/avr platforms/avr)
|
||||
add_subdirectory(${QMK_ROOT}/tmk_core/protocol/lufa tmk_core/protocol/lufa)
|
||||
|
||||
include_directories("C:/Users/Jack/Downloads/avr-gcc-12.1.0-x64-windows/avr/include")
|
||||
# add_subdirectory(${CMAKE_SOURCE_DIR}/platforms/avr platforms/avr)
|
||||
# add_subdirectory(${CMAKE_SOURCE_DIR}/tmk_core/protocol/lufa tmk_core/protocol/lufa)
|
||||
|
||||
set(elf_file ${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)
|
||||
|
||||
add_link_options(-Wl,--gc-sections,-Map=${map_file})
|
||||
|
||||
# create elf file
|
||||
add_executable(${elf_file}
|
||||
${ARGN}
|
||||
|
@ -1,54 +0,0 @@
|
||||
macro(add_qmk_executable_common target_name)
|
||||
|
||||
file(READ ${CMAKE_SOURCE_DIR}/info.json JSON_STRING)
|
||||
|
||||
string(JSON KEYBOARD_NAME GET ${JSON_STRING} keyboard_name)
|
||||
string(JSON MANUFACTURER GET ${JSON_STRING} manufacturer)
|
||||
string(JSON QMK_MCU GET ${JSON_STRING} processor)
|
||||
string(JSON VENDOR_ID GET ${JSON_STRING} usb vid)
|
||||
string(JSON PRODUCT_ID GET ${JSON_STRING} usb pid)
|
||||
string(JSON DEVICE_VER GET ${JSON_STRING} usb device_version)
|
||||
|
||||
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)"
|
||||
VERSION_MATCH ${DEVICE_VER})
|
||||
set(VERSION_MAJOR ${CMAKE_MATCH_1})
|
||||
set(VERSION_MINOR ${CMAKE_MATCH_2})
|
||||
set(VERSION_PATCH ${CMAKE_MATCH_3})
|
||||
math(EXPR VERSION_C_EVAL "${VERSION_MAJOR} * 10000 + ${VERSION_MINOR} * 100 + ${VERSION_PATCH}" OUTPUT_FORMAT HEXADECIMAL)
|
||||
|
||||
# include_directories(${QMK_ROOT}/quantum)
|
||||
# include_directories(${QMK_ROOT}/quantum/logging)
|
||||
# include_directories(${QMK_ROOT}/quantum/keymap_extras)
|
||||
# include_directories(${QMK_ROOT}/quantum/process_keycode)
|
||||
# include_directories(${QMK_ROOT}/quantum/sequencer)
|
||||
# include_directories(${QMK_ROOT}/quantum/bootmagic)
|
||||
# include_directories(${QMK_ROOT}/platforms)
|
||||
include_directories(${CMAKE_SOURCE_DIR})
|
||||
|
||||
add_compile_options(
|
||||
-include ${CMAKE_SOURCE_DIR}/config.h
|
||||
-mmcu=${QMK_MCU}
|
||||
)
|
||||
|
||||
add_link_options(
|
||||
-mmcu=${QMK_MCU}
|
||||
)
|
||||
|
||||
add_compile_definitions(
|
||||
QMK_KEYBOARD_H="${target_name}.h"
|
||||
KEYMAP_C="${CMAKE_SOURCE_DIR}/keymaps/default/keymap.c"
|
||||
MATRIX_ROWS=6
|
||||
MATRIX_COLS=15
|
||||
VENDOR_ID=${VENDOR_ID}
|
||||
PRODUCT_ID=${PRODUCT_ID}
|
||||
DEVICE_VER=${VERSION_C_EVAL}
|
||||
MANUFACTURER="${MANUFACTURER}"
|
||||
PRODUCT="${KEYBOARD_NAME}"
|
||||
)
|
||||
|
||||
# add_library(qmk)
|
||||
|
||||
add_subdirectory(${QMK_ROOT}/quantum quantum)
|
||||
add_subdirectory(${QMK_ROOT}/platforms platforms)
|
||||
add_subdirectory(${QMK_ROOT}/tmk_core/protocol tmk_core/protocol)
|
||||
endmacro(add_qmk_executable_common)
|
@ -26,10 +26,13 @@ target_include_directories(quantum PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/keymap_ext
|
||||
target_include_directories(quantum PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/process_keycode)
|
||||
target_include_directories(quantum PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/sequencer)
|
||||
target_include_directories(quantum PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/bootmagic)
|
||||
|
||||
target_link_libraries(quantum PUBLIC platforms)
|
||||
target_link_libraries(quantum PUBLIC platforms_avr)
|
||||
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "avr")
|
||||
target_link_libraries(quantum PUBLIC platforms_avr)
|
||||
endif()
|
||||
target_link_libraries(quantum PUBLIC tmk_core_protocol)
|
||||
|
||||
# if no printf
|
||||
# target_sources(quantum PRIVATE ${QMK_ROOT}/lib/printf/src/printf/printf.c)
|
||||
# target_include_directories(quantum PUBLIC ${QMK_ROOT}/lib/printf/src/)
|
||||
# target_sources(quantum PRIVATE ${CMAKE_SOURCE_DIR}/lib/printf/src/printf/printf.c)
|
||||
# target_include_directories(quantum PUBLIC ${CMAKE_SOURCE_DIR}/lib/printf/src/printf)
|
@ -10,4 +10,8 @@ add_compile_definitions(
|
||||
# NKRO_ENABLE
|
||||
)
|
||||
target_include_directories(tmk_core_protocol PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(tmk_core_protocol PUBLIC quantum)
|
||||
target_link_libraries(tmk_core_protocol PUBLIC quantum)
|
||||
|
||||
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "avr")
|
||||
add_subdirectory(lufa)
|
||||
endif()
|
@ -1,5 +1,4 @@
|
||||
# set(LUFA_PATH ${QMK_ROOT}/lib/lufa)
|
||||
set(LUFA_PATH ${QMK_ROOT}/lib/lufa)
|
||||
set(LUFA_PATH ${CMAKE_SOURCE_DIR}/lib/lufa)
|
||||
set(ARCH AVR8)
|
||||
set(USE_STATIC_OPTIONS "(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)")
|
||||
|
||||
@ -26,7 +25,7 @@ target_include_directories(tmk_core_protocol_lufa PUBLIC ${LUFA_PATH})
|
||||
|
||||
target_link_libraries(tmk_core_protocol_lufa PUBLIC quantum)
|
||||
|
||||
set(LUFA_ROOT_PATH ${QMK_ROOT}/lib/lufa/LUFA)
|
||||
set(LUFA_ROOT_PATH ${CMAKE_SOURCE_DIR}/lib/lufa/LUFA)
|
||||
|
||||
target_sources(tmk_core_protocol_lufa
|
||||
PUBLIC
|
||||
|
Reference in New Issue
Block a user