Skip to content

Commit ebe3cf2

Browse files
committed
Issue 590 - Determine any libgpiod version and add to compile command line.
1 parent 4535fdb commit ebe3cf2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,30 @@ endif()
324324
find_package(gpiod)
325325
if(GPIOD_FOUND)
326326
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_GPIOD")
327+
328+
# Version 2 uses a completely different API.
329+
# Try to determine version and put it on compile command line.
330+
331+
# Require pkg-config support
332+
find_package(PkgConfig REQUIRED)
333+
# Probe for libgpiod
334+
pkg_check_modules(LIBGPIOD REQUIRED libgpiod)
335+
# Abort if not found
336+
if(NOT LIBGPIOD_FOUND)
337+
message(FATAL_ERROR "libgpiod not found via pkg-config")
338+
endif()
339+
340+
# LIBGPIOD_VERSION holds the full x.y.z string
341+
342+
# Now split out major and minor versions into separate integers
343+
string(REPLACE "." ";" VLIST ${LIBGPIOD_VERSION})
344+
list(GET VLIST 0 LIBGPIOD_VERSION_MAJOR)
345+
list(GET VLIST 1 LIBGPIOD_VERSION_MINOR)
346+
message(STATUS "libgpiod version ${LIBGPIOD_VERSION} major=${LIBGPIOD_VERSION_MAJOR} minor=${LIBGPIOD_VERSION_MINOR}")
347+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLIBGPIOD_VERSION=${LIBGPIOD_VERSION}")
348+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLIBGPIOD_VERSION_MAJOR=${LIBGPIOD_VERSION_MAJOR}")
349+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLIBGPIOD_VERSION_MINOR=${LIBGPIOD_VERSION_MINOR}")
350+
327351
else()
328352
set(GPIOD_INCLUDE_DIRS "")
329353
set(GPIOD_LIBRARIES "")

0 commit comments

Comments
 (0)