PageRenderTime 39ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

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