Newstroke: add CMake targets to manage the files

This commit is contained in:
John Beard 2024-08-13 18:28:32 +01:00
parent 1ea5671228
commit 889aee3b1a
4 changed files with 125 additions and 5 deletions

55
cmake/FindKicadCli.cmake Normal file
View File

@ -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()

View File

@ -20,3 +20,5 @@ target_link_libraries( utf8_tests
common
${wxWidgets_LIBRARIES}
)
add_subdirectory( newstroke )

View File

@ -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()

View File

@ -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