qt.scm 12 KB

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