I’m making an embedded project (RPi Pico Project w. C++ SDK); I need to have a few peripheral libraries along with the FreeRTOS Kernel to perform task control. I used a template I found online, it told me to incorporate my libraries into the lib/ directory and link the libraries accordingly, but I can’t seem to get CMake to recognize the library and import the files I would like from the lib/ folder.
I found that i couldn’t get CMake to recognize the libraries i put into the lib directory.
This is what my current project structure looks like:
project/
├── CMakeLists.txt
├── README.md
├── lib/
│ ├── FreeRTOS-Kernel/ <- FreeRTOS kernel files
│ │ ├── CMakeLists.txt
│ │ └── (FreeRTOS files)
│ ├── st7735/ <- Peripheral library files
│ │ ├── CMakeLists.txt
│ │ ├── include/(header files)
│ │ └── (peripheral library files)
│ └── CMakeLists.txt <- for lib/ directory
└── src/
└── main.cpp
└── CMakeLists.txt
└── FreeRTOSConfig.h
These are the CMakeLists:
lib/st7735/CMakeLists:
set(ST7735_SOURCES
#list of peripheral lib source files
ST7735_TFT.cpp
ST7735_TFT_Assets.cpp
ST7735_TFT.cpp
ST7735_TFT_Font.cpp
ST7735_TFT_Print.cpp
ST7735_TFT_graphics.cpp
)
#Add ST7735 as a library
add_library(st7735 ${ST7735_SOURCES})
#Include directories
target_include_directories(st7735
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_link_libraries(st7735 pico_stdlib hardware_spi)
src/CMakeLists:
add_executable(${ProjectName}
main.cpp
)
target_include_directories(${ProjectName} PRIVATE
${CMAKE_CURRENT_LIST_DIR}
lib/st7735/include
)
target_link_libraries(${ProjectName}
pico_stdlib
FreeRTOS-Kernel-Heap4
pico_rand
hardware_spi
st7735
)
pico_enable_stdio_usb(${ProjectName} 1)
pico_enable_stdio_uart(${ProjectName} 0)
pico_add_extra_outputs(${ProjectName})
top level directory CMakesLists:
cmake_minimum_required(VERSION 3.12)
# Name project
SET(ProjectName pockpet)
# Set any variables required for importing libraries
SET(FREERTOS_KERNEL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib/FreeRTOS-Kernel)
# Import those libraries
include(pico_sdk_import.cmake)
include(${FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake)
# Define project
project(${ProjectName})
# Initialize the Raspberry Pi Pico SDK
pico_sdk_init()
# Add subdirectories
add_subdirectory(src)
# if you have anything in "lib" folder then uncomment below - remember to add a CMakeLists.txt
# file to the "lib" directory
add_subdirectory(lib/st7735)
#link peripheral lib
#target_link_libraries(${ProjectName} PRIVATE
#lpico_stdlib
#pico_rand
#hardware_spi
# st7735)
As you can see, there are many more CMakeLists to link libraries to the main.cpp, and i believe that I’m missing something that’s preventing me from calling the st7735 library from my main.cpp file, like so: #include "st7735/ST7735_TFT.hpp"
I’m relatively new to CMake, and any insight would be greatly appreciated!