diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9d2944805e..21afd66ad8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -337,6 +337,7 @@ check_include_file("linux/fb.h" HAVE_LINUX_FB_H)
add_feature_info("linux/fb.h"
HAVE_LINUX_FB_H
"Required for the fbdev backend")
+check_include_file("sys/sysmacros.h" HAVE_SYS_SYSMACROS_H)
########### global ###############
set(kwin_effects_dbus_xml ${CMAKE_CURRENT_SOURCE_DIR}/org.kde.kwin.Effects.xml)
diff --git a/config-kwin.h.cmake b/config-kwin.h.cmake
index dcdf80c833..7b04cb79b9 100644
--- a/config-kwin.h.cmake
+++ b/config-kwin.h.cmake
@@ -21,6 +21,7 @@
#cmakedefine01 HAVE_PR_SET_PDEATHSIG
#cmakedefine01 HAVE_SYS_PROCCTL_H
#cmakedefine01 HAVE_PROC_TRACE_CTL
+#cmakedefine01 HAVE_SYS_SYSMACROS_H
#cmakedefine01 HAVE_BREEZE_DECO
#cmakedefine01 HAVE_UDEV
#if HAVE_BREEZE_DECO
diff --git a/logind.cpp b/logind.cpp
index 8a92ae02d1..4a86d77e03 100644
--- a/logind.cpp
+++ b/logind.cpp
@@ -29,7 +29,10 @@ along with this program. If not, see .
#include
#include
+#include
+#if HAVE_SYS_SYSMACROS_H
#include
+#endif
#ifndef major
#include
#endif