Raspberry board export and CMakeLists.txt

What do you want to achieve?

I want to export my SLS files to a pi5 and compile them using c++.

What have you tried so far?

I followed the procedure outlined in https://github.com/SquareLineStudio/board_raspberry_pi/tree/v1.0.0 and found that the c++ files were not able to be linked.

After a lot of scratching I modified the CMakeLists.txt file thus:

cmake_minimum_required(VERSION 3.15)
set(CMAKE_SYSTEM_NAME Generic)

if (WIN32)
set(CMAKE_GENERATOR “MinGW Makefiles”)
endif (WIN32)

#set(CMAKE_BUILD_TYPE Release)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

#cross-compilation toolchain configuration
set(CMAKE_CROSSCOMPILING true)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_LIBRARY_ARCHITECTURE aarch64-linux-gnu)
set(CMAKE_C_COMPILER ${CMAKE_LIBRARY_ARCHITECTURE}-gcc)
set(CMAKE_CXX_COMPILER ${CMAKE_LIBRARY_ARCHITECTURE}-g++)
set(CMAKE_LINKER ${CMAKE_LIBRARY_ARCHITECTURE}-ld)

project(SquareLine_Project C CXX)

set(SDL_FOLDER sdl2-dev-rpi64)
set(CMAKE_FIND_ROOT_PATH ${SDL_FOLDER})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

set(CMAKE_BUILD_RPATH “${SDL_FOLDER}/include”)
set(CMAKE_INSTALL_RPATH ${CMAKE_BUILD_RPATH})

include_directories(
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/${SDL_FOLDER}/include
${PROJECT_SOURCE_DIR}/lvgl
# ${PROJECT_SOURCE_DIR}/lv_drivers
${PROJECT_SOURCE_DIR}/ui
)

FILE(GLOB_RECURSE LVGL_Sources CONFIGURE_DEPENDS ${SDL_FOLDER})
FILE(GLOB_RECURSE LVGL_Sources CONFIGURE_DEPENDS lvgl/.c)
#FILE(GLOB_RECURSE LV_DRIVERS_Sources CONFIGURE_DEPENDS lv_drivers/
.c)
FILE(GLOB_RECURSE UI_Sources CONFIGURE_DEPENDS ui/.c ui/.cpp)

add_executable(${PROJECT_NAME} main.cpp ${LVGL_Sources} ${LV_DRIVERS_Sources} ${UI_Sources})

target_link_libraries(${PROJECT_NAME} -L"${PROJECT_SOURCE_DIR}/${SDL_FOLDER}/lib" SDL2 )

In Summary: CXX needed to be in the project arguement; the -none needs to be removed from set(CMAKE_LIBRARY_ARCHITECTURE aarch64-none-linux-gnu) and main.cpp replaces main.c in add_executable and in the project folder.

It works now.

Screenshot or video

Others

  • SquareLine Studio version: 1.4.1
  • Operating system: Pi OS Bullseye
  • Target hardware: Raspberry

This is not a bug per se, as the board-template is made for C in the first place. The aarch64-linux-gnu vs aarch64-none-linux-gnu difference is explained in the README and handled by .sh/.bat scripts if you use them, both are valid, depending on where you get it from. As usual, you’re free to modify the board-template to your needs, as you did here. Good to know these were the only modifications needed for C++. Thanks for sharing the information with the community.