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

/tags/v5_9_9/bindings/ocaml/CMakeLists.txt

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