Skip to content
Snippets Groups Projects
Commit 2613831b authored by graham sanderson's avatar graham sanderson
Browse files

rework some header library dependencies

parent 56594e75
No related branches found
No related tags found
No related merge requests found
Showing
with 70 additions and 37 deletions
......@@ -27,6 +27,29 @@ function(pico_add_subdirectory subdir)
pico_promote_common_scope_vars()
endfunction()
# takes dependencies after the target
function(pico_add_header_aware_library_dependency TARGET)
if (${ARGC} LESS 2)
message(FATAL_ERROR "expected a target and at least one dependency")
endif()
if (NOT TARGET ${TARGET}_headers)
message(FATAL_ERROR "${TARGET} does not have headers")
endif()
# library should depend on its own header
target_link_libraries(${TARGET} INTERFACE ${TARGET}_headers)
foreach(DEPENDENCY IN LISTS ARGN)
if (DEPENDENCY MATCHES ".*_headers")
message(FATAL_ERROR "should not use headers with pico_add_header_aware_library_dependency")
endif()
# note, it would be nice to only add the dependency if it exists, but we do
# not necessarily add libraries in reverse dependency order, so we do this
# unconditionally, so this function shouuld only be passed dependencies that
# have headers, or link will fail with a missing library -lfoo_headers
target_link_libraries(${TARGET}_headers INTERFACE ${DEPENDENCY}_headers)
target_link_libraries(${TARGET} INTERFACE ${DEPENDENCY})
endforeach()
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}")
......@@ -66,7 +89,7 @@ macro(pico_simple_hardware_headers_target NAME)
target_include_directories(hardware_${NAME}_headers INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(hardware_${NAME}_headers INTERFACE pico_base_headers)
if (NOT PICO_NO_HARDWARE)
target_link_libraries(hardware_${NAME}_headers INTERFACE hardware_structs hardware_claim)
target_link_libraries(hardware_${NAME}_headers INTERFACE hardware_structs hardware_claim_headers)
endif()
endif()
endmacro()
......@@ -80,13 +103,17 @@ macro(pico_simple_hardware_headers_only_target NAME)
# 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)
add_library(hardware_${NAME}_headers INTERFACE)
target_include_directories(hardware_${NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(hardware_${NAME} INTERFACE pico_base_headers)
# a headers only target should still have an explicit _headers library for consistency
target_include_directories(hardware_${NAME}_headers INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(hardware_${NAME}_headers INTERFACE pico_base_headers)
if (NOT PICO_NO_HARDWARE)
target_link_libraries(hardware_${NAME} INTERFACE hardware_structs)
target_link_libraries(hardware_${NAME}_headers INTERFACE hardware_structs)
endif()
add_library(hardware_${NAME} INTERFACE)
target_link_libraries(hardware_${NAME} INTERFACE hardware_${NAME}_headers)
endif()
endmacro()
......@@ -104,7 +131,7 @@ macro(pico_simple_hardware_impl_target NAME)
${CMAKE_CURRENT_LIST_DIR}/${NAME}.c
)
target_link_libraries(hardware_${NAME} INTERFACE hardware_${NAME}_headers pico_platform)
target_link_libraries(hardware_${NAME} INTERFACE hardware_${NAME}_headers hardware_claim pico_platform)
endif()
endmacro()
......
if (NOT TARGET pico_stdlib_headers)
add_library(pico_stdlib_headers INTERFACE)
target_include_directories(pico_stdlib_headers INTERFACE include)
target_link_libraries(pico_stdlib_headers INTERFACE
hardware_gpio
hardware_uart
hardware_divider
pico_time
pico_util
)
# dependencies handled in implementation CMakeLists.txt
endif()
\ No newline at end of file
if (NOT TARGET pico_sync_headers)
add_library(pico_sync_headers INTERFACE)
target_include_directories(pico_sync_headers INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(pico_sync_headers INTERFACE hardware_sync pico_time)
target_link_libraries(pico_sync_headers INTERFACE
hardware_sync_headers
pico_time_headers)
endif()
if (NOT TARGET pico_sync_core)
......
if (NOT TARGET pico_time_headers)
add_library(pico_time_headers INTERFACE)
target_include_directories(pico_time_headers INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(pico_time_headers INTERFACE hardware_timer)
target_link_libraries(pico_time_headers INTERFACE hardware_timer_headers pico_sync_headers pico_util_headers)
endif()
if (NOT TARGET pico_time)
......@@ -12,5 +10,5 @@ if (NOT TARGET pico_time)
target_sources(pico_time INTERFACE
${CMAKE_CURRENT_LIST_DIR}/time.c
${CMAKE_CURRENT_LIST_DIR}/timeout_helper.c)
target_link_libraries(pico_time INTERFACE pico_time_headers pico_sync pico_util)
target_link_libraries(pico_time INTERFACE pico_time_headers hardware_timer pico_sync pico_util)
endif()
if (NOT TARGET pico_util_headers)
add_library(pico_util_headers INTERFACE)
target_include_directories(pico_util_headers INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(pico_util_headers INTERFACE pico_base_headers hardware_sync)
target_link_libraries(pico_util_headers INTERFACE pico_base_headers hardware_sync_headers)
endif()
if (NOT TARGET pico_util)
......
pico_simple_hardware_target(adc)
# additional library
target_link_libraries(hardware_adc INTERFACE hardware_resets)
\ No newline at end of file
pico_add_header_aware_library_dependency(hardware_adc hardware_gpio hardware_resets)
\ No newline at end of file
pico_simple_hardware_target(claim)
target_link_libraries(hardware_claim INTERFACE hardware_sync)
\ No newline at end of file
pico_add_header_aware_library_dependency(hardware_claim hardware_sync)
\ No newline at end of file
pico_simple_hardware_target(clocks)
target_link_libraries(hardware_clocks INTERFACE
pico_add_header_aware_library_dependency(hardware_clocks
hardware_gpio
hardware_irq
hardware_resets
......
pico_simple_hardware_target(dma)
target_link_libraries(hardware_dma INTERFACE hardware_claim)
\ No newline at end of file
pico_add_header_aware_library_dependency(hardware_dma hardware_claim)
\ No newline at end of file
pico_simple_hardware_target(flash)
target_link_libraries(hardware_flash INTERFACE pico_bootrom)
pico_add_header_aware_library_dependency(hardware_flash pico_bootrom)
pico_simple_hardware_target(gpio)
target_link_libraries(hardware_gpio INTERFACE hardware_irq)
\ No newline at end of file
pico_add_header_aware_library_dependency(hardware_gpio hardware_irq)
\ No newline at end of file
......@@ -3,4 +3,4 @@ pico_simple_hardware_target(irq)
# additional sources/libraries
target_sources(hardware_irq INTERFACE ${CMAKE_CURRENT_LIST_DIR}/irq_handler_chain.S)
target_link_libraries(hardware_irq INTERFACE pico_sync)
\ No newline at end of file
pico_add_header_aware_library_dependency(hardware_irq pico_sync)
\ No newline at end of file
pico_simple_hardware_target(pio)
# additional libraries
target_link_libraries(hardware_pio INTERFACE hardware_gpio hardware_claim)
\ No newline at end of file
pico_add_header_aware_library_dependency(hardware_pio hardware_gpio hardware_claim)
\ No newline at end of file
pico_simple_hardware_target(timer)
target_link_libraries(hardware_timer INTERFACE hardware_claim)
pico_add_header_aware_library_dependency(hardware_timer hardware_claim)
add_library(pico_bootrom INTERFACE)
add_library(pico_bootrom_headers INTERFACE)
target_include_directories(pico_bootrom_headers INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
add_library(pico_bootrom INTERFACE)
target_sources(pico_bootrom INTERFACE
${CMAKE_CURRENT_LIST_DIR}/bootrom.c
)
target_include_directories(pico_bootrom INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(pico_bootrom INTERFACE pico_base_headers)
target_link_libraries(pico_bootrom INTERFACE pico_bootrom_headers pico_base_headers)
......@@ -70,7 +70,7 @@ typedef int sys_prot_t;
#endif
#ifndef LWIP_PLATFORM_ASSERT
void panic(const char *fmt, ...);
#include "pico/platform.h"
#define LWIP_PLATFORM_ASSERT(x) panic(x)
#endif
......
if (NOT TARGET pico_multicore)
add_library(pico_multicore_headers INTERFACE)
target_include_directories(pico_multicore_headers INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
pico_add_impl_library(pico_multicore)
target_sources(pico_multicore INTERFACE
${CMAKE_CURRENT_LIST_DIR}/multicore.c)
target_include_directories(pico_multicore INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(pico_multicore INTERFACE pico_sync hardware_irq)
target_link_libraries(pico_multicore INTERFACE pico_multicore_headers)
pico_add_header_aware_library_dependency(pico_multicore pico_sync hardware_irq)
endif()
......
......@@ -10,12 +10,19 @@ if (NOT TARGET pico_stdlib)
target_sources(pico_stdlib INTERFACE
${CMAKE_CURRENT_LIST_DIR}/stdlib.c
)
target_link_libraries(pico_stdlib INTERFACE
pico_stdlib_headers
pico_add_header_aware_library_dependency(pico_stdlib
hardware_gpio
hardware_uart
hardware_divider
pico_time
pico_util
pico_platform
)
# these do not have _headers atm
target_link_libraries(pico_stdlib INTERFACE
pico_runtime
pico_stdio
pico_time
)
function(pico_enable_stdio_uart TARGET ENABLED)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment