Skip to content

Instantly share code, notes, and snippets.

@ndomx
Last active April 29, 2023 01:08
Show Gist options
  • Save ndomx/6aa13c4fe2b1572fa88c382b6f163cc8 to your computer and use it in GitHub Desktop.
Save ndomx/6aa13c4fe2b1572fa88c382b6f163cc8 to your computer and use it in GitHub Desktop.
RPi Pico W Minimal CMake file with wifi included
# CMakeLists.txt
# Based on the example CMake file provided by the official documentation
# this sample file allows you to connect your pico w to the internet
# without any further setup (wifi ssid and password are not included,
# you can include those values directly in the cmake command or declare them
# in an untracked header file)
#
# note: be sure to copy the header lwipopts.h to your workspace (it can
# be found in the examples: pico-examples/pico_w/wifi/lwipopts_examples_common.h).
# The workspace should look like this:
# |- build/ # empty build folder
# |- <target>.cpp # can be .c also
# |- CMakeLists.txt
# |- lwipopts.h
# |- pico_sdk_import.cmake
#
# usage:
# $ cd build
# $ cmake ..
# $ make
#
# Replace the <> wrapped variables with your own values
cmake_minimum_required(VERSION 3.13)
set(PICO_BOARD pico_w)
set(PICO_SDK_PATH <path-to-pico-sdk>) # Typically ~/pico-sdk
# To use the pico sdk directly from github,
# replace line 2 with:
# set(PICO_SDK_FETCH_FROM_GIT on)
include(pico_sdk_import.cmake)
project(<project-name> C CXX ASM) # Project name
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
pico_sdk_init()
# add source files to the target executable (i.e. <executable-name>.uf2)
add_executable(<executable-name>
<target>.cpp # this is where your `main` function is defined
)
pico_add_extra_outputs(<executable-name>)
target_include_directories(<executable-name> PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_link_libraries(<executable-name> pico_stdlib pico_cyw43_arch_lwip_threadsafe_background)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment