def test_cxx11_abi_define(): conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "gcc", "compiler.libcxx": "libstdc++", "compiler.version": "7.1", "compiler.cppstd": "17" }) be = AutotoolsToolchain(conanfile) assert be.gcc_cxx11_abi == "_GLIBCXX_USE_CXX11_ABI=0" env = be.environment() assert "-D_GLIBCXX_USE_CXX11_ABI=0" in env["CPPFLAGS"] conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "gcc", "compiler.libcxx": "libstdc++11", "compiler.version": "7.1", "compiler.cppstd": "17" }) be = AutotoolsToolchain(conanfile) env = be.environment() assert be.gcc_cxx11_abi is None assert "-D_GLIBCXX_USE_CXX11_ABI=0" not in env["CPPFLAGS"]
def test_ndebug(): conanfile = ConanFileMock() for bt in ['Release', 'RelWithDebInfo', 'MinSizeRel']: conanfile.settings = MockSettings({"build_type": bt}) be = AutotoolsToolchain(conanfile) assert be.ndebug == "NDEBUG" env = be.environment() assert "-DNDEBUG" in env["CPPFLAGS"] for bt in ['Debug', 'DebWithDebInfo']: conanfile.settings = MockSettings({"build_type": bt}) be = AutotoolsToolchain(conanfile) assert be.ndebug is None env = be.environment() assert "-DNDEBUG" not in env["CPPFLAGS"]
def test_apple_isysrootflag(): """Even when no cross building it is adjusted because it could target a Mac version""" conanfile = ConanFileMock() conanfile.conf = {"tools.apple:sdk_path": "/path/to/sdk"} conanfile.settings_build = MockSettings({ "build_type": "Debug", "os": "Macos", "arch": "x86_64" }) conanfile.settings = MockSettings({ "build_type": "Debug", "os": "iOS", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) expected = "-isysroot /path/to/sdk" assert be.apple_isysroot_flag == expected env = be.environment() assert expected in env["CXXFLAGS"] assert expected in env["CFLAGS"] assert expected in env["LDFLAGS"] # Only set when crossbuilding conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Debug", "os": "iOS", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) assert be.apple_isysroot_flag is None
def test_apple_arch_flag(): conanfile = ConanFileMock() conanfile.conf = {"tools.apple:sdk_path": "/path/to/sdk"} conanfile.settings_build = MockSettings({ "build_type": "Debug", "os": "Macos", "arch": "x86_64" }) conanfile.settings = MockSettings({ "build_type": "Debug", "os": "iOS", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) expected = "-arch arm64" assert be.apple_arch_flag == expected env = be.environment() assert expected in env["CXXFLAGS"] assert expected in env["CFLAGS"] assert expected in env["LDFLAGS"] # Only set when crossbuilding conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Debug", "os": "iOS", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) assert be.apple_arch_flag is None
class AutotoolsGen: def __init__(self, conanfile): self.toolchain = AutotoolsToolchain(conanfile) self.deps = AutotoolsDeps(conanfile) self.env = VirtualEnv(conanfile) def build_environment(self): envtoolchain = self.toolchain.environment() envdeps = self.deps.environment() build_env = self.env.build_environment() build_env.compose(envtoolchain) build_env.compose(envdeps) return build_env def run_environment(self): run_env = self.env.run_environment() return run_env def generate(self): build_env = self.build_environment() run_env = self.run_environment() # FIXME: Use settings, not platform Not always defined :( # os_ = self._conanfile.settings_build.get_safe("os") if platform.system() == "Windows": build_env.save_bat("conanbuildenv.bat") run_env.save_bat("conanrunenv.bat") else: build_env.save_sh("conanbuildenv.sh") run_env.save_sh("conanrunenv.sh") self.toolchain.generate_args()
def test_cppstd(): # Using "cppstd" is discarded conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "gcc", "compiler.libcxx": "libstdc++11", "compiler.version": "7.1", "cppstd": "17" }) be = AutotoolsToolchain(conanfile) env = be.environment() assert not "-std=c++17" in env["CXXFLAGS"] # Using "compiler.cppstd" works conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "gcc", "compiler.libcxx": "libstdc++11", "compiler.version": "7.1", "compiler.cppstd": "17" }) be = AutotoolsToolchain(conanfile) env = be.environment() assert "-std=c++17" in env["CXXFLAGS"] # With visual conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": "Visual Studio", "compiler.version": "14", "compiler.cppstd": "17" }) be = AutotoolsToolchain(conanfile) env = be.environment() assert "/std:c++latest" in env["CXXFLAGS"]
def test_custom_defines(): conanfile = ConanFileMock() conanfile.conf = {"tools.apple:sdk_path": "/path/to/sdk"} conanfile.settings = MockSettings({ "build_type": "RelWithDebInfo", "os": "iOS", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) be.defines = ["MyDefine1", "MyDefine2"] env = be.environment() assert "-DMyDefine1" in env["CPPFLAGS"] assert "-DMyDefine2" in env["CPPFLAGS"] assert "-DNDEBUG" in env["CPPFLAGS"]
def test_build_type_flag(): """Architecture flag is set in CXXFLAGS, CFLAGS and LDFLAGS""" conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Debug", "os": "Windows", "compiler": "Visual Studio", "arch": "x86_64" }) be = AutotoolsToolchain(conanfile) assert be.build_type_flags == ["-Zi", "-Ob0", "-Od"] env = be.environment() assert "-Zi -Ob0 -Od" in env["CXXFLAGS"] assert "-Zi -Ob0 -Od" in env["CFLAGS"] assert "-Zi -Ob0 -Od" not in env["LDFLAGS"]
def test_architecture_flag(config): """Architecture flag is set in CXXFLAGS, CFLAGS and LDFLAGS""" arch, expected = config conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Release", "os": "Macos", "compiler": "gcc", "arch": arch }) be = AutotoolsToolchain(conanfile) assert be.arch_flag == expected env = be.environment() assert expected in env["CXXFLAGS"] assert expected in env["CFLAGS"] assert expected in env["LDFLAGS"]
def test_libcxx(config): compiler, libcxx, expected_flag = config conanfile = ConanFileMock() conanfile.settings = MockSettings({ "build_type": "Release", "arch": "x86", "compiler": compiler, "compiler.libcxx": libcxx, "compiler.version": "7.1", "compiler.cppstd": "17" }) be = AutotoolsToolchain(conanfile) assert be.libcxx == expected_flag env = be.environment() if expected_flag: assert expected_flag in env["CXXFLAGS"]
def test_modify_environment(): """We can alter the environment generated by the toolchain passing the env to the generate""" f = temp_folder() chdir(f) conanfile = ConanFileMock() conanfile.settings = MockSettings({"os": "Linux", "arch": "x86_64"}) conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"}) conanfile.folders.set_base_install(f) be = AutotoolsToolchain(conanfile) env = be.environment() env.define("foo", "var") # We can pass the env to the generate once we adjusted or injected anything be.generate(env) with open("conanautotoolstoolchain.sh") as f: content = f.read() assert "foo" in content
def test_apple_min_os_flag(): """Even when no cross building it is adjusted because it could target a Mac version""" conanfile = ConanFileMock() conanfile.conf = {"tools.apple:sdk_path": "/path/to/sdk"} conanfile.settings = MockSettings({ "build_type": "Debug", "os": "Macos", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) expected = "-mmacosx-version-min=14" assert be.apple_min_version_flag == expected env = be.environment() assert expected in env["CXXFLAGS"] assert expected in env["CFLAGS"] assert expected in env["LDFLAGS"]
def test_custom_ldflags(): conanfile = ConanFileMock() conanfile.conf = {"tools.apple:sdk_path": "/path/to/sdk"} conanfile.settings = MockSettings({ "build_type": "RelWithDebInfo", "os": "iOS", "os.version": "14", "arch": "armv8" }) be = AutotoolsToolchain(conanfile) be.ldflags = ["MyFlag1", "MyFlag2"] env = be.environment() assert "MyFlag1" in env["LDFLAGS"] assert "MyFlag2" in env["LDFLAGS"] assert "-mios-version-min=14" in env["LDFLAGS"] assert "MyFlag" not in env["CXXFLAGS"] assert "MyFlag" not in env["CFLAGS"]
def test_modify_environment(): """We can alter the environment generated by the toolchain passing the env to the generate""" f = temp_folder() chdir(f) conanfile = ConanFileMock() conanfile.settings = MockSettings({"os": "Linux", "arch": "x86_64"}) conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"}) be = AutotoolsToolchain(conanfile) env = be.environment() env.define("foo", "var") # We can pass the env to the generate once we adjusted or injected anything be.generate(env) bat = "conanautotoolstoolchain.{}".format("bat" if platform.system() == "Windows" else "sh") with open(bat) as f: content = f.read() assert "foo" in content
def test_visual_runtime(runtime): """ Testing AutotoolsToolchain with the msvc compiler adjust the runtime """ # Issue: https://github.com/conan-io/conan/issues/10139 settings = MockSettings({"build_type": "Release", "compiler": "Visual Studio", "compiler.runtime": runtime, "os": "Windows", "arch": "x86_64"}) conanfile = ConanFileMock() conanfile.settings = settings conanfile.settings_build = settings autotoolschain = AutotoolsToolchain(conanfile) expected_flag = "-{}".format(runtime) assert autotoolschain.msvc_runtime_flag == expected_flag env = autotoolschain.environment().vars(conanfile) assert expected_flag in env["CFLAGS"] assert expected_flag in env["CXXFLAGS"]
def test_fpic(): conanfile = ConanFileMock() conanfile.settings = MockSettings({"os": "Linux"}) conanfile.options = MockOptions({"fPIC": True}) be = AutotoolsToolchain(conanfile) be.environment() assert be.fpic is True assert "-fPIC" in be.cxxflags conanfile.options = MockOptions({"fPIC": False}) be = AutotoolsToolchain(conanfile) be.environment() assert be.fpic is False assert "-fPIC" not in be.cxxflags conanfile.options = MockOptions({"shared": False}) be = AutotoolsToolchain(conanfile) be.environment() assert be.fpic is None assert "-fPIC" not in be.cxxflags