You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
8.3 KiB

16 years ago
  1. # Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; version 2 of the License.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program; if not, write to the Free Software
  14. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. GET_FILENAME_COMPONENT(MYSQL_CMAKE_SCRIPT_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
  16. INCLUDE(${MYSQL_CMAKE_SCRIPT_DIR}/cmake_parse_arguments.cmake)
  17. # MYSQL_ADD_PLUGIN(plugin_name source1...sourceN
  18. # [STORAGE_ENGINE]
  19. # [MANDATORY|DEFAULT]
  20. # [STATIC_ONLY|DYNAMIC_ONLY]
  21. # [MODULE_OUTPUT_NAME module_name]
  22. # [STATIC_OUTPUT_NAME static_name]
  23. # [RECOMPILE_FOR_EMBEDDED]
  24. # [LINK_LIBRARIES lib1...libN]
  25. # [DEPENDENCIES target1...targetN]
  26. # Append collections files for the plugin to the common files
  27. # Make sure we don't copy twice if running cmake again
  28. MACRO(PLUGIN_APPEND_COLLECTIONS plugin)
  29. SET(fcopied "${CMAKE_CURRENT_SOURCE_DIR}/tests/collections/FilesCopied")
  30. IF(NOT EXISTS ${fcopied})
  31. FILE(GLOB collections ${CMAKE_CURRENT_SOURCE_DIR}/tests/collections/*)
  32. FOREACH(cfile ${collections})
  33. FILE(READ ${cfile} contents)
  34. GET_FILENAME_COMPONENT(fname ${cfile} NAME)
  35. FILE(APPEND ${CMAKE_SOURCE_DIR}/mysql-test/collections/${fname} "${contents}")
  36. FILE(APPEND ${fcopied} "${fname}\n")
  37. MESSAGE(STATUS "Appended ${cfile}")
  38. ENDFOREACH()
  39. ENDIF()
  40. ENDMACRO()
  41. MACRO(MYSQL_ADD_PLUGIN)
  42. MYSQL_PARSE_ARGUMENTS(ARG
  43. "LINK_LIBRARIES;DEPENDENCIES;MODULE_OUTPUT_NAME;STATIC_OUTPUT_NAME"
  44. "STORAGE_ENGINE;STATIC_ONLY;MODULE_ONLY;MANDATORY;DEFAULT;DISABLED;RECOMPILE_FOR_EMBEDDED"
  45. ${ARGN}
  46. )
  47. # Add common include directories
  48. INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
  49. ${CMAKE_SOURCE_DIR}/sql
  50. ${CMAKE_SOURCE_DIR}/regex
  51. ${SSL_INCLUDE_DIRS}
  52. ${ZLIB_INCLUDE_DIR})
  53. LIST(GET ARG_DEFAULT_ARGS 0 plugin)
  54. SET(SOURCES ${ARG_DEFAULT_ARGS})
  55. LIST(REMOVE_AT SOURCES 0)
  56. STRING(TOUPPER ${plugin} plugin)
  57. STRING(TOLOWER ${plugin} target)
  58. # Figure out whether to build plugin
  59. IF(WITH_PLUGIN_${plugin})
  60. SET(WITH_${plugin} 1)
  61. ENDIF()
  62. IF(WITH_MAX_NO_NDB)
  63. SET(WITH_MAX 1)
  64. SET(WITHOUT_NDBCLUSTER 1)
  65. ENDIF()
  66. IF(ARG_DEFAULT)
  67. IF(NOT DEFINED WITH_${plugin} AND
  68. NOT DEFINED WITH_${plugin}_STORAGE_ENGINE)
  69. SET(WITH_${plugin} 1)
  70. ENDIF()
  71. ENDIF()
  72. IF(WITH_${plugin}_STORAGE_ENGINE
  73. OR WITH_{$plugin}
  74. OR WITH_ALL
  75. OR WITH_MAX
  76. AND NOT WITHOUT_${plugin}_STORAGE_ENGINE
  77. AND NOT WITHOUT_${plugin}
  78. AND NOT ARG_MODULE_ONLY)
  79. SET(WITH_${plugin} 1)
  80. ELSEIF(WITHOUT_${plugin}_STORAGE_ENGINE OR WITH_NONE OR ${plugin}_DISABLED)
  81. SET(WITHOUT_${plugin} 1)
  82. SET(WITH_${plugin}_STORAGE_ENGINE 0)
  83. SET(WITH_${plugin} 0)
  84. ENDIF()
  85. IF(ARG_MANDATORY)
  86. SET(WITH_${plugin} 1)
  87. ENDIF()
  88. IF(ARG_STORAGE_ENGINE)
  89. SET(with_var "WITH_${plugin}_STORAGE_ENGINE" )
  90. ELSE()
  91. SET(with_var "WITH_${plugin}")
  92. ENDIF()
  93. IF(NOT ARG_DEPENDENCIES)
  94. SET(ARG_DEPENDENCIES)
  95. ENDIF()
  96. SET(BUILD_PLUGIN 1)
  97. # Build either static library or module
  98. IF (WITH_${plugin} AND NOT ARG_MODULE_ONLY)
  99. ADD_LIBRARY(${target} STATIC ${SOURCES})
  100. SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_DEFINITONS "MYSQL_SERVER")
  101. DTRACE_INSTRUMENT(${target})
  102. ADD_DEPENDENCIES(${target} GenError ${ARG_DEPENDENCIES})
  103. IF(WITH_EMBEDDED_SERVER)
  104. # Embedded library should contain PIC code and be linkable
  105. # to shared libraries (on systems that need PIC)
  106. IF(ARG_RECOMPILE_FOR_EMBEDDED OR NOT _SKIP_PIC)
  107. # Recompile some plugins for embedded
  108. ADD_CONVENIENCE_LIBRARY(${target}_embedded ${SOURCES})
  109. DTRACE_INSTRUMENT(${target}_embedded)
  110. IF(ARG_RECOMPILE_FOR_EMBEDDED)
  111. SET_TARGET_PROPERTIES(${target}_embedded
  112. PROPERTIES COMPILE_DEFINITIONS "MYSQL_SERVER;EMBEDDED_LIBRARY")
  113. ENDIF()
  114. ADD_DEPENDENCIES(${target}_embedded GenError)
  115. ENDIF()
  116. ENDIF()
  117. IF(ARG_STATIC_OUTPUT_NAME)
  118. SET_TARGET_PROPERTIES(${target} PROPERTIES
  119. OUTPUT_NAME ${ARG_STATIC_OUTPUT_NAME})
  120. ENDIF()
  121. # Update mysqld dependencies
  122. SET (MYSQLD_STATIC_PLUGIN_LIBS ${MYSQLD_STATIC_PLUGIN_LIBS}
  123. ${target} ${ARG_LINK_LIBRARIES} CACHE INTERNAL "" FORCE)
  124. IF(ARG_MANDATORY)
  125. SET(${with_var} ON CACHE INTERNAL "Link ${plugin} statically to the server"
  126. FORCE)
  127. ELSE()
  128. SET(${with_var} ON CACHE BOOL "Link ${plugin} statically to the server"
  129. FORCE)
  130. ENDIF()
  131. IF(ARG_MANDATORY)
  132. SET (mysql_mandatory_plugins
  133. "${mysql_mandatory_plugins} builtin_${target}_plugin,"
  134. PARENT_SCOPE)
  135. ELSE()
  136. SET (mysql_optional_plugins
  137. "${mysql_optional_plugins} builtin_${target}_plugin,"
  138. PARENT_SCOPE)
  139. ENDIF()
  140. ELSEIF(NOT WITHOUT_${plugin} AND NOT ARG_STATIC_ONLY AND NOT WITHOUT_DYNAMIC_PLUGINS)
  141. IF(NOT ARG_MODULE_OUTPUT_NAME)
  142. IF(ARG_STORAGE_ENGINE)
  143. SET(ARG_MODULE_OUTPUT_NAME "ha_${target}")
  144. ELSE()
  145. SET(ARG_MODULE_OUTPUT_NAME "${target}")
  146. ENDIF()
  147. ENDIF()
  148. ADD_VERSION_INFO(${target} MODULE SOURCES)
  149. ADD_LIBRARY(${target} MODULE ${SOURCES})
  150. DTRACE_INSTRUMENT(${target})
  151. SET_TARGET_PROPERTIES (${target} PROPERTIES PREFIX ""
  152. COMPILE_DEFINITIONS "MYSQL_DYNAMIC_PLUGIN")
  153. TARGET_LINK_LIBRARIES (${target} mysqlservices)
  154. # Plugin uses symbols defined in mysqld executable.
  155. # Some operating systems like Windows and OSX and are pretty strict about
  156. # unresolved symbols. Others are less strict and allow unresolved symbols
  157. # in shared libraries. On Linux for example, CMake does not even add
  158. # executable to the linker command line (it would result into link error).
  159. # Thus we skip TARGET_LINK_LIBRARIES on Linux, as it would only generate
  160. # an additional dependency.
  161. IF(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
  162. TARGET_LINK_LIBRARIES (${target} mysqld ${ARG_LINK_LIBRARIES})
  163. ENDIF()
  164. ADD_DEPENDENCIES(${target} GenError ${ARG_DEPENDENCIES})
  165. IF(NOT ARG_MODULE_ONLY)
  166. # set cached variable, e.g with checkbox in GUI
  167. SET(${with_var} OFF CACHE BOOL "Link ${plugin} statically to the server"
  168. FORCE)
  169. ENDIF()
  170. SET_TARGET_PROPERTIES(${target} PROPERTIES
  171. OUTPUT_NAME "${ARG_MODULE_OUTPUT_NAME}")
  172. # Install dynamic library
  173. MYSQL_INSTALL_TARGETS(${target} DESTINATION ${INSTALL_PLUGINDIR} COMPONENT Server)
  174. INSTALL_DEBUG_TARGET(${target} DESTINATION ${INSTALL_PLUGINDIR}/debug)
  175. # Add installed files to list for RPMs
  176. FILE(APPEND ${CMAKE_BINARY_DIR}/support-files/plugins.files
  177. "%attr(755, root, root) %{_prefix}/${INSTALL_PLUGINDIR}/${ARG_MODULE_OUTPUT_NAME}.so\n"
  178. "%attr(755, root, root) %{_prefix}/${INSTALL_PLUGINDIR}/debug/${ARG_MODULE_OUTPUT_NAME}.so\n")
  179. # For internal testing in PB2, append collections files
  180. IF(DEFINED ENV{PB2WORKDIR})
  181. PLUGIN_APPEND_COLLECTIONS(${plugin})
  182. ENDIF()
  183. ELSE()
  184. IF(WITHOUT_${plugin})
  185. # Update cache variable
  186. STRING(REPLACE "WITH_" "WITHOUT_" without_var ${with_var})
  187. SET(${without_var} ON CACHE BOOL "Don't build ${plugin}"
  188. FORCE)
  189. ENDIF()
  190. SET(BUILD_PLUGIN 0)
  191. ENDIF()
  192. IF(BUILD_PLUGIN AND ARG_LINK_LIBRARIES)
  193. TARGET_LINK_LIBRARIES (${target} ${ARG_LINK_LIBRARIES})
  194. ENDIF()
  195. ENDMACRO()
  196. # Add all CMake projects under storage and plugin
  197. # subdirectories, configure sql_builtins.cc
  198. MACRO(CONFIGURE_PLUGINS)
  199. FILE(GLOB dirs_storage ${CMAKE_SOURCE_DIR}/storage/*)
  200. FILE(GLOB dirs_plugin ${CMAKE_SOURCE_DIR}/plugin/*)
  201. FOREACH(dir ${dirs_storage} ${dirs_plugin})
  202. IF (EXISTS ${dir}/CMakeLists.txt)
  203. ADD_SUBDIRECTORY(${dir})
  204. ENDIF()
  205. ENDFOREACH()
  206. FOREACH(dir ${dirs_plugin})
  207. IF (EXISTS ${dir}/.bzr)
  208. MESSAGE(STATUS "Found repo ${dir}/.bzr")
  209. LIST(APPEND PLUGIN_BZR_REPOS "${dir}")
  210. ENDIF()
  211. ENDFOREACH()
  212. SET(PLUGIN_REPOS "${PLUGIN_BZR_REPOS}" CACHE INTERNAL "")
  213. ENDMACRO()