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

Autotools adds apple deployement target flag #7862

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions conans/client/build/autotools_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
format_frameworks, format_framework_paths)
from conans.client.build.cppstd_flags import cppstd_from_settings, \
cppstd_flag_new as cppstd_flag
from conans.client import tools
from conans.client.tools.env import environment_append
from conans.client.tools.oss import OSInfo, args_to_string, cpu_count, cross_building, \
detected_architecture, detected_os, get_gnu_triplet, get_target_os_arch, get_build_os_arch
Expand Down Expand Up @@ -39,6 +40,7 @@ def __init__(self, conanfile, win_bash=False, include_rpath_flags=False):
self.subsystem = OSInfo().detect_windows_subsystem() if self._win_bash else None
self._deps_cpp_info = conanfile.deps_cpp_info
self._os = conanfile.settings.get_safe("os")
self._os_version = conanfile.settings.get_safe("os.version")
self._arch = conanfile.settings.get_safe("arch")
self._os_target, self._arch_target = get_target_os_arch(conanfile)

Expand Down Expand Up @@ -339,6 +341,15 @@ def append(*args):
tmp_compilation_flags = copy.copy(self.flags)
if self.fpic:
tmp_compilation_flags.append(pic_flag(self._conanfile.settings))
if tools.is_apple_os(self._os):
concat = " ".join(tmp_compilation_flags)
if os.environ.get("CFLAGS", None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't the version-min come defined also in CXXFLAGS? I think it would make sense check that var too, just in case, as C++ users are probably defining it in that var, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

concat += " " + os.environ.get("CFLAGS", None)
if os.environ.get("CXXFLAGS", None):
concat += " " + os.environ.get("CXXFLAGS", None)
if self._os_version and "-version-min" not in concat and "-target" not in concat:
tmp_compilation_flags.append(tools.apple_deployment_target_flag(self._os,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to understand a bit better (not a OSX user) what is the effect of not adding this flag. Is it a compilation error? What have been the users doing so far for this?

Also, is there a chance that this could be breaking for other users that do not expect this flag to be added? Should this flag be added in other generators as well (cmake, xcode)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this flag is not set and someone is trying to link a library with no minimal os version against an application explicitely specifying it then warning will span like mentioned here: bincrafters/community#1264 (comment)

Regarding the users that do not expect this flag to be added I wondered why they would have specify the os.version setting that (if I'm understanding well) states that the dependencies should support such OS.

Cmake generators allready handle the os.version flags by setting the CMAKE_OSX_DEPLOYMENT_TARGET definition: https://github.com/conan-io/conan/blob/develop/conans/client/build/cmake_flags.py#L216-L219

self._os_version))

cxx_flags = append(tmp_compilation_flags, self.cxx_flags, self.cppstd_flag)
c_flags = tmp_compilation_flags
Expand Down
27 changes: 27 additions & 0 deletions conans/test/unittests/client/build/autotools_environment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,3 +671,30 @@ def autotools_fpic_test(self):
self.assertFalse(ab.fpic)
ab.fpic = True
self.assertIn("-fPIC", ab.vars["CXXFLAGS"])

def mac_version_min_test(self):
options = MockOptions({})
settings = MockSettings({"os": "Macos"})
conanfile = MockConanfile(settings, options)
be = AutoToolsBuildEnvironment(conanfile)
expected = be.vars["CXXFLAGS"]
self.assertEqual("", expected)

settings = MockSettings({"os": "Macos",
"os.version": "10.13",
"compiler.version": "12.0"})
conanfile = MockConanfile(settings, options)
be = AutoToolsBuildEnvironment(conanfile)
expected = be.vars["CXXFLAGS"]
self.assertIn("10.13", expected)

with tools.environment_append({"CFLAGS": "-mmacosx-version-min=10.9"}):
be = AutoToolsBuildEnvironment(conanfile)
MartinDelille marked this conversation as resolved.
Show resolved Hide resolved
expected = be.vars["CFLAGS"]
self.assertIn("10.9", expected)
self.assertNotIn("10.13", expected)

with tools.environment_append({"CXXFLAGS": "-mmacosx-version-min=10.9"}):
be = AutoToolsBuildEnvironment(conanfile)
expected = be.vars["CFLAGS"]
self.assertNotIn("10.13", expected)