[CMake] CMake & OCaml

Alan W. Irwin irwin at beluga.phys.uvic.ca
Wed Aug 25 13:51:14 EDT 2010


On 2010-08-25 16:32+0100 Magnus Therning wrote:

> I've come to the conclusion that while CMake is a rather good build tool, it
> isn't very well designed to add full support for slightly esoteric languages
> and tool chains like OCaml.

I generally agree with that conclusion concerning CMake official
language support for both Ada and OCaml.  However, custom commands and
custom targets provide a good replacement for official language
support (see below).

For the Ada (gnat) case, gcc is used to compile object files (as well
as *.ali files, see below), and there is a powerful tool for checking
and building Ada executables called gnatmake.  So for the Ada case, I
was able to adapt (see Ada-related files in
cmake/modules/language_support/cmake in PLplot-5.9.6) the CMake
language support infrastructure to use gcc for the compiler and 
gnatmake for the linker, but it is not a completely satisfactory fit. 
For example, "Ada Library Information" files (*.ali) files are created
by the Ada compile step as well as the usual *.o files.  I believe
*.ali files could be treated by CMake in a spirit similar to what is
done for Fortran 95 module files, but in the Fortran case that support
is in the C++ code for CMake rather than in language support files.  I
personally feel that support of additional files created by the
compilation process should be generalized to be part of the language
support files rather than a detail added internally just for Fortran,
but I wouldn't know how to implement that so the current handling of
*.ali files is problematic.  The result is users of our CMake Ada
language support must specify a lot of options to help CMake find
dependencies and also repeat parts of the build to work around the
limitations.

I strongly believe that to move forward with official Ada language
support in CMake requires somebody with detailed knowledge of CMake
internals. Since I don't have such knowledge, I have asked CMake
developers in the past to take over this Ada language support project,
but there was no response to that request.  Note, I am stating that
just as a fact without complaining about it since I realize CMake
developers have a lot on their plates.  Also, I am grateful to both
Bill and Brad for giving me key support at various times to help me
get as far as I have done, but the limits of my CMake knowledge have
long since been reached so somebody else should step forward if Ada
support within CMake is to have a viable future.  If/when we are
forced to abandon this approach for PLplot's Ada bindings and
examples, the fallback will be to use CMake custom commands and custom
targets to keep track of the Ada-related files to be generated and
cleaned as well as the Ada-related CMake dependencies.  That approach
works well in the OCaml case, see below.

In the OCaml case there is also a powerful tool for building
executables called ocamlbuild (essentially an independent build system
for OCaml-related software).  As in the gnatmake case this command
might be adapted to use the CMake language support infrastructure (and
vice versa).  However, I didn't try that because I am sure from my Ada
experience that CMake internals would have to be changed to make this
work completely correctly.  Also, to get (partially) familiar with
ocamlbuild capabilities, we (PLplot developer Hezekiah M. Carty and
myself) first tried custom commands for building our ocaml bindings
and examples using ocamlbuild but the results were less than
satisfactory.  I don't remember the details, but I believe that both
dependency checking and cleaning up the huge number of different file
types that were generated was hard to implement in a satisfactory
manner.  These issues will have to be overcome if anybody wants to use
ocamlbuild as a basis for official CMake language support for ocaml.

Because of the limitations (some of which were probably our lack of
ocamlbuild knowledge) we decided to abandon the ocamlbuild approach
and replace it with CMake custom commands and dependencies to build
PLplot's ocaml bindings and examples. Those detailed custom commands
(9 of them to build our bindings in bindings/ocaml and 4 of them to
build our examples in examples/ocaml) and related custom targets are
probably too complicated to ever be supported with the CMake language
support infrastructure, but we do like the complete CMake dependency
control and generated file cleaning control this approach gives us,
and others may like our general approach as well for their own
CMake/OCaml projects if nobody is ever able to implement official
OCaml language support under CMake that is based on the ocamlbuild
command.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list