# CMakeLists.txt for Raspberry Pi Pico Project

**URL:** https://discourse.cmake.org/t/cmakelists-txt-for-raspberry-pi-pico-project/15273
**Category:** Code
**Tags:** os:windows
**Created:** [October 28, 2025, 4:11pm UTC](https://discourse.cmake.org/t/cmakelists-txt-for-raspberry-pi-pico-project/15273 "2025-10-28T16:11:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![DJim53](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/71e660/32.png) [@DJim53](https://discourse.cmake.org/u/DJim53)
#### Post date: [October 28, 2025, 4:11pm UTC](https://discourse.cmake.org/t/cmakelists-txt-for-raspberry-pi-pico-project/15273/1 "2025-10-28T16:11:37Z")

</div>

I would like to perform the initialisation of a PIO in a function in the raik060spilib.c instead of in raik060spicom.c.  
So I have include “raik060spicom.pio.h” in raik060spilib.h and raik060spilib.c.  
However, I don’t understand how to set my CMakeLists.txt to be able to compile my code.

My file tree is :

- RAIK060SPI

Do you have a solution to update my CMakeLists.txt below?

```auto
# Generated Cmake Pico project file

cmake_minimum_required(VERSION 3.13)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Initialise pico_sdk from installed location
# (note this can come from environment, CMake cache etc)

# == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work ==
if(WIN32)
    set(USERHOME $ENV{USERPROFILE})
else()
    set(USERHOME $ENV{HOME})
endif()
set(sdkVersion 2.1.1)
set(toolchainVersion 14_2_Rel1)
set(picotoolVersion 2.1.1)
set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake)
if (EXISTS ${picoVscode})
    include(${picoVscode})
endif()
# ====================================================================================
set(PICO_BOARD pico_w CACHE STRING "Board type")

# Pull in Raspberry Pi Pico SDK (must be before project)
include(pico_sdk_import.cmake)

project(raik060spicom C CXX ASM)

# Initialise the Raspberry Pi Pico SDK
pico_sdk_init()

# Add executable. Default name is the project name, version 0.1

add_executable(raik060spicom
    raik060spicom.c
    )

# Create file .h from pio file
pico_generate_pio_header(raik060spicom ${CMAKE_CURRENT_LIST_DIR}/raik060spicom.pio)

add_library(raik060spilib INTERFACE) #add and change here
#add_library(name of the .h file1 INTERFACE) #add and change here

# Add the source file raik060spilib.c to the raik060spilib interface
target_sources(raik060spilib INTERFACE
    ${CMAKE_CURRENT_SOURCE_DIR}/src/raik060spilib.c
)

target_include_directories(raik060spilib INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include
       #name of the .h file1 INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include

) #add and change here

# pull in common dependencies
target_link_libraries(raik060spicom pico_stdlib hardware_pio hardware_clocks raik060spilib)

if (PICO_CYW43_SUPPORTED)
    target_link_libraries(raik060spicom raik060spilib pico_cyw43_arch_none)
endif()

# create map/bin/hex file etc.
pico_add_extra_outputs(raik060spicom)

pico_enable_stdio_usb(raik060spicom 1)
pico_enable_stdio_uart(raik060spicom 0)

# add url via pico_set_program_url

```

---

<div class="post-metadata">

### Author: ![LegalizeAdulthood](https://discourse.cmake.org/user_avatar/discourse.cmake.org/legalizeadulthood/32/5282_2.png) [@LegalizeAdulthood](https://discourse.cmake.org/u/LegalizeAdulthood)
#### Post date: [October 28, 2025, 4:31pm UTC](https://discourse.cmake.org/t/cmakelists-txt-for-raspberry-pi-pico-project/15273/2 "2025-10-28T16:31:03Z")

</div>

Without debugging your specific problem, I’ll say that I did a presentation on programming the Pico for Utah C++ Programmers. Perhaps it will help.

[Embedded Programming with Raspberry Pi Pico](https://www.youtube.com/watch?v=13HnS_cvlVs)

---

<div class="post-metadata">

### Author: ![DJim53](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/71e660/32.png) [@DJim53](https://discourse.cmake.org/u/DJim53)
#### Post date: [October 28, 2025, 5:13pm UTC](https://discourse.cmake.org/t/cmakelists-txt-for-raspberry-pi-pico-project/15273/3 "2025-10-28T17:13:04Z")

</div>

Dear Richard,

Thank you for your reply but even if I have quicly watch you rpresentation, I have not found a solution to my problem.

---

<div class="post-metadata">

### Author: ![LegalizeAdulthood](https://discourse.cmake.org/user_avatar/discourse.cmake.org/legalizeadulthood/32/5282_2.png) [@LegalizeAdulthood](https://discourse.cmake.org/u/LegalizeAdulthood)
#### Post date: [October 29, 2025, 2:19am UTC](https://discourse.cmake.org/t/cmakelists-txt-for-raspberry-pi-pico-project/15273/4 "2025-10-29T02:19:34Z")

</div>

Have you asked in a Pico dedicated forum?

---

<div class="post-metadata">

### Author: ![DJim53](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/71e660/32.png) [@DJim53](https://discourse.cmake.org/u/DJim53)
#### Post date: [October 29, 2025, 7:39am UTC](https://discourse.cmake.org/t/cmakelists-txt-for-raspberry-pi-pico-project/15273/5 "2025-10-29T07:39:56Z")

</div>

Dear Richard,

Yes, I have start to ask the question on Raspberry Pi forum ([https://forums.raspberrypi.com/viewtopic.php?t=392807](https://forums.raspberrypi.com/viewtopic.php?t=392807)) but as I seems to be a CMakeLists.txt issue, I thought that I can have more help on this forum with CMake expert.
