Skip to content

Commit ce9d176

Browse files
authored
Merge pull request #113 from glneo/cmake-config-defaults
2 parents 390147a + 1dd9881 commit ce9d176

File tree

4 files changed

+24
-36
lines changed

4 files changed

+24
-36
lines changed

CMakeLists.txt

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,19 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
2222
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
2323
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic")
2424

25-
option(CONFIG "Config to use leave empty for `lv_conf.defaults`" "default")
25+
set(CONFIG "default" CACHE STRING "Config name to use. Leave empty for default `lv_conf.defaults`")
2626

2727
set(LV_CONF_DEFAULTS_PATH "${CMAKE_SOURCE_DIR}/lv_conf.defaults")
28-
set(LV_CONF_DEFAULTS_OLD_PATH "${CMAKE_SOURCE_DIR}/lv_conf.defaults.old")
2928

30-
# If CONFIG is not default, copy the selected config to lv_conf.defaults
29+
# If CONFIG is not default, update LV_CONF_DEFAULTS_PATH to the selected config
3130
if(NOT CONFIG STREQUAL "default")
32-
set(CONFIG_FILE "${CMAKE_SOURCE_DIR}/configs/${CONFIG}.defaults")
33-
34-
# Verify the config file exists
35-
if(NOT EXISTS "${CONFIG_FILE}")
36-
message(FATAL_ERROR "Config file not found: ${CONFIG_FILE}")
37-
endif()
38-
39-
# Backup the current lv_conf.defaults to lv_conf.defaults.old
40-
if(EXISTS "${LV_CONF_DEFAULTS_PATH}")
41-
file(RENAME "${LV_CONF_DEFAULTS_PATH}" "${LV_CONF_DEFAULTS_OLD_PATH}")
42-
message(STATUS "Backed up lv_conf.defaults to lv_conf.defaults.old")
43-
endif()
44-
45-
# Copy the config file to lv_conf.defaults
46-
configure_file("${CONFIG_FILE}" "${LV_CONF_DEFAULTS_PATH}" COPYONLY)
47-
message(STATUS "Copied configs/${CONFIG}.defaults to ${LV_CONF_DEFAULTS_PATH}")
48-
message(STATUS "Using config: configs/${CONFIG}.defaults")
49-
else()
50-
if(NOT EXISTS "${LV_CONF_DEFAULTS_PATH}")
51-
message(FATAL_ERROR "Config file not found: ${LV_CONF_DEFAULTS_PATH}")
52-
endif()
53-
message(STATUS "Using default lv_conf.defaults")
54-
message(STATUS "Using config: ${LV_CONF_DEFAULTS_PATH}")
31+
set(LV_CONF_DEFAULTS_PATH "${CMAKE_SOURCE_DIR}/configs/${CONFIG}.defaults")
5532
endif()
5633

34+
if(NOT EXISTS "${LV_CONF_DEFAULTS_PATH}")
35+
message(FATAL_ERROR "Config file not found: ${LV_CONF_DEFAULTS_PATH}")
36+
endif()
37+
message(STATUS "Using config: ${LV_CONF_DEFAULTS_PATH}")
5738

5839
set(LV_BUILD_SET_CONFIG_OPTS ON CACHE BOOL
5940
"create CMAKE variables from lv_conf_internal.h" FORCE)
@@ -65,12 +46,9 @@ set(LV_BUILD_CONF_PATH
6546
set(LVGL_TEMPLATE_PATH "${CMAKE_SOURCE_DIR}/lvgl/lv_conf_template.h")
6647
set(GENERATE_SCRIPT_PATH "${CMAKE_SOURCE_DIR}/lvgl/scripts/generate_lv_conf.py")
6748

68-
configure_file(${LVGL_TEMPLATE_PATH} ${CMAKE_BINARY_DIR}/lv_conf_template.h
69-
COPYONLY)
70-
configure_file(${LV_CONF_DEFAULTS_PATH} ${CMAKE_BINARY_DIR}/lv_conf.defaults
71-
COPYONLY)
72-
configure_file(${GENERATE_SCRIPT_PATH} ${CMAKE_BINARY_DIR}/generate_lv_conf.py
73-
COPYONLY)
49+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LVGL_TEMPLATE_PATH})
50+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LV_CONF_DEFAULTS_PATH})
51+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${GENERATE_SCRIPT_PATH})
7452

7553
execute_process(
7654
COMMAND

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,29 @@ git submodule update --init --recursive
2727

2828
## Configure drivers and libraries
2929

30+
By default `lv_conf.defaults` is by used to generate the configuration header
31+
file `lv_conf.h` that is used during the build.
3032
Adjust `lv_conf.defaults` to select the drivers and libraries that will be compiled by
3133
modifying the following definitions, setting them to `1` or `0`
3234

3335
You can also start with a default config based on the drivers you want to use,
34-
you can find a default config for each graphic driver inside the configs folder.
36+
you can find a default config for each graphic driver inside the `configs/` directory.
3537

36-
You can either replace `lv_conf.defaults` manually or using CMake
38+
You can either replace `lv_conf.defaults` manually before configuring:
39+
40+
```bash
41+
mv configs/<config_name>.defaults lv_conf.defaults
42+
cmake -B build
43+
```
44+
45+
or have CMake directly use that file in-place during configuration:
3746

3847
```bash
3948
cmake -B build -DCONFIG=<config_name>
4049
```
4150

42-
With `<config_name>` the name of the config without the `.defaults` extension, eg: `configs/wayland.defaults` becomes `wayland`.
51+
With `<config_name>` the name of the config without the `.defaults` extension,
52+
eg: `-DCONFIG=wayland` will use `configs/wayland.defaults`.
4353

4454
### Graphics drivers
4555

File renamed without changes.

lv_conf.defaults

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file gets converted into a `lv_conf.h` at compile time
22
# A list of all configuration options can be found inside `lvgl/lv_conf_template.h`
33
# You can also start from a vast list of configs inside the configs folder.
4-
# Use cmake to copy it into your workspace:
4+
# To use one of those configs directly, set the `CONFIG` CMake variable:
55
# eg: `cmake -B build -DCONFIG=drm-egl-2d` for `configs/drm-egl-2d.defaults`
66

77
LV_COLOR_DEPTH 16

0 commit comments

Comments
 (0)