diff options
author | Reinhold Gschweicher <pyro4hell@gmail.com> | 2022-05-10 23:48:41 +0200 |
---|---|---|
committer | Riku Isokoski <riksu9000@gmail.com> | 2022-05-16 11:59:44 +0300 |
commit | db0f909b461a6f2b706262cb4c2bae72007dc3f9 (patch) | |
tree | c945124b0423b6bbd3b9dd6ff8243b6b698f7e19 /src/displayapp/fonts/CMakeLists.txt | |
parent | 8485cdb54deaf5b24827330c8dc4d3e6675c7d72 (diff) |
generalize lv-font creation
In https://github.com/InfiniTimeOrg/InfiniTime/pull/1097 new font
generation capabilites were added. Generalize the font creation to
make it possible to reuse the `displayapp/fonts/CMakeLists.txt` file
for `InfiniSim` and just add the new cmake file to the project and
link against the new `infinitime_fonts` target.
In the following a list of changes.
Allow non-global installed `lv_font_conv` executable installed with
```sh
npm install lv_font_conv@1.5.2
```
In CMake we search for `lv_font_conv` executable. Add the found
executable to the python script `generate.py`, to remove the need for
`lv_font_conv` to be in the path.
Search for `python3` executable, if CMake version 3.12 is available.
Otherwise use `python` as hard coded executable.
Instead of adding the generated fonts to `SOURCE_FILES` variable, create
a static library `infinitime_fonts`. Link this library to the
executables instead.
Use `add_custom_target()` together with `add_custom_command()` to
generate the font.c files once (like the original PR does).
Diffstat (limited to 'src/displayapp/fonts/CMakeLists.txt')
-rw-r--r-- | src/displayapp/fonts/CMakeLists.txt | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/src/displayapp/fonts/CMakeLists.txt b/src/displayapp/fonts/CMakeLists.txt index ea61c3a2..d00c802b 100644 --- a/src/displayapp/fonts/CMakeLists.txt +++ b/src/displayapp/fonts/CMakeLists.txt @@ -1,19 +1,35 @@ -cmake_minimum_required(VERSION 3.10) - set(FONTS jetbrains_mono_42 jetbrains_mono_76 jetbrains_mono_bold_20 jetbrains_mono_extrabold_compressed lv_font_navi_80 lv_font_sys_48 open_sans_light) -find_program(LV_FONT_CONV "lv_font_conv" NO_CACHE REQUIRED) +find_program(LV_FONT_CONV "lv_font_conv" NO_CACHE REQUIRED + HINTS "${CMAKE_SOURCE_DIR}/node_modules/.bin") +message(STATUS "Using ${LV_FONT_CONV} to generate font files") configure_file(${CMAKE_CURRENT_LIST_DIR}/jetbrains_mono_bold_20.c_zero.patch - displayapp/fonts/jetbrains_mono_bold_20.c_zero.patch COPYONLY) -foreach(FONT ${FONTS}) - set_source_files_properties(displayapp/fonts/${FONT}.c - PROPERTIES GENERATED TRUE) + ${CMAKE_CURRENT_BINARY_DIR}/jetbrains_mono_bold_20.c_zero.patch COPYONLY) +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12) + # FindPython3 module introduces with CMake 3.12 + # https://cmake.org/cmake/help/latest/module/FindPython3.html + find_package(Python3 REQUIRED) +else() + set(Python3_EXECUTABLE "python") +endif() - add_custom_command(OUTPUT displayapp/fonts/${FONT}.c - COMMAND python ${CMAKE_CURRENT_LIST_DIR}/generate.py - -f ${FONT} ${CMAKE_CURRENT_LIST_DIR}/fonts.json - DEPENDS ${CMAKE_CURRENT_LIST_DIR}/fonts.json - WORKING_DIRECTORY displayapp/fonts - ) +# create static library building fonts +add_library(infinitime_fonts STATIC) +# add include directory to lvgl headers needed to compile the font files on its own +target_include_directories(infinitime_fonts PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../libs") +foreach(FONT ${FONTS}) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FONT}.c + COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/generate.py + --lv-font-conv "${LV_FONT_CONV}" + --font ${FONT} ${CMAKE_CURRENT_SOURCE_DIR}/fonts.json + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/fonts.json + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + add_custom_target(infinitime_fonts_${FONT} + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${FONT}.c + ) + target_sources(infinitime_fonts PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/${FONT}.c") + add_dependencies(infinitime_fonts infinitime_fonts_${FONT}) endforeach() |