Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5096

General • RP2040_SKELETON Cannot find source file:

$
0
0
I have looked at the RP2040_SKELETON sample to start building a project with a number of external libraries
https://github.com/daveythacher/RP2040_SKELETON

To start with I have tried to take some working code and separate a set of related functions into a separate library.
I have working code driving I2S audio and moved three related functions to a c file in a beep subdirectory of lib. These are a beep function to set up I2S output, a dma call back and a repeating timer function to stop the beep after a short time. These functions are in beep.c and there is a header file beep.h with function prototypes.

However on build I get an error "Cannot find source file" generated by the CMakeLists.txt which is in the src directory which is where the 'main' program file is found.

Code:

[cmake] CMake Error at src/CMakeLists.txt:13 (add_executable):[cmake]   Cannot find source file:[cmake] [cmake]     beep.c
Project structure

Image

The hierarchy of CMakeList.txt files is listed below.
I would welcome any advice to overcome this oversight.
Thanks
Ted
(Snowy Scotland)

Top level CMakeList.txt

Code:

cmake_minimum_required(VERSION 3.12)set(PICO_BOARD pico_w)#Add SDK must be before projectinclude(pico_sdk_import.cmake)# We also need PICO EXTRASinclude(pico_extras_import.cmake)project(audio_skeleton C CXX ASM)pico_sdk_init()# create disassembly with sourcefunction(pico_add_dis_output2 TARGET)    add_custom_command(TARGET ${TARGET} POST_BUILD        COMMAND ${CMAKE_OBJDUMP} -S $<TARGET_FILE:${TARGET}> >$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.dis2)    add_custom_command(TARGET ${TARGET} POST_BUILD        COMMAND arm-none-eabi-size ${CMAKE_CURRENT_LIST_DIR}/../build/src/$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.elf        VERBATIM    )endfunction()add_subdirectory(lib)add_subdirectory(src)
CMakeList.txt in src

Code:

#CmakeLists.txt in srccmake_minimum_required(VERSION 3.12)set(CMAKE_C_STANDARD 11)set(PICO_BOARD pico_w)#Add SDK must be before projectinclude(../pico_sdk_import.cmake)# We also need PICO EXTRASinclude(../pico_extras_import.cmake)project(audio_test C CXX ASM)pico_sdk_init()#This is where the error occurs# add source filesadd_executable(audio_skeleton  main.c)# add include pathstarget_include_directories(audio_skeleton PRIVATE    ../include)# compiler flagstarget_compile_options(audio_skeleton PRIVATE     $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>    -fno-exceptions     -fno-check-new     $<$<COMPILE_LANGUAGE:CXX>:-fno-enforce-eh-specs>    -g     -ffunction-sections     -fdata-sections     -O3    -funroll-loops     -Werror     -Wall)# preprocessor macrostarget_compile_definitions(audio_skeleton PRIVATE     PICO_HEAP_SIZE=2048    PICO_XOSC_STARTUP_DELAY_MULTIPLIER=64)# select linker script#pico_set_binary_type(app copy_to_ram)# enable usb output, disable uart outputpico_enable_stdio_usb(audio_skeleton 1)pico_enable_stdio_uart(audio_skeleton 0)# create map/bin/hex file etc.pico_add_extra_outputs(audio_skeleton)pico_add_dis_output2(audio_skeleton)  # link in libraries (almost every hardware/<blah>.h or pico/<blah>.h is hardware_blah or pico_blah)target_link_libraries(audio_skeleton     pico_runtime    pico_multicore    #pico_cyw43_arch_none    pico_stdlib    pico_audio_i2s)target_compile_definitions(audio_skeleton  PRIVATE        # compile time configuration of I2S        PICO_AUDIO_I2S_MONO_INPUT=1        #define for our example code        USE_AUDIO_I2S=1            PICO_AUDIO_I2S_DATA_PIN=28            PICO_AUDIO_I2S_CLOCK_PIN_BASE=26#            PICO_DEFAULT_UART=0#            PICO_DEFAULT_UART_TX_PIN=28#            PICO_DEFAULT_UART_RX_PIN=29        )## link in libraries for PICO W - wifitarget_link_libraries(audio_skeleton pico_stdlib pico_cyw43_arch_none)# pull in common dependenciestarget_link_libraries(audio_skeleton hardware_flash hardware_sync)# pull in my library codetarget_link_libraries(audio_skeleton beep)pico_set_linker_script(audio_skeleton ${CMAKE_SOURCE_DIR}/memmap_custom.ld)# create map/bin/hex/uf2 file etc.pico_add_extra_outputs(audio_skeleton )# linker optionstarget_link_options(audio_skeleton     PRIVATE "LINKER:--print-memory-usage")
CmakeList.txt in lib

Code:

#Code/lib/CMakeList.txt#add a sub directoryadd_subdirectory(beep)
CmakeList.txt in beep

Code:

#Code/lib/beep/CMakeList.txt#add a sub directory# It is not recommended to build dynamic libraries.add_library(beep INTERFACE)target_sources(beep INTERFACE    beep.c)# is this next bit needed?# For interface libraries this is not completely required. (This would likely be required for static and dynamic libraries.)# Use caution when building static libraries as there could be internal dependencies which need to be mitigated.target_link_libraries(beep INTERFACE    pico_multicore    hardware_dma    hardware_pio    hardware_timer)
projectfiles.png

Statistics: Posted by tfcroft4 — Thu Feb 08, 2024 7:47 pm — Replies 0 — Views 25



Viewing all articles
Browse latest Browse all 5096

Trending Articles