Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Use CMAKE_OSX_DEPLOYMENT_TARGET to get -version-min set in CMakeToolchain #9301

Merged
merged 2 commits into from Jul 21, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions conan/tools/cmake/toolchain.py
Expand Up @@ -313,12 +313,14 @@ class AppleSystemBlock(Block):
{% if CMAKE_SYSTEM_VERSION is defined %}
set(CMAKE_SYSTEM_VERSION {{ CMAKE_SYSTEM_VERSION }})
{% endif %}
set(DEPLOYMENT_TARGET ${CONAN_SETTINGS_HOST_MIN_OS_VERSION})
# Set the architectures for which to build.
set(CMAKE_OSX_ARCHITECTURES {{ CMAKE_OSX_ARCHITECTURES }} CACHE STRING "" FORCE)
# Setting CMAKE_OSX_SYSROOT SDK, when using Xcode generator the name is enough
# but full path is necessary for others
set(CMAKE_OSX_SYSROOT {{ CMAKE_OSX_SYSROOT }} CACHE STRING "" FORCE)
{% if CMAKE_OSX_DEPLOYMENT_TARGET is defined %}
set(CMAKE_OSX_DEPLOYMENT_TARGET {{ CMAKE_OSX_DEPLOYMENT_TARGET }})
{% endif %}
""")

def _get_architecture(self):
Expand Down Expand Up @@ -358,9 +360,6 @@ def context(self):
host_os_version = self._conanfile.settings.get_safe("os.version")
host_sdk_name = self._apple_sdk_name()

# TODO: Discuss how to handle CMAKE_OSX_DEPLOYMENT_TARGET to set min-version
# add a setting? check an option and if not present set a default?
# default to os.version?
ctxt_toolchain = {}
if host_sdk_name:
ctxt_toolchain["CMAKE_OSX_SYSROOT"] = host_sdk_name
Expand All @@ -371,6 +370,12 @@ def context(self):
ctxt_toolchain["CMAKE_SYSTEM_NAME"] = os_
ctxt_toolchain["CMAKE_SYSTEM_VERSION"] = host_os_version

if host_os_version:
# https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_DEPLOYMENT_TARGET.html
# Despite the OSX part in the variable name(s) they apply also to other SDKs than
# macOS like iOS, tvOS, or watchOS.
ctxt_toolchain["CMAKE_OSX_DEPLOYMENT_TARGET"] = host_os_version

return ctxt_toolchain


Expand Down