acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

cmake.md (3944B)

      1 ```eval_rst
      2 .. include:: /header.rst
      3 :github_url: |github_link_base|/get-started/platforms/cmake.md
      4 ```
      5 
      6 # CMake
      7 LVGL supports integrating with [CMake](https://cmake.org/). It comes with preconfigured targets for:
      8 - [Espressif (ESP32)](https://docs.espressif.com/projects/esp-idf/en/v3.3/get-started-cmake/index.html)
      9 - [MicroPython](https://docs.micropython.org/en/v1.15/develop/cmodules.html)
     10 - [Zephyr](https://docs.zephyrproject.org/latest/guides/zephyr_cmake_package.html)
     11 
     12 On top of the preconfigured targets you can also use "plain" CMake to integrate LVGL into any custom C/C++ project.
     13 
     14 ### Prerequisites
     15 - CMake ( >= 3.12.4 )
     16 - Compatible build tool e.g.
     17   - [Make](https://www.gnu.org/software/make/)
     18   - [Ninja](https://ninja-build.org/)
     19 
     20 ## Building LVGL with CMake
     21 There are many ways to include external CMake projects into your own. A modern one also used in this example is the CMake [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) module. This module conveniently allows us to download dependencies directly at configure time from e.g. [GitHub](https://github.com/). Here is an example how we might include LVGL into our own project.
     22 
     23 ```cmake
     24 cmake_minimum_required(VERSION 3.14)
     25 include(FetchContent)
     26 
     27 project(MyProject LANGUAGES C CXX)
     28 
     29 # Build an executable called "MyFirmware"
     30 add_executable(MyFirmware src/main.c)
     31 
     32 # Specify path to own LVGL config header
     33 set(LV_CONF_PATH
     34     ${CMAKE_CURRENT_SOURCE_DIR}/src/lv_conf.h
     35     CACHE STRING "" FORCE)
     36 
     37 # Fetch LVGL from GitHub
     38 FetchContent_Declare(lvgl URL https://github.com/lvgl/lvgl.git)
     39 FetchContent_MakeAvailable(lvgl)
     40 
     41 # The target "MyFirmware" depends on LVGL
     42 target_link_libraries(MyFirmware PRIVATE lvgl::lvgl)
     43 ```
     44 
     45 This configuration declares a dependency between the two targets **MyFirmware** and **lvgl**. Upon building the target **MyFirmware** this dependency will be resolved and **lvgl** will be built and linked with it. Since LVGL requires a config header called [lv_conf.h](https://github.com/lvgl/lvgl/blob/master/lv_conf_template.h) to be includable by its sources we also set the option `LV_CONF_PATH` to point to our own copy of it.
     46 
     47 ### Additional CMake options
     48 Besides `LV_CONF_PATH` there are two additional CMake options to specify include paths.
     49 
     50 `LV_LVGL_H_INCLUDE_SIMPLE` which specifies whether to `#include "lvgl.h"` absolut or relative
     51 
     52 | ON (default) | OFF            |
     53 | ------------ | -------------- |
     54 | "lvgl.h"     | "../../lvgl.h" |
     55 
     56 `LV_CONF_INCLUDE_SIMPLE` which specifies whether to `#include "lv_conf.h"` and `"lv_drv_conf.h"` absolut or relative
     57 
     58 | ON (default)    | OFF                   |
     59 | --------------- | --------------------- |
     60 | "lv_conf.h"     | "../../lv_conf.h"     |
     61 | "lv_drv_conf.h" | "../../lv_drv_conf.h" |
     62 
     63 I do not recommend disabling those options unless your folder layout makes it absolutely necessary.
     64 
     65 ## Building LVGL examples with CMake
     66 LVGL [examples](https://docs.lvgl.io/master/examples.html) have their own CMake target. If you want to build the examples simply add them to your dependencies.
     67 
     68 ```cmake
     69 # The target "MyFirmware" depends on LVGL and examples
     70 target_link_libraries(MyFirmware PRIVATE lvgl::lvgl lvgl::examples)
     71 ```
     72 
     73 ## Building LVGL drivers and demos with CMake
     74 Exactly the same goes for the [drivers](https://github.com/lvgl/lv_drivers) and the [demos](https://github.com/lvgl/lvgl/demos).
     75 
     76 ```cmake
     77 FetchContent_Declare(lv_drivers
     78                      GIT_REPOSITORY https://github.com/lvgl/lv_drivers)
     79 FetchContent_MakeAvailable(lv_drivers)
     80 
     81 # The target "MyFirmware" depends on LVGL, drivers and demos
     82 target_link_libraries(MyFirmware PRIVATE lvgl::lvgl lvgl::drivers lvgl::examples)
     83 ```
     84 
     85 # Build shared libraries with CMake
     86 By default, LVGL will be built as a static library (archive). CMake can instead be instructed to build LVGL as shared library (.so/.dll/etc.):
     87 ```cmake
     88 set(BUILD_SHARED_LIBS ON)
     89 ```
     90 OR
     91 ```
     92 $ cmake "-DBUILD_SHARED_LIBS=ON" .
     93 ```