From 185c09a95c4b29eefc0d76b964541719dab5966b Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Sun, 9 Mar 2014 12:55:02 +0100 Subject: [PATCH] Added CMake find module for udev library --- cmake/Modules/FindUDev.cmake | 52 ++++++++++++++++++++++++++++++++++ src/SFML/Window/CMakeLists.txt | 8 +++++- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 cmake/Modules/FindUDev.cmake diff --git a/cmake/Modules/FindUDev.cmake b/cmake/Modules/FindUDev.cmake new file mode 100644 index 000000000..e3c6e7087 --- /dev/null +++ b/cmake/Modules/FindUDev.cmake @@ -0,0 +1,52 @@ +# Configure libudev environment +# +# UDEV_FOUND - system has a libudev +# 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 +# +# copyright (c) 2011 Petr Vanek +# Redistribution and use of this file is allowed according to the terms of the BSD license. +# + +FIND_PATH( + UDEV_INCLUDE_DIR + libudev.h + /usr/include + /usr/local/include + ${UDEV_PATH_INCLUDES} +) + +FIND_LIBRARY( + UDEV_LIBRARIES + NAMES udev libudev + PATHS ${ADDITIONAL_LIBRARY_PATHS} + ${UDEV_PATH_LIB} +) + +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) + else (UDEV_STABLE) + set(UDEV_STABLE 1) + endif (UDEV_STABLE) + message(STATUS "libudev stable: ${UDEV_STABLE}") +ENDIF (UDEV_LIBRARIES AND UDEV_INCLUDE_DIR) + +IF (UDEV_FOUND) + MESSAGE(STATUS "Found UDev: ${UDEV_LIBRARIES}") + MESSAGE(STATUS " include: ${UDEV_INCLUDE_DIR}") +ELSE (UDEV_FOUND) + 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 (UDev_FIND_REQUIRED) +ENDIF (UDEV_FOUND) + diff --git a/src/SFML/Window/CMakeLists.txt b/src/SFML/Window/CMakeLists.txt index ff1c8e963..e7643193e 100644 --- a/src/SFML/Window/CMakeLists.txt +++ b/src/SFML/Window/CMakeLists.txt @@ -129,6 +129,12 @@ if(SFML_OS_LINUX) message(FATAL_ERROR "Xrandr library not found") endif() include_directories(${X11_INCLUDE_DIR}) + + find_package(UDev REQUIRED) + if(NOT UDEV_FOUND) + message(FATAL_ERROR "udev library not found") + endif() + include_directories(${UDEV_INCLUDE_DIR}) endif() # build the list of external libraries to link @@ -136,7 +142,7 @@ set(WINDOW_EXT_LIBS ${OPENGL_gl_LIBRARY}) if(SFML_OS_WINDOWS) set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} winmm gdi32) elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD) - set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} ${X11_X11_LIB} ${X11_Xrandr_LIB} udev) + set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} ${X11_X11_LIB} ${X11_Xrandr_LIB} ${UDEV_LIBRARIES}) if(SFML_OS_FREEBSD) set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} usbhid) endif()