1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

feat(cmake-build): Option to allow building shared libraries. (#3278)

Add option in CMake build to specify that shared libraries should be created (as
opposed to static). This is an exclusive option (not enabled by default).

Co-authored-by: simeplejack-src <example@example.com>
This commit is contained in:
simplejack-src 2022-04-20 06:04:56 -04:00 committed by GitHub
parent 17f5e0accb
commit 1cf2e5d886
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -81,3 +81,13 @@ FetchContent_MakeAvailable(lv_drivers)
# The target "MyFirmware" depends on LVGL, drivers and demos
target_link_libraries(MyFirmware PRIVATE lvgl::lvgl lvgl::drivers lvgl::examples)
```
# Build shared libraries with CMake
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.):
```cmake
set(BUILD_SHARED_LIBS ON)
```
OR
```
$ cmake "-DBUILD_SHARED_LIBS=ON" .
```

View File

@ -11,11 +11,19 @@ option(LV_CONF_INCLUDE_SIMPLE
option(LV_CONF_PATH "Path defined for lv_conf.h")
get_filename_component(LV_CONF_DIR ${LV_CONF_PATH} DIRECTORY)
# Option to build shared libraries (as opposed to static), default: OFF
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
file(GLOB_RECURSE SOURCES ${LVGL_ROOT_DIR}/src/*.c)
file(GLOB_RECURSE EXAMPLE_SOURCES ${LVGL_ROOT_DIR}/examples/*.c)
file(GLOB_RECURSE DEMO_SOURCES ${LVGL_ROOT_DIR}/demos/*.c)
add_library(lvgl STATIC ${SOURCES})
if (BUILD_SHARED_LIBS)
add_library(lvgl SHARED ${SOURCES})
else()
add_library(lvgl STATIC ${SOURCES})
endif()
add_library(lvgl::lvgl ALIAS lvgl)
add_library(lvgl_examples STATIC ${EXAMPLE_SOURCES})
add_library(lvgl::examples ALIAS lvgl_examples)
@ -59,9 +67,13 @@ set_target_properties(
lvgl
PROPERTIES OUTPUT_NAME lvgl
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
PUBLIC_HEADER "${LVGL_PUBLIC_HEADERS}")
install(
TARGETS lvgl
ARCHIVE DESTINATION "${LIB_INSTALL_DIR}"
LIBRARY DESTINATION "${LIB_INSTALL_DIR}"
RUNTIME DESTINATION "${LIB_INSTALL_DIR}"
PUBLIC_HEADER DESTINATION "${INC_INSTALL_DIR}")