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
23 changes: 19 additions & 4 deletions piolib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
cmake_minimum_required(VERSION 3.10...3.27)

#set project name
project(piolib)

# After project(), so that the target architecture (and hence the Debian
# multiarch library directory) is known
include(GNUInstallDirs)

add_subdirectory(examples)
# The examples are always built, but are only installed on request, so
# that a local install does not put them on everyone's PATH
option(PIOLIB_INSTALL_EXAMPLES "Install the piolib example programs" OFF)

#set project name
project(piolib)
add_subdirectory(examples)

add_compile_definitions(LIBRARY_BUILD=1)

Expand Down Expand Up @@ -34,7 +40,16 @@ set(INCLUDE_FILES
"pico/stdlib.h"
)

install(TARGETS pio ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT piolib)
install(TARGETS pio
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT piolib
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT piolib)

# pkg-config file; packagers can set PIOLIB_VERSION to the package version
set(PIOLIB_VERSION "0" CACHE STRING "Version reported by libpio.pc")
configure_file(libpio.pc.in libpio.pc @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libpio.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" COMPONENT piolib)

foreach ( file ${INCLUDE_FILES} )
get_filename_component( dir ${file} DIRECTORY )
install( FILES "include/${file}" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/piolib/${dir}" COMPONENT piolib)
Expand Down
2 changes: 2 additions & 0 deletions piolib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Install the prerequisites with `sudo apt install build-essential cmake` - you ne

1. `cmake .` (or create a build subdirectory and run `cmake ..`)
N.B. Use *cmake -DBUILD_SHARED_LIBS=1 .* to build piolib as a shared (as opposed to static) library.
The example programs are built but not installed; add *-DPIOLIB_INSTALL_EXAMPLES=ON* to install them too.
The default install prefix is /usr/local, which takes precedence over the packaged libpio; to try a build without displacing it, install to a private prefix (e.g. *-DCMAKE_INSTALL_PREFIX=$HOME/.local*) and point PKG_CONFIG_PATH and LD_LIBRARY_PATH at it.
2. `make`

If `ls -l /dev/pio0` reports that the file is not found, you may need to update your Pi 5 firmware to one with PIO support and make sure that you are running a suitably recent kernel.
Expand Down
44 changes: 25 additions & 19 deletions piolib/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
cmake_minimum_required(VERSION 3.10...3.27)

include(GNUInstallDirs)

#set project name
project(examples)

include(GNUInstallDirs)

function(install_example target)
if(PIOLIB_INSTALL_EXAMPLES)
install(TARGETS ${target} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT examples)
endif()
endfunction()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
option(ENABLE_WERROR "Treat compiler warnings as errors" OFF)
if(ENABLE_WERROR)
Expand All @@ -18,84 +24,84 @@ endif ()
add_executable(apitest apitest.c)
target_include_directories(apitest PRIVATE ../include)
target_link_libraries(apitest pio)
install(TARGETS apitest RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install_example(apitest)

add_executable(piotest piotest.c)
target_include_directories(piotest PRIVATE ../include)
target_link_libraries(piotest pio)
install(TARGETS piotest RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install_example(piotest)

add_executable(piopwm pwm.c)
target_include_directories(piopwm PRIVATE ../include)
target_link_libraries(piopwm pio)
install(TARGETS piopwm RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install_example(piopwm)

add_executable(pioseq genseq.c)
target_include_directories(pioseq PRIVATE ../include)
target_link_libraries(pioseq pio)
install(TARGETS pioseq RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install_example(pioseq)

add_executable(piows2812 ws2812.c)
target_include_directories(piows2812 PRIVATE ../include)
target_link_libraries(piows2812 pio)
install(TARGETS piows2812 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install_example(piows2812)

add_executable(dpi_csync dpi_csync.c)
target_include_directories(dpi_csync PRIVATE ../include)
target_link_libraries(dpi_csync pio)
install(TARGETS dpi_csync RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install_example(dpi_csync)

add_executable(rp1sm rp1sm.c)
target_include_directories(rp1sm PRIVATE ../include)
target_link_libraries(rp1sm pio)
install(TARGETS rp1sm RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install_example(rp1sm)

add_executable(quadenc quadrature_encoder.c)
target_include_directories(quadenc PRIVATE ../include)
target_link_libraries(quadenc pio)
install(TARGETS quadenc RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install_example(quadenc)

add_executable(txcount txcount.c)
target_include_directories(txcount PRIVATE ../include)
target_link_libraries(txcount pio)
install(TARGETS txcount RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install_example(txcount)

add_executable(blockingtest blockingtest.c)
target_include_directories(blockingtest PRIVATE ../include)
target_link_libraries(blockingtest pio pthread)
install(TARGETS blockingtest RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install_example(blockingtest)

add_executable(rxsource rxsource.c)
target_include_directories(rxsource PRIVATE ../include)
target_link_libraries(rxsource pio)
install(TARGETS rxsource RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install_example(rxsource)

add_executable(irqtest irqtest.c)
target_include_directories(irqtest PRIVATE ../include ../../pinctrl)
target_link_libraries(irqtest pio gpiolib)
install(TARGETS irqtest RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install_example(irqtest)

add_executable(irqhog irqhog.c)
target_include_directories(irqhog PRIVATE ../include)
target_link_libraries(irqhog pio)
install(TARGETS irqhog RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install_example(irqhog)

add_executable(irqtest2 irqtest2.c)
target_include_directories(irqtest2 PRIVATE ../include ../../pinctrl)
target_link_libraries(irqtest2 pio gpiolib)
install(TARGETS irqtest2 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install_example(irqtest2)

add_executable(txsink txsink.c)
target_include_directories(txsink PRIVATE ../include)
target_link_libraries(txsink pio)
install(TARGETS txsink RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install_example(txsink)

add_executable(blink blink.c)
target_include_directories(blink PRIVATE ../include)
target_link_libraries(blink pio)
install(TARGETS blink RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install_example(blink)

add_executable(mirror mirror.c)
target_include_directories(mirror PRIVATE ../include)
target_link_libraries(mirror pio)
install(TARGETS mirror RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install_example(mirror)
11 changes: 11 additions & 0 deletions piolib/libpio.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@

Name: libpio
Description: Library for accessing Raspberry Pi 5 PIO hardware
Version: @PIOLIB_VERSION@
Libs: -L${libdir} -lpio
Libs.private: -lpthread
Cflags: -I${includedir}/piolib
Loading