PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/v5_9_8/bindings/f77/CMakeLists.txt

#
CMake | 293 lines | 211 code | 30 blank | 52 comment | 15 complexity | e3cf6d9d1074cc49593981eab1b2833d MD5 | raw file
Possible License(s): LGPL-2.0, BSD-3-Clause-No-Nuclear-License-2014, Apache-2.0, GPL-2.0
  1. # bindings/f77/CMakeLists.txt
  2. ### Process this file with cmake to produce Makefile
  3. ###
  4. # Copyright (C) 2006 Andrew Ross
  5. #
  6. # This file is part of PLplot.
  7. #
  8. # PLplot is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU Library General Public License as published
  10. # by the Free Software Foundation; version 2 of the License.
  11. #
  12. # PLplot is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Library General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Library General Public License
  18. # along with PLplot; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. if(ENABLE_f77)
  21. ## Generate source files depending on type of PLFLT
  22. ## Note: sed will possibly fail on windows. Would this be better
  23. ## done using the cmake configure_file option eventually?
  24. ## Answer: no. The configuration option requires @ placeholders
  25. ## throughout the f77 source files which make them extremely hard
  26. ## to understand/maintain. Instead, we ask those Windows users who
  27. ## want the single-precision library to install sed (from MSYS or
  28. ## wherever).
  29. if(PL_DOUBLE)
  30. add_custom_command(
  31. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sfstubs.f
  32. COMMAND ${CMAKE_COMMAND}
  33. -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/sfstubs.fm4 ${CMAKE_CURRENT_BINARY_DIR}/sfstubs.f
  34. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/sfstubs.fm4
  35. )
  36. add_custom_command(
  37. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/plplot_parameters.h
  38. COMMAND ${CMAKE_COMMAND}
  39. -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/plplot_parameters.fm4 ${CMAKE_CURRENT_BINARY_DIR}/plplot_parameters.h
  40. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/plplot_parameters.fm4
  41. )
  42. else(PL_DOUBLE)
  43. add_custom_command(
  44. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sfstubs.f
  45. COMMAND sed
  46. -f ${CMAKE_CURRENT_SOURCE_DIR}/double2single.sed ${CMAKE_CURRENT_SOURCE_DIR}/sfstubs.fm4 > ${CMAKE_CURRENT_BINARY_DIR}/sfstubs.f
  47. DEPENDS
  48. ${CMAKE_CURRENT_SOURCE_DIR}/double2single.sed
  49. ${CMAKE_CURRENT_SOURCE_DIR}/sfstubs.fm4
  50. )
  51. # For this case, use more extensive examples/f77 sed script since
  52. # have double-precision floating-point constants to convert.
  53. add_custom_command(
  54. OUTPUT
  55. ${CMAKE_CURRENT_BINARY_DIR}/plplot_parameters.h
  56. COMMAND sed
  57. -f ${CMAKE_SOURCE_DIR}/examples/f77/double2single.sed ${CMAKE_CURRENT_SOURCE_DIR}/plplot_parameters.fm4 > ${CMAKE_CURRENT_BINARY_DIR}/plplot_parameters.h
  58. DEPENDS
  59. ${CMAKE_SOURCE_DIR}/examples/f77/double2single.sed
  60. ${CMAKE_CURRENT_SOURCE_DIR}/plplot_parameters.fm4
  61. )
  62. endif(PL_DOUBLE)
  63. add_custom_target(build_plplot_parameters_h ALL
  64. DEPENDS
  65. ${CMAKE_CURRENT_BINARY_DIR}/plplot_parameters.h
  66. )
  67. install(
  68. FILES
  69. ${CMAKE_CURRENT_BINARY_DIR}/plplot_parameters.h
  70. DESTINATION ${F77_INCLUDE_DIR}
  71. )
  72. set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/sfstubs.f
  73. PROPERTIES GENERATED ON)
  74. if(WIN32)
  75. # Set the flags for the C compiler. The C stubs need to have the
  76. # correction case and calling convention for the Fortran compiler
  77. IF(TARGET_FORTRAN MATCHES "IVF")
  78. SET(DEFFILE "_ifort")
  79. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DIVF")
  80. ELSEIF(TARGET_FORTRAN MATCHES "CVF")
  81. SET(DEFFILE "")
  82. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DCVF")
  83. ENDIF(TARGET_FORTRAN MATCHES "IVF")
  84. endif(WIN32)
  85. if(F77_CMD_LINE)
  86. set(HAVE_F77PARSE_CL_FALSE C)
  87. else(F77_CMD_LINE)
  88. set(HAVE_F77PARSE_CL_TRUE C)
  89. endif(F77_CMD_LINE)
  90. configure_file(
  91. ${CMAKE_CURRENT_SOURCE_DIR}/configurable.f.cmake
  92. ${CMAKE_CURRENT_BINARY_DIR}/configurable.f
  93. )
  94. # Set the include path
  95. include_directories(
  96. ${CMAKE_CURRENT_SOURCE_DIR}
  97. ${CMAKE_SOURCE_DIR}/lib/qsastime
  98. ${CMAKE_SOURCE_DIR}/include
  99. ${CMAKE_BINARY_DIR}
  100. ${CMAKE_BINARY_DIR}/include
  101. )
  102. ## Build C part of F77 bindings
  103. # Check consistency of plplot_parameters.fm4.
  104. add_custom_target(
  105. check_f77_parameters
  106. COMMAND ${CMAKE_COMMAND} -E remove -f
  107. ${CMAKE_CURRENT_BINARY_DIR}/plplot_parameters.fm4_compare
  108. COMMAND
  109. sed -f ${CMAKE_CURRENT_SOURCE_DIR}/global_defines.sed <
  110. ${CMAKE_SOURCE_DIR}/bindings/swig-support/plplotcapi.i >
  111. ${CMAKE_CURRENT_BINARY_DIR}/plplot_parameters.fm4_compare
  112. COMMAND
  113. ${CMAKE_COMMAND} -E echo "Check that plplot_parameters.fm4 is consistent with the #defines in bindings/swig-support/plplotcapi.i"
  114. COMMAND
  115. cmp ${CMAKE_CURRENT_SOURCE_DIR}/plplot_parameters.fm4
  116. ${CMAKE_CURRENT_BINARY_DIR}/plplot_parameters.fm4_compare
  117. )
  118. set(plplotf77c${LIB_TAG}_LIB_SRCS
  119. sc3d.c
  120. sccont.c
  121. scstubs.c
  122. )
  123. if(BUILD_SHARED_LIBS)
  124. SET_SOURCE_FILES_PROPERTIES( ${plplotf77c${LIB_TAG}_LIB_SRCS}
  125. PROPERTIES COMPILE_FLAGS "-DUSINGDLL" )
  126. endif(BUILD_SHARED_LIBS)
  127. add_library(plplotf77c${LIB_TAG} ${plplotf77c${LIB_TAG}_LIB_SRCS})
  128. target_link_libraries(plplotf77c${LIB_TAG} plplot${LIB_TAG})
  129. if(USE_RPATH)
  130. get_target_property(LIB_INSTALL_RPATH plplot${LIB_TAG} INSTALL_RPATH)
  131. set_target_properties(plplotf77c${LIB_TAG}
  132. PROPERTIES
  133. SOVERSION ${plplotf77_SOVERSION}
  134. VERSION ${plplotf77_VERSION}
  135. INSTALL_RPATH "${LIB_INSTALL_RPATH}"
  136. INSTALL_NAME_DIR "${LIB_DIR}"
  137. )
  138. else(USE_RPATH)
  139. set_target_properties(plplotf77c${LIB_TAG}
  140. PROPERTIES
  141. SOVERSION ${plplotf77_SOVERSION}
  142. VERSION ${plplotf77_VERSION}
  143. INSTALL_NAME_DIR "${LIB_DIR}"
  144. )
  145. endif(USE_RPATH)
  146. # Set the path and the suffix for the (shared) libraries
  147. if(CYGWIN)
  148. if(BUILD_SHARED_LIBS)
  149. set(SHLIB_DIR "${BIN_DIR}")
  150. endif(BUILD_SHARED_LIBS)
  151. set(VERSION_SUFFIX "-${plplotf77_VERSION}")
  152. else(CYGWIN)
  153. set(VERSION_SUFFIX "")
  154. endif(CYGWIN)
  155. install(TARGETS plplotf77c${LIB_TAG}
  156. EXPORT export_plplot
  157. ARCHIVE DESTINATION ${LIB_DIR}
  158. LIBRARY DESTINATION ${LIB_DIR}
  159. RUNTIME DESTINATION ${BIN_DIR}
  160. )
  161. ## Build fortran part of F77 bindings
  162. if(STATIC_OPTS)
  163. # Put the file configurable.f in a separate static library
  164. set(plplotf77opts${LIB_TAG}_LIB_SRCS
  165. configurable.f
  166. )
  167. set(plplotf77${LIB_TAG}_LIB_SRCS
  168. strutil.f
  169. sfstubs.f
  170. )
  171. else(STATIC_OPTS)
  172. set(plplotf77${LIB_TAG}_LIB_SRCS
  173. strutil.f
  174. sfstubs.f
  175. configurable.f
  176. )
  177. endif(STATIC_OPTS)
  178. if(WIN32 AND BUILD_SHARED_LIBS AND NOT CYGWIN AND NOT MINGW)
  179. SET(plplotf77${LIB_TAG}_LIB_SRCS ${plplotf77${LIB_TAG}_LIB_SRCS} plplotf77${DEFFILE}.def)
  180. endif(WIN32 AND BUILD_SHARED_LIBS AND NOT CYGWIN AND NOT MINGW)
  181. add_library(plplotf77${LIB_TAG} ${plplotf77${LIB_TAG}_LIB_SRCS})
  182. if(STATIC_OPTS)
  183. add_library(plplotf77opts${LIB_TAG} STATIC ${plplotf77opts${LIB_TAG}_LIB_SRCS})
  184. target_link_libraries(plplotf77${LIB_TAG} plplotf77c${LIB_TAG})
  185. target_link_libraries(plplotf77opts${LIB_TAG} plplotf77${LIB_TAG} plplotf77c${LIB_TAG})
  186. else(STATIC_OPTS)
  187. target_link_libraries(plplotf77${LIB_TAG} plplotf77c${LIB_TAG})
  188. endif(STATIC_OPTS)
  189. if(USE_RPATH)
  190. set_target_properties(plplotf77${LIB_TAG}
  191. PROPERTIES
  192. SOVERSION ${plplotf77_SOVERSION}
  193. VERSION ${plplotf77_VERSION}
  194. INSTALL_RPATH "${LIB_INSTALL_RPATH}"
  195. INSTALL_NAME_DIR "${LIB_DIR}"
  196. )
  197. else(USE_RPATH)
  198. set_target_properties(plplotf77${LIB_TAG}
  199. PROPERTIES
  200. SOVERSION ${plplotf77_SOVERSION}
  201. VERSION ${plplotf77_VERSION}
  202. INSTALL_NAME_DIR "${LIB_DIR}"
  203. )
  204. endif(USE_RPATH)
  205. install(TARGETS plplotf77${LIB_TAG}
  206. EXPORT export_plplot
  207. ARCHIVE DESTINATION ${LIB_DIR}
  208. LIBRARY DESTINATION ${LIB_DIR}
  209. RUNTIME DESTINATION ${BIN_DIR}
  210. )
  211. if(STATIC_OPTS)
  212. install(TARGETS plplotf77opts${LIB_TAG}
  213. EXPORT export_plplot
  214. ARCHIVE DESTINATION ${LIB_DIR}
  215. LIBRARY DESTINATION ${LIB_DIR}
  216. RUNTIME DESTINATION ${BIN_DIR}
  217. )
  218. endif(STATIC_OPTS)
  219. # Configure pkg-config *.pc file corresponding to libplplotf77${LIB_TAG}
  220. if(PKG_CONFIG_EXECUTABLE)
  221. if(LIB_TAG)
  222. set(PC_PRECISION "double")
  223. else(LIB_TAG)
  224. set(PC_PRECISION "single")
  225. endif(LIB_TAG)
  226. # Each list element must consist of a colon-separated string with the
  227. # following fields which are parsed out in the foreach loop below and
  228. # used to configure the corresponding pkg-config *.pc file.
  229. # BINDING - ENABLE_${BINDING} keeps track of whether a
  230. # binding has been enabled (ON) or not (OFF).
  231. # Also, ${BINDING} used to determine PC_FILE_SUFFIX
  232. # which helps to determine name of configured
  233. # *.pc file.
  234. # PC_SHORT_NAME - Used in *.pc NAME: field
  235. # PC_LONG_NAME - Used in *.pc Description: field
  236. # PC_LIBRARY_NAME - Used in *.pc Libs: field
  237. # Also used to determine PC_LINK_FLAGS and
  238. # PC_COMPILE_FLAGS used in *.pc Libs: and Cflags:
  239. # fields.
  240. set(PC_DATA "f77:F77:F77 bindings, :plplotf77${LIB_TAG}${VERSION_SUFFIX}")
  241. string(REGEX REPLACE "^(.*):.*:.*:.*$" "\\1" BINDING ${PC_DATA})
  242. set(PC_FILE_SUFFIX "-${BINDING}")
  243. set(PC_REQUIRES "plplot${LIB_TAG}")
  244. string(REGEX REPLACE "^.*:(.*):.*:.*$" "\\1" PC_SHORT_NAME ${PC_DATA})
  245. string(REGEX REPLACE "^.*:.*:(.*):.*$" "\\1" PC_LONG_NAME ${PC_DATA})
  246. string(REGEX REPLACE "^.*:.*:.*:(.*)$" "\\1" PC_LIBRARY_NAME ${PC_DATA})
  247. set(PC_LINK_FLAGS "${lib${PC_LIBRARY_NAME}_LINK_FLAGS}")
  248. set(PC_COMPILE_FLAGS "${lib${PC_LIBRARY_NAME}_COMPILE_FLAGS}")
  249. set(PC_COMPILE_FLAGS "-I${F77_INCLUDE_DIR} ${PC_COMPILE_FLAGS}")
  250. set(PC_LINK_FLAGS
  251. "-l${PC_LIBRARY_NAME} -lplplotf77c${LIB_TAG}${VERSION_SUFFIX} ${PC_LINK_FLAGS}"
  252. )
  253. set(PC_CONFIGURED_FILE
  254. ${CMAKE_BINARY_DIR}/pkgcfg/plplot${LIB_TAG}${PC_FILE_SUFFIX}.pc
  255. )
  256. configure_file(
  257. ${CMAKE_SOURCE_DIR}/pkgcfg/plplot-template.pc.cmake
  258. ${PC_CONFIGURED_FILE}
  259. @ONLY
  260. )
  261. install(FILES ${PC_CONFIGURED_FILE} DESTINATION ${PKG_CONFIG_DIR})
  262. endif(PKG_CONFIG_EXECUTABLE)
  263. endif(ENABLE_f77)