diff --git a/CMakeLists.txt b/CMakeLists.txt index f440664..337bbaf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,33 +4,33 @@ project(lvgl C CXX) # Set the correct FreeRTOS port for your system (e.g., Posix for WSL) set(FREERTOS_PORT GCC_POSIX CACHE STRING "Port for FreeRTOS on Posix environment") -# Check if the FreeRTOS directory exists -if(EXISTS "${PROJECT_SOURCE_DIR}/FreeRTOS") - message(STATUS "FreeRTOS found, integrating into the build") +option(USE_FREERTOS "Enable FreeRTOS" OFF) # Turn this on to enable FreeRTOS - # Add FreeRTOS configuration as an interface library +if(USE_FREERTOS) + message(STATUS "FreeRTOS is enabled") + + # FreeRTOS integration when USE_FREERTOS is enabled add_library(freertos_config INTERFACE) target_include_directories(freertos_config SYSTEM INTERFACE ${PROJECT_SOURCE_DIR}/config) target_compile_definitions(freertos_config INTERFACE projCOVERAGE_TEST=0) - add_definitions(-DFREERTOS_PORT=${FREERTOS_PORT}) # Add FreeRTOS as a subdirectory add_subdirectory(FreeRTOS) - # Include directories for FreeRTOS headers + # FreeRTOS-specific include directories include_directories(${PROJECT_SOURCE_DIR}/FreeRTOS/include) include_directories(${PROJECT_SOURCE_DIR}/FreeRTOS/portable/ThirdParty/GCC/Posix) include_directories(${PROJECT_SOURCE_DIR}/config) - # Add FreeRTOS source files + # Add FreeRTOS sources file(GLOB FREERTOS_SOURCES "${PROJECT_SOURCE_DIR}/FreeRTOS/*.c" "${PROJECT_SOURCE_DIR}/FreeRTOS/portable/MemMang/heap_4.c" "${PROJECT_SOURCE_DIR}/FreeRTOS/portable/ThirdParty/GCC/Posix/*.c" ) else() - message(STATUS "FreeRTOS not found, skipping FreeRTOS integration") - set(FREERTOS_SOURCES "") + message(STATUS "FreeRTOS is disabled") + set(FREERTOS_SOURCES "") # No FreeRTOS sources if FreeRTOS is disabled endif() # Main include files of the project @@ -69,21 +69,30 @@ add_compile_definitions($<$:LV_USE_FFMPEG=1>) add_subdirectory(lvgl) target_include_directories(lvgl PUBLIC ${PROJECT_SOURCE_DIR} ${SDL2_INCLUDE_DIRS}) -# Create the main executable and add source files -add_executable(main - ${PROJECT_SOURCE_DIR}/main/src/main.c - ${PROJECT_SOURCE_DIR}/main/src/freertos_main.cpp - ${PROJECT_SOURCE_DIR}/main/src/mouse_cursor_icon.c - ${PROJECT_SOURCE_DIR}/main/src/FreeRTOS_Posix_Port.c - ${FREERTOS_SOURCES} -) +# Create the main executable, depending on the FreeRTOS option +if(USE_FREERTOS) + add_executable(main + ${PROJECT_SOURCE_DIR}/main/src/main.c + ${PROJECT_SOURCE_DIR}/main/src/freertos_main.cpp + ${PROJECT_SOURCE_DIR}/main/src/mouse_cursor_icon.c + ${PROJECT_SOURCE_DIR}/main/src/FreeRTOS_Posix_Port.c + ${FREERTOS_SOURCES} # Add only if USE_FREERTOS is enabled + ) + # Link FreeRTOS libraries + target_link_libraries(main freertos_config FreeRTOS) +else() + add_executable(main + ${PROJECT_SOURCE_DIR}/main/src/main.c + ${PROJECT_SOURCE_DIR}/main/src/mouse_cursor_icon.c + ) +endif() # Define LVGL configuration as a simple include target_compile_definitions(main PRIVATE LV_CONF_INCLUDE_SIMPLE) target_link_libraries(main lvgl lvgl::examples lvgl::demos lvgl::thorvg ${SDL2_LIBRARIES} m pthread) -# Only link FreeRTOS if the FreeRTOS directory exists -if(EXISTS "${PROJECT_SOURCE_DIR}/FreeRTOS") +# Only link freertos_config if the FreeRTOS directory exists +if(USE_FREERTOS) target_link_libraries(main freertos_config) endif() diff --git a/README.md b/README.md index 0d69362..2aa34f0 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ Therefore, it is crucial to allocate sufficient heap memory to ensure smooth exe ### Enable FreeRTOS To enable the rtos part of this project select in lv_conf.h `#define LV_USE_OS LV_OS_NONE` to `#define LV_USE_OS LV_OS_FREERTOS` +Additionaly you have to enable the compilation of all FreeRTOS Files by turn on `option(USE_FREERTOS "Enable FreeRTOS" OFF) ` in the CMakeLists.txt file. ### CMake @@ -127,4 +128,4 @@ It requires a working version of GCC, GDB and make in your path. To allow debugging inside VSCode you will also require a GDB [extension](https://marketplace.visualstudio.com/items?itemName=webfreak.debug) or other suitable debugger. All the requirements, build and debug settings have been pre-configured in the [.workspace](simulator.code-workspace) file. -The project can use **SDL** but it can be easily relaced by any other built-in LVGL dirvers. \ No newline at end of file +The project can use **SDL** but it can be easily relaced by any other built-in LVGL dirvers.