qt.scm 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013-2015, 2021-2022 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2013 Cyril Roelandt <tipecaml@gmail.com>
  4. ;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
  5. ;;; Copyright © 2019 Hartmut Goebel <h.goebel@crazy-compilers.com>
  6. ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
  7. ;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
  8. ;;;
  9. ;;; This file is part of GNU Guix.
  10. ;;;
  11. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  12. ;;; under the terms of the GNU General Public License as published by
  13. ;;; the Free Software Foundation; either version 3 of the License, or (at
  14. ;;; your option) any later version.
  15. ;;;
  16. ;;; GNU Guix is distributed in the hope that it will be useful, but
  17. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;;; GNU General Public License for more details.
  20. ;;;
  21. ;;; You should have received a copy of the GNU General Public License
  22. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  23. (define-module (guix build-system qt)
  24. #:use-module (guix store)
  25. #:use-module (guix utils)
  26. #:use-module (guix gexp)
  27. #:use-module (guix monads)
  28. #:use-module ((guix build qt-utils)
  29. #:select (%qt-wrap-excluded-inputs))
  30. #:use-module (guix search-paths)
  31. #:use-module (guix build-system)
  32. #:use-module (guix build-system cmake)
  33. #:use-module (guix build-system gnu)
  34. #:use-module (guix packages)
  35. #:use-module (ice-9 match)
  36. #:export (%qt-build-system-modules
  37. qt-build
  38. qt-build-system))
  39. ;; Commentary:
  40. ;;
  41. ;; This build system is an extension of the 'cmake-build-system'. It
  42. ;; accommodates the needs of Qt and KDE applications by adding a phase run
  43. ;; after the 'install' phase:
  44. ;;
  45. ;; 'qt-wrap' phase:
  46. ;;
  47. ;; This phase looks for Qt5 plugin paths, QML paths and some XDG paths as well
  48. ;; as the corresponding environment variables. If any of these is found in
  49. ;; the output or if respective environment variables are set, then all
  50. ;; programs in the output's "bin", "sbin", "libexec and "lib/libexec"
  51. ;; directories are wrapped in scripts defining the necessary environment
  52. ;; variables.
  53. ;;
  54. ;; Code:
  55. (define %qt-build-system-modules
  56. ;; Build-side modules imported and used by default.
  57. `((guix build qt-build-system)
  58. (guix build qt-utils)
  59. ,@%cmake-build-system-modules))
  60. (define (default-cmake)
  61. "Return the default CMake package."
  62. ;; Do not use `@' to avoid introducing circular dependencies.
  63. (let ((module (resolve-interface '(gnu packages cmake))))
  64. (module-ref module 'cmake-minimal)))
  65. (define (default-qtbase)
  66. "Return the default qtbase package."
  67. ;; Do not use `@' to avoid introducing circular dependencies.
  68. (let ((module (resolve-interface '(gnu packages qt))))
  69. (module-ref module 'qtbase-5)))
  70. ;; This barely is a copy from (guix build-system cmake), only adjusted to use
  71. ;; the variables defined here.
  72. (define* (lower name
  73. #:key source inputs native-inputs outputs system target
  74. (cmake (default-cmake))
  75. (qtbase (default-qtbase))
  76. #:allow-other-keys
  77. #:rest arguments)
  78. "Return a bag for NAME."
  79. (define private-keywords
  80. `(#:cmake #:inputs #:native-inputs #:outputs
  81. ,@(if target '() '(#:target))))
  82. (bag
  83. (name name)
  84. (system system)
  85. (target target)
  86. (build-inputs `(,@(if source
  87. `(("source" ,source))
  88. '())
  89. ,@`(("cmake" ,cmake))
  90. ,@`(("qtbase" ,qtbase))
  91. ,@native-inputs
  92. ,@(if target
  93. ;; Use the standard cross inputs of
  94. ;; 'gnu-build-system'.
  95. (standard-cross-packages target 'host)
  96. '())
  97. ;; Keep the standard inputs of 'gnu-build-system'.
  98. ,@(standard-packages)))
  99. (host-inputs inputs)
  100. ;; The cross-libc is really a target package, but for bootstrapping
  101. ;; reasons, we can't put it in 'host-inputs'. Namely, 'cross-gcc' is a
  102. ;; native package, so it would end up using a "native" variant of
  103. ;; 'cross-libc' (built with 'gnu-build'), whereas all the other packages
  104. ;; would use a target variant (built with 'gnu-cross-build'.)
  105. (target-inputs (if target
  106. (standard-cross-packages target 'target)
  107. '()))
  108. (outputs outputs)
  109. (build (if target qt-cross-build qt-build))
  110. (arguments (strip-keyword-arguments private-keywords arguments))))
  111. (define* (qt-build name inputs
  112. #:key
  113. (qtbase (default-qtbase))
  114. source (guile #f)
  115. (outputs '("out")) (configure-flags ''())
  116. (search-paths '())
  117. (make-flags ''())
  118. (out-of-source? #t)
  119. (build-type "RelWithDebInfo")
  120. (tests? #t)
  121. (test-target "test")
  122. (parallel-build? #t) (parallel-tests? #f)
  123. (validate-runpath? #t)
  124. (patch-shebangs? #t)
  125. (strip-binaries? #t)
  126. (strip-flags ''("--strip-debug"))
  127. (strip-directories ''("lib" "lib64" "libexec"
  128. "bin" "sbin"))
  129. (phases '%standard-phases)
  130. (qt-wrap-excluded-outputs ''())
  131. (qt-wrap-excluded-inputs %qt-wrap-excluded-inputs)
  132. (system (%current-system))
  133. (imported-modules %qt-build-system-modules)
  134. (modules '((guix build qt-build-system)
  135. (guix build utils))))
  136. "Build SOURCE using CMAKE, and with INPUTS. This assumes that SOURCE
  137. provides a 'CMakeLists.txt' file as its build system."
  138. (define builder
  139. (with-imported-modules imported-modules
  140. #~(begin
  141. (use-modules #$@(sexp->gexp modules))
  142. (qt-build #:source #+source
  143. #:system #$system
  144. #:outputs #$(outputs->gexp outputs)
  145. #:inputs #$(input-tuples->gexp inputs)
  146. #:search-paths '#$(sexp->gexp
  147. (map search-path-specification->sexp
  148. search-paths))
  149. #:phases #$(if (pair? phases)
  150. (sexp->gexp phases)
  151. phases)
  152. #:qtbase #+qtbase
  153. #:qt-wrap-excluded-outputs #$qt-wrap-excluded-outputs
  154. #:qt-wrap-excluded-inputs #$qt-wrap-excluded-inputs
  155. #:configure-flags #$configure-flags
  156. #:make-flags #$make-flags
  157. #:out-of-source? #$out-of-source?
  158. #:build-type #$build-type
  159. #:tests? #$tests?
  160. #:test-target #$test-target
  161. #:parallel-build? #$parallel-build?
  162. #:parallel-tests? #$parallel-tests?
  163. #:validate-runpath? #$validate-runpath?
  164. #:patch-shebangs? #$patch-shebangs?
  165. #:strip-binaries? #$strip-binaries?
  166. #:strip-flags #$strip-flags
  167. #:strip-directories #$strip-directories))))
  168. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  169. system #:graft? #f)))
  170. (gexp->derivation name builder
  171. #:system system
  172. #:guile-for-build guile)))
  173. ;;;
  174. ;;; Cross-compilation.
  175. ;;;
  176. (define* (qt-cross-build name
  177. #:key
  178. source target
  179. build-inputs target-inputs host-inputs
  180. (qtbase (default-qtbase))
  181. (guile #f)
  182. (outputs '("out"))
  183. (configure-flags ''())
  184. (search-paths '())
  185. (native-search-paths '())
  186. (make-flags ''())
  187. (out-of-source? #t)
  188. (build-type "RelWithDebInfo")
  189. (tests? #f) ; nothing can be done
  190. (test-target "test")
  191. (parallel-build? #t) (parallel-tests? #f)
  192. (validate-runpath? #t)
  193. (patch-shebangs? #t)
  194. (strip-binaries? #t)
  195. (strip-flags ''("--strip-debug"
  196. "--enable-deterministic-archives"))
  197. (strip-directories ''("lib" "lib64" "libexec"
  198. "bin" "sbin"))
  199. (phases '%standard-phases)
  200. (system (%current-system))
  201. (build (nix-system->gnu-triplet system))
  202. (imported-modules %qt-build-system-modules)
  203. (modules '((guix build qt-build-system)
  204. (guix build utils))))
  205. "Cross-build NAME using CMAKE for TARGET, where TARGET is a GNU triplet and
  206. with INPUTS. This assumes that SOURCE provides a 'CMakeLists.txt' file as its
  207. build system."
  208. (define builder
  209. (with-imported-modules imported-modules
  210. #~(begin
  211. (use-modules #$@(sexp->gexp modules))
  212. (define %build-host-inputs
  213. #+(input-tuples->gexp build-inputs))
  214. (define %build-target-inputs
  215. (append #$(input-tuples->gexp host-inputs)
  216. #+(input-tuples->gexp target-inputs)))
  217. (define %outputs
  218. #$(outputs->gexp outputs))
  219. (qt-build #:source #+source
  220. #:system #$system
  221. #:build #$build
  222. #:target #$target
  223. #:outputs %outputs
  224. #:inputs %build-target-inputs
  225. #:native-inputs %build-host-inputs
  226. #:search-paths '#$(sexp->gexp
  227. (map search-path-specification->sexp
  228. search-paths))
  229. #:native-search-paths '#$(map
  230. search-path-specification->sexp
  231. native-search-paths)
  232. #:phases #$phases
  233. #:qtbase #+qtbase
  234. #:configure-flags #$configure-flags
  235. #:make-flags #$make-flags
  236. #:out-of-source? #$out-of-source?
  237. #:build-type #$build-type
  238. #:tests? #$tests?
  239. #:test-target #$test-target
  240. #:parallel-build? #$parallel-build?
  241. #:parallel-tests? #$parallel-tests?
  242. #:validate-runpath? #$validate-runpath?
  243. #:patch-shebangs? #$patch-shebangs?
  244. #:make-dynamic-linker-cache? #f ;cross-compiling
  245. #:strip-binaries? #$strip-binaries?
  246. #:strip-flags #$strip-flags
  247. #:strip-directories #$strip-directories))))
  248. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  249. system #:graft? #f)))
  250. (gexp->derivation name builder
  251. #:system system
  252. #:guile-for-build guile)))
  253. (define qt-build-system
  254. (build-system
  255. (name 'qt)
  256. (description
  257. "The CMake build system augmented with definition of suitable environment
  258. variables for Qt and KDE in program wrappers.")
  259. (lower lower)))