diff options
author | Maxime Schmitt <maxime.schmitt91@gmail.com> | 2022-10-09 18:40:25 +0200 |
---|---|---|
committer | Maxime Schmitt <maxime.schmitt91@gmail.com> | 2022-10-09 18:40:25 +0200 |
commit | 8cd2ee08926860a64f67066b7975685b4fa39a11 (patch) | |
tree | df8a8e70afcca9011ce3ff3a65e043d565b1b294 /cmake | |
parent | 294d8cfabba223e2aa0c0faecbfa50953cd729d8 (diff) |
Udev/sd-device wrapper
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/modules/FindSystemd.cmake | 42 | ||||
-rw-r--r-- | cmake/modules/FindUDev.cmake | 64 |
2 files changed, 75 insertions, 31 deletions
diff --git a/cmake/modules/FindSystemd.cmake b/cmake/modules/FindSystemd.cmake new file mode 100644 index 0000000..1459f88 --- /dev/null +++ b/cmake/modules/FindSystemd.cmake @@ -0,0 +1,42 @@ +# +# - Find systemd libraries +# +# SYSTEMD_INCLUDE_DIRS - where to find systemd/sd-journal.h, etc. +# SYSTEMD_LIBRARIES - List of libraries when using libsystemd. +# SYSTEMD_FOUND - True if libsystemd is found. +# A "systemd" target is created when found + +pkg_search_module(PC_SYSTEMD QUIET libsystemd) + +find_path(SYSTEMD_INCLUDE_DIR + NAMES + systemd/sd-device.h + HINTS + ${PC_SYSTEMD_INCLUDE_DIRS} +) + +find_library(SYSTEMD_LIBRARY + NAMES + systemd + HINTS + ${PC_SYSTEMD_LIBRARY_DIRS} +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Systemd + REQUIRED_VARS SYSTEMD_LIBRARY SYSTEMD_INCLUDE_DIR + VERSION_VAR PC_SYSTEMD_VERSION) + +if(SYSTEMD_FOUND) + set(SYSTEMD_LIBRARIES ${SYSTEMD_LIBRARY}) + set(SYSTEMD_INCLUDE_DIRS ${SYSTEMD_INCLUDE_DIR}) + + add_library(systemd INTERFACE IMPORTED GLOBAL) + target_include_directories(systemd INTERFACE ${SYSTEMD_INCLUDE_DIRS}) + target_link_libraries(systemd INTERFACE ${SYSTEMD_LIBRARIES}) +else() + set(SYSTEMD_LIBRARIES) + set(SYSTEMD_INCLUDE_DIRS) +endif() + +mark_as_advanced(SYSTEMD_LIBRARIES SYSTEMD_INCLUDE_DIRS)
\ No newline at end of file diff --git a/cmake/modules/FindUDev.cmake b/cmake/modules/FindUDev.cmake index 5bf2d4a..ddfdfc7 100644 --- a/cmake/modules/FindUDev.cmake +++ b/cmake/modules/FindUDev.cmake @@ -4,50 +4,52 @@ # UDEV_INCLUDE_DIR - where to find header files # UDEV_LIBRARIES - the libraries to link against udev # UDEV_STABLE - it's true when is the version greater or equals to 143 - version when the libudev was stabilized in its API +# An "udev" target is created when found # +# Adapted from a version of Petr Vanek # copyright (c) 2011 Petr Vanek <petr@scribus.info> +# copyright (c) 2022 Maxime Schmitt <maxime.schmitt91@gmail.com> +# # Redistribution and use of this file is allowed according to the terms of the BSD license. # -find_path( - UDEV_INCLUDE_DIR +pkg_search_module(PC_UDEV QUIET libudev) + +find_path(UDEV_INCLUDE_DIR + NAMES libudev.h - /usr/include - /usr/local/include - ${UDEV_PATH_INCLUDES} + HINTS + ${PC_UDEV_INCLUDE_DIRS} ) -find_library( - UDEV_LIBRARIES - NAMES udev libudev - PATHS ${ADDITIONAL_LIBRARY_PATHS} - ${UDEV_PATH_LIB} +find_library(UDEV_LIBRARY + NAMES udev + HINTS + ${PC_UDEV_LIBRARY_DIRS} ) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(UDev + REQUIRED_VARS UDEV_LIBRARY UDEV_INCLUDE_DIR + VERSION_VAR PC_UDEV_VERSION) -if(UDEV_LIBRARIES AND UDEV_INCLUDE_DIR) - set(UDEV_FOUND "YES") - execute_process(COMMAND pkg-config --atleast-version=143 libudev RESULT_VARIABLE UDEV_STABLE) - # retvale is 0 of the condition is "true" so we need to negate the value... - if(UDEV_STABLE) - set(UDEV_STABLE 0) +if(UDEV_FOUND) + if(PC_UDEV_VERSION GREATER_EQUAL "143") + set(UDEV_STABLE TRUE) else() - set(UDEV_STABLE 1) + set(UDEV_STABLE FALSE) endif() - message(STATUS "libudev stable: ${UDEV_STABLE}") -endif() -if(UDEV_FOUND) - message(STATUS "Found UDev: ${UDEV_LIBRARIES}") - message(STATUS " include: ${UDEV_INCLUDE_DIR}") + set(UDEV_LIBRARIES ${UDEV_LIBRARY}) + set(UDEV_INCLUDE_DIRS ${UDEV_INCLUDE_DIR}) + + message(STATUS "Libudev stable: ${UDEV_STABLE}") + + add_library(udev INTERFACE IMPORTED GLOBAL) + target_include_directories(udev INTERFACE ${UDEV_INCLUDE_DIRS}) + target_link_libraries(udev INTERFACE ${UDEV_LIBRARIES}) else() - message(STATUS "UDev not found.") - message(STATUS "UDev: You can specify includes: -DUDEV_PATH_INCLUDES=/opt/udev/include") - message(STATUS " currently found includes: ${UDEV_INCLUDE_DIR}") - message(STATUS "UDev: You can specify libs: -DUDEV_PATH_LIB=/opt/udev/lib") - message(STATUS " currently found libs: ${UDEV_LIBRARIES}") - if(UDev_FIND_REQUIRED) - message(FATAL_ERROR "Could not find UDev library") - endif() + set(UDEV_LIBRARIES) + set(UDEV_INCLUDE_DIRS) endif() -mark_as_advanced(UDEV_INCLUDE_DIR UDEV_LIBRARIES)
\ No newline at end of file +mark_as_advanced(UDEV_LIBRARIES UDEV_INCLUDE_DIRS)
\ No newline at end of file |