PageRenderTime 58ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/bindings/f77/CMakeLists.txt

#
CMake | 278 lines | 194 code | 29 blank | 55 comment | 13 complexity | 71bcfee7643e36bb4458dfc843380166 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. set(plplotf77${LIB_TAG}_LIB_SRCS
  163. strutil.f
  164. sfstubs.f
  165. configurable.f
  166. )
  167. if(WIN32 AND BUILD_SHARED_LIBS AND NOT CYGWIN AND NOT MINGW)
  168. SET(plplotf77${LIB_TAG}_LIB_SRCS ${plplotf77${LIB_TAG}_LIB_SRCS} plplotf77${DEFFILE}.def)
  169. endif(WIN32 AND BUILD_SHARED_LIBS AND NOT CYGWIN AND NOT MINGW)
  170. add_library(plplotf77${LIB_TAG} ${plplotf77${LIB_TAG}_LIB_SRCS})
  171. if(NON_TRANSITIVE)
  172. # empty list ==> non-transitive linking for everything that links to
  173. # libplplotf77cd and libplplotf77d in the shared libraries case.
  174. target_link_libraries(plplotf77c${LIB_TAG} LINK_INTERFACE_LIBRARIES)
  175. target_link_libraries(plplotf77${LIB_TAG} LINK_INTERFACE_LIBRARIES)
  176. # This configures the pkg-config method to use non-transitive linking.
  177. set(PC_REQUIRES_TAG "Requires.private")
  178. else(NON_TRANSITIVE)
  179. # This configures the pkg-config method to use transitive linking
  180. set(PC_REQUIRES_TAG "Requires")
  181. endif(NON_TRANSITIVE)
  182. target_link_libraries(plplotf77${LIB_TAG} plplotf77c${LIB_TAG})
  183. if(USE_RPATH)
  184. set_target_properties(plplotf77${LIB_TAG}
  185. PROPERTIES
  186. SOVERSION ${plplotf77_SOVERSION}
  187. VERSION ${plplotf77_VERSION}
  188. INSTALL_RPATH "${LIB_INSTALL_RPATH}"
  189. INSTALL_NAME_DIR "${LIB_DIR}"
  190. )
  191. else(USE_RPATH)
  192. set_target_properties(plplotf77${LIB_TAG}
  193. PROPERTIES
  194. SOVERSION ${plplotf77_SOVERSION}
  195. VERSION ${plplotf77_VERSION}
  196. INSTALL_NAME_DIR "${LIB_DIR}"
  197. )
  198. endif(USE_RPATH)
  199. install(TARGETS plplotf77${LIB_TAG}
  200. EXPORT export_plplot
  201. ARCHIVE DESTINATION ${LIB_DIR}
  202. LIBRARY DESTINATION ${LIB_DIR}
  203. RUNTIME DESTINATION ${BIN_DIR}
  204. )
  205. # Configure pkg-config *.pc file corresponding to libplplotf77${LIB_TAG}
  206. if(PKG_CONFIG_EXECUTABLE)
  207. if(LIB_TAG)
  208. set(PC_PRECISION "double")
  209. else(LIB_TAG)
  210. set(PC_PRECISION "single")
  211. endif(LIB_TAG)
  212. # Each list element must consist of a colon-separated string with the
  213. # following fields which are parsed out in the foreach loop below and
  214. # used to configure the corresponding pkg-config *.pc file.
  215. # BINDING - ENABLE_${BINDING} keeps track of whether a
  216. # binding has been enabled (ON) or not (OFF).
  217. # Also, ${BINDING} used to determine PC_FILE_SUFFIX
  218. # which helps to determine name of configured
  219. # *.pc file.
  220. # PC_SHORT_NAME - Used in *.pc NAME: field
  221. # PC_LONG_NAME - Used in *.pc Description: field
  222. # PC_LIBRARY_NAME - Used in *.pc Libs: field
  223. # Also used to determine PC_LINK_FLAGS and
  224. # PC_COMPILE_FLAGS used in *.pc Libs: and Cflags:
  225. # fields.
  226. set(PC_DATA "f77:F77:F77 bindings, :plplotf77${LIB_TAG}${VERSION_SUFFIX}")
  227. string(REGEX REPLACE "^(.*):.*:.*:.*$" "\\1" BINDING ${PC_DATA})
  228. set(PC_FILE_SUFFIX "-${BINDING}")
  229. set(PC_REQUIRES "plplot${LIB_TAG}")
  230. string(REGEX REPLACE "^.*:(.*):.*:.*$" "\\1" PC_SHORT_NAME ${PC_DATA})
  231. string(REGEX REPLACE "^.*:.*:(.*):.*$" "\\1" PC_LONG_NAME ${PC_DATA})
  232. string(REGEX REPLACE "^.*:.*:.*:(.*)$" "\\1" PC_LIBRARY_NAME ${PC_DATA})
  233. set(PC_LINK_FLAGS "${lib${PC_LIBRARY_NAME}_LINK_FLAGS}")
  234. set(PC_COMPILE_FLAGS "${lib${PC_LIBRARY_NAME}_COMPILE_FLAGS}")
  235. set(PC_COMPILE_FLAGS "-I${F77_INCLUDE_DIR} ${PC_COMPILE_FLAGS}")
  236. set(PC_LINK_FLAGS
  237. "-l${PC_LIBRARY_NAME} -lplplotf77c${LIB_TAG}${VERSION_SUFFIX} ${PC_LINK_FLAGS}"
  238. )
  239. set(PC_CONFIGURED_FILE
  240. ${CMAKE_BINARY_DIR}/pkgcfg/plplot${LIB_TAG}${PC_FILE_SUFFIX}.pc
  241. )
  242. configure_file(
  243. ${CMAKE_SOURCE_DIR}/pkgcfg/plplot-template.pc.cmake
  244. ${PC_CONFIGURED_FILE}
  245. @ONLY
  246. )
  247. install(FILES ${PC_CONFIGURED_FILE} DESTINATION ${PKG_CONFIG_DIR})
  248. endif(PKG_CONFIG_EXECUTABLE)
  249. endif(ENABLE_f77)