From 44f0603702347500b9d35e830a98e873f43ada96 Mon Sep 17 00:00:00 2001 From: Phil Elwell Date: Thu, 26 Nov 2026 13:02:57 +0000 Subject: [PATCH 1/4] piolib: Install a pkg-config file Generate and install libpio.pc, so that users of the library can find it with pkg-config (PKG_CHECK_MODULES in autotools, pkg_check_modules in CMake) rather than hard-coding the piolib include directory. The headers are installed in /piolib and include each other by relative name, so Cflags adds that directory to the search path. The version defaults to 0; packagers can set PIOLIB_VERSION. Co-Authored-By: Claude Opus 5.5 --- piolib/CMakeLists.txt | 7 +++++++ piolib/libpio.pc.in | 11 +++++++++++ 2 files changed, 18 insertions(+) create mode 100644 piolib/libpio.pc.in diff --git a/piolib/CMakeLists.txt b/piolib/CMakeLists.txt index 2b437b9..62901e9 100644 --- a/piolib/CMakeLists.txt +++ b/piolib/CMakeLists.txt @@ -35,6 +35,13 @@ set(INCLUDE_FILES ) install(TARGETS pio ARCHIVE 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) diff --git a/piolib/libpio.pc.in b/piolib/libpio.pc.in new file mode 100644 index 0000000..b4a9ae4 --- /dev/null +++ b/piolib/libpio.pc.in @@ -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 From 3a3e1f8590607251e4625a5ae15cc80818b78406 Mon Sep 17 00:00:00 2001 From: Phil Elwell Date: Thu, 26 Nov 2026 13:44:10 +0000 Subject: [PATCH 2/4] piolib: Include GNUInstallDirs after project() GNUInstallDirs needs to know the target architecture to choose the library directory, which it only does once project() has enabled the languages. Included before project(), as it was in both piolib and its examples, a standalone build warned "Unable to determine default CMAKE_INSTALL_LIBDIR directory because no target architecture is known" and installed the library in /lib even for a prefix of /usr, rather than in the Debian multiarch directory (lib/aarch64-linux-gnu) where the packaged libpio lives. Builds from the top-level utils directory were unaffected, as project(utils) comes first. Co-Authored-By: Claude Opus 5.5 --- piolib/CMakeLists.txt | 8 +++++--- piolib/examples/CMakeLists.txt | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/piolib/CMakeLists.txt b/piolib/CMakeLists.txt index 62901e9..e4b7f3b 100644 --- a/piolib/CMakeLists.txt +++ b/piolib/CMakeLists.txt @@ -1,12 +1,14 @@ 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) -#set project name -project(piolib) - add_compile_definitions(LIBRARY_BUILD=1) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") diff --git a/piolib/examples/CMakeLists.txt b/piolib/examples/CMakeLists.txt index 7e40e9c..80edb9c 100644 --- a/piolib/examples/CMakeLists.txt +++ b/piolib/examples/CMakeLists.txt @@ -1,10 +1,10 @@ cmake_minimum_required(VERSION 3.10...3.27) -include(GNUInstallDirs) - #set project name project(examples) +include(GNUInstallDirs) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") option(ENABLE_WERROR "Treat compiler warnings as errors" OFF) if(ENABLE_WERROR) From b10928a3ca62909fc662e77e443dc642edda9919 Mon Sep 17 00:00:00 2001 From: Phil Elwell Date: Thu, 26 Nov 2026 13:44:29 +0000 Subject: [PATCH 3/4] piolib: Put the shared library in the piolib install component The install rule for the pio target only had an ARCHIVE clause, so only the static library was assigned to the "piolib" component; a shared libpio.so fell into the default component, and was missed by "cmake --install --component piolib". Give the LIBRARY artefacts the same destination and component. Co-Authored-By: Claude Opus 5.5 --- piolib/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/piolib/CMakeLists.txt b/piolib/CMakeLists.txt index e4b7f3b..5f9fc58 100644 --- a/piolib/CMakeLists.txt +++ b/piolib/CMakeLists.txt @@ -36,7 +36,9 @@ 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") From a5b51e544c07b4eb327f4d8149661d8ef3f8e926 Mon Sep 17 00:00:00 2001 From: Phil Elwell Date: Thu, 26 Nov 2026 13:44:39 +0000 Subject: [PATCH 4/4] piolib: Only install the examples on request Installing piolib also installed all of its example programs (apitest, blink, mirror, piotest, ...) into /bin, which for the default /usr/local prefix puts them on everyone's PATH, where they linger after reverting to the packaged libpio. None of them is shipped in a package. Keep building the examples, but only install them if the new option PIOLIB_INSTALL_EXAMPLES is ON (default OFF), in an "examples" install component. The README describes the option, and how to try a build without displacing the packaged library. Co-Authored-By: Claude Opus 5.5 --- piolib/CMakeLists.txt | 4 ++++ piolib/README.md | 2 ++ piolib/examples/CMakeLists.txt | 40 +++++++++++++++++++--------------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/piolib/CMakeLists.txt b/piolib/CMakeLists.txt index 5f9fc58..a8ae476 100644 --- a/piolib/CMakeLists.txt +++ b/piolib/CMakeLists.txt @@ -7,6 +7,10 @@ project(piolib) # multiarch library directory) is known include(GNUInstallDirs) +# 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) + add_subdirectory(examples) add_compile_definitions(LIBRARY_BUILD=1) diff --git a/piolib/README.md b/piolib/README.md index ddcff6e..6419630 100644 --- a/piolib/README.md +++ b/piolib/README.md @@ -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. diff --git a/piolib/examples/CMakeLists.txt b/piolib/examples/CMakeLists.txt index 80edb9c..db72174 100644 --- a/piolib/examples/CMakeLists.txt +++ b/piolib/examples/CMakeLists.txt @@ -5,6 +5,12 @@ 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) @@ -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)