guix_mirror_bot pushed a commit to branch c++-team
in repository guix.

commit 7e5b447d727cedf22a50ce613383ff2c8ab205b6
Author: Dariqq <[email protected]>
AuthorDate: Sat Aug 9 10:06:22 2025 +0000

    build-system: cmake: Use a toolchain file for cross compiling.
    
    * guix/build-system/cmake.scm (make-toolchain-alist): New procedure.
    (make-cmake-toolchain): New procedure.
    
    (cmake-cross-build): Replace cross configure-flags with CMAKE_TOOLCHAIN_FILE
    
    Change-Id: Id754f5d7612b03aca18e1238c12a2b6b13f64381
    Signed-off-by: Greg Hogan <[email protected]>
---
 guix/build-system/cmake.scm | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/guix/build-system/cmake.scm b/guix/build-system/cmake.scm
index 724d24a210..c5cd0672c9 100644
--- a/guix/build-system/cmake.scm
+++ b/guix/build-system/cmake.scm
@@ -70,6 +70,28 @@
     ((? target-avr?)         "avr")
     (_                       (car (string-split target #\-)))))
 
+(define* (make-toolchain-alist target)
+  `((CMAKE_SYSTEM_NAME . ,(cmake-system-name-for-target target))
+    (CMAKE_SYSTEM_PROCESSOR . ,(cmake-system-processor-for-target target))
+    (CMAKE_C_COMPILER . ,(cc-for-target target))
+    (CMAKE_CXX_COMPILER . ,(cxx-for-target target))
+    (PKG_CONFIG_EXECUTABLE . ,(pkg-config-for-target target))))
+
+(define (make-cmake-toolchain target)
+  (computed-file (string-append target "-toolchain.cmake")
+                 #~(begin
+                     (use-modules (ice-9 match))
+                     (call-with-output-file #$output
+                       (lambda (port)
+                         (define (cmake-set-value key value)
+                           (format port "set(~a ~s)~%" key value))
+                         (for-each
+                          (match-lambda
+                            ((key . value)
+                             (cmake-set-value key value)))
+                          '#$(make-toolchain-alist target)))))))
+
+
 (define %cmake-build-system-modules
   ;; Build-side modules imported by default.
   `((guix build cmake-build-system)
@@ -252,6 +274,9 @@ provides a 'CMakeLists.txt' file as its build system."
   "Cross-build NAME using CMAKE for TARGET, where TARGET is a GNU triplet and
 with INPUTS.  This assumes that SOURCE provides a 'CMakeLists.txt' file as its
 build system."
+  (define toolchain
+    (make-cmake-toolchain target))
+
   (define builder
     (with-imported-modules imported-modules
       #~(begin
@@ -283,12 +308,8 @@ build system."
                                                  
search-path-specification->sexp
                                                  native-search-paths)
                        #:phases #$phases
-                       #:configure-flags `(#$(string-append 
"-DCMAKE_C_COMPILER="
-                                                            (cc-for-target 
target))
-                                           #$(string-append 
"-DCMAKE_CXX_COMPILER="
-                                                            (cxx-for-target 
target))
-                                           #$(string-append 
"-DCMAKE_SYSTEM_NAME="
-                                                            
(cmake-system-name-for-target target))
+                       #:configure-flags `(,(string-append 
"-DCMAKE_TOOLCHAIN_FILE="
+                                                           #+toolchain)
                                            ,@#$(if (pair? configure-flags)
                                                    (sexp->gexp configure-flags)
                                                    configure-flags))

Reply via email to