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
66install(
67  FILES "${LV_CONF_PATH}"
68  DESTINATION "${CMAKE_INSTALL_PREFIX}/${INC_INSTALL_DIR}/../"
69  RENAME "lv_conf.h"
70  OPTIONAL)
71
72configure_file("${LVGL_ROOT_DIR}/lvgl.pc.in" lvgl.pc @ONLY)
73
74install(
75  FILES "${CMAKE_BINARY_DIR}/lvgl.pc"
76  DESTINATION "${LIB_INSTALL_DIR}/pkgconfig/")
77
78set_target_properties(
79  lvgl
80  PROPERTIES OUTPUT_NAME lvgl
81             ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
82             LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
83             RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
84             PUBLIC_HEADER "${LVGL_PUBLIC_HEADERS}")
85
86install(
87  TARGETS lvgl
88  ARCHIVE DESTINATION "${LIB_INSTALL_DIR}"
89  LIBRARY DESTINATION "${LIB_INSTALL_DIR}"
90  RUNTIME DESTINATION "${LIB_INSTALL_DIR}"
91  PUBLIC_HEADER DESTINATION "${INC_INSTALL_DIR}")
92