qt-build-system.scm 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014 Federico Beffa <beffa@fbengineering.ch>
  3. ;;; Copyright © 2014, 2015, 2021 Ludovic Courtès <ludo@gnu.org>
  4. ;;; Copyright © 2018 Mark H Weaver <mhw@netris.org>
  5. ;;; Copyright © 2019, 2020 Hartmut Goebel <h.goebel@crazy-compilers.com>
  6. ;;;
  7. ;;; This file is part of GNU Guix.
  8. ;;;
  9. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  10. ;;; under the terms of the GNU General Public License as published by
  11. ;;; the Free Software Foundation; either version 3 of the License, or (at
  12. ;;; your option) any later version.
  13. ;;;
  14. ;;; GNU Guix is distributed in the hope that it will be useful, but
  15. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;;; GNU General Public License for more details.
  18. ;;;
  19. ;;; You should have received a copy of the GNU General Public License
  20. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  21. (define-module (guix build qt-build-system)
  22. #:use-module ((guix build cmake-build-system) #:prefix cmake:)
  23. #:use-module (guix build utils)
  24. #:use-module (ice-9 match)
  25. #:use-module (ice-9 regex)
  26. #:use-module (ice-9 ftw)
  27. #:use-module (srfi srfi-1)
  28. #:use-module (srfi srfi-26)
  29. #:export (%standard-phases
  30. qt-build))
  31. ;; Commentary:
  32. ;;
  33. ;; Builder-side code of the standard Qt build procedure.
  34. ;;
  35. ;; Code:
  36. (define* (check-setup #:rest args)
  37. ;; Make Qt render "offscreen". In many cases this allows to run tests
  38. ;; without starting a X11 server.
  39. (setenv "QT_QPA_PLATFORM" "offscreen")
  40. ;; Qt/KDE tests often need dbus (`dbus-launch …`) which is not fully
  41. ;; set-up the the build container.
  42. (setenv "DBUS_FATAL_WARNINGS" "0")
  43. ;; Set here to ease overwriting 'check (even if set there, too)
  44. (setenv "CTEST_OUTPUT_ON_FAILURE" "1")
  45. #t)
  46. (define (variables-for-wrapping base-directories)
  47. (define (collect-sub-dirs base-directories file-type subdirectory
  48. selectors)
  49. ;; Append SUBDIRECTORY and each of BASE-DIRECTORIES, and return the subset
  50. ;; that exists and has at least one of the SELECTORS sub-directories,
  51. ;; unless SELECTORS is the empty list. FILE-TYPE should by 'directory or
  52. ;; 'regular file. For the later, it allows searching for plain files
  53. ;; rather than directories.
  54. (define exists? (match file-type
  55. ('directory directory-exists?)
  56. ('regular file-exists?)))
  57. (filter-map (lambda (dir)
  58. (let ((directory (string-append dir subdirectory)))
  59. (and (exists? directory)
  60. (or (null? selectors)
  61. (any (lambda (selector)
  62. (exists?
  63. (string-append directory selector)))
  64. selectors))
  65. directory)))
  66. base-directories))
  67. (filter-map
  68. (match-lambda
  69. ((variable file-type directory selectors ...)
  70. (match (collect-sub-dirs base-directories file-type directory
  71. selectors)
  72. (()
  73. #f)
  74. (directories
  75. `(,variable = ,directories)))))
  76. ;; These shall match the search-path-specification for Qt and KDE
  77. ;; libraries.
  78. (list '("XDG_DATA_DIRS" directory "/share"
  79. ;; These are "selectors": consider /share if and only if at least
  80. ;; one of these sub-directories exist. This avoids adding
  81. ;; irrelevant packages to XDG_DATA_DIRS just because they have a
  82. ;; /share sub-directory.
  83. "/glib-2.0/schemas" "/sounds" "/themes"
  84. "/cursors" "/wallpapers" "/icons" "/mime")
  85. '("XDG_CONFIG_DIRS" directory "/etc/xdg")
  86. '("QT_PLUGIN_PATH" directory "/lib/qt5/plugins")
  87. '("QML2_IMPORT_PATH" directory "/lib/qt5/qml")
  88. '("QTWEBENGINEPROCESS_PATH" regular
  89. "/lib/qt5/libexec/QtWebEngineProcess"))))
  90. (define* (wrap-all-programs #:key inputs outputs
  91. (qt-wrap-excluded-outputs '())
  92. #:allow-other-keys)
  93. "Implement phase \"qt-wrap\": look for GSettings schemas and
  94. gtk+-v.0 libraries and create wrappers with suitably set environment variables
  95. if found.
  96. Wrapping is not applied to outputs whose name is listed in
  97. QT-WRAP-EXCLUDED-OUTPUTS. This is useful when an output is known not
  98. to contain any Qt binaries, and where wrapping would gratuitously
  99. add a dependency of that output on Qt."
  100. (define (find-files-to-wrap directory)
  101. (append-map
  102. (lambda (dir)
  103. (if (directory-exists? dir) (find-files dir ".*") (list)))
  104. (list (string-append directory "/bin")
  105. (string-append directory "/sbin")
  106. (string-append directory "/libexec")
  107. (string-append directory "/lib/libexec"))))
  108. (define input-directories
  109. ;; FIXME: Filter out unwanted inputs, e.g. cmake
  110. (match inputs
  111. (((_ . dir) ...)
  112. dir)))
  113. (define handle-output
  114. (match-lambda
  115. ((output . directory)
  116. (unless (member output qt-wrap-excluded-outputs)
  117. (let ((bin-list (find-files-to-wrap directory))
  118. (vars-to-wrap (variables-for-wrapping
  119. (append (list directory)
  120. input-directories))))
  121. (when (not (null? vars-to-wrap))
  122. (for-each (cut apply wrap-program <> inputs vars-to-wrap)
  123. bin-list)))))))
  124. (for-each handle-output outputs)
  125. #t)
  126. (define %standard-phases
  127. (modify-phases cmake:%standard-phases
  128. (add-before 'check 'check-setup check-setup)
  129. (add-after 'install 'qt-wrap wrap-all-programs)))
  130. (define* (qt-build #:key inputs (phases %standard-phases)
  131. #:allow-other-keys #:rest args)
  132. "Build the given package, applying all of PHASES in order."
  133. (apply cmake:cmake-build #:inputs inputs #:phases phases args))