def test_solaris(self):
     with mock.patch("platform.system", mock.MagicMock(return_value='SunOS')), \
          mock.patch("platform.machine", mock.MagicMock(return_value="x86_64")):
         conanfile = MockConanfile(MockSettings({}))
         build_os, build_arch, _, _ = get_cross_building_settings(conanfile)
         self.assertEqual("SunOS", build_os)
         self.assertEqual("x86_64", build_arch)
Ejemplo n.º 2
0
def get_generator(conanfile):
    # Returns the name of the generator to be used by CMake
    if "CONAN_CMAKE_GENERATOR" in os.environ:
        return os.environ["CONAN_CMAKE_GENERATOR"]

    compiler = conanfile.settings.get_safe("compiler")
    arch = conanfile.settings.get_safe("arch")
    compiler_version =conanfile. settings.get_safe("compiler.version")
    os_build, _, _, _ = get_cross_building_settings(conanfile)

    if not compiler or not compiler_version or not arch:
        if os_build == "Windows":
            logger.warning("CMake generator could not be deduced from settings")
            return None
        return "Unix Makefiles"

    if compiler == "Visual Studio":
        _visuals = {'8': '8 2005',
                    '9': '9 2008',
                    '10': '10 2010',
                    '11': '11 2012',
                    '12': '12 2013',
                    '14': '14 2015',
                    '15': '15 2017',
                    '16': '16 2019'}.get(compiler_version, "UnknownVersion %s" % compiler_version)
        base = "Visual Studio %s" % _visuals
        return base

    # The generator depends on the build machine, not the target
    if os_build == "Windows" and compiler != "qcc":
        return "MinGW Makefiles"  # it is valid only under Windows

    return "Unix Makefiles"
 def test_freebsd(self):
     with mock.patch("platform.system", mock.MagicMock(return_value='FreeBSD')), \
          mock.patch("platform.machine", mock.MagicMock(return_value="x86_64")):
         settings = MockSettings({})
         build_os, build_arch, _, _ = get_cross_building_settings(settings)
         self.assertEqual("FreeBSD", build_os)
         self.assertEqual("x86_64", build_arch)
 def test_vxworks(self):
     with mock.patch("platform.system", mock.MagicMock(return_value='VxWorks')), \
          mock.patch("platform.machine", mock.MagicMock(return_value="armv7")):
         conanfile = MockConanfile(MockSettings({}))
         build_os, build_arch, _, _ = get_cross_building_settings(conanfile)
         self.assertEqual("VxWorks", build_os)
         self.assertEqual("armv7", build_arch)
 def test_linux(self):
     with mock.patch("platform.system", mock.MagicMock(return_value='Linux')), \
          mock.patch("platform.machine", mock.MagicMock(return_value="x86_64")), \
          mock.patch.object(OSInfo, '_get_linux_distro_info'):
         conanfile = MockConanfile(MockSettings({}))
         build_os, build_arch, _, _ = get_cross_building_settings(conanfile)
         self.assertEqual("Linux", build_os)
         self.assertEqual("x86_64", build_arch)
