diff --git a/CMakeLists.txt b/CMakeLists.txt index e67b1f4b9d8..a9b20744aa2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1370,27 +1370,59 @@ if(UNIX AND NOT APPLE) ) option(INSTALL_USER_UDEV_RULES "Install user udev rule file for USB HID and Bulk controllers" ON) - if (INSTALL_USER_UDEV_RULES) - install( - FILES - "${CMAKE_CURRENT_SOURCE_DIR}/res/linux/mixxx-usb-uaccess.rules" - DESTINATION - "${MIXXX_INSTALL_DATADIR}/udev/rules.d" - ) - install(CODE " - message(STATUS \"Important Note: Installation of udev rules\n\" - \"The udev rule file for USB HID and Bulk controller permissions will be\n\" - \"installed to:\n\" - \" ${CMAKE_INSTALL_PREFIX}/${MIXXX_INSTALL_DATADIR}/udev/rules.d.\n\" - \"If you are installing Mixxx from source for your own use, copy\n\" - \"mixxx-usb-uaccess.rules to /etc/udev/rules.d/ and run:\n\" - \" udevadm control --reload-rules && udevadm trigger\n\" - \"as root to load the rules.\n\" - \"If you are building a package for a distribution, the correct directory for\n\" - \"system rules is either /lib/udev/rules.d (e.g. Debian, Fedora) or\n\" - \"/usr/lib/udev/rules.d (e.g. Arch Linux) with an appropriate priority prefix.\n\" - \"Adjust your package script accordingly and set -DINSTALL_USER_UDEV_RULES=OFF\") - ") + if(INSTALL_USER_UDEV_RULES) + set(MIXXX_UDEVDIR "${MIXXX_INSTALL_DATADIR}/udev") + if (CMAKE_INSTALL_PREFIX STREQUAL "/usr" OR CMAKE_INSTALL_PREFIX STREQUAL "/" ) + # /usr and / install prefixes at treated by cmake GNUInstallDirs as + # synonym for "system location". In this case we can look up the correct udevdir + # using pkg-config. + # See: https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html#special-cases + find_package(PkgConfig) + if (PKG_CONFIG_FOUND) + pkg_check_modules( PKGCONFIG_UDEV udev) + if (PKGCONFIG_UDEV_FOUND) + execute_process( + COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=udevdir udev + OUTPUT_VARIABLE PKGCONFIG_UDEVDIR + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(PKGCONFIG_UDEVDIR) + file(TO_CMAKE_PATH "${PKGCONFIG_UDEVDIR}" MIXXX_UDEVDIR) + endif() + endif() + endif() + endif() + if (MIXXX_UDEVDIR STREQUAL "${MIXXX_INSTALL_DATADIR}/udev") + install( + FILES + "${CMAKE_CURRENT_SOURCE_DIR}/res/linux/mixxx-usb-uaccess.rules" + DESTINATION + "${MIXXX_UDEVDIR}/rules.d" + ) + install(CODE " + message(STATUS \"Important Note: Installation of udev rules\n\" + \"The udev rule file for USB HID and Bulk controller permissions have been\n\" + \"installed to:\n\" + \" ${MIXXX_UDEVDIR}/rules.d.\n\" + \"If you are installing Mixxx from source for your own use, copy\n\" + \"mixxx-usb-uaccess.rules to /etc/udev/rules.d/ and run:\n\" + \" udevadm control --reload-rules && udevadm trigger\n\" + \"as root to load the rules.\n\" + \"If you are building a package for a distribution, the correct directory for\n\" + \"system rules is either /lib/udev/rules.d (e.g. Debian, Fedora) or\n\" + \"/usr/lib/udev/rules.d (e.g. Arch Linux) with an appropriate priority prefix.\n\" + \"Adjust your package script accordingly and set -DINSTALL_USER_UDEV_RULES=OFF\") + ") + else() + install( + FILES + "${CMAKE_CURRENT_SOURCE_DIR}/res/linux/mixxx-usb-uaccess.rules" + DESTINATION + "${MIXXX_UDEVDIR}/rules.d" + RENAME + "69-mixxx-usb-uaccess.rules" + ) + endif() endif() endif()