Skip to content

Commit 304060c

Browse files
Initial scripting to auto-build libpico.a
1 parent 76430b3 commit 304060c

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed

pico-sdk-lib/CMakeLists.txt

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
3+
# Pull in PICO SDK (must be before project)
4+
include(pico_sdk_import.cmake)
5+
6+
project(pico_lib C CXX ASM)
7+
set(CMAKE_C_STANDARD 11)
8+
set(CMAKE_CXX_STANDARD 17)
9+
10+
# Initialize the SDK
11+
pico_sdk_init()
12+
13+
add_library(pico STATIC)
14+
15+
target_compile_definitions(pico PUBLIC
16+
PICO_PRINTF_ALWAYS_INCLUDED=1 )
17+
18+
19+
target_link_libraries(pico
20+
boot_stage2
21+
hardware_adc
22+
hardware_base
23+
hardware_claim
24+
hardware_clocks
25+
hardware_divider
26+
hardware_dma
27+
hardware_flash
28+
hardware_gpio
29+
hardware_i2c
30+
hardware_interp
31+
hardware_irq
32+
hardware_pio
33+
hardware_pll
34+
hardware_pwm
35+
hardware_resets
36+
hardware_rtc
37+
hardware_spi
38+
hardware_sync
39+
hardware_timer
40+
hardware_uart
41+
hardware_vreg
42+
hardware_watchdog
43+
hardware_xosc
44+
pico_bit_ops
45+
pico_bootrom
46+
pico_bootsel_via_double_reset
47+
pico_cxx_options
48+
pico_divider
49+
pico_double
50+
pico_fix
51+
pico_float
52+
pico_int64_ops
53+
pico_malloc
54+
pico_mem_ops
55+
pico_multicore
56+
pico_platform
57+
pico_runtime
58+
pico_standard_link
59+
pico_stdio
60+
pico_stdio_usb
61+
pico_stdlib
62+
pico_unique_id
63+
tinyusb
64+
)
65+
66+
add_custom_command(TARGET pico POST_BUILD
67+
COMMAND ar dv libpico.a stdio_uart.c.obj stdio.c.obj printf.c.obj
68+
)
69+

pico-sdk-lib/build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
rm -rf build
3+
mkdir build
4+
cd build
5+
PICO_SDK_PATH=../../pico-sdk/ PATH="$(cd ../system/arm*/bin; pwd):$PATH" cmake ..
6+
make
7+
cp libpico.a ../../lib/.
8+

pico-sdk-lib/pico_sdk_import.cmake

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake
2+
3+
# This can be dropped into an external project to help locate this SDK
4+
# It should be include()ed prior to project()
5+
6+
# todo document
7+
8+
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
9+
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
10+
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
11+
endif ()
12+
13+
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
14+
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
15+
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
16+
endif ()
17+
18+
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
19+
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
20+
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
21+
endif ()
22+
23+
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the PICO SDK")
24+
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of PICO SDK from git if not otherwise locatable")
25+
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
26+
27+
if (NOT PICO_SDK_PATH)
28+
if (PICO_SDK_FETCH_FROM_GIT)
29+
include(FetchContent)
30+
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
31+
if (PICO_SDK_FETCH_FROM_GIT_PATH)
32+
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
33+
endif ()
34+
FetchContent_Declare(
35+
pico_sdk
36+
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
37+
GIT_TAG master
38+
)
39+
if (NOT pico_sdk)
40+
message("Downloading PICO SDK")
41+
FetchContent_Populate(pico_sdk)
42+
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
43+
endif ()
44+
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
45+
else ()
46+
message(FATAL_ERROR
47+
"PICO SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
48+
)
49+
endif ()
50+
endif ()
51+
52+
get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
53+
if (NOT EXISTS ${PICO_SDK_PATH})
54+
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
55+
endif ()
56+
57+
set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
58+
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
59+
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the PICO SDK")
60+
endif ()
61+
62+
set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the PICO SDK" FORCE)
63+
64+
include(${PICO_SDK_INIT_CMAKE_FILE})

0 commit comments

Comments
 (0)