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
23#
24# Global constants, only to be changed between major releases.
25#
26
27SET(SHARED_LIB_MAJOR_VERSION "20")
28SET(SHARED_LIB_MINOR_VERSION "3")
29SET(PROTOCOL_VERSION "10")
30SET(DOT_FRM_VERSION "6")
31
32# Generate "something" to trigger cmake rerun when MYSQL_VERSION changes
33CONFIGURE_FILE(
34  ${CMAKE_SOURCE_DIR}/MYSQL_VERSION
35  ${CMAKE_BINARY_DIR}/VERSION.dep
36)
37
38# Read value for a variable from MYSQL_VERSION.
39
40MACRO(MYSQL_GET_CONFIG_VALUE keyword var)
41 IF(NOT ${var})
42   FILE (STRINGS ${CMAKE_SOURCE_DIR}/MYSQL_VERSION str REGEX "^[ ]*${keyword}=")
43   IF(str)
44     STRING(REPLACE "${keyword}=" "" str ${str})
45     STRING(REGEX REPLACE  "[ ].*" ""  str "${str}")
46     SET(${var} ${str})
47   ENDIF()
48 ENDIF()
49ENDMACRO()
50
51
52# Read mysql version for configure script
53
54MACRO(GET_MYSQL_VERSION)
55  MYSQL_GET_CONFIG_VALUE("MYSQL_VERSION_MAJOR" MAJOR_VERSION)
56  MYSQL_GET_CONFIG_VALUE("MYSQL_VERSION_MINOR" MINOR_VERSION)
57  MYSQL_GET_CONFIG_VALUE("MYSQL_VERSION_PATCH" PATCH_VERSION)
58  MYSQL_GET_CONFIG_VALUE("MYSQL_VERSION_EXTRA" EXTRA_VERSION)
59
60  IF(NOT DEFINED MAJOR_VERSION OR
61     NOT DEFINED MINOR_VERSION OR
62     NOT DEFINED PATCH_VERSION)
63    MESSAGE(FATAL_ERROR "MYSQL_VERSION file cannot be parsed.")
64  ENDIF()
65
66  SET(VERSION
67    "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}${EXTRA_VERSION}")
68  MESSAGE(STATUS "MySQL ${VERSION}")
69  SET(MYSQL_BASE_VERSION
70    "${MAJOR_VERSION}.${MINOR_VERSION}" CACHE INTERNAL "MySQL Base version")
71  SET(MYSQL_NO_DASH_VERSION
72    "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}")
73
74  # Use NDBVERSION irregardless of whether this is Cluster or not, if not
75  # then the regex will be ignored anyway.
76  STRING(REGEX REPLACE "^.*-ndb-" "" NDBVERSION "${VERSION}")
77  STRING(REPLACE "-" "_" MYSQL_RPM_VERSION "${NDBVERSION}")
78  MATH(EXPR MYSQL_VERSION_ID
79    "10000*${MAJOR_VERSION} + 100*${MINOR_VERSION} + ${PATCH_VERSION}")
80  MARK_AS_ADVANCED(VERSION MYSQL_VERSION_ID MYSQL_BASE_VERSION)
81  SET(CPACK_PACKAGE_VERSION_MAJOR ${MAJOR_VERSION})
82  SET(CPACK_PACKAGE_VERSION_MINOR ${MINOR_VERSION})
83  SET(CPACK_PACKAGE_VERSION_PATCH ${PATCH_VERSION})
84ENDMACRO()
85
86# Get mysql version and other interesting variables
87GET_MYSQL_VERSION()
88
89SET(SHARED_LIB_PATCH_VERSION ${PATCH_VERSION})
90
91# Beware : This is a hack to reset SHARED_LIB_PATCH_VERSION in accordance
92# with the change in value of SHARED_LIB_MINOR_VERSION.
93MATH(EXPR SHARED_LIB_PATCH_VERSION "${SHARED_LIB_PATCH_VERSION}-13")
94
95SET(MYSQL_TCP_PORT_DEFAULT "3306")
96
97IF(NOT MYSQL_TCP_PORT)
98  SET(MYSQL_TCP_PORT ${MYSQL_TCP_PORT_DEFAULT})
99  SET(MYSQL_TCP_PORT_DEFAULT "0")
100ELSEIF(MYSQL_TCP_PORT EQUAL MYSQL_TCP_PORT_DEFAULT)
101  SET(MYSQL_TCP_PORT_DEFAULT "0")
102ENDIF()
103
104
105IF(NOT MYSQL_UNIX_ADDR)
106  SET(MYSQL_UNIX_ADDR "/tmp/mysql.sock")
107ENDIF()
108IF(NOT COMPILATION_COMMENT)
109  SET(COMPILATION_COMMENT "Source distribution")
110ENDIF()
111
112# Get the sys schema version from the mysql_sys_schema.sql file
113# however if compiling without performance schema, always use version 1.0.0
114MACRO(GET_SYS_SCHEMA_VERSION)
115  FILE (STRINGS ${CMAKE_SOURCE_DIR}/scripts/mysql_sys_schema.sql str REGEX "SELECT \\'([0-9]+\\.[0-9]+\\.[0-9]+)\\' AS sys_version")
116  IF(str)
117    STRING(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" SYS_SCHEMA_VERSION "${str}")
118  ENDIF()
119ENDMACRO()
120
121GET_SYS_SCHEMA_VERSION()
122
123INCLUDE(package_name)
124IF(NOT CPACK_PACKAGE_FILE_NAME)
125  GET_PACKAGE_FILE_NAME(CPACK_PACKAGE_FILE_NAME)
126ENDIF()
127
128IF(NOT CPACK_SOURCE_PACKAGE_FILE_NAME)
129  SET(CPACK_SOURCE_PACKAGE_FILE_NAME "percona-server-${VERSION}")
130  IF("${VERSION}" MATCHES "-ndb-")
131    STRING(REGEX REPLACE "^.*-ndb-" "" NDBVERSION "${VERSION}")
132    SET(CPACK_SOURCE_PACKAGE_FILE_NAME "mysql-cluster-gpl-${NDBVERSION}")
133  ENDIF()
134ENDIF()
135SET(CPACK_PACKAGE_CONTACT "Percona Engineering <mysql-dev@percona.com>")
136SET(CPACK_PACKAGE_VENDOR "Percona")
137SET(CPACK_SOURCE_GENERATOR "TGZ")
138INCLUDE(cpack_source_ignore_files)
139
140# Defintions for windows version resources
141SET(PRODUCTNAME "Percona Server")
142SET(COMPANYNAME ${CPACK_PACKAGE_VENDOR})
143
144# Windows 'date' command has unpredictable output, so cannot rely on it to
145# set MYSQL_COPYRIGHT_YEAR - if someone finds a portable way to do so then
146# it might be useful
147#IF (WIN32)
148#  EXECUTE_PROCESS(COMMAND "date" "/T" OUTPUT_VARIABLE TMP_DATE)
149#  STRING(REGEX REPLACE "(..)/(..)/..(..).*" "\\3\\2\\1" MYSQL_COPYRIGHT_YEAR ${TMP_DATE})
150IF(UNIX)
151  EXECUTE_PROCESS(COMMAND "date" "+%Y" OUTPUT_VARIABLE MYSQL_COPYRIGHT_YEAR OUTPUT_STRIP_TRAILING_WHITESPACE)
152ENDIF()
153
154# Add version information to the exe and dll files
155# Refer to http://msdn.microsoft.com/en-us/library/aa381058(VS.85).aspx
156# for more info.
157IF(MSVC)
158    GET_FILENAME_COMPONENT(MYSQL_CMAKE_SCRIPT_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
159
160    SET(FILETYPE VFT_APP)
161    CONFIGURE_FILE(${MYSQL_CMAKE_SCRIPT_DIR}/versioninfo.rc.in
162    ${CMAKE_BINARY_DIR}/versioninfo_exe.rc)
163
164    SET(FILETYPE VFT_DLL)
165    CONFIGURE_FILE(${MYSQL_CMAKE_SCRIPT_DIR}/versioninfo.rc.in
166      ${CMAKE_BINARY_DIR}/versioninfo_dll.rc)
167
168  FUNCTION(ADD_VERSION_INFO target target_type sources_var)
169    IF("${target_type}" MATCHES "SHARED" OR "${target_type}" MATCHES "MODULE")
170      SET(rcfile ${CMAKE_BINARY_DIR}/versioninfo_dll.rc)
171    ELSEIF("${target_type}" MATCHES "EXE")
172      SET(rcfile ${CMAKE_BINARY_DIR}/versioninfo_exe.rc)
173    ENDIF()
174    SET(${sources_var} ${${sources_var}} ${rcfile} PARENT_SCOPE)
175  ENDFUNCTION()
176ELSE()
177  FUNCTION(ADD_VERSION_INFO)
178  ENDFUNCTION()
179ENDIF()
180