-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
102 lines (86 loc) · 4.16 KB
/
Copy pathCMakeLists.txt
File metadata and controls
102 lines (86 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
cmake_minimum_required(VERSION 3.16)
project(lvgl_safe_examples LANGUAGES C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
# ---------------------------------------------------------------------------
# 1. Locate the unpacked pre-built LVGL Safe package
# ---------------------------------------------------------------------------
# Each platform gets its own tarball, extracted as a sibling
# lvgl_safe-x.y.z-<platform>/ subdirectory (<prefix>/include, <prefix>/lib and
# <prefix>/lib/cmake/lvgl_safe). Several platform packages can live in the repo
# side by side - only the subdirectory whose name matches the host platform is
# considered, so the same CMakeLists.txt picks the right static library
# (liblvgl_safe.a, lvgl_safe.lib, ...) without any extra flags. The package is
# never unpacked directly into the repository root.
#
# Override with -DLS_PACKAGE_PREFIX=/path/to/unpacked/lvgl_safe-x.y.z-<platform>
if(NOT LS_PACKAGE_PREFIX)
if(WIN32)
set(LS_PLATFORM_TAG "windows")
else()
set(LS_PLATFORM_TAG "linux")
endif()
file(GLOB LS_PACKAGE_PREFIX_SUBDIRS
LIST_DIRECTORIES true
"${CMAKE_CURRENT_SOURCE_DIR}/lvgl_safe-*")
list(SORT LS_PACKAGE_PREFIX_SUBDIRS)
# Newest version last after the sort, so search it first.
list(REVERSE LS_PACKAGE_PREFIX_SUBDIRS)
# Only a package built for this host platform is a valid candidate.
set(LS_PACKAGE_PREFIX_CANDIDATES "")
foreach(candidate IN LISTS LS_PACKAGE_PREFIX_SUBDIRS)
if(candidate MATCHES "-${LS_PLATFORM_TAG}(-|$)")
list(APPEND LS_PACKAGE_PREFIX_CANDIDATES "${candidate}")
endif()
endforeach()
foreach(candidate IN LISTS LS_PACKAGE_PREFIX_CANDIDATES)
if(EXISTS "${candidate}/lib/cmake/lvgl_safe/lvgl_safeConfig.cmake")
set(LS_PACKAGE_PREFIX "${candidate}")
break()
endif()
endforeach()
if(NOT LS_PACKAGE_PREFIX)
message(FATAL_ERROR
"No unpacked LVGL Safe package for '${LS_PLATFORM_TAG}' found in "
"${CMAKE_CURRENT_SOURCE_DIR}. Extract lvgl_safe-x.y.z-${LS_PLATFORM_TAG}.tar.gz "
"as a sibling directory here, or pass -DLS_PACKAGE_PREFIX=<path> to point at "
"the unpacked package.")
endif()
endif()
get_filename_component(LS_PACKAGE_PREFIX "${LS_PACKAGE_PREFIX}" ABSOLUTE)
set(LS_PACKAGE_PREFIX "${LS_PACKAGE_PREFIX}" CACHE PATH
"Unpacked LVGL Safe package (headers, static library, CMake config)")
if(NOT EXISTS "${LS_PACKAGE_PREFIX}/lib/cmake/lvgl_safe/lvgl_safeConfig.cmake")
message(FATAL_ERROR
"${LS_PACKAGE_PREFIX} does not look like an unpacked LVGL Safe package: "
"lib/cmake/lvgl_safe/lvgl_safeConfig.cmake is missing.")
endif()
# ---------------------------------------------------------------------------
# 2. Import the library through the CMake config package it ships
# ---------------------------------------------------------------------------
find_package(lvgl_safe REQUIRED CONFIG
PATHS "${LS_PACKAGE_PREFIX}"
NO_DEFAULT_PATH)
message(STATUS "Found LVGL Safe ${lvgl_safe_VERSION} in ${LS_PACKAGE_PREFIX}")
# IMPORTANT NOTE: the shipped include/ls_conf.h is authoritative — its values are baked
# into the struct layouts inside liblvgl_safe.a, ls_conf.h must not be changed as all
# functionality of the lib is already made available.
# ---------------------------------------------------------------------------
# 3. SDL2 backend used by the examples (${LS_SDL2_LIBRARY})
# ---------------------------------------------------------------------------
find_package(SDL2 QUIET)
if(TARGET SDL2::SDL2)
set(LS_SDL2_LIBRARY SDL2::SDL2)
if(WIN32 AND TARGET SDL2::SDL2main)
set(LS_SDL2_LIBRARY SDL2::SDL2main ${LS_SDL2_LIBRARY})
endif()
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(LS_SDL2 REQUIRED IMPORTED_TARGET sdl2)
set(LS_SDL2_LIBRARY PkgConfig::LS_SDL2)
endif()
message(STATUS "SDL2 target for examples: ${LS_SDL2_LIBRARY}")
# ---------------------------------------------------------------------------
# 4. Examples
# ---------------------------------------------------------------------------
add_subdirectory(examples)