Switch from qmake to cmake as the build-system

This commit is contained in:
Jaidyn Ann 2024-02-03 22:48:23 -06:00 committed by Jaidyn Ann
parent b80d43f031
commit f5893d3249

View File

@ -19,6 +19,7 @@ exec "$CHICKEN_CSI" -s "$0" "$@"
(chicken process) (chicken process)
(chicken process-context) (chicken process-context)
(chicken string) (chicken string)
regex
shell shell
srfi-1) srfi-1)
@ -35,12 +36,11 @@ exec "$CHICKEN_CSI" -s "$0" "$@"
(file-readable? p) (file-readable? p)
(file-executable? p))) (file-executable? p)))
(define QTDIR (define CMAKE_PATH
(or (get-environment-variable "QTDIR") (or (get-environment-variable "CMAKE_PATH")
(and (file-execute-access? "/usr/bin/qmake") "/usr") (and (file-execute-access? "/usr/bin/cmake") "/usr/bin/cmake")
(and (file-execute-access? "/usr/local/bin/qmake") "/usr/local") (and (file-execute-access? "/usr/local/bin/cmake") "/usr/local/bin/cmake")
(and (file-execute-access? "/opt/local/bin/qmake") "/opt/local") (quit "please set the CMAKE_PATH environment variable") ) )
(quit "please set the QTDIR environment variable") ) )
(define (chicken-prefix) (define (chicken-prefix)
(let ((csc-path (get-environment-variable "CHICKEN_CSC"))) (let ((csc-path (get-environment-variable "CHICKEN_CSC")))
@ -54,7 +54,7 @@ exec "$CHICKEN_CSI" -s "$0" "$@"
(define binpath (make-pathname prefix "bin")) (define binpath (make-pathname prefix "bin"))
(define csc (make-pathname binpath "csc")) (define csc (make-pathname binpath "csc"))
(define keepfiles #f) (define keepfiles #f)
(define qmake (make-pathname QTDIR "bin/qmake")) (define cmake CMAKE_PATH)
(define mingw32 (eq? (build-platform) 'mingw32)) (define mingw32 (eq? (build-platform) 'mingw32))
(define macosx (eq? (software-version) 'macosx)) (define macosx (eq? (software-version) 'macosx))
(define outfile #f) (define outfile #f)
@ -102,40 +102,51 @@ exec "$CHICKEN_CSI" -s "$0" "$@"
(loop more (cons arg opts) files)) (loop more (cons arg opts) files))
(loop more opts (cons arg files))))))) (loop more opts (cons arg files)))))))
(define (qs* string)
(conc #\" (string-substitute "\"" "\\\"" string) #\"))
(define (compile-qt-extension cppfiles hfiles) (define (compile-qt-extension cppfiles hfiles)
(let* ((cppfile (car cppfiles)) (let* ((cppfile (car cppfiles))
(pro (pathname-replace-extension cppfile "pro")) (build-dir (or (pathname-directory cppfile) "./"))
(cmakelists (make-pathname build-dir "CMakeLists.txt"))
(name (pathname-file cppfile)) (name (pathname-file cppfile))
(mkfile (qs (pathname-replace-extension cppfile "make"))) (mkfile (qs (make-pathname build-dir "Makefile")))
(output (or outfile (make-pathname #f name "so")))) (output (or outfile (make-pathname #f name "so"))))
(with-output-to-file pro (with-output-to-file cmakelists
(lambda () (lambda ()
(let ((csc (qs (normalize-pathname csc))) (let ((csc (qs (normalize-pathname csc)))
(libdir (qs (normalize-pathname libpath))) (libdir (qs* (normalize-pathname libpath)))
(incdir (qs (normalize-pathname incpath))) (incdir (qs* (normalize-pathname incpath)))
(cincdir (qs (normalize-pathname cincpath)))) (cincdir (qs* (normalize-pathname cincpath))))
(print (print
#<#EOF #<#EOF
SOURCES=#{(string-intersperse cppfiles)} cmake_minimum_required(VERSION 3.16.0)
QT+=uitools gui widgets multimedia
TEMPLATE=lib project(qt-light VERSION 1.0.0 LANGUAGES CXX)
HEADERS=#{(string-intersperse hfiles)}
TARGET=#{name} set(CMAKE_CXX_STANDARD 17)
unix:QMAKE_LFLAGS_RELEASE+= `#{csc} -libs -ldflags` -L#{libdir} set(CMAKE_CXX_STANDARD_REQUIRED ON)
unix:QMAKE_CFLAGS_RELEASE+=-w `#{csc} -cflags` -I#{incdir} -I#{cincdir}
unix:QMAKE_CXXFLAGS_RELEASE+=-w `#{csc} -cflags` -I#{incdir} -I#{cincdir} set(CMAKE_AUTOMOC ON)
unix:QMAKE_CFLAGS_WARN_ON=-w set(CMAKE_AUTORCC ON)
unix:QMAKE_CXXFLAGS_WARN_ON=-w set(CMAKE_AUTOUIC ON)
win32:QMAKE_LFLAGS_RELEASE+=-L#{libdir}
win32:QMAKE_CFLAGS_RELEASE+=-w -I#{incdir} -I#{cincdir} -DHAVE_CHICKEN_CONFIG_H -DPIC find_package(Qt6 COMPONENTS Core REQUIRED)
win32:QMAKE_CXXFLAGS_RELEASE+=-w -I#{incdir} -I#{cincdir} -DHAVE_CHICKEN_CONFIG_H -DPIC find_package(Qt6 COMPONENTS Multimedia REQUIRED)
win32:QMAKE_CFLAGS_WARN_ON=--w find_package(Qt6 COMPONENTS Widgets REQUIRED)
win32:QMAKE_CXXFLAGS_WARN_ON=-w find_package(Qt6 COMPONENTS UiTools REQUIRED)
win32:LIBS+=-lchicken -lm -lws2_32
QT+=opengl add_library(#{name} SHARED
#{(string-intersperse cppfiles)}
)
target_include_directories(#{name} PRIVATE #{incdir} #{cincdir})
target_link_directories(#{name} PRIVATE #{libdir})
target_link_libraries(#{name} PRIVATE Qt6::Core Qt6::Multimedia Qt6::Widgets Qt6::UiTools)
EOF EOF
) ) )) ) ) ))
(run (,qmake ,(qs pro) -o ,mkfile)) (run (,cmake ,build-dir))
(delete-file* output) (delete-file* output)
(display mkfile) (display mkfile)
(run (,gmake -f ,mkfile clean ,(if mingw32 "release" "all"))) (run (,gmake -f ,mkfile clean ,(if mingw32 "release" "all")))
@ -144,8 +155,8 @@ EOF
(if mingw32 "release" #f) (if mingw32 "release" #f)
(if mingw32 name (string-append "lib" name)) (if mingw32 name (string-append "lib" name))
(cond (mingw32 "dll") (cond (mingw32 "dll")
(macosx "1.0.0.dylib") (macosx ".dylib")
(else "so.1.0.0"))) (else ".so")))
output) output)
(when macosx (when macosx
(run (,install_name_tool -change "libchicken.dylib" ,(make-pathname libpath "libchicken" "dylib") ,output))) (run (,install_name_tool -change "libchicken.dylib" ,(make-pathname libpath "libchicken" "dylib") ,output)))