Ejemplo n.º 6
0
    def __init__(self, conanfile, generator=None, cmake_system_name=True,
                 parallel=True, build_type=None, toolset=None, make_program=None,
                 set_cmake_flags=False):
        """
        :param settings_or_conanfile: Conanfile instance (or settings for retro compatibility)
        :param generator: Generator name to use or none to autodetect
        :param cmake_system_name: False to not use CMAKE_SYSTEM_NAME variable,
               True for auto-detect or directly a string with the system name
        :param parallel: Try to build with multiple cores if available
        :param build_type: Overrides default build type comming from settings
        :param toolset: Toolset name to use (such as llvm-vs2014) or none for default one,
                applies only to certain generators (e.g. Visual Studio)
        :param set_cmake_flags: whether or not to set CMake flags like CMAKE_CXX_FLAGS, CMAKE_C_FLAGS, etc.
               it's vital to set for certain projects (e.g. using CMAKE_SIZEOF_VOID_P or CMAKE_LIBRARY_ARCHITECTURE)
        """
        if not isinstance(conanfile, ConanFile):
            raise ConanException("First argument of CMake() has to be ConanFile. Use CMake(self)")

        self._settings = conanfile.settings
        self._conanfile = conanfile

        self._os = self._settings.get_safe("os")
        self._os_build, _, self._os_host, _ = get_cross_building_settings(self._settings)

        self._compiler = self._settings.get_safe("compiler")
        self._compiler_version = self._settings.get_safe("compiler.version")
        self._arch = self._settings.get_safe("arch")

        os_ver_str = "os.api_level" if self._os == "Android" else "os.version"
        self._op_system_version = self._settings.get_safe(os_ver_str)

        self._libcxx = self._settings.get_safe("compiler.libcxx")
        self._runtime = self._settings.get_safe("compiler.runtime")
        self._build_type = self._settings.get_safe("build_type")
        self._cppstd = self._settings.get_safe("cppstd")

        self.generator = generator or self._generator()
        self.toolset = self._toolset(toolset)
        self.build_dir = None
        self._cmake_system_name = _get_env_cmake_system_name()
        if self._cmake_system_name is None:  # Not overwritten using environment
            self._cmake_system_name = cmake_system_name
        self.parallel = parallel
        self._set_cmake_flags = set_cmake_flags
        self.definitions = self._get_cmake_definitions()
        if build_type and build_type != self._build_type:
            # Call the setter to warn and update the definitions if needed
            self.build_type = build_type

        make_program = os.getenv("CONAN_MAKE_PROGRAM") or make_program
        if make_program:
            if not tools.which(make_program):
                self._conanfile.output.warn("The specified make program '%s' cannot be found"
                                            "and will be ignored" % make_program)
            else:
                self._conanfile.output.info("Using '%s' as CMAKE_MAKE_PROGRAM" % make_program)
                self.definitions["CMAKE_MAKE_PROGRAM"] = make_program
 def test_cygwin(self):
     with mock.patch("platform.system", mock.MagicMock(return_value='CYGWIN_NT-10.0')), \
          mock.patch("platform.machine", mock.MagicMock(return_value="x86_64")), \
          mock.patch.object(OSInfo, "get_win_version_name", return_value="Windows 98"), \
          mock.patch.object(OSInfo, "get_win_os_version", return_value="4.0"):
         settings = MockSettings({})
         build_os, build_arch, _, _ = get_cross_building_settings(settings)
         self.assertEqual("Windows", build_os)
         self.assertEqual("x86_64", build_arch)
 def test_mingw64(self):
     with mock.patch("platform.system", mock.MagicMock(return_value='MINGW64_NT-10.0')), \
          mock.patch("platform.machine", mock.MagicMock(return_value="x86_64")), \
          mock.patch.object(OSInfo, "get_win_version_name", return_value="Windows 98"), \
          mock.patch.object(OSInfo, "get_win_os_version", return_value="4.0"):
         conanfile = MockConanfile(MockSettings({}))
         build_os, build_arch, _, _ = get_cross_building_settings(conanfile)
         self.assertEqual("Windows", build_os)
         self.assertEqual("x86_64", build_arch)
