From 889aee3b1a6c9cdc50293a1f4098b29bcf306f1d Mon Sep 17 00:00:00 2001 From: John Beard Date: Tue, 13 Aug 2024 18:28:32 +0100 Subject: [PATCH] Newstroke: add CMake targets to manage the files --- cmake/FindKicadCli.cmake | 55 +++++++++++++++++++++++++++++ tools/CMakeLists.txt | 2 ++ tools/newstroke/CMakeLists.txt | 63 ++++++++++++++++++++++++++++++++++ tools/newstroke/README.txt | 10 +++--- 4 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 cmake/FindKicadCli.cmake create mode 100644 tools/newstroke/CMakeLists.txt diff --git a/cmake/FindKicadCli.cmake b/cmake/FindKicadCli.cmake new file mode 100644 index 0000000000..11bf85901f --- /dev/null +++ b/cmake/FindKicadCli.cmake @@ -0,0 +1,55 @@ +# - Find kicad-cli +# Find the kicad-cli tool +# +# Used for managing KiCad files in the repo (e.g. test +# files, stroke font files, + +find_program(KICAD_CLI + NAMES kicad-cli +) + +if (KICAD_CLI) + message(STATUS "kicad-cli found: ${KICAD_CLI}") +else() + message(STATUS "kicad-cli not found") +endif() + + +# +# Helper function to upgrade a symbol library file +# using the installed kicad-cli tool +# +# Usage: +# KICAD_CLI_UPGRADE_SYMS(FILE TARGET [FORCE]) +# +# Arguments: +# FILE - The symbol library file to upgrade +# TARGET - The CMake target to add the upgrade command to +# FORCE - Optional argument to force the upgrade +# +function(KICAD_CLI_UPGRADE_SYMS FILE TARGET) + if (NOT KICAD_CLI) + message(FATAL_ERROR "Cannot run upgrade target (kicad-cli not found)") + endif() + + # Parse the optional FORCE argument + set(options FORCE) + set(oneValueArgs) + set(multiValueArgs) + cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + # Check if FORCE was provided + if (ARGS_FORCE) + set(FORCE_ARG "--force") + else() + set(FORCE_ARG "") + endif() + + add_custom_command( + TARGET ${TARGET} + COMMAND ${KICAD_CLI} sym upgrade ${FORCE_ARG} ${FILE} + DEPENDS ${FILE} + COMMENT + "Upgrading symbol lib format: ${FILE}" + ) +endfunction() \ No newline at end of file diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 4d5aeb782f..6ffad8940b 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -20,3 +20,5 @@ target_link_libraries( utf8_tests common ${wxWidgets_LIBRARIES} ) + +add_subdirectory( newstroke ) \ No newline at end of file diff --git a/tools/newstroke/CMakeLists.txt b/tools/newstroke/CMakeLists.txt new file mode 100644 index 0000000000..4553f94248 --- /dev/null +++ b/tools/newstroke/CMakeLists.txt @@ -0,0 +1,63 @@ + +find_package(KicadCli) + +# +# List of all newstroke symbol files that define the newstroke font +# glyphs. These files are used to generate the newstroke font data +# in newstroke_font.cpp. +# +set(NEWSTROKE_SOURCE_FILES + font.kicad_sym + symbol.kicad_sym + CJK_symbol.kicad_sym + CJK_wide_U+4E00.kicad_sym + CJK_wide_U+5AE6.kicad_sym + CJK_wide_U+66B9.kicad_sym + CJK_wide_U+7212.kicad_sym + CJK_wide_U+7D2A.kicad_sym + CJK_wide_U+8814.kicad_sym + CJK_wide_U+92B4.kicad_sym + CJK_wide_U+9C60.kicad_sym + half_full.kicad_sym + hiragana.kicad_sym + katakana.kicad_sym +) + + +add_custom_command( + OUTPUT + ${CMAKE_BINARY_DIR}/common/newstroke_font.cpp + COMMAND + python3 fontconv.py + DEPENDS + ${NEWSTROKE_SOURCE_FILES} + fontconv.py + WORKING_DIRECTORY + ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT + "Generating newstroke font data" +) + + +add_custom_target( + newstroke_generate_cpp + DEPENDS + ${CMAKE_BINARY_DIR}/common/newstroke_font.cpp +) + + +if (NOT KICAD_CLI) + message(STATUS "Cannot create newstroke_upgrade_syms target (kicad-cli not found)") +else() + add_custom_target(newstroke_upgrade_syms + COMMENT "Running format update on all newstroke .kicad_sym files" + ) + + foreach(NEWSTROKE_SOURCE_FILE ${NEWSTROKE_SOURCE_FILES}) + KICAD_CLI_UPGRADE_SYMS( + ${CMAKE_CURRENT_SOURCE_DIR}/${NEWSTROKE_SOURCE_FILE} + newstroke_upgrade_syms + ) + endforeach() +endif() + diff --git a/tools/newstroke/README.txt b/tools/newstroke/README.txt index 7a2090ccd0..daaeee2bf4 100644 --- a/tools/newstroke/README.txt +++ b/tools/newstroke/README.txt @@ -11,7 +11,7 @@ Files font.kicad_sym - main glyph library in KiCAD library format symbol.kicad_sym - glyph library for most math, tech and other symbols CJK_symbol.kicad_sym - CJK symbols -CJK_wide.kicad_sym - CKJ characters +CJK_wide*.kicad_sym - CJK characters in ranges katakana.kicad_sym - Japanese script hiragana.kicad_sym - Japanese script half_full.kicad_sym - U+FF00 half- and full-width forms @@ -30,15 +30,15 @@ old/font.pro - KiCAD project Requirements ------------ -KiCAD 6 or newer (https://www.kicad.org/download/) - for glyph editing +KiCAD 8 or newer (https://www.kicad.org/download/) - for glyph editing Python 3.10 or newer - for font generation Usage ----- -* Edit glyps with KiCAD 6 or newer EESchema library editor. +* Edit glyphs with KiCAD 8 or newer EESchema library editor. * Add/modify Unicode positions to charlist. -* Generate font using following command line: - +* Run the `newstroke_generate_cpp` CMake target + * Internally, this runs: python fontconv.py Checking changes