From 20c8621f0bf867672eae827bf381dc64779bd79b Mon Sep 17 00:00:00 2001 From: 2bndy5 <2bndy5@gmail.com> Date: Sat, 22 Jan 2022 17:32:49 -0800 Subject: [PATCH] conditionally build examples with pigpio --- examples_RPi/CMakeLists.txt | 10 ++++++++-- examples_RPi/Makefile | 11 ++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/examples_RPi/CMakeLists.txt b/examples_RPi/CMakeLists.txt index cbf1ea6d..80ae0c16 100644 --- a/examples_RPi/CMakeLists.txt +++ b/examples_RPi/CMakeLists.txt @@ -19,10 +19,16 @@ message(STATUS "using RF24 library: ${RF24}") find_library(RF24Network rf24network REQUIRED) message(STATUS "using RF24Network library: ${RF24Network}") +find_library(LibPIGPIO pigpio) + foreach(example ${EXAMPLES_LIST}) # make a target add_executable(${example} ${example}.cpp) - # link the RF24 lib to the target. Notice we specify pthread as a linked lib here - target_link_libraries(${example} PUBLIC ${RF24} pthread ${RF24Network}) + if ("${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND") + target_link_libraries(${example} PUBLIC ${RF24} pthread ${RF24Network}) + else() + message(STATUS "linking to ${LibPIGPIO} for interrupt support") + target_link_libraries(${example} PUBLIC ${RF24} pthread ${RF24Network} ${LibPIGPIO}) + endif() endforeach() diff --git a/examples_RPi/Makefile b/examples_RPi/Makefile index 0b77c460..43522374 100644 --- a/examples_RPi/Makefile +++ b/examples_RPi/Makefile @@ -25,11 +25,20 @@ ifneq "${RPI}" "1" RPI=$(shell cat /proc/cpuinfo | grep Hardware | grep -c BCM2709) endif +pigpio_detected=0 +ifeq ($(wildcard "/usr/lib/libpigpio.so")) +pigpio_detected=1 +endif + ifeq "$(RPI)" "1" # The recommended compiler flags for the Raspberry Pi CCFLAGS=-Ofast -mfpu=vfp -mfloat-abi=hard -march=$(ARCH) -mtune=arm1176jzf-s -std=c++0x +ifeq "$(pigpio_detected)" "1" +CCFLAGS=$(CCFLAGS) -lpigpio +endif +else +CCFLAGS=$(CCFLAGS) -DRF24_NO_INTERRUPT endif - # define all programs PROGRAMS = rx-test helloworld_rx helloworld_tx