PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/bindings/f95/CMakeLists.txt

#
CMake | 243 lines | 160 code | 26 blank | 57 comment | 12 complexity | 7e813b2956d9be62e6c0bd8774ec2bf1 MD5 | raw file
Possible License(s): LGPL-2.0, BSD-3-Clause-No-Nuclear-License-2014, Apache-2.0, GPL-2.0
  1. # bindings/f95/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_f95)
  21. # Set the include path
  22. include_directories(
  23. ${CMAKE_SOURCE_DIR}/include
  24. ${CMAKE_SOURCE_DIR}/lib/qsastime
  25. ${CMAKE_BINARY_DIR}
  26. ${CMAKE_BINARY_DIR}/include
  27. ${CMAKE_CURRENT_SOURCE_DIR}
  28. ${CMAKE_CURRENT_BINARY_DIR}
  29. )
  30. # Configure the Fortran include file that specifies the kind of
  31. # floating-point (single vs double) PLplot supports.
  32. if(PL_DOUBLE)
  33. set(ONE_IN_DEFAULT_PRECISION "1.0d0")
  34. else(PL_DOUBLE)
  35. set(ONE_IN_DEFAULT_PRECISION "1.0")
  36. endif(PL_DOUBLE)
  37. configure_file(
  38. ${CMAKE_CURRENT_SOURCE_DIR}/plflt.inc.in
  39. ${CMAKE_CURRENT_BINARY_DIR}/plflt.inc
  40. @ONLY
  41. )
  42. ## Build C part of F95 bindings
  43. if(WIN32)
  44. # Set the flags for the C compiler. The C stubs need to have the
  45. # correct case and calling convention for the Fortran compiler
  46. IF(TARGET_FORTRAN MATCHES "IVF")
  47. SET(DEFFILE "_ifort")
  48. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DIVF")
  49. ELSEIF(TARGET_FORTRAN MATCHES "CVF")
  50. SET(DEFFILE "")
  51. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DCVF")
  52. ENDIF(TARGET_FORTRAN MATCHES "IVF")
  53. endif(WIN32)
  54. set(plplotf95c${LIB_TAG}_LIB_SRCS
  55. sc3d.c
  56. sccont.c
  57. scstubs.c
  58. )
  59. if(BUILD_SHARED_LIBS)
  60. SET_SOURCE_FILES_PROPERTIES(${plplotf95c${LIB_TAG}_LIB_SRCS}
  61. PROPERTIES COMPILE_FLAGS "-DUSINGDLL" )
  62. endif(BUILD_SHARED_LIBS)
  63. add_library(plplotf95c${LIB_TAG} ${plplotf95c${LIB_TAG}_LIB_SRCS})
  64. target_link_libraries(plplotf95c${LIB_TAG} plplot${LIB_TAG})
  65. if(USE_RPATH)
  66. get_target_property(LIB_INSTALL_RPATH plplot${LIB_TAG} INSTALL_RPATH)
  67. set_target_properties(plplotf95c${LIB_TAG}
  68. PROPERTIES
  69. SOVERSION ${plplotf95_SOVERSION}
  70. VERSION ${plplotf95_VERSION}
  71. INSTALL_RPATH "${LIB_INSTALL_RPATH}"
  72. INSTALL_NAME_DIR "${LIB_DIR}"
  73. )
  74. else(USE_RPATH)
  75. set_target_properties(plplotf95c${LIB_TAG}
  76. PROPERTIES
  77. SOVERSION ${plplotf95_SOVERSION}
  78. VERSION ${plplotf95_VERSION}
  79. INSTALL_NAME_DIR "${LIB_DIR}"
  80. )
  81. endif(USE_RPATH)
  82. install(TARGETS plplotf95c${LIB_TAG}
  83. EXPORT export_plplot
  84. ARCHIVE DESTINATION ${LIB_DIR}
  85. LIBRARY DESTINATION ${LIB_DIR}
  86. RUNTIME DESTINATION ${BIN_DIR}
  87. )
  88. # Build fortran part of F95 bindings.
  89. # Notes:
  90. # configurable.f90 is actually not currently configurable.
  91. # The CMake Fortran dependency scanner finds the Fortran include
  92. # file, sfstub.h, and the configured Fortran include file,
  93. # ${CMAKE_CURRENT_BINARY_DIR}/plflt.inc, and also deals properly with
  94. # the dependencies on those files. Therefore, there is no need to
  95. # include those files in the SRCS list or do anything special with
  96. # their dependencies.
  97. # Check consistency of plplot_parameters.h.
  98. add_custom_target(
  99. check_f95_parameters
  100. COMMAND ${CMAKE_COMMAND} -E remove -f
  101. ${CMAKE_CURRENT_BINARY_DIR}/plplot_parameters.h_compare
  102. COMMAND
  103. sed -f ${CMAKE_CURRENT_SOURCE_DIR}/global_defines.sed <
  104. ${CMAKE_SOURCE_DIR}/bindings/swig-support/plplotcapi.i >
  105. ${CMAKE_CURRENT_BINARY_DIR}/plplot_parameters.h_compare
  106. COMMAND
  107. ${CMAKE_COMMAND} -E echo "Check that plplot_parameters.h is consistent with the #defines in bindings/swig-support/plplotcapi.i"
  108. COMMAND
  109. cmp ${CMAKE_CURRENT_SOURCE_DIR}/plplot_parameters.h
  110. ${CMAKE_CURRENT_BINARY_DIR}/plplot_parameters.h_compare
  111. )
  112. set(plplotf95${LIB_TAG}_LIB_SRCS
  113. strutil.f90
  114. configurable.f90
  115. sfstubsf95.f90
  116. )
  117. if(WIN32 AND BUILD_SHARED_LIBS AND NOT MINGW AND NOT CYGWIN)
  118. SET(plplotf95${LIB_TAG}_LIB_SRCS ${plplotf95${LIB_TAG}_LIB_SRCS} plplotf95${DEFFILE}.def)
  119. endif(WIN32 AND BUILD_SHARED_LIBS AND NOT MINGW AND NOT CYGWIN)
  120. add_library(plplotf95${LIB_TAG} ${plplotf95${LIB_TAG}_LIB_SRCS})
  121. if(NON_TRANSITIVE)
  122. # empty list ==> non-transitive linking for everything that links to
  123. # libplplotf95cd and libplplotf95d in the shared libraries case.
  124. target_link_libraries(plplotf95c${LIB_TAG} LINK_INTERFACE_LIBRARIES)
  125. target_link_libraries(plplotf95${LIB_TAG} LINK_INTERFACE_LIBRARIES)
  126. # This configures the pkg-config method to use non-transitive linking.
  127. set(PC_REQUIRES_TAG "Requires.private")
  128. else(NON_TRANSITIVE)
  129. # This configures the pkg-config method to use transitive linking
  130. set(PC_REQUIRES_TAG "Requires")
  131. endif(NON_TRANSITIVE)
  132. target_link_libraries(plplotf95${LIB_TAG} plplotf95c${LIB_TAG})
  133. if(USE_RPATH)
  134. set_target_properties(plplotf95${LIB_TAG}
  135. PROPERTIES
  136. SOVERSION ${plplotf95_SOVERSION}
  137. VERSION ${plplotf95_VERSION}
  138. INSTALL_RPATH "${LIB_INSTALL_RPATH}"
  139. INSTALL_NAME_DIR "${LIB_DIR}"
  140. )
  141. else(USE_RPATH)
  142. set_target_properties(plplotf95${LIB_TAG}
  143. PROPERTIES
  144. SOVERSION ${plplotf95_SOVERSION}
  145. VERSION ${plplotf95_VERSION}
  146. INSTALL_NAME_DIR "${LIB_DIR}"
  147. )
  148. endif(USE_RPATH)
  149. # Set the path and the suffix for the (shared) libraries
  150. if(CYGWIN)
  151. if(BUILD_SHARED_LIBS)
  152. set(SHLIB_DIR "${BIN_DIR}")
  153. endif(BUILD_SHARED_LIBS)
  154. set(VERSION_SUFFIX "-${plplotf95_VERSION}")
  155. else(CYGWIN)
  156. set(VERSION_SUFFIX "")
  157. endif(CYGWIN)
  158. install(TARGETS plplotf95${LIB_TAG}
  159. EXPORT export_plplot
  160. ARCHIVE DESTINATION ${LIB_DIR}
  161. LIBRARY DESTINATION ${LIB_DIR}
  162. RUNTIME DESTINATION ${BIN_DIR}
  163. )
  164. # For CMake-2.6.0 and above, the module files are created by
  165. # default during the library build in the bindings/f95 directory.
  166. install(
  167. FILES
  168. ${CMAKE_BINARY_DIR}/bindings/f95/plplot.mod
  169. ${CMAKE_BINARY_DIR}/bindings/f95/plplotp.mod
  170. ${CMAKE_BINARY_DIR}/bindings/f95/plplot_flt.mod
  171. DESTINATION ${F95_MOD_DIR}
  172. )
  173. # Configure pkg-config *.pc file corresponding to libplplotf95${LIB_TAG}
  174. if(PKG_CONFIG_EXECUTABLE)
  175. if(LIB_TAG)
  176. set(PC_PRECISION "double")
  177. else(LIB_TAG)
  178. set(PC_PRECISION "single")
  179. endif(LIB_TAG)
  180. # Each list element must consist of a colon-separated string with the
  181. # following fields which are parsed out in the foreach loop below and
  182. # used to configure the corresponding pkg-config *.pc file.
  183. # BINDING - ENABLE_${BINDING} keeps track of whether a
  184. # binding has been enabled (ON) or not (OFF).
  185. # Also, ${BINDING} used to determine PC_FILE_SUFFIX
  186. # which helps to determine name of configured
  187. # *.pc file.
  188. # PC_SHORT_NAME - Used in *.pc NAME: field
  189. # PC_LONG_NAME - Used in *.pc Description: field
  190. # PC_LIBRARY_NAME - Used in *.pc Libs: field
  191. # Also used to determine PC_LINK_FLAGS and
  192. # PC_COMPILE_FLAGS used in *.pc Libs: and Cflags:
  193. # fields.
  194. set(PC_DATA "f95:F95:F95 bindings, :plplotf95${LIB_TAG}${VERSION_SUFFIX}")
  195. string(REGEX REPLACE "^(.*):.*:.*:.*$" "\\1" BINDING ${PC_DATA})
  196. set(PC_FILE_SUFFIX "-${BINDING}")
  197. set(PC_REQUIRES "plplot${LIB_TAG}")
  198. string(REGEX REPLACE "^.*:(.*):.*:.*$" "\\1" PC_SHORT_NAME ${PC_DATA})
  199. string(REGEX REPLACE "^.*:.*:(.*):.*$" "\\1" PC_LONG_NAME ${PC_DATA})
  200. string(REGEX REPLACE "^.*:.*:.*:(.*)$" "\\1" PC_LIBRARY_NAME ${PC_DATA})
  201. set(PC_LINK_FLAGS "${lib${PC_LIBRARY_NAME}_LINK_FLAGS}")
  202. set(PC_COMPILE_FLAGS "${lib${PC_LIBRARY_NAME}_COMPILE_FLAGS}")
  203. set(PC_LINK_FLAGS
  204. "-l${PC_LIBRARY_NAME} -lplplotf95c${LIB_TAG}${VERSION_SUFFIX} ${PC_LINK_FLAGS}"
  205. )
  206. set(PC_COMPILE_FLAGS "-I${F95_MOD_DIR} ${PC_COMPILE_FLAGS}")
  207. set(PC_CONFIGURED_FILE
  208. ${CMAKE_BINARY_DIR}/pkgcfg/plplot${LIB_TAG}${PC_FILE_SUFFIX}.pc
  209. )
  210. configure_file(
  211. ${CMAKE_SOURCE_DIR}/pkgcfg/plplot-template.pc.cmake
  212. ${PC_CONFIGURED_FILE}
  213. @ONLY
  214. )
  215. install(FILES ${PC_CONFIGURED_FILE} DESTINATION ${PKG_CONFIG_DIR})
  216. endif(PKG_CONFIG_EXECUTABLE)
  217. endif(ENABLE_f95)