1# Option to define LV_LVGL_H_INCLUDE_SIMPLE, default: ON
2option(LV_LVGL_H_INCLUDE_SIMPLE
3       "Use #include \"lvgl.h\" instead of #include \"../../lvgl.h\"" ON)
4
5# Option to define LV_CONF_INCLUDE_SIMPLE, default: ON
6option(LV_CONF_INCLUDE_SIMPLE
7       "Simple include of \"lv_conf.h\" and \"lv_drv_conf.h\"" ON)
8
9# Option to set LV_CONF_PATH, if set parent path LV_CONF_DIR is added to
10# includes
11option(LV_CONF_PATH "Path defined for lv_conf.h")
12get_filename_component(LV_CONF_DIR ${LV_CONF_PATH} DIRECTORY)
13
14# Option to build shared libraries (as opposed to static), default: OFF
15option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
16
17file(GLOB_RECURSE SOURCES ${LVGL_ROOT_DIR}/src/*.c)
18file(GLOB_RECURSE EXAMPLE_SOURCES ${LVGL_ROOT_DIR}/examples/*.c)
19file(GLOB_RECURSE DEMO_SOURCES ${LVGL_ROOT_DIR}/demos/*.c)
20
21if (BUILD_SHARED_LIBS)
22  add_library(lvgl SHARED ${SOURCES})
23else()
24  add_library(lvgl STATIC ${SOURCES})
25endif()
26
27add_library(lvgl::lvgl ALIAS lvgl)
28add_library(lvgl_examples STATIC ${EXAMPLE_SOURCES})
29add_library(lvgl::examples ALIAS lvgl_examples)
30add_library(lvgl_demos STATIC ${DEMO_SOURCES})
31add_library(lvgl::demos ALIAS lvgl_demos)
32
33target_compile_definitions(
34  lvgl PUBLIC $<$<BOOL:${LV_LVGL_H_INCLUDE_SIMPLE}>:LV_LVGL_H_INCLUDE_SIMPLE>
35              $<$<BOOL:${LV_CONF_INCLUDE_SIMPLE}>:LV_CONF_INCLUDE_SIMPLE>)
36
37# Include root and optional parent path of LV_CONF_PATH
38target_include_directories(lvgl SYSTEM PUBLIC ${LVGL_ROOT_DIR} ${LV_CONF_DIR})
39
40# Include /examples folder
41target_include_directories(lvgl_examples SYSTEM
42                           PUBLIC ${LVGL_ROOT_DIR}/examples)
43target_include_directories(lvgl_demos SYSTEM
44                           PUBLIC ${LVGL_ROOT_DIR}/demos)
45
46target_link_libraries(lvgl_examples PUBLIC lvgl)
47target_link_libraries(lvgl_demos PUBLIC lvgl)
48
49# Lbrary and headers can be installed to system using make install
50file(GLOB LVGL_PUBLIC_HEADERS "${CMAKE_SOURCE_DIR}/lv_conf.h"
51     "${CMAKE_SOURCE_DIR}/lvgl.h")
52
53if("${LIB_INSTALL_DIR}" STREQUAL "")
54  set(LIB_INSTALL_DIR "lib")
55endif()
56if("${INC_INSTALL_DIR}" STREQUAL "")
57  set(INC_INSTALL_DIR "include/lvgl")
58endif()
59
60install(
61  DIRECTORY "${CMAKE_SOURCE_DIR}/src"
62  DESTINATION "${CMAKE_INSTALL_PREFIX}/${INC_INSTALL_DIR}/"
63  FILES_MATCHING
64  PATTERN "*.h")
65
66set_target_properties(
67  lvgl
68  PROPERTIES OUTPUT_NAME lvgl
69             ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
70             LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
71             RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
72             PUBLIC_HEADER "${LVGL_PUBLIC_HEADERS}")
73
74install(
75  TARGETS lvgl
76  ARCHIVE DESTINATION "${LIB_INSTALL_DIR}"
77  LIBRARY DESTINATION "${LIB_INSTALL_DIR}"
78  RUNTIME DESTINATION "${LIB_INSTALL_DIR}"
79  PUBLIC_HEADER DESTINATION "${INC_INSTALL_DIR}")
80