Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ if (NOT EXISTS "${PICO_PLATFORM_CMAKE_FILE}")
Either specify a valid PICO_PLATFORM (or PICO_PLATFORM_CMAKE_FILE).")
endif ()

# Initialize board related build/compile settings
include(${CMAKE_CURRENT_LIST_DIR}/board_setup.cmake)

# todo add option to disable skip flag
# call add_subdirectory(subdir) unless SKIP_SUBDIR evaluates to true
function(pico_add_subdirectory subdir)
# todo add option to disable skip flag
string(TOUPPER ${subdir} subdir_upper)
set(replace_flag SKIP_${subdir_upper})
if (NOT ${replace_flag})
Expand All @@ -24,10 +26,12 @@ function(pico_add_subdirectory subdir)
endif ()
endfunction()

# add a link option to wrap the given function name; i.e. -Wl:wrap=FUNCNAME for gcc
function(pico_wrap_function TARGET FUNCNAME)
target_link_options(${TARGET} INTERFACE "LINKER:--wrap=${FUNCNAME}")
endfunction()

# add map file generation for the given target
function(pico_add_map_output TARGET)
get_target_property(target_type ${TARGET} TYPE)
if ("EXECUTABLE" STREQUAL "${target_type}")
Expand All @@ -37,11 +41,23 @@ function(pico_add_map_output TARGET)
endif ()
endfunction()

# create a hardware_NAME_headers target (see pico_pico_simple_hardware_headers_target)
# create a hardware_NAME target (see pico_pico_simple_hardware_target)
macro(pico_simple_hardware_target NAME)
pico_simple_hardware_headers_target(${NAME})
pico_simple_hardware_impl_target(${NAME})
endmacro()

# create an INTERFACE library named target, and define LIB_TARGET=1 (upper case) as a compile option
function(pico_add_impl_library target)
add_library(${target} INTERFACE)
string(TOUPPER ${target} TARGET_UPPER)
target_compile_definitions(${target} INTERFACE LIB_${TARGET_UPPER}=1)
endfunction()

# create an INTERFACE library named hardware_NAME_headers INTERFACE library if it doesn't already exist,
# and add include/ relative to the calling directory to the includes.
# and hardware_structs and hardware_claim as dependencies of the library
macro(pico_simple_hardware_headers_target NAME)
if (NOT TARGET hardware_${NAME}_headers)
add_library(hardware_${NAME}_headers INTERFACE)
Expand All @@ -54,8 +70,15 @@ macro(pico_simple_hardware_headers_target NAME)
endif()
endmacro()

# create an INTERFACE library named hardware_NAME if it doesn't exist, along with a hardware_NAME_headers
# INTERFACE library that it depends on. The hardware_NAME_headers library add include/ relative to
# and pico_base_headers, and harddware_structs as a dependency of the library
macro(pico_simple_hardware_headers_only_target NAME)
if (NOT TARGET hardware_${NAME})
# Choosing not to add LIB_HARDWARE_ defines to avoid command line bloat pending a need (they aren't
# super interesting except to determine functionality as they are mostly passive accessors, however
# they could be useful to determine if the header is available.
# pico_add_sdk_impl_library(hardware_${NAME})
add_library(hardware_${NAME} INTERFACE)

