Skip to content

Commit

Permalink
fPIC auto-managed in autotools build helper (conan-io#2887)
Browse files Browse the repository at this point in the history
* Added fpic auto configure to AutoTools helper

* fix indentation

* fix
  • Loading branch information
danimtb authored and lasote committed May 28, 2018
1 parent 089ad52 commit 63786ac
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 11 deletions.
25 changes: 14 additions & 11 deletions conans/client/build/autotools_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self, conanfile, win_bash=False, include_rpath_flags=False):
self._include_rpath_flags = include_rpath_flags
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._arch = conanfile.settings.get_safe("arch")
self._build_type = conanfile.settings.get_safe("build_type")
self._compiler = conanfile.settings.get_safe("compiler")
Expand All @@ -55,34 +56,37 @@ def __init__(self, conanfile, win_bash=False, include_rpath_flags=False):
self.cppstd_flag = cppstd_flag(self._compiler, self._compiler_version, self._cppstd)
# Not -L flags, ["-m64" "-m32"]
self.link_flags = self._configure_link_flags() # TEST!
# Not declared by default
self.fpic = None
# Precalculate -fPIC
self.fpic = self._configure_fpic()

# Precalculate build, host, target triplets
self.build, self.host, self.target = self._get_host_build_target_flags()

def _configure_fpic(self):
if str(self._os) not in ["Windows", "WindowsStore"]:
fpic = self._conanfile.options.get_safe("fPIC")
if fpic is not None:
shared = self._conanfile.options.get_safe("shared")
return True if (fpic or shared) else None

def _get_host_build_target_flags(self):
"""Based on google search for build/host triplets, it could need a lot
and complex verification"""

arch_detected = detected_architecture() or platform.machine()
os_detected = platform.system()
arch_settings = self._conanfile.settings.get_safe("arch")
os_settings = self._conanfile.settings.get_safe("os")
compiler = self._conanfile.settings.get_safe("compiler")

if (os_detected is None or arch_detected is None or arch_settings is None or
os_settings is None):
if os_detected is None or arch_detected is None or self._arch is None or self._os is None:
return False, False, False
if not cross_building(self._conanfile.settings, os_detected, arch_detected):
return False, False, False

try:
build = get_gnu_triplet(os_detected, arch_detected, compiler)
build = get_gnu_triplet(os_detected, arch_detected, self._compiler)
except ConanException:
build = None
try:
host = get_gnu_triplet(os_settings, arch_settings, compiler)
host = get_gnu_triplet(self._os, self._arch, self._compiler)
except ConanException:
host = None
return build, host, None
Expand Down Expand Up @@ -184,8 +188,7 @@ def _configure_link_flags(self):
ret.append(sysf)

if self._include_rpath_flags:
the_os = self._conanfile.settings.get_safe("os_build") or \
self._conanfile.settings.get_safe("os")
the_os = self._conanfile.settings.get_safe("os_build") or self._os
ret.extend(rpath_flags(the_os, self._compiler, self._deps_cpp_info.lib_paths))

return ret
Expand Down
37 changes: 37 additions & 0 deletions conans/test/build_helpers/autotools_configure_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,40 @@ def custom_configure(obj, configure_dir=None, args=None, build=None, host=None,
# TEST with custom vars
mocked_result = be.configure(vars=my_vars)
self.assertEqual(mocked_result, my_vars)

def autotools_fpic_test(self):
runner = None
settings = MockSettings({"os": "Linux"})
options = MockOptions({"fPIC": True, "shared": False})
conanfile = MockConanfile(settings, options, runner)
ab = AutoToolsBuildEnvironment(conanfile)
self.assertTrue(ab.fpic)

options = MockOptions({"fPIC": True, "shared": True})
conanfile = MockConanfile(settings, options, runner)
ab = AutoToolsBuildEnvironment(conanfile)
self.assertTrue(ab.fpic)

options = MockOptions({"fPIC": False, "shared": True})
conanfile = MockConanfile(settings, options, runner)
ab = AutoToolsBuildEnvironment(conanfile)
self.assertTrue(ab.fpic)

options = MockOptions({"fPIC": False, "shared": False})
conanfile = MockConanfile(settings, options, runner)
ab = AutoToolsBuildEnvironment(conanfile)
self.assertFalse(ab.fpic)

settings = MockSettings({"os": "Windows"})
options = MockOptions({"fPIC": True, "shared": True})
conanfile = MockConanfile(settings, options, runner)
ab = AutoToolsBuildEnvironment(conanfile)
self.assertFalse(ab.fpic)

settings = MockSettings({"os": "Macos", "compiler": "clang"})
options = MockOptions({"fPIC": False, "shared": False})
conanfile = MockConanfile(settings, options, runner)
ab = AutoToolsBuildEnvironment(conanfile)
self.assertFalse(ab.fpic)
ab.fpic = True
self.assertIn("-fPIC", ab.vars["CXXFLAGS"])

0 comments on commit 63786ac

Please sign in to comment.