123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- (define-module (guix build cmake-build-system)
- #:use-module ((guix build gnu-build-system) #:prefix gnu:)
- #:use-module (guix build utils)
- #:use-module (ice-9 match)
- #:export (%standard-phases
- cmake-build))
- (define* (configure #:key outputs (configure-flags '()) (out-of-source? #t)
- build-type target
- #:allow-other-keys)
- "Configure the given package."
- (let* ((out (assoc-ref outputs "out"))
- (abs-srcdir (getcwd))
- (srcdir (if out-of-source?
- (string-append "../" (basename abs-srcdir))
- ".")))
- (format #t "source directory: ~s (relative from build: ~s)~%"
- abs-srcdir srcdir)
- (when out-of-source?
- (mkdir "../build")
- (chdir "../build"))
- (format #t "build directory: ~s~%" (getcwd))
- (let ((args `(,srcdir
- ,@(if build-type
- (list (string-append "-DCMAKE_BUILD_TYPE="
- build-type))
- '())
- ,(string-append "-DCMAKE_INSTALL_PREFIX=" out)
-
- "-DCMAKE_INSTALL_LIBDIR=lib"
-
- "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE"
-
- ,(string-append "-DCMAKE_INSTALL_RPATH=" out "/lib")
-
- "-DCMAKE_VERBOSE_MAKEFILE=ON"
-
- ,@(if target
- (list (string-append "-DCMAKE_C_COMPILER="
- target "-gcc")
- (string-append "-DCMAKE_CXX_COMPILER="
- target "-g++")
- (if (string-contains target "mingw")
- "-DCMAKE_SYSTEM_NAME=Windows"
- "-DCMAKE_SYSTEM_NAME=Linux"))
- '())
- ,@configure-flags)))
- (format #t "running 'cmake' with arguments ~s~%" args)
- (apply invoke "cmake" args))))
- (define* (check #:key (tests? #t) (parallel-tests? #t) (test-target "test")
- #:allow-other-keys)
- (let ((gnu-check (assoc-ref gnu:%standard-phases 'check)))
- (setenv "CTEST_OUTPUT_ON_FAILURE" "1")
- (gnu-check #:tests? tests? #:test-target test-target
- #:parallel-tests? parallel-tests?)))
- (define %standard-phases
-
-
- (modify-phases gnu:%standard-phases
- (delete 'bootstrap)
- (replace 'check check)
- (replace 'configure configure)))
- (define* (cmake-build #:key inputs (phases %standard-phases)
- #:allow-other-keys #:rest args)
- "Build the given package, applying all of PHASES in order."
- (apply gnu:gnu-build #:inputs inputs #:phases phases args))
|