PageRenderTime 45ms CodeModel.GetById 39ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/tags/v5_9_8/bindings/ocaml/CMakeLists.txt

#
CMake | 339 lines | 233 code | 26 blank | 80 comment | 8 complexity | a3aa921c2e63549789e88fbd2d0f2c8f MD5 | raw file
  1# -*- mode: cmake -*-
  2# bindings/ocaml/CMakeLists.txt
  3### Process this file with cmake to produce Makefile
  4#
  5#
  6# Copyright (C) 2008 Andrew Ross
  7# Copyright (C) 2009 Hezekiah M. Carty
  8# Copyright (C) 2009 Alan W. Irwin
  9#
 10# This file is part of PLplot.
 11#
 12# PLplot is free software; you can redistribute it and/or modify
 13# it under the terms of the GNU Library General Public License as published
 14# by the Free Software Foundation; version 2 of the License.
 15#
 16# PLplot is distributed in the hope that it will be useful,
 17# but WITHOUT ANY WARRANTY; without even the implied warranty of
 18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 19# GNU Library General Public License for more details.
 20#
 21# You should have received a copy of the GNU Library General Public License
 22# along with PLplot; if not, write to the Free Software
 23# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 24
 25if(ENABLE_ocaml)
 26
 27  # Optionally build the Plcairo module
 28  add_subdirectory(plcairo)
 29
 30  # optional command to generate generated_plplot_h.inc.  This generated
 31  # version of the file should be identical to plplot_h.inc.
 32  if(GENERATE_PLPLOT_H_INC)
 33    add_custom_command(
 34      OUTPUT
 35      ${CMAKE_CURRENT_BINARY_DIR}/generated_plplot_h.inc
 36      COMMAND ${OCAML} ${CMAKE_CURRENT_SOURCE_DIR}/touchup.ml ${CMAKE_CURRENT_SOURCE_DIR}/plplot_h ${CMAKE_CURRENT_BINARY_DIR}/generated_plplot_h.inc
 37      DEPENDS
 38      ${CMAKE_CURRENT_SOURCE_DIR}/touchup.ml
 39      ${CMAKE_CURRENT_SOURCE_DIR}/plplot_h
 40      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
 41      )
 42    add_custom_target(generate_plplot_h.inc
 43      DEPENDS
 44      ${CMAKE_CURRENT_BINARY_DIR}/generated_plplot_h.inc
 45      )
 46  endif(GENERATE_PLPLOT_H_INC)
 47
 48  #Detailed CMake logic to build ocaml bindings for PLplot.
 49  set(camlidl_GENERATED_SOURCE
 50    ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.h
 51    ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.ml
 52    ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.mli
 53    ${CMAKE_CURRENT_BINARY_DIR}/plplot_core_stubs.c
 54    )
 55
 56  # camlidl produces most of the C and OCaml code required to bind PLplot
 57  add_custom_command(
 58    OUTPUT
 59    ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.idl
 60    ${camlidl_GENERATED_SOURCE}
 61    # camlidl source file must be in ${CMAKE_CURRENT_BINARY_DIR}.
 62    COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/plplot_core.idl ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.idl
 63    COMMAND ${CAMLIDL} -header -I ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.idl
 64    DEPENDS
 65    ${CMAKE_CURRENT_SOURCE_DIR}/plplot_core.idl
 66    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
 67    )
 68
 69  # ocamlc -c compiles *.c into *.o.
 70  # ocamlmklib links *.o into *.so and *.a
 71  add_custom_command(
 72    OUTPUT
 73    ${CMAKE_CURRENT_BINARY_DIR}/plplot_core_stubs.o
 74    ${CMAKE_CURRENT_BINARY_DIR}/plplot_impl.o
 75    ${CMAKE_CURRENT_BINARY_DIR}/dllplplot_stubs.so
 76    ${CMAKE_CURRENT_BINARY_DIR}/libplplot_stubs.a
 77    COMMAND ${OCAMLC} -c ${CMAKE_CURRENT_BINARY_DIR}/plplot_core_stubs.c
 78    COMMAND ${OCAMLC} -ccopt -I${CMAKE_SOURCE_DIR}/include -ccopt -I${CMAKE_BINARY_DIR}/include -ccopt -I${CMAKE_SOURCE_DIR}/lib/qsastime  -c ${CMAKE_CURRENT_SOURCE_DIR}/plplot_impl.c
 79    COMMAND ${OCAMLMKLIB} -o plplot_stubs -L${CAMLIDL_LIB_DIR} -lcamlidl -L${CMAKE_BINARY_DIR}/src -lplplot${LIB_TAG} ${CMAKE_CURRENT_BINARY_DIR}/plplot_core_stubs.o ${CMAKE_CURRENT_BINARY_DIR}/plplot_impl.o
 80    DEPENDS
 81    ${CMAKE_CURRENT_BINARY_DIR}/plplot_core_stubs.c
 82    ${CMAKE_CURRENT_SOURCE_DIR}/plplot_impl.c
 83    plplot${LIB_TAG}
 84    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
 85    )
 86  add_custom_target(target_lib_plplot_stubs
 87    DEPENDS
 88    ${CMAKE_CURRENT_BINARY_DIR}/dllplplot_stubs.so
 89    ${CMAKE_CURRENT_BINARY_DIR}/libplplot_stubs.a
 90    )
 91
 92  # ocamlc -c compiles *.mli into *.cmi
 93  add_custom_command(
 94    OUTPUT
 95    ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmi
 96    ${CMAKE_CURRENT_BINARY_DIR}/plplot.mli
 97    ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmi
 98    COMMAND ${OCAMLC} -c ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.mli
 99    # ocamlc *.mli source file must be in ${CMAKE_CURRENT_BINARY_DIR}.
100    COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/plplot.mli ${CMAKE_CURRENT_BINARY_DIR}/plplot.mli
101    COMMAND ${OCAMLC} -c ${CMAKE_CURRENT_BINARY_DIR}/plplot.mli
102    DEPENDS
103    ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.mli
104    ${CMAKE_CURRENT_SOURCE_DIR}/plplot.mli
105    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
106    )
107  add_custom_target(target_plplot_cmi
108    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmi
109    )
110
111  # ocamlc -c compiles  *.ml into *.cmo and simultaneously checks against
112  # *.cmi produced from *.mli above.
113  add_custom_command(
114    OUTPUT
115    ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmo
116    ${CMAKE_CURRENT_BINARY_DIR}/plplot.ml
117    ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmo
118    COMMAND ${OCAMLC} -c ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.ml
119    # ocamlc and ocamlopt *.ml source file must be in
120    # ${CMAKE_CURRENT_BINARY_DIR}.
121    COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/plplot.ml ${CMAKE_CURRENT_BINARY_DIR}/plplot.ml
122    COMMAND ${OCAMLC} -c ${CMAKE_CURRENT_BINARY_DIR}/plplot.ml
123    DEPENDS
124    ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.ml
125    ${CMAKE_CURRENT_SOURCE_DIR}/plplot.ml
126    ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmi
127    ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmi
128    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
129    )
130  add_custom_target(target_plplot_cmo
131    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmo
132    )
133
134  # ocamlc -a -custom builds a *.cma library from *.cmo
135  add_custom_command(
136    OUTPUT
137    ${CMAKE_CURRENT_BINARY_DIR}/plplot.cma
138    COMMAND ${OCAMLC} -a -custom -o ${CMAKE_CURRENT_BINARY_DIR}/plplot.cma ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmo ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmo -dllib -lplplot_stubs -ccopt -L${CMAKE_CURRENT_BINARY_DIR} -cclib -lplplot_stubs -ccopt -L${CAMLIDL_LIB_DIR} -cclib -lcamlidl -ccopt -L${CMAKE_BINARY_DIR}/src -cclib -lplplot${LIB_TAG} -dllpath ${CMAKE_BINARY_DIR}/src
139    DEPENDS
140    ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmo
141    ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmo
142    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
143    )
144  add_custom_target(target_plplot_cma
145    DEPENDS
146    ${CMAKE_CURRENT_BINARY_DIR}/plplot.cma
147    )
148
149  # These targets depend on common files in their respective
150  # file-dependency chains.  Therefore, to avoid screwing up parallel
151  # builds must serialize with target depends.
152  add_dependencies(target_plplot_cmi target_lib_plplot_stubs)
153  add_dependencies(target_plplot_cmo target_plplot_cmi)
154  add_dependencies(target_plplot_cma target_plplot_cmo)
155
156  add_custom_target(plplot_ocaml ALL)
157
158  if(OCAMLOPT)
159    # ocamlopt compiles *.ml into *.o and *.cmx and simultaneously
160    # checks against *.cmi produced from *.mli above.
161    add_custom_command(
162      OUTPUT
163      ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmx
164      ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.o
165      ${CMAKE_CURRENT_BINARY_DIR}/plplot.ml
166      ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmx
167      ${CMAKE_CURRENT_BINARY_DIR}/plplot.o
168      COMMAND ${OCAMLOPT} -c ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.ml
169      # ocamlc and ocamlopt *.ml source file must be in
170      # ${CMAKE_CURRENT_BINARY_DIR}.
171      COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/plplot.ml ${CMAKE_CURRENT_BINARY_DIR}/plplot.ml
172      COMMAND ${OCAMLOPT} -c ${CMAKE_CURRENT_BINARY_DIR}/plplot.ml
173      DEPENDS
174      ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.ml
175      ${CMAKE_CURRENT_SOURCE_DIR}/plplot.ml
176      ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmi
177      ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmi
178      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
179      )
180    add_custom_target(target_plplot_cmx
181      DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmx
182      )
183
184    # ocamlopt -a builds the libraries *.cmxa and *.a respectively from
185    # the *.cmx and *.o files.  The plplot_stubs library also plays
186    # a role.
187    add_custom_command(
188      OUTPUT
189      ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmxa
190      ${CMAKE_CURRENT_BINARY_DIR}/plplot.a
191      COMMAND ${OCAMLOPT} -a -o ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmxa ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmx ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmx -ccopt -L${CMAKE_CURRENT_BINARY_DIR} -cclib -lplplot_stubs -ccopt -L${CAMLIDL_LIB_DIR} -cclib -lcamlidl -ccopt -L${CMAKE_BINARY_DIR}/src -cclib -lplplot${LIB_TAG}
192      DEPENDS
193      ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmx
194      ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmx
195      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
196      )
197    add_custom_target(target_plplot_cmxa
198      DEPENDS
199      ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmxa
200      )
201
202    # Must serialize these targets against highest dependency ocamlc
203    # target, target_plplot_cma, because of common custom commands in
204    # their file-dependency chains which would be screwed up in a
205    # parallel build without this serialization.
206
207    add_dependencies(target_plplot_cmx target_plplot_cma)
208    add_dependencies(target_plplot_cmxa target_plplot_cmx)
209
210    add_dependencies(plplot_ocaml target_plplot_cmxa)
211
212    # Need to keep track of file dependencies since this is a custom target.
213    set_property(GLOBAL PROPERTY FILES_plplot_ocaml
214      ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmxa
215      ${CMAKE_CURRENT_BINARY_DIR}/plplot.a
216      )
217  else (OCAMLOPT)
218    add_dependencies(plplot_ocaml target_plplot_cma)
219    # Need to keep track of file dependencies since this is a custom target.
220    set_property(GLOBAL PROPERTY FILES_plplot_ocaml
221      ${CMAKE_CURRENT_BINARY_DIR}/plplot.cma
222      )
223  endif(OCAMLOPT)
224
225  if(OCAMLDOC)
226    # Build OCaml API reference documentation
227    set(OCAMLDOC_FILE_LIST
228      Plplot.Plot.html
229      Plplot.Quick_plot.html
230      Plplot.html
231      index.html
232      index_attributes.html
233      index_class_types.html
234      index_classes.html
235      index_exceptions.html
236      index_methods.html
237      index_module_types.html
238      index_modules.html
239      index_types.html
240      index_values.html
241      style.css
242      type_Plplot.Plot.html
243      type_Plplot.Quick_plot.html
244      type_Plplot.html
245      )
246
247    set(OCAMLDOC_FILES)
248    foreach(html_file ${OCAMLDOC_FILE_LIST})
249      list(APPEND OCAMLDOC_FILES ${CMAKE_CURRENT_BINARY_DIR}/${html_file})
250    endforeach(html_file ${OCAMLDOC_FILE_LIST})
251    # ocamldoc builds the module's documentation using specially formatted
252    # comments in the source file.
253    add_custom_command(
254      OUTPUT ${OCAMLDOC_FILES}
255      COMMAND ${OCAMLDOC} -html ${CMAKE_CURRENT_SOURCE_DIR}/plplot.mli
256      DEPENDS
257      ${CMAKE_CURRENT_BINARY_DIR}/plplot.mli
258      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
259      )
260    add_custom_target(target_build_ocaml_doc DEPENDS ${OCAMLDOC_FILES})
261    # associated custom command has common file depends with custom command
262    # that is associated with target_plplot_cmi.  Therefore must serialize
263    # the two custom targets.
264    add_dependencies(target_plplot_cmi target_build_ocaml_doc)
265  endif(OCAMLDOC)
266
267  # Basic build done, now trying to finish up by adapting bits
268  # and pieces of old build procedure below.
269
270  # Configure the META file
271  configure_file(META.in ${CMAKE_CURRENT_BINARY_DIR}/META)
272  # Configure pkg-config *.pc file corresponding to plplot.cma
273  if(PKG_CONFIG_EXECUTABLE)
274    if(LIB_TAG)
275      set(PC_PRECISION "double")
276    else(LIB_TAG)
277      set(PC_PRECISION "single")
278    endif(LIB_TAG)
279    # Each list element must consist of a colon-separated string with the
280    # following fields which are parsed out in the foreach loop below and
281    # used to configure the corresponding pkg-config *.pc file.
282    # BINDING 	      	  - ENABLE_${BINDING} keeps track of whether a
283    # 			    binding has been enabled (ON) or not (OFF).
284    #			    Also, ${BINDING} used to determine PC_FILE_SUFFIX
285    #			    which helps to determine name of configured
286    #			    *.pc file.
287    # PC_SHORT_NAME	  - Used in *.pc NAME: field
288    # PC_LONG_NAME	  - Used in *.pc Description: field
289    # PC_LIBRARY_NAME	  - Used in *.pc Libs: field
290    #                         Also used to determine PC_LINK_FLAGS and
291    #                         PC_COMPILE_FLAGS used in *.pc Libs: and Cflags:
292    #			    fields.
293    set(PC_DATA "ocaml:::plplot${LIB_TAG}")
294
295    string(REGEX REPLACE "^(.*):.*:.*:.*$" "\\1" BINDING ${PC_DATA})
296    set(PC_FILE_SUFFIX "-${BINDING}")
297    set(PC_REQUIRES "plplot${LIB_TAG}")
298    string(REGEX REPLACE "^.*:(.*):.*:.*$" "\\1" PC_SHORT_NAME ${PC_DATA})
299    string(REGEX REPLACE "^.*:.*:(.*):.*$" "\\1" PC_LONG_NAME ${PC_DATA})
300    string(REGEX REPLACE "^.*:.*:.*:(.*)$" "\\1" PC_LIBRARY_NAME ${PC_DATA})
301    set(PC_LINK_FLAGS "${lib${PC_LIBRARY_NAME}_LINK_FLAGS}")
302    set(PC_COMPILE_FLAGS "${lib${PC_LIBRARY_NAME}_COMPILE_FLAGS}")
303    set(PC_LINK_FLAGS "-l${PC_LIBRARY_NAME} ${PC_LINK_FLAGS}")
304    set(PC_CONFIGURED_FILE
305      ${CMAKE_BINARY_DIR}/pkgcfg/plplot${LIB_TAG}${PC_FILE_SUFFIX}.pc
306      )
307    configure_file(
308      ${CMAKE_SOURCE_DIR}/pkgcfg/plplot-template.pc.cmake
309      ${PC_CONFIGURED_FILE}
310      @ONLY
311      )
312    install(FILES ${PC_CONFIGURED_FILE} DESTINATION ${PKG_CONFIG_DIR})
313  endif(PKG_CONFIG_EXECUTABLE)
314
315  set(OCAML_FULL_INSTALL_FILES
316    ${CMAKE_CURRENT_BINARY_DIR}/plplot.cma
317    ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmi
318    ${CMAKE_CURRENT_BINARY_DIR}/libplplot_stubs.a
319    ${CMAKE_CURRENT_BINARY_DIR}/plplot.mli
320    )
321  if (OCAMLOPT)
322    set(OCAML_FULL_INSTALL_FILES
323      ${OCAML_FULL_INSTALL_FILES}
324      ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmxa
325      ${CMAKE_CURRENT_BINARY_DIR}/plplot.a
326      )
327  endif (OCAMLOPT)
328
329  # Most files go in the plplot subdirectory
330  install(FILES ${OCAML_FULL_INSTALL_FILES} ${CMAKE_CURRENT_BINARY_DIR}/META
331    DESTINATION ${OCAML_INSTALL_DIR}/plplot
332    )
333
334  # Shared library stubs go in stublibs
335  install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/dllplplot_stubs.so
336    DESTINATION ${OCAML_INSTALL_DIR}/stublibs
337    )
338
339endif(ENABLE_ocaml)