qt.scm 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. #:export (%qt-build-system-modules
  36. qt-build
  37. qt-build-system))
  38. ;; Commentary:
  39. ;;
  40. ;; This build system is an extension of the 'cmake-build-system'. It
  41. ;; accommodates the needs of Qt and KDE applications by adding a phase run
  42. ;; after the 'install' phase:
  43. ;;
  44. ;; 'qt-wrap' phase:
  45. ;;
  46. ;; This phase looks for Qt5 plugin paths, QML paths and some XDG paths as well
  47. ;; as the corresponding environment variables. If any of these is found in
  48. ;; the output or if respective environment variables are set, then all
  49. ;; programs in the output's "bin", "sbin", "libexec and "lib/libexec"
  50. ;; directories are wrapped in scripts defining the necessary environment
  51. ;; variables.
  52. ;;
  53. ;; Code:
  54. (define %qt-build-system-modules
  55. ;; Build-side modules imported and used by default.
  56. `((guix build qt-build-system)
  57. (guix build qt-utils)
  58. ,@%cmake-build-system-modules))
  59. (define (default-cmake)
  60. "Return the default CMake package."
  61. ;; Do not use `@' to avoid introducing circular dependencies.
  62. (let ((module (resolve-interface '(gnu packages cmake))))
  63. (module-ref module 'cmake-minimal)))
  64. (define (default-qtbase)
  65. "Return the default qtbase package."
  66. ;; Do not use `@' to avoid introducing circular dependencies.
  67. (let ((module (resolve-interface '(gnu packages qt))))
  68. (module-ref module 'qtbase-5)))
  69. ;; This barely is a copy from (guix build-system cmake), only adjusted to use
  70. ;; the variables defined here.
  71. (define* (lower name
  72. #:key source inputs native-inputs outputs system target
  73. (cmake (default-cmake))
  74. (qtbase (default-qtbase))
  75. #:allow-other-keys
  76. #:rest arguments)
  77. "Return a bag for NAME."
  78. (define private-keywords
  79. `(#:cmake #:inputs #:native-inputs #:outputs
  80. ,@(if target '() '(#:target))))
  81. (bag
  82. (name name)
  83. (system system)
  84. (target target)
  85. (build-inputs `(,@(if source
  86. `(("source" ,source))
  87. '())
  88. ,@`(("cmake" ,cmake))
  89. ,@`(("qtbase" ,qtbase))
  90. ,@native-inputs
  91. ,@(if target
  92. ;; Use the standard cross inputs of
  93. ;; 'gnu-build-system'.
  94. (standard-cross-packages target 'host)
  95. '())
  96. ;; Keep the standard inputs of 'gnu-build-system'.
  97. ,@(standard-packages)))
  98. (host-inputs inputs)
  99. ;; The cross-libc is really a target package, but for bootstrapping
  100. ;; reasons, we can't put it in 'host-inputs'. Namely, 'cross-gcc' is a
  101. ;; native package, so it would end up using a "native" variant of
  102. ;; 'cross-libc' (built with 'gnu-build'), whereas all the other packages
  103. ;; would use a target variant (built with 'gnu-cross-build'.)
  104. (target-inputs (if target
  105. (standard-cross-packages target 'target)
  106. '()))
  107. (outputs outputs)
  108. (build (if target qt-cross-build qt-build))
  109. (arguments (strip-keyword-arguments private-keywords arguments))))
  110. (define* (qt-build name inputs
  111. #:key
  112. (qtbase (default-qtbase))
  113. source (guile #f)
  114. (outputs '("out")) (configure-flags ''())
  115. (search-paths '())
  116. (make-flags ''())
  117. (out-of-source? #t)
  118. (build-type "RelWithDebInfo")
  119. (tests? #t)
  120. (test-target "test")
  121. (parallel-build? #t) (parallel-tests? #f)
  122. (validate-runpath? #t)
  123. (patch-shebangs? #t)
  124. (strip-binaries? #t)
  125. (strip-flags %strip-flags)
  126. (strip-directories %strip-directories)
  127. (phases '%standard-phases)
  128. (qt-wrap-excluded-outputs ''())
  129. (qt-wrap-excluded-inputs %qt-wrap-excluded-inputs)
  130. (system (%current-system))
  131. (imported-modules %qt-build-system-modules)
  132. (modules '((guix build qt-build-system)
  133. (guix build utils))))
  134. "Build SOURCE using CMAKE, and with INPUTS. This assumes that SOURCE
  135. provides a 'CMakeLists.txt' file as its build system."
  136. (define builder
  137. (with-imported-modules imported-modules
  138. #~(begin
  139. (use-modules #$@(sexp->gexp modules))
  140. (qt-build #:source #+source
  141. #:system #$system
  142. #:outputs #$(outputs->gexp outputs)
  143. #:inputs #$(input-tuples->gexp inputs)
  144. #:search-paths '#$(sexp->gexp
  145. (map search-path-specification->sexp
  146. search-paths))
  147. #:phases #$(if (pair? phases)
  148. (sexp->gexp phases)
  149. phases)
  150. #:qtbase #+qtbase
  151. #:qt-wrap-excluded-outputs #$qt-wrap-excluded-outputs
  152. #:qt-wrap-excluded-inputs #$qt-wrap-excluded-inputs
  153. #:configure-flags #$configure-flags
  154. #:make-flags #$make-flags
  155. #:out-of-source? #$out-of-source?
  156. #:build-type #$build-type
  157. #:tests? #$tests?
  158. #:test-target #$test-target
  159. #:parallel-build? #$parallel-build?
  160. #:parallel-tests? #$parallel-tests?
  161. #:validate-runpath? #$validate-runpath?
  162. #:patch-shebangs? #$patch-shebangs?
  163. #:strip-binaries? #$strip-binaries?
  164. #:strip-flags #$strip-flags
  165. #:strip-directories #$strip-directories))))
  166. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  167. system #:graft? #f)))
  168. (gexp->derivation name builder
  169. #:graft? #f ;consistent with 'gnu-build'
  170. #:system system
  171. #:guile-for-build guile)))
  172. ;;;
  173. ;;; Cross-compilation.
  174. ;;;
  175. (define* (qt-cross-build name
  176. #:key
  177. source target
  178. build-inputs target-inputs host-inputs
  179. (qtbase (default-qtbase))
  180. (guile #f)
  181. (outputs '("out"))
  182. (configure-flags ''())
  183. (search-paths '())
  184. (native-search-paths '())
  185. (make-flags ''())
  186. (out-of-source? #t)
  187. (build-type "RelWithDebInfo")
  188. (tests? #f) ; nothing can be done
  189. (test-target "test")
  190. (parallel-build? #t) (parallel-tests? #f)
  191. (validate-runpath? #t)
  192. (patch-shebangs? #t)
  193. (strip-binaries? #t)
  194. (strip-flags %strip-flags)
  195. (strip-directories %strip-directories)
  196. (phases '%standard-phases)
  197. (system (%current-system))
  198. (build (nix-system->gnu-triplet system))
  199. (imported-modules %qt-build-system-modules)
  200. (modules '((guix build qt-build-system)
  201. (guix build utils))))
  202. "Cross-build NAME using CMAKE for TARGET, where TARGET is a GNU triplet and
  203. with INPUTS. This assumes that SOURCE provides a 'CMakeLists.txt' file as its
  204. build system."
  205. (define builder
  206. (with-imported-modules imported-modules
  207. #~(begin
  208. (use-modules #$@(sexp->gexp modules))
  209. (define %build-host-inputs
  210. #+(input-tuples->gexp build-inputs))
  211. (define %build-target-inputs
  212. (append #$(input-tuples->gexp host-inputs)
  213. #+(input-tuples->gexp target-inputs)))
  214. (define %outputs
  215. #$(outputs->gexp outputs))
  216. (qt-build #:source #+source
  217. #:system #$system
  218. #:build #$build
  219. #:target #$target
  220. #:outputs %outputs
  221. #:inputs %build-target-inputs
  222. #:native-inputs %build-host-inputs
  223. #:search-paths '#$(sexp->gexp
  224. (map search-path-specification->sexp
  225. search-paths))
  226. #:native-search-paths '#$(map
  227. search-path-specification->sexp
  228. native-search-paths)
  229. #:phases #$phases
  230. #:qtbase #+qtbase
  231. #:configure-flags #$configure-flags
  232. #:make-flags #$make-flags
  233. #:out-of-source? #$out-of-source?
  234. #:build-type #$build-type
  235. #:tests? #$tests?
  236. #:test-target #$test-target
  237. #:parallel-build? #$parallel-build?
  238. #:parallel-tests? #$parallel-tests?
  239. #:validate-runpath? #$validate-runpath?
  240. #:patch-shebangs? #$patch-shebangs?
  241. #:make-dynamic-linker-cache? #f ;cross-compiling
  242. #:strip-binaries? #$strip-binaries?
  243. #:strip-flags #$strip-flags
  244. #:strip-directories #$strip-directories))))
  245. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  246. system #:graft? #f)))
  247. (gexp->derivation name builder
  248. #:graft? #f ;consistent with 'gnu-build'
  249. #:system system
  250. #:guile-for-build guile)))
  251. (define qt-build-system
  252. (build-system
  253. (name 'qt)
  254. (description
  255. "The CMake build system augmented with definition of suitable environment
  256. variables for Qt and KDE in program wrappers.")
  257. (lower lower)))