Ejemplo n.º 9
0
    def __init__(self, conanfile, generator=None, cmake_system_name=True,
                 parallel=True, build_type=None, toolset=None, make_program=None, set_cmake_flags=False):
        """
        :param settings_or_conanfile: Conanfile instance (or settings for retro compatibility)
        :param generator: Generator name to use or none to autodetect
        :param cmake_system_name: False to not use CMAKE_SYSTEM_NAME variable,
               True for auto-detect or directly a string with the system name
        :param parallel: Try to build with multiple cores if available
        :param build_type: Overrides default build type comming from settings
        :param toolset: Toolset name to use (such as llvm-vs2014) or none for default one,
                applies only to certain generators (e.g. Visual Studio)
        :param set_cmake_flags: whether or not to set CMake flags like CMAKE_CXX_FLAGS, CMAKE_C_FLAGS, etc.
               it's vital to set for certain projects (e.g. using CMAKE_SIZEOF_VOID_P or CMAKE_LIBRARY_ARCHITECTURE)
        """
        if not isinstance(conanfile, ConanFile):
            raise ConanException("First argument of CMake() has to be ConanFile. Use CMake(self)")

        self._settings = conanfile.settings
        self._conanfile = conanfile

        self._os = self._settings.get_safe("os")
        self._os_build, _, self._os_host, _ = get_cross_building_settings(self._settings)

        self._compiler = self._settings.get_safe("compiler")
        self._compiler_version = self._settings.get_safe("compiler.version")
        self._arch = self._settings.get_safe("arch")
        self._op_system_version = self._settings.get_safe("os.version")
        self._libcxx = self._settings.get_safe("compiler.libcxx")
        self._runtime = self._settings.get_safe("compiler.runtime")
        self._build_type = self._settings.get_safe("build_type")
        self._cppstd = self._settings.get_safe("cppstd")

        self.generator = generator or self._generator()
        self.toolset = self._toolset(toolset)
        self.build_dir = None
        self._cmake_system_name = _get_env_cmake_system_name()
        if self._cmake_system_name is None:  # Not overwritten using environment
            self._cmake_system_name = cmake_system_name
        self.parallel = parallel
        self._set_cmake_flags = set_cmake_flags
        self.definitions = self._get_cmake_definitions()
        if build_type and build_type != self._build_type:
            # Call the setter to warn and update the definitions if needed
            self.build_type = build_type

        make_program = os.getenv("CONAN_MAKE_PROGRAM") or make_program
        if make_program:
            if not tools.which(make_program):
                self._conanfile.output.warn("The specified make program '%s' cannot be found"
                                            "and will be ignored" % make_program)
            else:
                self._conanfile.output.info("Using '%s' as CMAKE_MAKE_PROGRAM" % make_program)
                self.definitions["CMAKE_MAKE_PROGRAM"] = make_program
Ejemplo n.º 10
0
def get_generator(conanfile):
    # Returns the name of the generator to be used by CMake
    if "CONAN_CMAKE_GENERATOR" in os.environ:
        return os.environ["CONAN_CMAKE_GENERATOR"]

    compiler = conanfile.settings.get_safe("compiler")
    compiler_base = conanfile.settings.get_safe("compiler.base")
    arch = conanfile.settings.get_safe("arch")
    compiler_version = conanfile.settings.get_safe("compiler.version")
    compiler_base_version = conanfile.settings.get_safe(
        "compiler.base.version")
    os_build, _, _, _ = get_cross_building_settings(conanfile)

    if not compiler or not compiler_version or not arch:
        if os_build == "Windows":
            logger.warning(
                "CMake generator could not be deduced from settings")
            return None
        return "Unix Makefiles"

    cmake_years = {
        '8': '8 2005',
        '9': '9 2008',
        '10': '10 2010',
        '11': '11 2012',
        '12': '12 2013',
        '14': '14 2015',
        '15': '15 2017',
        '16': '16 2019',
        '17': '17 2022'
    }

    if compiler == "msvc":
        if compiler_version is None:
            raise ConanException("compiler.version must be defined")
        from conan.tools.microsoft.visual import vs_ide_version
        vs_version = vs_ide_version(conanfile)
        return "Visual Studio %s" % cmake_years[vs_version]

    if compiler == "Visual Studio" or compiler_base == "Visual Studio":
        version = compiler_base_version or compiler_version
        major_version = version.split('.', 1)[0]
        _visuals = cmake_years.get(major_version,
                                   "UnknownVersion %s" % version)
        base = "Visual Studio %s" % _visuals
        return base

    # The generator depends on the build machine, not the target
    if os_build == "Windows" and compiler != "qcc":
        return "MinGW Makefiles"  # it is valid only under Windows

    return "Unix Makefiles"
Ejemplo n.º 11
0
    def _cross_content(self):
        os_build, arch_build, os_host, arch_host = get_cross_building_settings(self._conanfile)
        os_target, arch_target = os_host, arch_host  # TODO: assume target the same as a host for now?

        build_machine = self._to_meson_machine(os_build, arch_build)
        host_machine = self._to_meson_machine(os_host, arch_host)
        target_machine = self._to_meson_machine(os_target, arch_target)

        context = self._context
        context['build_machine'] = build_machine
        context['host_machine'] = host_machine
        context['target_machine'] = target_machine
        return self._render(self._cross_file_template, context)
