1313# along with this program; if not, write to the Free Software
1414# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1515
16- # Creates a project to build plugin either as static or shared library
17- # Parameters:
18- # plugin - storage engine name.
19- # variable BUILD_TYPE should be set to "STATIC" or "DYNAMIC"
20- # Remarks:
21- # ${PLUGIN}_SOURCES variable containing source files to produce the
22- # library must set before calling this macro
2316
24- MACRO (MYSQL_PLUGIN plugin )
17+ GET_FILENAME_COMPONENT (MYSQL_CMAKE_SCRIPT_DIR ${CMAKE_CURRENT_LIST_FILE} PATH )
18+ INCLUDE (${MYSQL_CMAKE_SCRIPT_DIR} /cmake_parse_arguments.cmake )
19+
20+ # MYSQL_ADD_PLUGIN(plugin_name source1...sourceN
21+ # [STORAGE_ENGINE]
22+ # [MANDATORY|DEFAULT]
23+ # [STATIC_ONLY|DYNAMIC_ONLY]
24+ # [MODULE_OUTPUT_NAME module_name]
25+ # [STATIC_OUTPUT_NAME static_name]
26+ # [RECOMPILE_FOR_EMBEDDED]
27+ # [LINK_LIBRARIES lib1...libN]
28+ # [DEPENDENCIES target1...targetN]
29+
30+ MACRO (MYSQL_ADD_PLUGIN )
31+ CMAKE_PARSE_ARGUMENTS (ARG
32+ "LINK_LIBRARIES;DEPENDENCIES;MODULE_OUTPUT_NAME;STATIC_OUTPUT_NAME"
33+ "STORAGE_ENGINE;STATIC_ONLY;MODULE_ONLY;MANDATORY;DEFAULT;DISABLED;RECOMPILE_FOR_EMBEDDED"
34+ ${ARGN}
35+ )
36+
2537 # Add common include directories
2638 INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR} /include
2739 ${CMAKE_SOURCE_DIR} /sql
2840 ${CMAKE_SOURCE_DIR} /regex
2941 ${SSL_INCLUDE_DIRS}
3042 ${ZLIB_INCLUDE_DIR} )
3143
44+ LIST (GET ARG_DEFAULT_ARGS 0 plugin)
45+ SET (SOURCES ${ARG_DEFAULT_ARGS} )
46+ LIST (REMOVE_AT SOURCES 0)
3247 STRING (TOUPPER ${plugin} plugin)
3348 STRING (TOLOWER ${plugin} target)
34-
35- IF (NOT ${plugin} _PLUGIN_STATIC AND NOT ${plugin} _PLUGIN_DYNAMIC)
36- MESSAGE (FATAL_ERROR
37- "Neither ${plugin} _PLUGIN_STATIC nor ${plugin} _PLUGIN_DYNAMIC is defined.
38- Please set at least one of these variables to the name of the output
39- library in CMakeLists.txt prior to calling MYSQL_PLUGIN"
40- )
41- ENDIF ()
4249
50+ # Figure out whether to build plugin
4351 IF (WITH_PLUGIN_${plugin} )
4452 SET (WITH_${plugin} 1)
4553 ENDIF ()
4654
47- IF (WITH_${plugin} _STORAGE_ENGINE OR WITH_{$plugin} OR WITH_ALL
48- OR WITH_MAX AND NOT WITHOUT_${plugin} _STORAGE_ENGINE AND NOT
49- WITHOUT_${plugin} )
55+ IF (WITH_${plugin} _STORAGE_ENGINE
56+ OR WITH_{$plugin}
57+ OR WITH_ALL
58+ OR WITH_MAX
59+ OR ARG_DEFAULT
60+ AND NOT WITHOUT_${plugin} _STORAGE_ENGINE
61+ AND NOT WITHOUT_${plugin}
62+ AND NOT ARG_MODULE_ONLY)
63+
5064 SET (WITH_${plugin} 1)
5165 ELSEIF (WITHOUT_${plugin} _STORAGE_ENGINE OR WITH_NONE OR ${plugin} _DISABLED)
5266 SET (WITHOUT_${plugin} 1)
5367 SET (WITH_${plugin} _STORAGE_ENGINE 0)
5468 SET (WITH_${plugin} 0)
5569 ENDIF ()
56-
57- IF (${plugin} _PLUGIN_MANDATORY)
58- SET (WITH_${plugin} 1)
59- ENDIF ()
6070
61- IF (${plugin} MATCHES NDBCLUSTER AND WITH_MAX_NO_NDB)
62- SET (WITH_${plugin} 0)
63- SET (WITH_${plugin} _STORAGE_ENGINE 0)
64- SET (WITHOUT_${plugin} 1)
65- SET (WITHOUT_${plugin} _STORAGE_ENGINE 0)
71+
72+ IF (ARG_MANDATORY)
73+ SET (WITH_${plugin} 1)
6674 ENDIF ()
75+
6776
68- IF (STORAGE_ENGINE )
69- SET (with_var "WITH_${plugin} _STORAGE_ENGINE" )
77+ IF (ARG_STORAGE_ENGINE )
78+ SET (with_var "WITH_${plugin} _STORAGE_ENGINE" )
7079 ELSE ()
71- SET (with_var "WITH_${plugin} " )
80+ SET (with_var "WITH_${plugin} " )
7281 ENDIF ()
7382
74-
75- IF (WITH_${plugin} AND ${plugin} _PLUGIN_STATIC)
76- ADD_DEFINITIONS (-DMYSQL_SERVER )
77- #Create static library.
78- ADD_LIBRARY (${target} ${${plugin}_SOURCES} )
79- DTRACE_INSTRUMENT (${target} )
80- ADD_DEPENDENCIES (${target} GenError )
81- IF (WITH_EMBEDDED_SERVER AND NOT ${plugin} _PLUGIN_DYNAMIC)
82- # Recompile couple of plugins for embedded
83- ADD_LIBRARY (${target} _embedded ${${plugin}_SOURCES} )
84- DTRACE_INSTRUMENT (${target} _embedded )
85- SET_TARGET_PROPERTIES (${target} _embedded
86- PROPERTIES COMPILE_DEFINITIONS "EMBEDDED_LIBRARY" )
87- ADD_DEPENDENCIES (${target} _embedded GenError )
88- ENDIF ()
89- IF (${plugin} _LIBS)
90- TARGET_LINK_LIBRARIES (${target} ${${plugin}_LIBS} )
83+ IF (NOT ARG_DEPENDENCIES)
84+ SET (ARG_DEPENDENCIES)
85+ ENDIF ()
86+ # Build either static library or module
87+ IF (WITH_${plugin} AND NOT ARG_MODULE_ONLY)
88+ ADD_LIBRARY (${target} STATIC ${SOURCES} )
89+ SET_TARGET_PROPERTIES (${target} PROPERTIES COMPILE_DEFINITONS "MYSQL_SERVER" )
90+ DTRACE_INSTRUMENT (${target} )
91+ ADD_DEPENDENCIES (${target} GenError ${ARG_DEPENDENCIES} )
92+ IF (WITH_EMBEDDED_SERVER)
93+ # Embedded library should contain PIC code and be linkable
94+ # to shared libraries (on systems that need PIC)
95+ IF (ARG_RECOMPILE_FOR_EMBEDDED OR NOT _SKIP_PIC)
96+ # Recompile some plugins for embedded
97+ ADD_CONVENIENCE_LIBRARY (${target} _embedded ${SOURCES} )
98+ DTRACE_INSTRUMENT (${target} _embedded )
99+ IF (ARG_RECOMPILE_FOR_EMBEDDED)
100+ SET_TARGET_PROPERTIES (${target} _embedded
101+ PROPERTIES COMPILE_DEFINITIONS "MYSQL_SERVER;EMBEDDED_LIBRARY" )
102+ ENDIF ()
103+ ADD_DEPENDENCIES (${target} _embedded GenError )
104+ ENDIF ()
91105 ENDIF ()
92106
93- SET_TARGET_PROPERTIES (${target} PROPERTIES
94- OUTPUT_NAME "${${plugin} _PLUGIN_STATIC}" )
107+ IF (ARG_STATIC_OUTPUT_NAME)
108+ SET_TARGET_PROPERTIES (${target} PROPERTIES
109+ OUTPUT_NAME ${ARG_STATIC_OUTPUT_NAME} )
110+ ENDIF ()
111+
95112 # Update mysqld dependencies
96113 SET (MYSQLD_STATIC_PLUGIN_LIBS ${MYSQLD_STATIC_PLUGIN_LIBS}
97- ${target} PARENT_SCOPE )
114+ ${target} CACHE INTERNAL "" )
115+
98116 SET (mysql_plugin_defs "${mysql_plugin_defs} ,builtin_${target} _plugin"
99- PARENT_SCOPE )
100- SET (${with_var} ON CACHE BOOL "Link ${plugin} statically to the server"
101- FORCE )
102-
103- ELSEIF (NOT WITHOUT_${plugin} AND ${plugin} _PLUGIN_DYNAMIC
104- AND NOT WITHOUT_DYNAMIC_PLUGINS)
105-
106- # Create a shared module.
107- ADD_DEFINITIONS (-DMYSQL_DYNAMIC_PLUGIN )
108- ADD_LIBRARY (${target} MODULE ${${plugin}_SOURCES} )
109- IF (${plugin} _LIBS)
110- TARGET_LINK_LIBRARIES (${target} ${${plugin}_LIBS} )
111- ENDIF ()
112- DTRACE_INSTRUMENT (${target} )
113- SET_TARGET_PROPERTIES (${target} PROPERTIES PREFIX "" )
117+ PARENT_SCOPE )
118+ IF (ARG_STORAGE_ENGINE)
119+ SET (${with_var} ON CACHE BOOL "Link ${plugin} statically to the server"
120+ FORCE )
121+ ENDIF ()
122+ ELSEIF (NOT WITHOUT_${plugin} AND NOT ARG_STATIC_ONLY AND NOT WITHOUT_DYNAMIC_PLUGINS)
123+
124+ ADD_LIBRARY (${target} MODULE ${SOURCES} )
125+ DTRACE_INSTRUMENT (${target} )
126+ SET_TARGET_PROPERTIES (${target} PROPERTIES PREFIX ""
127+ COMPILE_DEFINITIONS "MYSQL_DYNAMIC_PLUGIN" )
114128 TARGET_LINK_LIBRARIES (${target} mysqlservices )
115-
116129 # Plugin uses symbols defined in mysqld executable.
117130 # Some operating systems like Windows and OSX and are pretty strict about
118131 # unresolved symbols. Others are less strict and allow unresolved symbols
@@ -121,41 +134,26 @@ MACRO(MYSQL_PLUGIN plugin)
121134 # Thus we skip TARGET_LINK_LIBRARIES on Linux, as it would only generate
122135 # an additional dependency.
123136 IF (NOT CMAKE_SYSTEM_NAME STREQUAL "Linux" )
124- TARGET_LINK_LIBRARIES (${target} mysqld )
125- ENDIF ()
126- ADD_DEPENDENCIES (${target} GenError )
127-
128- IF (${plugin} _PLUGIN_DYNAMIC)
129- SET_TARGET_PROPERTIES (${target} PROPERTIES
130- OUTPUT_NAME "${${plugin} _PLUGIN_DYNAMIC}" )
137+ TARGET_LINK_LIBRARIES (${target} mysqld ${ARG_LINK_LIBRARIES} )
131138 ENDIF ()
132-
133- # Update cache "WITH" variable for plugins that support static linking
134- IF (${plugin} _PLUGIN_STATIC)
135- SET (${with_var} OFF CACHE BOOL "Link ${plugin} statically to the server"
136- FORCE )
139+ ADD_DEPENDENCIES (${target} GenError ${ARG_DEPENDENCIES} )
140+
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 ()
137147 ENDIF ()
138-
148+ SET_TARGET_PROPERTIES (${target} PROPERTIES
149+ OUTPUT_NAME "${ARG_MODULE_OUTPUT_NAME} " )
139150 # Install dynamic library
140151 SET (INSTALL_LOCATION lib/plugin)
141152 INSTALL (TARGETS ${target} DESTINATION ${INSTALL_LOCATION} )
142153 INSTALL_DEBUG_SYMBOLS (${target} )
143- ELSE ()
144- IF (STORAGE_ENGINE)
145- SET (without_var "WITHOUT_${plugin} _STORAGE_ENGINE" )
146- ELSE ()
147- SET (without_var "WITHOUT_${plugin} " )
148- ENDIF ()
149- SET (${without_var} ON CACHE BOOL "Link ${plugin} statically to the server"
150- FORCE )
151- MARK_AS_ADVANCED (${without_var} )
152154 ENDIF ()
153155ENDMACRO ()
154156
155- MACRO (MYSQL_STORAGE_ENGINE engine )
156- SET (STORAGE_ENGINE 1)
157- MYSQL_PLUGIN (${engine} )
158- ENDMACRO ()
159157
160158# Add all CMake projects under storage and plugin
161159# subdirectories, configure sql_builtins.cc
@@ -167,12 +165,4 @@ MACRO(CONFIGURE_PLUGINS)
167165 ADD_SUBDIRECTORY (${dir} )
168166 ENDIF ()
169167 ENDFOREACH ()
170- # Special handling for partition(not really pluggable)
171- IF (NOT WITHOUT_PARTITION_STORAGE_ENGINE)
172- SET (WITH_PARTITION_STORAGE_ENGINE 1)
173- SET (mysql_plugin_defs "${mysql_plugin_defs} ,builtin_partition_plugin" )
174- ENDIF (NOT WITHOUT_PARTITION_STORAGE_ENGINE )
175- ADD_DEFINITIONS (${STORAGE_ENGINE_DEFS} )
176- CONFIGURE_FILE (${CMAKE_SOURCE_DIR} /sql/sql_builtin.cc.in
177- ${CMAKE_BINARY_DIR} /sql/sql_builtin.cc )
178168ENDMACRO ()
0 commit comments