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