LVGL-simulation-example/CMakeLists.txt
MootSeeker 0a8220a874
Add FreeRTOS Kernel and C++ Support to Simulator (#59)
* Add FreeRTOS

* Add FreeRTOS Task

* Update README.md

* Upgrade to C++

* Update Code to run multiple tasks

* Add ui folder

Add UI folder for SquareLine Studio files

* Update ui.cpp

* Add UI files to CMake from SquareLine Studio

Add UI files to CMake path.
UI folder setup so files from SquareLine Studio can be used.
Add more heap to debug SDL.

* Update README.md

* Add drop den menu test

* Add global include file

* remove cpp file to test stability

* Fixing wrong cmake configuration

remove ui files from here

* work

* Change project structure

Changed project structure and CMake file so freertos implementation will be activated when enabled in lv_conf.h

* Refactor project structure and CMake configuration, remove unused UI components

- Restructured the project and updated the CMake file to conditionally activate FreeRTOS based on lv_conf.h settings.
- Removed UI files and C++ files related to SquareLine Studio to improve project stability.
- Added a global include.
- Updated the README.md to reflect the changes.
- Increased heap size for debugging with SDL.

* Move to CPP file

Moved to cpp file created task with lv_thread_init()

* Update freertos_main.cpp

* Clean up code

Not using task notification, since pxTCD is always NULL

Changed back to LV_OS_NONE since user of this project has to device what he want to use

Commented freertos posix file with AI :)

Cleanup freertos_main.cpp as mentioned in PR

* Update README.md

Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>

* Update README.md

* Update main/src/FreeRTOS_Posix_Port.c

Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>

* Update main/src/main.c

Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>

* Update README.md

Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>

* Update README.md

* Update README.md

---------

Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>
2024-09-12 10:45:51 +02:00

188 lines
6.6 KiB
CMake

cmake_minimum_required(VERSION 3.10)
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")
# Add FreeRTOS configuration as an interface library
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
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
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 "")
endif()
# Main include files of the project
include_directories(${PROJECT_SOURCE_DIR}/main/inc)
# Define options for LVGL with default values (OFF)
option(LV_USE_DRAW_SDL "Use SDL draw unit" OFF)
option(LV_USE_LIBPNG "Use libpng to decode PNG" OFF)
option(LV_USE_LIBJPEG_TURBO "Use libjpeg turbo to decode JPEG" OFF)
option(LV_USE_FFMPEG "Use libffmpeg to display video using lv_ffmpeg" OFF)
option(LV_USE_FREETYPE "Use freetype library" OFF)
# Set C and C++ standards
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Set the output path for the executable
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
# Find and include SDL2 library
find_package(SDL2 REQUIRED)
# Remove ARM-specific compile and linker options
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
# Add compile definitions based on the selected options
add_compile_definitions($<$<BOOL:${LV_USE_DRAW_SDL}>:LV_USE_DRAW_SDL=1>)
add_compile_definitions($<$<BOOL:${LV_USE_LIBPNG}>:LV_USE_LIBPNG=1>)
add_compile_definitions($<$<BOOL:${LV_USE_LIBJPEG_TURBO}>:LV_USE_LIBJPEG_TURBO=1>)
add_compile_definitions($<$<BOOL:${LV_USE_FFMPEG}>:LV_USE_FFMPEG=1>)
# Add LVGL subdirectory
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}
)
# 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")
target_link_libraries(main freertos_config)
endif()
# Custom target to run the executable
add_custom_target(run COMMAND ${EXECUTABLE_OUTPUT_PATH}/main DEPENDS main)
# Conditionally include and link SDL2_image if LV_USE_DRAW_SDL is enabled
if(LV_USE_DRAW_SDL)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
find_package(SDL2_image REQUIRED)
target_include_directories(lvgl PUBLIC ${SDL2_IMAGE_INCLUDE_DIRS})
target_link_libraries(main ${SDL2_IMAGE_LIBRARIES})
endif()
# Conditionally include and link libpng if LV_USE_LIBPNG is enabled
if(LV_USE_LIBPNG)
find_package(PNG REQUIRED)
target_include_directories(lvgl PUBLIC ${PNG_INCLUDE_DIRS})
target_link_libraries(main ${PNG_LIBRARIES})
endif()
# Conditionally include and link libjpeg-turbo if LV_USE_LIBJPEG_TURBO is enabled
if(LV_USE_LIBJPEG_TURBO)
find_package(JPEG REQUIRED)
target_include_directories(lvgl PUBLIC ${JPEG_INCLUDE_DIRS})
target_link_libraries(main ${JPEG_LIBRARIES})
endif()
# Conditionally include and link FFmpeg libraries if LV_USE_FFMPEG is enabled
if(LV_USE_FFMPEG)
target_link_libraries(main avformat avcodec avutil swscale z)
endif()
# Conditionally include and link FreeType if LV_USE_FREETYPE is enabled
if(LV_USE_FREETYPE)
find_package(Freetype REQUIRED)
target_include_directories(lvgl PUBLIC ${FREETYPE_INCLUDE_DIRS})
target_link_libraries(main ${FREETYPE_LIBRARIES})
endif()
# Apply additional compile options if the build type is Debug
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(lvgl PRIVATE
-pedantic-errors
-Wall
-Wclobbered
-Wdeprecated
-Wdouble-promotion
-Wempty-body
-Wextra
-Wformat-security
-Wmaybe-uninitialized
# -Wmissing-prototypes
-Wpointer-arith
-Wmultichar
-Wno-pedantic # ignored for now, we convert functions to pointers for properties table.
-Wreturn-type
-Wshadow
-Wshift-negative-value
-Wsizeof-pointer-memaccess
-Wtype-limits
-Wundef
-Wuninitialized
-Wunreachable-code
-Wfloat-conversion
-Wstrict-aliasing
)
# Check if the compiler supports sanitizers (e.g., leak, address, undefined)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fsanitize=leak" HAS_SANITIZE_LEAK)
check_cxx_compiler_flag("-fsanitize=address" HAS_SANITIZE_ADDRESS)
check_cxx_compiler_flag("-fsanitize=undefined" HAS_SANITIZE_UNDEFINED)
# Prepare the list of sanitizers
set(SANITIZERS "")
if (HAS_SANITIZE_ADDRESS)
set(SANITIZERS "${SANITIZERS},address")
endif()
if (HAS_SANITIZE_UNDEFINED)
set(SANITIZERS "${SANITIZERS},undefined")
endif()
if (HAS_SANITIZE_LEAK)
set(SANITIZERS "${SANITIZERS},leak")
endif()
# Remove leading comma if there are any sanitizers
string(REGEX REPLACE "^," "" SANITIZERS "${SANITIZERS}")
# Add the sanitizers to the compile options if any are supported
if (SANITIZERS)
message(STATUS "Sanitizers enabled: ${SANITIZERS}")
target_compile_options(main PRIVATE -fsanitize=${SANITIZERS})
target_link_options(main PRIVATE -fsanitize=${SANITIZERS})
else()
message(STATUS "Sanitizers not enabled")
endif()
endif()