2017-04-23 15:42:45 +00:00
|
|
|
# ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
# The Original Code is Copyright (C) 2016, Blender Foundation
|
|
|
|
# All rights reserved.
|
|
|
|
# ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
|
|
|
# Xcode and system configuration for Apple.
|
|
|
|
|
|
|
|
if(NOT CMAKE_OSX_ARCHITECTURES)
|
2020-07-16 07:25:55 +00:00
|
|
|
execute_process(COMMAND uname -m OUTPUT_VARIABLE ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
message(STATUS "Detected native architecture ${ARCHITECTURE}.")
|
|
|
|
set(CMAKE_OSX_ARCHITECTURES ${ARCHITECTURE} CACHE STRING
|
|
|
|
"Choose the architecture you want to build Blender for: arm64 or x86_64"
|
2019-04-17 04:35:54 +00:00
|
|
|
FORCE)
|
2017-04-23 15:42:45 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT DEFINED OSX_SYSTEM)
|
2019-04-17 04:35:54 +00:00
|
|
|
execute_process(
|
|
|
|
COMMAND xcodebuild -version -sdk macosx SDKVersion
|
|
|
|
OUTPUT_VARIABLE OSX_SYSTEM
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2017-04-23 15:42:45 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# workaround for incorrect cmake xcode lookup for developer previews - XCODE_VERSION does not
|
|
|
|
# take xcode-select path into account but would always look into /Applications/Xcode.app
|
|
|
|
# while dev versions are named Xcode<version>-DP<preview_number>
|
|
|
|
execute_process(
|
2019-04-17 04:35:54 +00:00
|
|
|
COMMAND xcode-select --print-path
|
|
|
|
OUTPUT_VARIABLE XCODE_CHECK OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2017-04-23 15:42:45 +00:00
|
|
|
string(REPLACE "/Contents/Developer" "" XCODE_BUNDLE ${XCODE_CHECK}) # truncate to bundlepath in any case
|
|
|
|
|
2020-03-26 08:14:22 +00:00
|
|
|
if(NOT ${CMAKE_GENERATOR} MATCHES "Xcode")
|
2020-03-26 07:57:52 +00:00
|
|
|
# Unix makefile generator does not fill XCODE_VERSION var, so we get it with a command.
|
|
|
|
# Note that `xcodebuild -version` gives output in two lines: first line will include
|
|
|
|
# Xcode version, second one will include build number. We are only interested in the
|
|
|
|
# former one. Here is an example of the output:
|
|
|
|
# Xcode 11.4
|
|
|
|
# Build version 11E146
|
|
|
|
# The expected XCODE_VERSION in this case is 11.4.
|
|
|
|
|
2019-04-17 04:35:54 +00:00
|
|
|
execute_process(COMMAND xcodebuild -version OUTPUT_VARIABLE XCODE_VERS_BUILD_NR)
|
2020-03-26 07:57:52 +00:00
|
|
|
|
|
|
|
# Convert output to a single line by replacling newlines with spaces.
|
|
|
|
# This is needed because regex replace can not operate through the newline character
|
|
|
|
# and applies substitutions for each individual lines.
|
|
|
|
string(REPLACE "\n" " " XCODE_VERS_BUILD_NR_SINGLE_LINE "${XCODE_VERS_BUILD_NR}")
|
|
|
|
|
|
|
|
string(REGEX REPLACE "(.*)Xcode ([0-9\\.]+).*" "\\2" XCODE_VERSION "${XCODE_VERS_BUILD_NR_SINGLE_LINE}")
|
|
|
|
|
2019-04-17 04:35:54 +00:00
|
|
|
unset(XCODE_VERS_BUILD_NR)
|
2020-03-26 07:57:52 +00:00
|
|
|
unset(XCODE_VERS_BUILD_NR_SINGLE_LINE)
|
2017-04-23 15:42:45 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
message(STATUS "Detected OS X ${OSX_SYSTEM} and Xcode ${XCODE_VERSION} at ${XCODE_BUNDLE}")
|
|
|
|
|
2020-07-02 10:28:57 +00:00
|
|
|
# Require a relatively recent Xcode version.
|
|
|
|
if(${XCODE_VERSION} VERSION_LESS 10.0)
|
|
|
|
message(FATAL_ERROR "Only Xcode version 10.0 and newer is supported")
|
2020-03-26 08:14:22 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# note: xcode-select path could be ambiguous,
|
|
|
|
# cause /Applications/Xcode.app/Contents/Developer or /Applications/Xcode.app would be allowed
|
|
|
|
# so i use a selfcomposed bundlepath here
|
|
|
|
set(OSX_SYSROOT_PREFIX ${XCODE_BUNDLE}/Contents/Developer/Platforms/MacOSX.platform)
|
|
|
|
message(STATUS "OSX_SYSROOT_PREFIX: " ${OSX_SYSROOT_PREFIX})
|
2020-03-26 08:42:08 +00:00
|
|
|
|
|
|
|
# Collect list of OSX system versions which will be used to detect path to corresponding SDK.
|
|
|
|
# Start with macOS SDK version reported by xcodebuild and include possible extra ones.
|
|
|
|
#
|
|
|
|
# The reason for need of extra ones is because it's possible that xcodebuild will report
|
|
|
|
# SDK version in the full manner (aka major.minor.patch), but the actual path will only
|
|
|
|
# include major.minor.
|
|
|
|
#
|
|
|
|
# This happens, for example, on macOS Catalina 10.15.4 and Xcode 11.4: xcodebuild on this
|
|
|
|
# system outputs "10.15.4", but the actual SDK path is MacOSX10.15.sdk.
|
|
|
|
#
|
|
|
|
# This should be safe from picking wrong SDK version because (a) xcodebuild reports full semantic
|
|
|
|
# SDK version, so such SDK does exist on the system. And if it doesn't exist with full version
|
|
|
|
# in the path, what SDK is in the major.minor folder then.
|
|
|
|
set(OSX_SDK_TEST_VERSIONS ${OSX_SYSTEM})
|
|
|
|
if(OSX_SYSTEM MATCHES "([0-9]+)\\.([0-9]+)\\.([0-9]+)")
|
|
|
|
string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1.\\2" OSX_SYSTEM_NO_PATCH "${OSX_SYSTEM}")
|
|
|
|
list(APPEND OSX_SDK_TEST_VERSIONS ${OSX_SYSTEM_NO_PATCH})
|
|
|
|
unset(OSX_SYSTEM_NO_PATCH)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Loop through all possible versions and pick the first one which resolves to a valid SDK path.
|
|
|
|
set(OSX_SDK_PATH)
|
|
|
|
set(OSX_SDK_FOUND FALSE)
|
|
|
|
set(OSX_SDK_PREFIX ${OSX_SYSROOT_PREFIX}/Developer/SDKs)
|
2020-03-26 12:07:19 +00:00
|
|
|
set(OSX_SDKROOT)
|
2020-03-26 08:42:08 +00:00
|
|
|
foreach(OSX_SDK_VERSION ${OSX_SDK_TEST_VERSIONS})
|
|
|
|
set(CURRENT_OSX_SDK_PATH "${OSX_SDK_PREFIX}/MacOSX${OSX_SDK_VERSION}.sdk")
|
|
|
|
if(EXISTS ${CURRENT_OSX_SDK_PATH})
|
|
|
|
set(OSX_SDK_PATH "${CURRENT_OSX_SDK_PATH}")
|
2020-03-26 12:07:19 +00:00
|
|
|
set(OSX_SDKROOT macosx${OSX_SDK_VERSION})
|
2020-03-26 08:42:08 +00:00
|
|
|
set(OSX_SDK_FOUND TRUE)
|
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
unset(OSX_SDK_PREFIX)
|
|
|
|
unset(OSX_SDK_TEST_VERSIONS)
|
|
|
|
|
|
|
|
if(NOT OSX_SDK_FOUND)
|
|
|
|
message(FATAL_ERROR "Unable to find SDK for macOS version ${OSX_SYSTEM}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
message(STATUS "Detected OSX_SYSROOT: ${OSX_SDK_PATH}")
|
|
|
|
|
|
|
|
set(CMAKE_OSX_SYSROOT ${OSX_SDK_PATH} CACHE PATH "" FORCE)
|
|
|
|
unset(OSX_SDK_PATH)
|
|
|
|
unset(OSX_SDK_FOUND)
|
|
|
|
|
2020-03-26 08:14:22 +00:00
|
|
|
if(${CMAKE_GENERATOR} MATCHES "Xcode")
|
|
|
|
# to silence sdk not found warning, just overrides CMAKE_OSX_SYSROOT
|
2020-03-26 12:07:19 +00:00
|
|
|
set(CMAKE_XCODE_ATTRIBUTE_SDKROOT ${OSX_SDKROOT})
|
2017-04-23 15:42:45 +00:00
|
|
|
endif()
|
2020-03-26 12:07:19 +00:00
|
|
|
unset(OSX_SDKROOT)
|
2017-04-23 15:42:45 +00:00
|
|
|
|
2020-07-16 07:25:55 +00:00
|
|
|
|
2020-07-02 10:28:57 +00:00
|
|
|
# 10.13 is our min. target, if you use higher sdk, weak linking happens
|
2020-07-16 07:25:55 +00:00
|
|
|
if("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "arm64")
|
|
|
|
set(OSX_MIN_DEPLOYMENT_TARGET 11.00)
|
|
|
|
else()
|
|
|
|
set(OSX_MIN_DEPLOYMENT_TARGET 10.13)
|
|
|
|
endif()
|
|
|
|
|
2017-09-28 18:52:22 +00:00
|
|
|
if(CMAKE_OSX_DEPLOYMENT_TARGET)
|
2020-07-16 07:25:55 +00:00
|
|
|
if(${CMAKE_OSX_DEPLOYMENT_TARGET} VERSION_LESS ${OSX_MIN_DEPLOYMENT_TARGET})
|
|
|
|
message(STATUS "Setting deployment target to ${OSX_MIN_DEPLOYMENT_TARGET}, lower versions are not supported")
|
|
|
|
set(CMAKE_OSX_DEPLOYMENT_TARGET "${OSX_MIN_DEPLOYMENT_TARGET}" CACHE STRING "" FORCE)
|
2019-04-17 04:35:54 +00:00
|
|
|
endif()
|
2017-04-23 15:42:45 +00:00
|
|
|
else()
|
2020-07-16 07:25:55 +00:00
|
|
|
set(CMAKE_OSX_DEPLOYMENT_TARGET "${OSX_MIN_DEPLOYMENT_TARGET}" CACHE STRING "" FORCE)
|
2017-04-23 15:42:45 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT ${CMAKE_GENERATOR} MATCHES "Xcode")
|
2020-02-14 22:57:56 +00:00
|
|
|
# Force CMAKE_OSX_DEPLOYMENT_TARGET for makefiles, will not work else (CMake bug?)
|
2019-04-17 04:35:54 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
|
|
|
|
add_definitions("-DMACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
|
2017-04-23 15:42:45 +00:00
|
|
|
endif()
|