I'm trying to link some C++/cmake code with some OCaml code. If the C++ side were simple, I'd just add its object file to ocamlopt. If the OCaml side were simple, I'd add its object file to cmake. But they're both complex programs with lots of dependencies.
Currently, I have it working, but it's a bit of a hack:
I run
ocamlopt -output-obj
to get the main OCaml object:add_custom_command( OUTPUT ocaml_main.o DEPENDS ocaml.ml COMMAND ocamlfind ocamlopt -package mylib -linkpkg -output-obj -o ocaml_main.o ocaml.ml )
I run ocamlopt again with
-o
and$PATH
set to include a fakegcc
executable. This fakegcc
removes the initial-o ocaml_main.o
argument and all.o
files except forstd_exit.o
and prints out the rest.This output is added to the CMake arguments (using
target_link_libraries
).
Is there a cleaner way to do this (i.e. get all of the OCaml dependencies, recursively, ready for linking)? Using plain ocamlfind query
gets me part of the way, but misses e.g. the extra linker flags embedded in the cmxa files.