Skip to content

Commit

Permalink
Bug #32349239 WRONG VERSION REPORTED FROM MYSQLD WHEN BUILDING ON MAC…
Browse files Browse the repository at this point in the history
…OS 11

Version information printed by MySQL executables includes the value of
the cmake variable SYSTEM_TYPE, which is based on the cmake variable
PLATFORM.

On macOS the default value for PLATFORM is based on 'uname -r' with
some arithmetic to map from unix version, to macOS version.  This
arithmetic did not work at all for macOS 11, and executables would
report something like: "Ver 8.0.24 for osx10.16 on x86_64"

This patch replaces the use of 'uname -r' with the results from 'sw_vers'.
We also remove "osx" from the default PLATFORM name, and use "macos" instead.

With this, version information will be:
   Ver 8.0.24 for macos11.1 on x86_64
or
   Ver 8.0.24 for macos10.15 on x86_64

Also set CMAKE_OSX_DEPLOYMENT_TARGET explicitly, unless it is defined
on the cmake command line.

Change-Id: I97984bdaa09d025422709fc15569e12f3ee2ff11
  • Loading branch information
Tor Didriksen committed Jan 13, 2021
1 parent 825b08d commit 83b87ae
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions cmake/package_name.cmake
@@ -1,4 +1,4 @@
# Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2010, 2021, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -69,30 +69,42 @@ MACRO(GET_PACKAGE_FILE_NAME Var)
ENDIF()
ENDIF()
ELSEIF(APPLE)
IF(CMAKE_OSX_DEPLOYMENT_TARGET)
SET(DEFAULT_PLATFORM "osx${CMAKE_OSX_DEPLOYMENT_TARGET}")
ELSE()
SET(VER "${CMAKE_SYSTEM_VERSION}")
STRING(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" VER "${VER}")
# Subtract 4 from Darwin version to get correct osx10.X
MATH(EXPR VER "${VER} -4")
SET(DEFAULT_PLATFORM "osx10.${VER}")
# CMAKE_SYSTEM_PROCESSOR seems to based on 'uname -r'
# CMAKE_SYSTEM_VERSION cannot be trusted for version information:

# CMAKE_SYSTEM_VERSION 19.2.0
# sw_vers
# ProductName: Mac OS X
# ProductVersion: 10.15.2
# BuildVersion: 19C57

# CMAKE_SYSTEM_VERSION 20.2.0
# sw_vers
# ProductName: macOS
# ProductVersion: 11.1
# BuildVersion: 20C69

EXECUTE_PROCESS(COMMAND sw_vers
OUTPUT_VARIABLE SW_VERS_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
STRING(REPLACE "\n" ";" SW_VERS_OUTPUT_LIST "${SW_VERS_OUTPUT}")
LIST(GET SW_VERS_OUTPUT_LIST 0 SW_VERS_PRODUCTNAME)
LIST(GET SW_VERS_OUTPUT_LIST 1 SW_VERS_PRODUCTVERSION)

STRING(REGEX MATCH
"ProductVersion:[\n\t ]*([0-9]+)\\.([0-9]+)" UNUSED ${SW_VERS_PRODUCTVERSION})
IF(NOT CMAKE_MATCH_1 OR NOT CMAKE_MATCH_2)
MESSAGE(FATAL_ERROR "Could not run sw_vers")
ENDIF()

IF(CMAKE_OSX_ARCHITECTURES)
LIST(LENGTH CMAKE_OSX_ARCHITECTURES LEN)
IF(LEN GREATER 1)
SET(DEFAULT_MACHINE "universal")
ELSE()
SET(DEFAULT_MACHINE "${CMAKE_OSX_ARCHITECTURES}")
ENDIF()
ELSE()
IF(64BIT)
SET(DEFAULT_MACHINE "x86_64")
ENDIF()
ENDIF()
SET(DEFAULT_PLATFORM "macos${CMAKE_MATCH_1}.${CMAKE_MATCH_2}")

MESSAGE(STATUS "DEFAULT_PLATFORM ${DEFAULT_PLATFORM}")

IF(DEFAULT_MACHINE MATCHES "i386")
IF(64BIT)
SET(DEFAULT_MACHINE "x86_64")
ELSE()
SET(DEFAULT_MACHINE "x86")
ENDIF()
ENDIF()
Expand Down

0 comments on commit 83b87ae

Please sign in to comment.