Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add OCaml 5 support #67

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
44 changes: 34 additions & 10 deletions dune_test/dune
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
(env(_(flags (-w -34))))
; (env
; (_
; (flags
; (:standard -w -34))))

(copy_files ui/Root.qml)

(library
(name mystubs_dune_test)
(public_name lablqmlDemos.mystubs)
(libraries lablqml)
(modules)
(foreign_stubs
(language cxx)
(names controller_c moc_controller_c c_c moc_c_c dataItem_c moc_dataItem_c qrc_resources)
(names
controller_c
moc_controller_c
c_c
moc_c_c
dataItem_c
moc_dataItem_c
qrc_resources)
(flags
((: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 All @@ -28,8 +41,6 @@
Controller)))
(link_flags
(-ccopt
-Wl,-no-as-needed
-ccopt
-fPIC
-cclib
-lstdc++
Expand All @@ -43,25 +54,38 @@
(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 controller_c.cpp controller.h c_c.cpp c.h dataItem.h dataItem_c.cpp)
(targets
controller_c.cpp
controller.h
c_c.cpp
c.h
dataItem.h
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.

12 changes: 3 additions & 9 deletions dune_test_515/dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,21 @@
(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
-Wl,-no-as-needed
-ccopt
-fPIC
-cclib
-lstdc++
Expand Down Expand Up @@ -54,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
Loading