2021-01-20 16:44:27 +00:00
|
|
|
if (NOT TARGET pico_printf)
|
|
|
|
# library to be depended on - we make this depend on particular implementations using per target generator expressions
|
2021-05-04 13:00:17 +00:00
|
|
|
pico_add_impl_library(pico_printf)
|
2021-01-20 16:44:27 +00:00
|
|
|
|
|
|
|
# no custom implementation; falls thru to compiler
|
2021-05-04 13:00:17 +00:00
|
|
|
pico_add_impl_library(pico_printf_compiler)
|
2021-01-20 16:44:27 +00:00
|
|
|
|
|
|
|
add_library(pico_printf_headers INTERFACE)
|
|
|
|
target_include_directories(pico_printf_headers INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
|
|
|
|
|
|
|
|
# add alias "default" which is just pico.
|
|
|
|
add_library(pico_printf_default INTERFACE)
|
|
|
|
target_link_libraries(pico_printf_default INTERFACE pico_printf_pico)
|
|
|
|
|
|
|
|
set(PICO_DEFAULT_PRINTF_IMPL pico_printf_default)
|
|
|
|
|
|
|
|
target_link_libraries(pico_printf INTERFACE
|
|
|
|
$<IF:$<BOOL:$<TARGET_PROPERTY:PICO_TARGET_PRINTF_IMPL>>,$<TARGET_PROPERTY:PICO_TARGET_PRINTF_IMPL>,${PICO_DEFAULT_PRINTF_IMPL}>)
|
|
|
|
|
2021-05-04 13:00:17 +00:00
|
|
|
pico_add_impl_library(pico_printf_pico)
|
2021-01-20 16:44:27 +00:00
|
|
|
target_sources(pico_printf_pico INTERFACE
|
|
|
|
${CMAKE_CURRENT_LIST_DIR}/printf.c
|
|
|
|
)
|
|
|
|
|
|
|
|
target_link_libraries(pico_printf_pico INTERFACE pico_printf_headers)
|
|
|
|
|
2021-05-04 13:00:17 +00:00
|
|
|
pico_add_impl_library(pico_printf_none)
|
2021-01-20 16:44:27 +00:00
|
|
|
target_sources(pico_printf_none INTERFACE
|
|
|
|
${CMAKE_CURRENT_LIST_DIR}/printf_none.S
|
|
|
|
)
|
|
|
|
|
|
|
|
target_link_libraries(pico_printf_none INTERFACE pico_printf_headers)
|
|
|
|
|
|
|
|
function(wrap_printf_functions TARGET)
|
|
|
|
# note that printf and vprintf are in pico_stdio so we can provide thread safety
|
|
|
|
pico_wrap_function(${TARGET} sprintf)
|
|
|
|
pico_wrap_function(${TARGET} snprintf)
|
|
|
|
pico_wrap_function(${TARGET} vsnprintf)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
wrap_printf_functions(pico_printf_pico)
|
|
|
|
wrap_printf_functions(pico_printf_none)
|
|
|
|
|
|
|
|
macro(pico_set_printf_implementation TARGET IMPL)
|
|
|
|
get_target_property(target_type ${TARGET} TYPE)
|
|
|
|
if ("EXECUTABLE" STREQUAL "${target_type}")
|
|
|
|
set_target_properties(${TARGET} PROPERTIES PICO_TARGET_PRINTF_IMPL "pico_printf_${IMPL}")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "printf implementation must be set on executable not library")
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
endif()
|