Ejemplo n.º 12
0
    def __init__(self,
                 conanfile,
                 generator=None,
                 cmake_system_name=True,
                 parallel=True,
                 build_type=None,
                 toolset=None):
        """
        :param settings_or_conanfile: Conanfile instance (or settings for retro compatibility)
        :param generator: Generator name to use or none to autodetect
        :param cmake_system_name: False to not use CMAKE_SYSTEM_NAME variable,
               True for auto-detect or directly a string with the system name
        :param parallel: Try to build with multiple cores if available
        :param build_type: Overrides default build type comming from settings
        :param toolset: Toolset name to use (such as llvm-vs2014) or none for default one,
                applies only to certain generators (e.g. Visual Studio)
        """
        if not isinstance(conanfile, ConanFile):
            raise ConanException(
                "First argument of CMake() has to be ConanFile. Use CMake(self)"
            )

        self._settings = conanfile.settings
        self._conanfile = conanfile

        self._os = self._settings.get_safe("os")
        self._os_build, _, self._os_host, _ = get_cross_building_settings(
            self._settings)

        self._compiler = self._settings.get_safe("compiler")
        self._compiler_version = self._settings.get_safe("compiler.version")
        self._arch = self._settings.get_safe("arch")
        self._op_system_version = self._settings.get_safe("os.version")
        self._libcxx = self._settings.get_safe("compiler.libcxx")
        self._runtime = self._settings.get_safe("compiler.runtime")
        self._build_type = self._settings.get_safe("build_type")

        self.generator = generator or self._generator()
        self.toolset = self._toolset(toolset)
        self.build_dir = None
        self._cmake_system_name = _get_env_cmake_system_name()
        if self._cmake_system_name is None:  # Not overwritten using environment
            self._cmake_system_name = cmake_system_name
        self.parallel = parallel
        self.definitions = self._get_cmake_definitions()
        if build_type and build_type != self._build_type:
            # Call the setter to warn and update the definitions if needed
            self.build_type = build_type
Ejemplo n.º 13
0
    def _get_package_names(self, packages, arch_names):
        """ Parse package names according it architecture

        :param packages: list with all package to be installed e.g. ["libusb-dev libfoobar-dev"]
        :param arch_names: Package suffix/prefix name used by installer tool
        :return: list with all parsed names e.g. ["libusb-dev:armhf libfoobar-dev:armhf"]
        """
        if self._conanfile and self._conanfile.settings and cross_building(self._conanfile):
            _, build_arch, _, host_arch = get_cross_building_settings(self._conanfile)
            arch = host_arch or build_arch
            parsed_packages = []
            for package in packages:
                for package_name in package.split(" "):
                    parsed_packages.append(self._tool.get_package_name(package_name, arch,
                                                                       arch_names))
            return parsed_packages
        return packages
Ejemplo n.º 14
0
def get_generator(settings):
    if "CONAN_CMAKE_GENERATOR" in os.environ:
        return os.environ["CONAN_CMAKE_GENERATOR"]

    compiler = settings.get_safe("compiler")
    arch = settings.get_safe("arch")
    compiler_version = settings.get_safe("compiler.version")
    os_build, _, _, _ = get_cross_building_settings(settings)
    os_host = settings.get_safe("os")

    if not compiler or not compiler_version or not arch:
        if os_build == "Windows":
            logger.warning(
                "CMake generator could not be deduced from settings")
            return None
        return "Unix Makefiles"

    if compiler == "Visual Studio":
        _visuals = {
            '8': '8 2005',
            '9': '9 2008',
            '10': '10 2010',
            '11': '11 2012',
            '12': '12 2013',
            '14': '14 2015',
            '15': '15 2017',
            '16': '16 2019'
        }
        base = "Visual Studio %s" % _visuals.get(
            compiler_version, "UnknownVersion %s" % compiler_version)
        if os_host != "WindowsCE" and Version(compiler_version) < "16":
            if arch == "x86_64":
                base += " Win64"
            elif "arm" in arch:
                base += " ARM"
        return base

    # The generator depends on the build machine, not the target
    if os_build == "Windows" and compiler != "qcc":
        return "MinGW Makefiles"  # it is valid only under Windows

    return "Unix Makefiles"