target_include_directories(hardware_${NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
Expand All @@ -66,8 +89,14 @@ macro(pico_simple_hardware_headers_only_target NAME)
endif()
endmacro()

# create an INTERFACE library named hardware_NAME if it doesn't exist, dependent on a pre-existing hardware_NAME_headers
# INTERFACE library and pico_platform. The file NAME.c relative to the caller is added to the C sources for the hardware_NAME
macro(pico_simple_hardware_impl_target NAME)
if (NOT TARGET hardware_${NAME})
# Choosing not to add LIB_HARDWARE_ defines to avoid command line bloat pending a need (they aren't
# super interesting except to determine functionality as they are mostly passive accessors, however
# they could be useful to determine if the header is available.
# pico_add_sdk_impl_library(hardware_${NAME})
add_library(hardware_${NAME} INTERFACE)

target_sources(hardware_${NAME} INTERFACE
Expand Down
2 changes: 1 addition & 1 deletion src/common/pico_binary_info/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ add_library(pico_binary_info_headers INTERFACE)

target_include_directories(pico_binary_info_headers INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)

add_library(pico_binary_info INTERFACE)
pico_add_impl_library(pico_binary_info)

target_link_libraries(pico_binary_info INTERFACE pico_binary_info_headers)

Expand Down
6 changes: 3 additions & 3 deletions src/common/pico_stdlib/include/pico/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ extern "C" {
// respective INTERFACE libraries, so these defines are set if the library
// is included for the target executable

#if PICO_STDIO_UART
#if LIB_PICO_STDIO_UART
#include "pico/stdio_uart.h"
#endif

#if PICO_STDIO_USB
#if LIB_PICO_STDIO_USB
#include "pico/stdio_usb.h"
#endif

#if PICO_STDIO_SEMIHOSTING
#if LIB_PICO_STDIO_SEMIHOSTING
#include "pico/stdio_semihosting.h"
#endif

Expand Down
10 changes: 5 additions & 5 deletions src/common/pico_sync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@ if (NOT TARGET pico_sync_headers)
endif()

if (NOT TARGET pico_sync_core)
add_library(pico_sync_core INTERFACE)
pico_add_impl_library(pico_sync_core)
target_sources(pico_sync_core INTERFACE
${CMAKE_CURRENT_LIST_DIR}/lock_core.c
)
target_link_libraries(pico_sync_core INTERFACE pico_sync_headers)
endif()

if (NOT TARGET pico_sync_sem)
add_library(pico_sync_sem INTERFACE)
pico_add_impl_library(pico_sync_sem)
target_sources(pico_sync_sem INTERFACE
${CMAKE_CURRENT_LIST_DIR}/sem.c
)
target_link_libraries(pico_sync_sem INTERFACE pico_sync_core pico_time)
endif()

if (NOT TARGET pico_sync_mutex)
add_library(pico_sync_mutex INTERFACE)
pico_add_impl_library(pico_sync_mutex)
target_sources(pico_sync_mutex INTERFACE
${CMAKE_CURRENT_LIST_DIR}/mutex.c
)
target_link_libraries(pico_sync_mutex INTERFACE pico_sync_core pico_time)
endif()

if (NOT TARGET pico_sync_critical_section)
add_library(pico_sync_critical_section INTERFACE)
pico_add_impl_library(pico_sync_critical_section)
target_sources(pico_sync_critical_section INTERFACE
${CMAKE_CURRENT_LIST_DIR}/critical_section.c
)
target_link_libraries(pico_sync_critical_section INTERFACE pico_sync_core pico_time)
endif()

if (NOT TARGET pico_sync)
add_library(pico_sync INTERFACE)
pico_add_impl_library(pico_sync)
target_link_libraries(pico_sync INTERFACE pico_sync_sem pico_sync_mutex pico_sync_critical_section pico_sync_core)
endif()

Expand Down
2 changes: 1 addition & 1 deletion src/common/pico_time/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if (NOT TARGET pico_time_headers)
endif()

if (NOT TARGET pico_time)
add_library(pico_time INTERFACE)
pico_add_impl_library(pico_time)

target_sources(pico_time INTERFACE
${CMAKE_CURRENT_LIST_DIR}/time.c
Expand Down
2 changes: 1 addition & 1 deletion src/common/pico_util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if (NOT TARGET pico_util_headers)
endif()

if (NOT TARGET pico_util)
add_library(pico_util INTERFACE)
pico_add_impl_library(pico_util)
target_sources(pico_util INTERFACE
${CMAKE_CURRENT_LIST_DIR}/datetime.c
${CMAKE_CURRENT_LIST_DIR}/pheap.c
Expand Down
2 changes: 1 addition & 1 deletion src/host/pico_bit_ops/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_library(pico_bit_ops INTERFACE)
pico_add_impl_library(pico_bit_ops)

target_sources(pico_bit_ops INTERFACE
${CMAKE_CURRENT_LIST_DIR}/bit_ops.c)
Expand Down
2 changes: 1 addition & 1 deletion src/host/pico_divider/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_library(pico_divider INTERFACE)
pico_add_impl_library(pico_divider)

target_sources(pico_divider INTERFACE
${CMAKE_CURRENT_LIST_DIR}/divider.c)
Expand Down
2 changes: 1 addition & 1 deletion src/host/pico_multicore/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if (NOT TARGET pico_multicore)
add_library(pico_multicore INTERFACE)
pico_add_impl_library(pico_multicore)

target_include_directories(pico_multicore INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/host/pico_platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (NOT TARGET pico_platform_headers)
endif()

if (NOT TARGET pico_platform)
add_library(pico_platform INTERFACE)
pico_add_impl_library(pico_platform)

target_sources(pico_platform INTERFACE
${CMAKE_CURRENT_LIST_DIR}/platform_base.c
Expand Down
2 changes: 1 addition & 1 deletion src/host/pico_printf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if (NOT TARGET pico_printf)
add_library(pico_printf INTERFACE)
pico_add_impl_library(pico_printf)
function(pico_set_printf_implementation)
endfunction()
endif()
Expand Down
8 changes: 4 additions & 4 deletions src/host/pico_stdio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
if (NOT TARGET pico_stdio)
add_library(pico_stdio INTERFACE)
pico_add_impl_library(pico_stdio)

target_include_directories(pico_stdio INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)

target_sources(pico_stdio INTERFACE
${CMAKE_CURRENT_LIST_DIR}/stdio.c
)
add_library(pico_stdio_usb INTERFACE)
add_library(pico_stdio_uart INTERFACE)
add_library(pico_stdio_semihosting INTERFACE)
pico_add_impl_library(pico_stdio_usb)
pico_add_impl_library(pico_stdio_uart)
pico_add_impl_library(pico_stdio_semihosting)

function(pico_enable_stdio_uart)
endfunction()
Expand Down
2 changes: 1 addition & 1 deletion src/host/pico_stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if (NOT TARGET pico_stdlib)
add_library(pico_stdlib INTERFACE)
pico_add_impl_library(pico_stdlib)

target_sources(pico_stdlib INTERFACE
${CMAKE_CURRENT_LIST_DIR}/stdlib.c
Expand Down
6 changes: 1 addition & 5 deletions src/rp2_common/hardware_claim/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
add_library(hardware_claim INTERFACE)
target_include_directories(hardware_claim INTERFACE include)
target_sources(hardware_claim INTERFACE
${CMAKE_CURRENT_LIST_DIR}/claim.c)

pico_simple_hardware_target(claim)
target_link_libraries(hardware_claim INTERFACE hardware_sync)
3 changes: 1 addition & 2 deletions src/rp2_common/hardware_divider/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
add_library(hardware_divider INTERFACE)
pico_simple_hardware_headers_only_target(divider)
target_sources(hardware_divider INTERFACE ${CMAKE_CURRENT_LIST_DIR}/divider.S)
target_include_directories(hardware_divider INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(hardware_divider INTERFACE hardware_structs)
10 changes: 2 additions & 8 deletions src/rp2_common/hardware_flash/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
add_library(hardware_flash INTERFACE)

target_sources(hardware_flash INTERFACE
${CMAKE_CURRENT_LIST_DIR}/flash.c
)

target_include_directories(hardware_flash INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(hardware_flash INTERFACE pico_base_headers pico_bootrom)
pico_simple_hardware_target(flash)
target_link_libraries(hardware_flash INTERFACE pico_bootrom)
3 changes: 1 addition & 2 deletions src/rp2_common/hardware_resets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
add_library(hardware_resets INTERFACE)
target_include_directories(hardware_resets INTERFACE include)
pico_simple_hardware_headers_only_target(resets)
15 changes: 3 additions & 12 deletions src/rp2_common/pico_bit_ops/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
if (NOT TARGET pico_bit_ops)
#shims for ROM functions for -lgcc functions (listed below)
add_library(pico_bit_ops INTERFACE)
pico_add_impl_library(pico_bit_ops)

# no custom implementation; falls thru to compiler
add_library(pico_bit_ops_compiler INTERFACE)
# PICO_BUILD_DEFINE: PICO_BIT_OPS_COMPILER, whether compiler provided bit_ops bit functions support is being used, type=bool, default=0, but dependent on CMake options, group=pico_bit_ops
target_compile_definitions(pico_bit_ops_compiler INTERFACE
PICO_BIT_OPS_COMPILER=1
)
pico_add_impl_library(pico_bit_ops_compiler)

# add alias "default" which is just pico.
add_library(pico_bit_ops_default INTERFACE)
target_link_libraries(pico_bit_ops_default INTERFACE pico_bit_ops_pico)

set(PICO_DEFAULT_BIT_OPS_IMPL pico_bit_ops_default)

add_library(pico_bit_ops_pico INTERFACE)
pico_add_impl_library(pico_bit_ops_pico)
target_link_libraries(pico_bit_ops INTERFACE
$<IF:$<BOOL:$<TARGET_PROPERTY:PICO_TARGET_BIT_OPS_IMPL>>,$<TARGET_PROPERTY:PICO_TARGET_BIT_OPS_IMPL>,${PICO_DEFAULT_BIT_OPS_IMPL}>)

# PICO_BUILD_DEFINE: PICO_BIT_OPS_PICO, whether optimized pico/bootrom provided bit_ops bit functions support is being used, type=bool, default=1, but dependent on CMake options, group=pico_bit_ops
target_compile_definitions(pico_bit_ops_pico INTERFACE
PICO_BIT_OPS_PICO=1
)

target_sources(pico_bit_ops_pico INTERFACE
${CMAKE_CURRENT_LIST_DIR}/bit_ops_aeabi.S
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_library(pico_bootsel_via_double_reset INTERFACE)
pico_add_impl_library(pico_bootsel_via_double_reset)

target_sources(pico_bootsel_via_double_reset INTERFACE
${CMAKE_CURRENT_LIST_DIR}/pico_bootsel_via_double_reset.c
Expand Down
12 changes: 3 additions & 9 deletions src/rp2_common/pico_divider/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
if (NOT TARGET pico_divider)
# library to be depended on - we make this depend on particular implementations using per target generator expressions
add_library(pico_divider INTERFACE)
pico_add_impl_library(pico_divider)

# no custom implementation; falls thru to compiler
add_library(pico_divider_compiler INTERFACE)
target_compile_definitions(pico_divider_compiler INTERFACE
PICO_DIVIDER_COMPILER=1
)
pico_add_impl_library(pico_divider_compiler)

# add alias "default" which is just hardware.
add_library(pico_divider_default INTERFACE)
Expand All @@ -27,10 +24,7 @@ if (NOT TARGET pico_divider)
hardware_regs
)

add_library(pico_divider_hardware INTERFACE)
target_compile_definitions(pico_divider_hardware INTERFACE
PICO_DIVIDER_HARDWARE=1
)
pico_add_impl_library(pico_divider_hardware)

target_link_libraries(pico_divider_hardware INTERFACE pico_divider_hardware_explicit)

Expand Down
18 changes: 4 additions & 14 deletions src/rp2_common/pico_double/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
if (NOT TARGET pico_double)
# library to be depended on - we make this depend on particular implementations using per target generator expressions
add_library(pico_double INTERFACE)
pico_add_impl_library(pico_double)

# no custom implementation; falls thru to compiler
add_library(pico_double_compiler INTERFACE)
# PICO_BUILD_DEFINE: PICO_DOUBLE_COMPILER, whether compiler provided double support is being used, type=bool, default=0, but dependent on CMake options, group=pico_double
target_compile_definitions(pico_double_compiler INTERFACE
PICO_DOUBLE_COMPILER=1
)
pico_add_impl_library(pico_double_compiler)

add_library(pico_double_headers INTERFACE)
target_include_directories(pico_double_headers INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
Expand All @@ -21,30 +17,24 @@ if (NOT TARGET pico_double)
target_link_libraries(pico_double INTERFACE
$<IF:$<BOOL:$<TARGET_PROPERTY:PICO_TARGET_DOUBLE_IMPL>>,$<TARGET_PROPERTY:PICO_TARGET_DOUBLE_IMPL>,${PICO_DEFAULT_DOUBLE_IMPL}>)

add_library(pico_double_pico INTERFACE)
pico_add_impl_library(pico_double_pico)
target_sources(pico_double_pico INTERFACE
${CMAKE_CURRENT_LIST_DIR}/double_aeabi.S
${CMAKE_CURRENT_LIST_DIR}/double_init_rom.c
${CMAKE_CURRENT_LIST_DIR}/double_math.c
${CMAKE_CURRENT_LIST_DIR}/double_v1_rom_shim.S
)
# PICO_BUILD_DEFINE: PICO_DOUBLE_PICO, whether optimized pico/bootrom provided double support is being used, type=bool, default=1, but dependent on CMake options, group=pico_double
target_compile_definitions(pico_double_pico INTERFACE
PICO_DOUBLE_PICO=1
)

target_link_libraries(pico_double_pico INTERFACE pico_bootrom pico_double_headers)

add_library(pico_double_none INTERFACE)
pico_add_impl_library(pico_double_none)
target_sources(pico_double_none INTERFACE
${CMAKE_CURRENT_LIST_DIR}/double_none.S
)

target_link_libraries(pico_double_none INTERFACE pico_double_headers)

# PICO_BUILD_DEFINE: PICO_DOUBLE_NONE, whether double support is disabled and functions will panic, type=bool, default=0, but dependent on CMake options, group=pico_double
target_compile_definitions(pico_double_none INTERFACE
PICO_DOUBLE_NONE=1
PICO_PRINTF_SUPPORT_FLOAT=0 # printing floats/doubles won't work, so we can save space by removing it
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_library(pico_fix_rp2040_usb_device_enumeration INTERFACE)
pico_add_impl_library(pico_fix_rp2040_usb_device_enumeration)

target_sources(pico_fix_rp2040_usb_device_enumeration INTERFACE
${CMAKE_CURRENT_LIST_DIR}/rp2040_usb_device_enumeration.c
Expand Down
Loading