Skip to content

Commit

Permalink
Towards Qt6 and OCaml 5
Browse files Browse the repository at this point in the history
Signed-off-by: Kakadu <Kakadu@pm.me>
  • Loading branch information
Kakadu committed Jan 31, 2024
1 parent 16ea193 commit 60adff1
Show file tree
Hide file tree
Showing 17 changed files with 240 additions and 245 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ watch:
doc:
cd doc && sphinx-build . _build


deps:
opam install --yes ppx_show ppx_string_interpolation ppxlib dune-configurator dune ppx_inline_test
16 changes: 12 additions & 4 deletions config/discover.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ end

let write_sexp fn sexp = Out_channel.write_all fn ~data:(Sexp.to_string sexp)

let qtquick_pkg,rcc, moc =
match Sys.getenv "QT" with
| Some "6" -> "Qt6Quick", "/usr/lib/qt6/libexec/rcc", "/usr/lib/qt6/libexec/moc"
| _ -> "Qt5Quick", "rcc", "moc"

let () =
C.main ~name:"mylib" (fun c ->
let default : C.Pkg_config.package_conf = { libs = []; cflags = [] } in
Expand All @@ -31,16 +36,19 @@ let () =
| None -> C.die "pkg-config is not available"
| Some pc -> pc
in
Option.value (C.Pkg_config.query pc ~package:"Qt5Quick") ~default
Option.value (C.Pkg_config.query pc ~package:qtquick_pkg) ~default
in
let check_which s =
if Stdlib.Sys.command (Printf.sprintf "which %s-qt5" s) = 0 then
sprintf "%s-qt5" s
else s
in
let qmake_bin = check_which "qmake" in
write_sexp "moc.sexp" (sexp_of_string @@ check_which "moc");
write_sexp "rcc.sexp" (sexp_of_string @@ check_which "rcc");
let qmake_bin = check_which (match Sys.getenv "QT" with
| Some "6" -> "qmake6"
| _ -> "qmake")
in
write_sexp "moc.sexp" (sexp_of_string @@ check_which moc);
write_sexp "rcc.sexp" (sexp_of_string @@ check_which rcc);
write_sexp "qmake.sexp" (sexp_of_string qmake_bin);

let run_qmake ?prefix spec =
Expand Down
19 changes: 14 additions & 5 deletions dune_test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
(library
(name mystubs_dune_test)
(public_name lablqmlDemos.mystubs)
(libraries lablqml)
(modules)
(foreign_stubs
(language cxx)
Expand All @@ -23,7 +24,8 @@
((:include %{project_root}/config/c_flags.sexp)
-fPIC
-Dprotected=public
-std=c++11
-std=c++17
-I%{project_root}/lib
-O3)))
(install_c_headers controller))

Expand Down Expand Up @@ -52,19 +54,19 @@
(targets moc_controller_c.cpp)
(deps controller.h)
(action
(run moc %{deps} -o %{targets})))
(run %{read:../config/moc.sexp} %{deps} -o %{targets})))

(rule
(targets moc_dataItem_c.cpp)
(deps dataItem.h)
(action
(run moc %{deps} -o %{targets})))
(run %{read:../config/moc.sexp} %{deps} -o %{targets})))

(rule
(targets moc_c_c.cpp)
(deps c.h)
(action
(run moc %{deps} -o %{targets})))
(run %{read:../config/moc.sexp} %{deps} -o %{targets})))

(rule
(targets
Expand All @@ -76,7 +78,14 @@
dataItem_c.cpp)
(deps Controller.ml)
(action
(run ../ppx/pp/pp_qt.exe -ext cpp %{deps})))
(run
../ppx/pp/pp_qt.exe
; -nolocks
-tracelocks
;
-ext
cpp
%{deps})))

(rule
(targets qrc_resources.cpp)
Expand Down
52 changes: 0 additions & 52 deletions dune_test/src/controller_c.cpp

This file was deleted.

10 changes: 3 additions & 7 deletions dune_test_515/dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@
(executable
(name app)
(public_name lablqmlDemos.app515)
(libraries MyControls
lablqml lwt.unix threads mystubs_dune_hack)
(libraries MyControls lablqml lwt.unix threads mystubs_dune_hack)
(modules app)
(flags
(:standard -w -33-27))

(foreign_stubs
(language cxx)
(names qrc_resources proj2_qmltyperegistrations)
;; TODO: It iseems dune doesn't know about these two dependecies
(flags
((:include %{project_root}/../config/c_flags.sexp)
-fPIC
-std=c++11
-std=c++17
-O3)))
(link_flags
(-ccopt
Expand Down Expand Up @@ -52,15 +50,13 @@
(deps stubs/moc_Singleton1_c.cpp.json)
(action
(run
moc
/usr/lib/qt6/libexec/moc
%{read:../config/I_QT_INSTALL_HEADERS.sexp}
--collect-json
%{deps}
-o
%{target})))



; TODO: generated file should depend on the contents of .qrc file
; xpath -q -e '/RCC/qresource/file/text()' hack/src/resources.qrc
; from the apt package libxml-xpath-perl
Expand Down
15 changes: 7 additions & 8 deletions dune_test_515/stubs/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
(public_name app.MyControls)
(name MyControls)
(modules MyControls)
(libraries lablqml )
(libraries lablqml)
(preprocess
(per_module
((pps lablqml.ppx)
MyControls)))
)

MyControls))))

(library
(name mystubs_dune_hack)
Expand All @@ -19,20 +17,21 @@
(flags
((:include %{project_root}/../config/c_flags.sexp)
-fPIC
-std=c++11
-std=c++17
-I.
-I%{project_root}/lib/
-I../../lib
-O3)))
(install_c_headers Singleton1))


(rule
(targets moc_Singleton1_c.cpp moc_Singleton1_c.cpp.json)
(deps Singleton1.h)
;(enabled_if
; (>= %{read:QT_VERSION.sexp} 5.15)) ;; Doesn't work
(action
(run
moc
%{read:../../config/moc.sexp}
%{read:../../config/I_QT_INSTALL_HEADERS.sexp}
--output-json
%{deps}
Expand All @@ -53,7 +52,7 @@
(targets moc_myslider_c.cpp)
(deps myslider.h)
(action
(run moc %{deps} -o %{targets})))
(run %{read:../../config/moc.sexp} %{deps} -o %{targets})))

(rule
(targets myslider_c.cpp myslider.h)
Expand Down
4 changes: 2 additions & 2 deletions lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
(flags
((:include %{project_root}/config/c_flags.sexp)
-Wall
-std=c++11
-std=c++17
-O3
-I
.
; dirty hack next line
-Dprivate=public
; -Dprivate=public
-fPIC)))
(c_library_flags
(:include %{project_root}/config/c_library_flags.sexp))
Expand Down
Loading

0 comments on commit 60adff1

Please sign in to comment.