Ejemplo n.º 15
0
def get_generator(settings):
    if "CONAN_CMAKE_GENERATOR" in os.environ:
        return os.environ["CONAN_CMAKE_GENERATOR"]

    compiler = settings.get_safe("compiler")
    arch = settings.get_safe("arch")
    compiler_version = settings.get_safe("compiler.version")
    os_build, _, _, _ = get_cross_building_settings(settings)

    if not compiler or not compiler_version or not arch:
        if os_build == "Windows":
            # Not enough settings to set a generator in Windows
            return None
        return "Unix Makefiles"

    if compiler == "Visual Studio":
        _visuals = {
            '8': '8 2005',
            '9': '9 2008',
            '10': '10 2010',
            '11': '11 2012',
            '12': '12 2013',
            '14': '14 2015',
            '15': '15 2017'
        }
        base = "Visual Studio %s" % _visuals.get(
            compiler_version, "UnknownVersion %s" % compiler_version)
        if arch == "x86_64":
            return base + " Win64"
        elif "arm" in arch:
            return base + " ARM"
        else:
            return base

    # The generator depends on the build machine, not the target
    if os_build == "Windows":
        return "MinGW Makefiles"  # it is valid only under Windows

    return "Unix Makefiles"
Ejemplo n.º 16
0
    def _cmake_cross_build_defines(self, cmake_version):
        os_ = self._ss("os")
        arch = self._ss("arch")
        os_ver_str = "os.api_level" if os_ == "Android" else "os.version"
        op_system_version = self._ss(os_ver_str)

        env_sn = get_env("CONAN_CMAKE_SYSTEM_NAME", "")
        env_sn = {"False": False, "True": True, "": None}.get(env_sn, env_sn)
        cmake_system_name = env_sn or self._forced_cmake_system_name

        os_build, _, _, _ = get_cross_building_settings(self._conanfile)
        compiler = self._ss("compiler")
        libcxx = self._ss("compiler.libcxx")

        definitions = OrderedDict()
        os_ver = get_env("CONAN_CMAKE_SYSTEM_VERSION", op_system_version)
        toolchain_file = get_env("CONAN_CMAKE_TOOLCHAIN_FILE", "")

        if toolchain_file != "":
            logger.info("Setting Cross build toolchain file: %s" % toolchain_file)
            definitions["CMAKE_TOOLCHAIN_FILE"] = toolchain_file
            return definitions

        if cmake_system_name is False:
            return definitions

        # System name and system version
        if cmake_system_name is not True:  # String not empty
            definitions["CMAKE_SYSTEM_NAME"] = cmake_system_name
        else:  # detect if we are cross building and the system name and version
            skip_x64_x86 = os_ in ['Windows', 'Linux']
            if cross_building(self._conanfile, skip_x64_x86=skip_x64_x86):  # We are cross building
                apple_system_name = "Darwin" if Version(cmake_version) < Version("3.14") else None
                cmake_system_name_map = {"Macos": "Darwin",
                                         "iOS": apple_system_name or "iOS",
                                         "tvOS": apple_system_name or "tvOS",
                                         "watchOS": apple_system_name or "watchOS",
                                         "Neutrino": "QNX",
                                         "": "Generic",
                                         None: "Generic"}
                definitions["CMAKE_SYSTEM_NAME"] = cmake_system_name_map.get(os_, os_)

        if os_ver:
            definitions["CMAKE_SYSTEM_VERSION"] = os_ver
            if is_apple_os(os_):
                definitions["CMAKE_OSX_DEPLOYMENT_TARGET"] = os_ver

        # system processor
        cmake_system_processor = os.getenv("CONAN_CMAKE_SYSTEM_PROCESSOR")
        if cmake_system_processor:
            definitions["CMAKE_SYSTEM_PROCESSOR"] = cmake_system_processor

        if definitions:  # If enabled cross compile
            for env_var in ["CONAN_CMAKE_FIND_ROOT_PATH",
                            "CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM",
                            "CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY",
                            "CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE"]:

                value = os.getenv(env_var)
                if value:
                    definitions[env_var] = value

            if self._conanfile and self._conanfile.deps_cpp_info.sysroot:
                sysroot_path = self._conanfile.deps_cpp_info.sysroot
            else:
                sysroot_path = os.getenv("CONAN_CMAKE_FIND_ROOT_PATH", None)

            if sysroot_path:
                # Needs to be set here, can't be managed in the cmake generator, CMake needs
                # to know about the sysroot before any other thing
                definitions["CMAKE_SYSROOT"] = sysroot_path.replace("\\", "/")

            # Adjust Android stuff
            if str(os_) == "Android" and definitions["CMAKE_SYSTEM_NAME"] == "Android":
                arch_abi_settings = tools.to_android_abi(arch)
                if arch_abi_settings:
                    definitions["CMAKE_ANDROID_ARCH_ABI"] = arch_abi_settings
                    definitions["ANDROID_ABI"] = arch_abi_settings

                conan_cmake_android_ndk = os.getenv("CONAN_CMAKE_ANDROID_NDK")
                if conan_cmake_android_ndk:
                    definitions["ANDROID_NDK"] = conan_cmake_android_ndk

                definitions["ANDROID_PLATFORM"] = "android-%s" % op_system_version
                definitions["ANDROID_TOOLCHAIN"] = compiler

                # More details about supported stdc++ libraries here:
                # https://developer.android.com/ndk/guides/cpp-support.html
                if libcxx:
                    definitions["ANDROID_STL"] = libcxx
                else:
                    definitions["ANDROID_STL"] = 'none'

        logger.info("Setting Cross build flags: %s"
                    % ", ".join(["%s=%s" % (k, v) for k, v in definitions.items()]))
        return definitions
