1# Copyright (c) 2009, 2021, Oracle and/or its affiliates.
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, version 2.0,
5# as published by the Free Software Foundation.
6#
7# This program is also distributed with certain software (including
8# but not limited to OpenSSL) that is licensed under separate terms,
9# as designated in a particular file or component or in included license
10# documentation.  The authors of MySQL hereby grant you an additional
11# permission to link the program and your derivative works with the
12# separately licensed software that they have included with MySQL.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License, version 2.0, for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22
23if(APPLE)
24 LIST(APPEND CMAKE_CXX_LINK_EXECUTABLE "dsymutil <TARGET>")
25 LIST(APPEND CMAKE_C_LINK_EXECUTABLE "dsymutil <TARGET>")
26 LIST(APPEND CMAKE_CXX_CREATE_SHARED_LIBRARY "dsymutil <TARGET>")
27 LIST(APPEND CMAKE_C_CREATE_SHARED_LIBRARY "dsymutil <TARGET>")
28 LIST(APPEND CMAKE_CXX_CREATE_SHARED_MODULE "dsymutil <TARGET>")
29 LIST(APPEND CMAKE_C_CREATE_SHARED_MODULE "dsymutil <TARGET>")
30ENDIF()
31
32GET_FILENAME_COMPONENT(MYSQL_CMAKE_SCRIPT_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
33INCLUDE(${MYSQL_CMAKE_SCRIPT_DIR}/cmake_parse_arguments.cmake)
34MACRO (INSTALL_DSYM_DIRECTORIES targets)
35  IF(APPLE)
36    FOREACH(target ${targets})
37      GET_TARGET_PROPERTY(location ${target} LOCATION)
38      GET_TARGET_PROPERTY(type ${target} TYPE)
39      # It's a dirty hack, but cmake too stupid and mysql cmake files too buggy */
40      STRING(REGEX REPLACE "/liblibmysql.dylib$" "/libmysqlclient.${SHARED_LIB_MAJOR_VERSION}.dylib" location ${location})
41      IF(DEBUG_EXTNAME)
42        STRING(REGEX REPLACE "/mysqld$" "/mysqld-debug" location ${location})
43      ENDIF()
44      IF(type MATCHES "EXECUTABLE" OR type MATCHES "MODULE" OR type MATCHES "SHARED_LIBRARY")
45        INSTALL(DIRECTORY "${location}.dSYM" DESTINATION ${INSTALL_LOCATION} COMPONENT Debuginfo)
46      ENDIF()
47    ENDFOREACH()
48  ENDIF()
49ENDMACRO()
50
51# For windows: install .pdf file for each target.
52MACRO (INSTALL_DEBUG_SYMBOLS targets)
53  IF(MSVC)
54  FOREACH(target ${targets})
55    GET_TARGET_PROPERTY(type ${target} TYPE)
56    IF(NOT INSTALL_LOCATION)
57      IF(type MATCHES "STATIC_LIBRARY"
58          OR type MATCHES "MODULE_LIBRARY"
59          OR type MATCHES "SHARED_LIBRARY")
60        SET(INSTALL_LOCATION "lib")
61      ELSEIF(type MATCHES "EXECUTABLE")
62        SET(INSTALL_LOCATION "bin")
63      ELSE()
64        MESSAGE(FATAL_ERROR
65          "cannot determine type of ${target}. Don't now where to install")
66     ENDIF()
67    ENDIF()
68
69    IF(target STREQUAL "mysqld")
70      SET(comp Server)
71    ELSE()
72      SET(comp Debuginfo)
73    ENDIF()
74
75    # No .pdb file for static libraries.
76    IF(NOT type MATCHES "STATIC_LIBRARY")
77      INSTALL(FILES $<TARGET_PDB_FILE:${target}>
78        DESTINATION ${INSTALL_LOCATION} COMPONENT ${comp})
79    ENDIF()
80  ENDFOREACH()
81  ENDIF()
82ENDMACRO()
83
84
85FUNCTION(INSTALL_SCRIPT)
86 MYSQL_PARSE_ARGUMENTS(ARG
87  "DESTINATION;COMPONENT"
88  ""
89  ${ARGN}
90  )
91
92  SET(script ${ARG_DEFAULT_ARGS})
93  IF(NOT ARG_DESTINATION)
94    SET(ARG_DESTINATION ${INSTALL_BINDIR})
95  ENDIF()
96  IF(ARG_COMPONENT)
97    SET(COMP COMPONENT ${ARG_COMPONENT})
98  ELSE()
99    SET(COMP)
100  ENDIF()
101
102  INSTALL(FILES
103    ${script}
104    DESTINATION ${ARG_DESTINATION}
105    PERMISSIONS OWNER_READ OWNER_WRITE
106    OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
107    WORLD_READ WORLD_EXECUTE  ${COMP}
108  )
109ENDFUNCTION()
110
111
112# Installs targets, also installs pdbs on Windows.
113#
114#
115
116FUNCTION(MYSQL_INSTALL_TARGETS)
117  MYSQL_PARSE_ARGUMENTS(ARG
118    "DESTINATION;COMPONENT"
119  ""
120  ${ARGN}
121  )
122  SET(TARGETS ${ARG_DEFAULT_ARGS})
123  IF(NOT TARGETS)
124    MESSAGE(FATAL_ERROR "Need target list for MYSQL_INSTALL_TARGETS")
125  ENDIF()
126  IF(NOT ARG_DESTINATION)
127     MESSAGE(FATAL_ERROR "Need DESTINATION parameter for MYSQL_INSTALL_TARGETS")
128  ENDIF()
129
130  IF(ARG_COMPONENT)
131    SET(COMP COMPONENT ${ARG_COMPONENT})
132  ENDIF()
133  INSTALL(TARGETS ${TARGETS} DESTINATION ${ARG_DESTINATION} ${COMP})
134  SET(INSTALL_LOCATION ${ARG_DESTINATION} )
135  INSTALL_DEBUG_SYMBOLS("${TARGETS}")
136  INSTALL_DSYM_DIRECTORIES("${TARGETS}")
137  SET(INSTALL_LOCATION)
138ENDFUNCTION()
139
140# Optionally install mysqld/client/embedded from debug build run.
141# outside of the current build dir
142# (unless multi-config generator is used like Visual Studio or Xcode).
143# For single-config generators like Makefile generators we default Debug
144# build directory to ${buildroot}/../debug.
145GET_FILENAME_COMPONENT(BINARY_PARENTDIR ${CMAKE_BINARY_DIR} PATH)
146SET(DEBUGBUILDDIR "${BINARY_PARENTDIR}/debug" CACHE INTERNAL
147  "Directory of debug build")
148
149
150FUNCTION(INSTALL_DEBUG_TARGET target)
151  MYSQL_PARSE_ARGUMENTS(ARG
152    "DESTINATION;RENAME;COMPONENT"
153    ""
154    ${ARGN}
155    )
156
157  # Relevant only for RelWithDebInfo builds
158  IF(BUILD_IS_SINGLE_CONFIG AND CMAKE_BUILD_TYPE STREQUAL "Debug")
159    RETURN()
160  ENDIF()
161
162  GET_TARGET_PROPERTY(target_type ${target} TYPE)
163  GET_TARGET_PROPERTY(target_name ${target} DEBUG_OUTPUT_NAME)
164  IF(NOT target_name)
165    GET_TARGET_PROPERTY(target_name ${target} OUTPUT_NAME)
166    IF(NOT target_name)
167      SET(target_name "${target}")
168    ENDIF()
169  ENDIF()
170
171  # On windows we install client libraries
172  IF(target_type STREQUAL "STATIC_LIBRARY")
173    SET(debug_target_location
174      "${CMAKE_BINARY_DIR}/archive_output_directory/Debug/${target_name}.lib")
175    # On UNIX we install mysqlserver which has name libmysqld.a
176    IF(UNIX)
177      IF(BUILD_IS_SINGLE_CONFIG)
178        SET(debug_target_location
179          "${DEBUGBUILDDIR}/archive_output_directory/lib${target_name}.a")
180      ELSE()
181        SET(debug_target_location
182          "${CMAKE_BINARY_DIR}/archive_output_directory/Debug/lib${target_name}.a")
183      ENDIF()
184      MESSAGE(STATUS
185        "library target ${target} debug_target ${debug_target_location}")
186    ENDIF()
187  # mysqld or mysqld-debug
188  ELSEIF(target_type STREQUAL "EXECUTABLE")
189    GET_TARGET_PROPERTY(runtime_output_directory ${target}
190      RUNTIME_OUTPUT_DIRECTORY)
191    IF(NOT runtime_output_directory)
192      MESSAGE(FATAL_ERROR "unknown executable!!")
193    ENDIF()
194
195    STRING(REPLACE
196      "${CMAKE_BINARY_DIR}/" "" RELATIVE_DIR ${runtime_output_directory})
197
198    SET(EXE_SUFFIX "${CMAKE_EXECUTABLE_SUFFIX}")
199    IF(BUILD_IS_SINGLE_CONFIG)
200      SET(debug_target_location
201        "${DEBUGBUILDDIR}/${RELATIVE_DIR}/${target_name}${EXE_SUFFIX}")
202    ELSE()
203      SET(debug_target_location
204        "${CMAKE_BINARY_DIR}/${RELATIVE_DIR}/Debug/${target_name}${EXE_SUFFIX}")
205    ENDIF()
206    MESSAGE(STATUS
207      "executable target ${target} debug_target ${debug_target_location}")
208
209  # Plugins and components
210  ELSEIF(target_type STREQUAL "MODULE_LIBRARY")
211    SET(DLL_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}")
212    IF(APPLE)
213      SET(DLL_SUFFIX ".so") # we do not use .dylib
214    ENDIF()
215    GET_TARGET_PROPERTY(
216      target_output_directory ${target}  LIBRARY_OUTPUT_DIRECTORY)
217    IF(NOT target_output_directory)
218      MESSAGE(FATAL_ERROR "unknown module!!")
219    ENDIF()
220
221    STRING(REPLACE
222      "${CMAKE_BINARY_DIR}/" "" RELATIVE_DIR ${target_output_directory})
223
224    IF(BUILD_IS_SINGLE_CONFIG)
225      SET(debug_target_location
226        "${DEBUGBUILDDIR}/${RELATIVE_DIR}/${target_name}${DLL_SUFFIX}")
227    ELSE()
228      SET(debug_target_location
229        "${CMAKE_BINARY_DIR}/${RELATIVE_DIR}/Debug/${target_name}${DLL_SUFFIX}")
230    ENDIF()
231    # MESSAGE(STATUS
232    # "module target ${target} debug_target ${debug_target_location}")
233  ENDIF()
234
235  # This is only used for mysqld / mysqld-debug / libmysqlserver.a
236  IF(ARG_RENAME)
237    SET(RENAME_PARAM RENAME ${ARG_RENAME})
238  ELSE()
239    SET(RENAME_PARAM)
240  ENDIF()
241
242  IF(NOT ARG_DESTINATION)
243    MESSAGE(FATAL_ERROR "Need DESTINATION parameter for INSTALL_DEBUG_TARGET")
244  ENDIF()
245
246  IF(NOT ARG_COMPONENT)
247    SET(ARG_COMPONENT DebugBinaries)
248  ENDIF()
249
250  # Define permissions
251  # For executable files
252  SET(PERMISSIONS_EXECUTABLE
253      PERMISSIONS
254      OWNER_READ OWNER_WRITE OWNER_EXECUTE
255      GROUP_READ GROUP_EXECUTE
256      WORLD_READ WORLD_EXECUTE)
257
258  # Permissions for shared library (honors CMAKE_INSTALL_NO_EXE which is
259  # typically set on Debian)
260  IF(CMAKE_INSTALL_SO_NO_EXE)
261    SET(PERMISSIONS_SHARED_LIBRARY
262      PERMISSIONS
263      OWNER_READ OWNER_WRITE
264      GROUP_READ
265      WORLD_READ)
266  ELSE()
267    SET(PERMISSIONS_SHARED_LIBRARY ${PERMISSIONS_EXECUTABLE})
268  ENDIF()
269
270  # Shared modules get the same permissions as shared libraries
271  SET(PERMISSIONS_MODULE_LIBRARY ${PERMISSIONS_SHARED_LIBRARY})
272
273  #  Define permissions for static library
274  SET(PERMISSIONS_STATIC_LIBRARY
275      PERMISSIONS
276      OWNER_READ OWNER_WRITE
277      GROUP_READ
278      WORLD_READ)
279
280  INSTALL(FILES ${debug_target_location}
281    DESTINATION ${ARG_DESTINATION}
282    ${RENAME_PARAM}
283    ${PERMISSIONS_${target_type}}
284    CONFIGURATIONS Release RelWithDebInfo
285    COMPONENT ${ARG_COMPONENT}
286    OPTIONAL)
287
288  # For windows, install .pdb files for .exe and .dll files.
289  IF(MSVC AND NOT target_type STREQUAL "STATIC_LIBRARY")
290    GET_FILENAME_COMPONENT(ext ${debug_target_location} EXT)
291    STRING(REPLACE "${ext}" ".pdb"
292      debug_pdb_target_location "${debug_target_location}" )
293    IF (RENAME_PARAM)
294      STRING(REPLACE "${ext}" ".pdb"  pdb_rename "${ARG_RENAME}")
295      SET(PDB_RENAME_PARAM RENAME "${pdb_rename}")
296    ENDIF()
297
298    INSTALL(FILES ${debug_pdb_target_location}
299      DESTINATION ${ARG_DESTINATION}
300      ${PDB_RENAME_PARAM}
301      CONFIGURATIONS Release RelWithDebInfo
302      COMPONENT ${ARG_COMPONENT}
303      OPTIONAL)
304  ENDIF()
305ENDFUNCTION()
306
307