Skip to content

Commit

Permalink
improve AutotoolsToolchain support for VS (conan-io#10429)
Browse files Browse the repository at this point in the history
* improve AutotoolsToolchain support for VS

* remove print

* Added scope to VCVars.generate

Co-authored-by: Francisco Ramírez <[email protected]>
  • Loading branch information
memsharded and franramirez688 authored Jan 26, 2022
1 parent 4b4fb62 commit f45d0a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
6 changes: 6 additions & 0 deletions conan/tools/gnu/autotoolstoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from conan.tools.env import Environment
from conan.tools.files import save_toolchain_args
from conan.tools.gnu.get_gnu_triplet import _get_gnu_triplet
from conan.tools.microsoft import VCVars, is_msvc
from conans.tools import args_to_string


Expand Down Expand Up @@ -132,6 +133,10 @@ def environment(self):
self.cxxflags.append("-fPIC")
self.cflags.append("-fPIC")

if is_msvc(self._conanfile):
env.define("CXX", "cl")
env.define("CC", "cl")

# FIXME: Previously these flags where checked if already present at env 'CFLAGS', 'CXXFLAGS'
# and 'self.cxxflags', 'self.cflags' before adding them
for f in list(filter(bool, [self.apple_isysroot_flag,
Expand All @@ -155,6 +160,7 @@ def generate(self, env=None, scope="build"):
env = env.vars(self._conanfile, scope=scope)
env.save_script("conanautotoolstoolchain")
self.generate_args()
VCVars(self._conanfile).generate(scope=scope)

def generate_args(self):
configure_args = []
Expand Down
16 changes: 1 addition & 15 deletions conans/test/functional/toolchains/gnu/autotools/test_win_bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def test_autotools_bash_complete():
conanfile = textwrap.dedent("""
from conans import ConanFile
from conan.tools.gnu import Autotools
from conan.tools.microsoft import VCVars
from conan.tools.env import Environment
class TestConan(ConanFile):
Expand All @@ -39,17 +38,6 @@ class TestConan(ConanFile):
generators = "AutotoolsToolchain"
win_bash = True
def generate(self):
# Add vcvars launcher
VCVars(self).generate()
# Force autotools to use "cl" compiler
# FIXME: Should this be added to AutotoolsToolchain when visual?
env = Environment()
env.define("CXX", "cl")
env.define("CC", "cl")
env.vars(self).save_script("conan_compiler")
def build(self):
# These commands will run in bash activating first the vcvars and
# then inside the bash activating the
Expand All @@ -71,7 +59,5 @@ def build(self):
check_exe_run(client.out, "main", "msvc", None, "Release", "x86_64", None)

bat_contents = client.load("conanbuild.bat")
sh_contents = client.load("conanbuild.sh")

assert "conanvcvars.bat" in bat_contents
assert "conan_compiler.sh" in sh_contents and "conanautotoolstoolchain.sh" in sh_contents

0 comments on commit f45d0a8

Please sign in to comment.