Ejemplo n.º 17
0
    def _cmake_cross_build_defines(self):

        os_ = self._ss("os")
        arch = self._ss("arch")
        os_ver_str = "os.api_level" if os_ == "Android" else "os.version"
        op_system_version = self._ss(os_ver_str)

        env_sn = get_env("CONAN_CMAKE_SYSTEM_NAME", "")
        env_sn = {"False": False, "True": True, "": None}.get(env_sn, env_sn)
        cmake_system_name = env_sn or self._forced_cmake_system_name

        os_build, _, _, _ = get_cross_building_settings(self._conanfile.settings)

        ret = OrderedDict()
        os_ver = get_env("CONAN_CMAKE_SYSTEM_VERSION", op_system_version)
        toolchain_file = get_env("CONAN_CMAKE_TOOLCHAIN_FILE", "")

        if toolchain_file != "":
            logger.info("Setting Cross build toolchain file: %s" % toolchain_file)
            ret["CMAKE_TOOLCHAIN_FILE"] = toolchain_file
            return ret

        if cmake_system_name is False:
            return ret

        # System name and system version
        if cmake_system_name is not True:  # String not empty
            ret["CMAKE_SYSTEM_NAME"] = cmake_system_name
        else:  # detect if we are cross building and the system name and version
            if cross_building(self._conanfile.settings):  # We are cross building
                if os_ != os_build:
                    if os_:  # the_os is the host (regular setting)
                        ret["CMAKE_SYSTEM_NAME"] = ("Darwin" if os_ in ["iOS", "tvOS", "watchOS"]
                                                    else os_)
                    else:
                        ret["CMAKE_SYSTEM_NAME"] = "Generic"
        if os_ver:
            ret["CMAKE_SYSTEM_VERSION"] = os_ver
            if str(os_) == "Macos":
                ret["CMAKE_OSX_DEPLOYMENT_TARGET"] = os_ver

        # system processor
        cmake_system_processor = os.getenv("CONAN_CMAKE_SYSTEM_PROCESSOR")
        if cmake_system_processor:
            ret["CMAKE_SYSTEM_PROCESSOR"] = cmake_system_processor

        if ret:  # If enabled cross compile
            for env_var in ["CONAN_CMAKE_FIND_ROOT_PATH",
                            "CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM",
                            "CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY",
                            "CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE"]:

                value = os.getenv(env_var)
                if value:
                    ret[env_var] = value

            if self._conanfile and self._conanfile.deps_cpp_info.sysroot:
                sysroot_path = self._conanfile.deps_cpp_info.sysroot
            else:
                sysroot_path = os.getenv("CONAN_CMAKE_FIND_ROOT_PATH", None)

            if sysroot_path:
                # Needs to be set here, can't be managed in the cmake generator, CMake needs
                # to know about the sysroot before any other thing
                ret["CMAKE_SYSROOT"] = sysroot_path.replace("\\", "/")

            # Adjust Android stuff
            if os_ == "Android":
                arch_abi_settings = {"armv8": "arm64-v8a",
                                     "armv7": "armeabi-v7a",
                                     "armv7hf": "armeabi-v7a",
                                     "armv6": "armeabi-v6",
                                     "armv5": "armeabi"
                                     }.get(arch, arch)
                if arch_abi_settings:
                    ret["CMAKE_ANDROID_ARCH_ABI"] = arch_abi_settings

        logger.info("Setting Cross build flags: %s"
                    % ", ".join(["%s=%s" % (k, v) for k, v in ret.items()]))
        return ret
