Skip to content

Commit

Permalink
Autotools adds apple deployement target flag (#7862)
Browse files Browse the repository at this point in the history
* Autotools adds apple deployement target flag

* Check ???-version-min and -target aren't already in the compilation
flags

* Add failing test

* Fix test

* Check CXX flags too
  • Loading branch information
MartinDelille authored Oct 20, 2020
1 parent cbe988f commit fc2078a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
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):
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,
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)
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)

0 comments on commit fc2078a

Please sign in to comment.