Skip to content

Commit

Permalink
[CMake] default to SPIDEV driver (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Jul 7, 2024
1 parent b74dd13 commit 2bf2412
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 36 deletions.
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,6 @@ if(DEFINED SLOW_ADDR_POLL_RESPONSE)
message(STATUS "SLOW_ADDR_POLL_RESPONSE set to ${SLOW_ADDR_POLL_RESPONSE}")
target_compile_definitions(${LibTargetName} PUBLIC SLOW_ADDR_POLL_RESPONSE=${SLOW_ADDR_POLL_RESPONSE})
endif()
# conditionally disable interruot support (a pigpio specific feature)
if("${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND" OR DEFINED RF24_NO_INTERRUPT)
message(STATUS "Disabling IRQ pin support")
target_compile_definitions(${LibTargetName} PUBLIC RF24_NO_INTERRUPT)
endif()

###########################
# target install rules for the RF24Network lib
Expand Down
42 changes: 22 additions & 20 deletions cmake/AutoConfig_RF24_DRIVER.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,33 @@ else()
endif()


if(${RF24_DRIVER} STREQUAL "UNKNOWN") # invokes automatic configuration
if("${SOC}" STREQUAL "BCM2708" OR "${SOC}" STREQUAL "BCM2709" OR "${SOC}" STREQUAL "BCM2835")
set(RF24_DRIVER RPi CACHE STRING "using folder /utility/RPi" FORCE)
elseif(NOT "${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND")
message(STATUS "Found pigpio library: ${LibPIGPIO}")
set(RF24_DRIVER pigpio CACHE STRING "using folder /utility/pigpio" FORCE)
elseif(NOT "${LibWiringPi}" STREQUAL "LibWiringPi-NOTFOUND")
message(STATUS "Found wiringPi library: ${LibWiringPi}")
set(RF24_DRIVER wiringPi CACHE STRING "using folder /utility/wiringPi" FORCE)
elseif(NOT "${LibLittleWire}" STREQUAL "LibLittleWire-NOTFOUND")
message(STATUS "Found LittleWire library: ${LibLittleWire}")
set(RF24_DRIVER LittleWire CACHE STRING "using folder /utility/LittleWire" FORCE)
elseif(NOT "${LibMRAA}" STREQUAL "LibMRAA-NOTFOUND")
message(STATUS "Found MRAA library: ${LibMRAA}")
set(RF24_DRIVER MRAA CACHE STRING "using folder /utility/MRAA" FORCE)
elseif(SPIDEV_EXISTS) # should be a non-empty string if SPI is enabled
message(STATUS "detected that SPIDEV is enabled: ${SPIDEV_EXISTS}")
set(RF24_DRIVER SPIDEV CACHE STRING "using folder /utility/SPIDEV" FORCE)
endif()
endif()
# if(${RF24_DRIVER} STREQUAL "UNKNOWN") # invokes automatic configuration
# if("${SOC}" STREQUAL "BCM2708" OR "${SOC}" STREQUAL "BCM2709" OR "${SOC}" STREQUAL "BCM2835")
# set(RF24_DRIVER RPi CACHE STRING "using folder /utility/RPi" FORCE)
# elseif(NOT "${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND")
# message(STATUS "Found pigpio library: ${LibPIGPIO}")
# set(RF24_DRIVER pigpio CACHE STRING "using folder /utility/pigpio" FORCE)
# elseif(NOT "${LibWiringPi}" STREQUAL "LibWiringPi-NOTFOUND")
# message(STATUS "Found wiringPi library: ${LibWiringPi}")
# set(RF24_DRIVER wiringPi CACHE STRING "using folder /utility/wiringPi" FORCE)
# elseif(NOT "${LibLittleWire}" STREQUAL "LibLittleWire-NOTFOUND")
# message(STATUS "Found LittleWire library: ${LibLittleWire}")
# set(RF24_DRIVER LittleWire CACHE STRING "using folder /utility/LittleWire" FORCE)
# elseif(NOT "${LibMRAA}" STREQUAL "LibMRAA-NOTFOUND")
# message(STATUS "Found MRAA library: ${LibMRAA}")
# set(RF24_DRIVER MRAA CACHE STRING "using folder /utility/MRAA" FORCE)
# elseif(SPIDEV_EXISTS) # should be a non-empty string if SPI is enabled
# message(STATUS "detected that SPIDEV is enabled: ${SPIDEV_EXISTS}")
# set(RF24_DRIVER SPIDEV CACHE STRING "using folder /utility/SPIDEV" FORCE)
# endif()
# endif()

# override the auto-detect if RF24_DRIVER is defined in an env var
if(DEFINED ENV{RF24_DRIVER})
message(STATUS "RF24_DRIVER (set from env var) = $ENV{RF24_DRIVER}")
set(RF24_DRIVER $ENV{RF24_DRIVER} CACHE STRING "" FORCE)
elseif(${RF24_DRIVER} STREQUAL "UNKNOWN")
set(RF24_DRIVER SPIDEV CACHE STRING "using folder RF24/utility/SPIDEV" FORCE)
endif()

message(STATUS "Using driver: ${RF24_DRIVER}")
16 changes: 5 additions & 11 deletions examples_RPi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,18 @@ elseif("${RF24_DRIVER}" STREQUAL "wiringPi")
else()
message(FATAL "Lib ${RF24_DRIVER} not found.")
endif()
elseif(NOT "${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND" AND NOT DEFINED RF24_NO_INTERUPT)
if(NOT "${RF24_DRIVER}" STREQUAL "pigpio")
message(STATUS "linking to ${LibPIGPIO} for interrupt support")
else()
elseif("${RF24_DRIVER}" STREQUAL "pigpio")
if(NOT "${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND")
message(STATUS "linking to ${LibPIGPIO}")
list(APPEND linked_libs ${LibPIGPIO})
else()
message(FATAL "Lib ${RF24_DRIVER} not found.")
endif()
list(APPEND linked_libs ${LibPIGPIO})
else()
message(STATUS "Disabling IRQ pin support")
endif()

foreach(example ${EXAMPLES_LIST})
# make a target
add_executable(${example} ${example}.cpp)
# link the RF24 lib to the target.
target_link_libraries(${example} PUBLIC ${linked_libs})
# conditionally disable interruot support (a pigpio specific feature)
if("${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND" OR DEFINED RF24_NO_INTERRUPT)
target_compile_definitions(${example} PUBLIC RF24_NO_INTERRUPT)
endif()
endforeach()

0 comments on commit 2bf2412

Please sign in to comment.