build: add check for macOS SDK version

this provides an easy way to check for a specific macOS SDK version and
with that the availability of features.
This commit is contained in:
der richter 2019-05-05 17:07:52 +02:00 committed by Jan Ekström
parent 9a2c760614
commit 850b303732
2 changed files with 22 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import os
import inflector
from distutils.version import StrictVersion
from waflib.ConfigSet import ConfigSet
from waflib import Utils
@ -8,7 +9,7 @@ __all__ = [
"check_pkg_config_cflags", "check_cc", "check_statement", "check_libs",
"check_headers", "compose_checks", "check_true", "any_version",
"load_fragment", "check_stub", "check_ctx_vars", "check_program",
"check_pkg_config_datadir"]
"check_pkg_config_datadir", "check_macos_sdk"]
any_version = None
@ -186,3 +187,13 @@ def load_fragment(fragment):
fragment_code = fp.read()
fp.close()
return fragment_code
def check_macos_sdk(version):
def fn(ctx, dependency_identifier):
if ctx.env.MACOS_SDK_VERSION:
if StrictVersion(ctx.env.MACOS_SDK_VERSION) >= StrictVersion(version):
ctx.define(inflector.define_key(dependency_identifier), 1)
return True
return False
return fn

View File

@ -1,4 +1,5 @@
import re
import string
import os.path
from waflib import Utils
from distutils.version import StrictVersion
@ -116,9 +117,18 @@ def __find_swift_library(ctx):
def __find_macos_sdk(ctx):
ctx.start_msg('Checking for macOS SDK')
sdk = __run(['xcrun', '--sdk', 'macosx', '--show-sdk-path'])
sdk_build_version = __run(['xcrun', '--sdk', 'macosx', '--show-sdk-build-version' ])
if sdk:
ctx.end_msg(sdk)
ctx.env.MACOS_SDK = sdk
if sdk_build_version:
verRe = re.compile("(\d+)(\D+)(\d+)")
version_parts = verRe.search(sdk_build_version)
major = int(version_parts.group(1))-4
minor = string.ascii_lowercase.index(version_parts.group(2).lower())
ctx.env.MACOS_SDK_VERSION = '10.' + str(major) + '.' + str(minor)
else:
ctx.end_msg(False)