Ejemplo n.º 18
0
    def _cmake_cross_build_defines(self, the_os, os_ver):
        ret = OrderedDict()
        os_ver = get_env("CONAN_CMAKE_SYSTEM_VERSION", os_ver)
        toolchain_file = get_env("CONAN_CMAKE_TOOLCHAIN_FILE", "")

        if toolchain_file != "":
            logger.info("Setting Cross build toolchain file: %s" % toolchain_file)
            ret["CMAKE_TOOLCHAIN_FILE"] = toolchain_file
            return ret

        if self._cmake_system_name is False:
            return ret

        if self._cmake_system_name is not True:  # String not empty
            ret["CMAKE_SYSTEM_NAME"] = self._cmake_system_name
            ret["CMAKE_SYSTEM_VERSION"] = os_ver
        else:  # detect if we are cross building and the system name and version
            if cross_building(self._conanfile.settings):  # We are cross building
                build_os, _, host_os, _ = get_cross_building_settings(self._conanfile.settings)
                if host_os != build_os:
                    if the_os:  # the_os is the host (regular setting)
                        ret["CMAKE_SYSTEM_NAME"] = "Darwin" if the_os in ["iOS", "tvOS",
                                                                          "watchOS"] else the_os
                        if os_ver:
                            ret["CMAKE_SYSTEM_VERSION"] = os_ver
                    else:
                        ret["CMAKE_SYSTEM_NAME"] = "Generic"

        if ret:  # If enabled cross compile
            for env_var in ["CONAN_CMAKE_SYSTEM_PROCESSOR",
                            "CONAN_CMAKE_FIND_ROOT_PATH",
                            "CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM",
                            "CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY",
                            "CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE"]:

                value = os.getenv(env_var, None)
                if value:
                    ret[env_var] = value

            if self._conanfile and self._conanfile.deps_cpp_info.sysroot:
                sysroot_path = self._conanfile.deps_cpp_info.sysroot
            else:
                sysroot_path = os.getenv("CONAN_CMAKE_FIND_ROOT_PATH", None)

            if sysroot_path:
                # Needs to be set here, can't be managed in the cmake generator, CMake needs
                # to know about the sysroot before any other thing
                ret["CMAKE_SYSROOT"] = sysroot_path.replace("\\", "/")

            # Adjust Android stuff
            if self._os == "Android":
                arch_abi_settings = {"armv8": "arm64-v8a",
                                     "armv7": "armeabi-v7a",
                                     "armv7hf": "armeabi-v7a",
                                     "armv6": "armeabi-v6",
                                     "armv5": "armeabi"
                                     }.get(self._arch,
                                           self._arch)
                if arch_abi_settings:
                    ret["CMAKE_ANDROID_ARCH_ABI"] = arch_abi_settings

        logger.info("Setting Cross build flags: %s"
                    % ", ".join(["%s=%s" % (k, v) for k, v in ret.items()]))
        return ret