Esempio n. 1
0
    def __init__(self, conanfile, backend=None, build_type=None):
        """
        :param conanfile: Conanfile instance (or settings for retro compatibility)
        :param backend: Generator name to use or none to autodetect.
               Possible values: ninja,vs,vs2010,vs2015,vs2017,xcode
        :param build_type: Overrides default build type comming from settings
        """
        self._conanfile = conanfile
        self._settings = conanfile.settings

        self._os = self._ss("os")
        self._compiler = self._ss("compiler")
        self._compiler_version = self._ss("compiler.version")
        self._build_type = self._ss("build_type")

        self.backend = backend or "ninja"  # Other backends are poorly supported, not default other.

        self.options = dict()
        if self._conanfile.package_folder:
            self.options['prefix'] = self._conanfile.package_folder
        self.options['libdir'] = DEFAULT_LIB
        self.options['bindir'] = DEFAULT_BIN
        self.options['sbindir'] = DEFAULT_BIN
        self.options['libexecdir'] = DEFAULT_BIN
        self.options['includedir'] = DEFAULT_INCLUDE

        # C++ standard
        cppstd = cppstd_from_settings(self._conanfile.settings)
        cppstd_conan2meson = {
            None: 'none',
            '98': 'c++03',
            'gnu98': 'gnu++03',
            '11': 'c++11',
            'gnu11': 'gnu++11',
            '14': 'c++14',
            'gnu14': 'gnu++14',
            '17': 'c++17',
            'gnu17': 'gnu++17',
            '20': 'c++1z',
            'gnu20': 'gnu++1z'
        }
        self.options['cpp_std'] = cppstd_conan2meson[cppstd]

        # shared
        shared = self._so("shared")
        self.options[
            'default_library'] = "shared" if shared is None or shared else "static"

        # fpic
        if self._os and "Windows" not in self._os:
            fpic = self._so("fPIC")
            if fpic is not None:
                shared = self._so("shared")
                self.options['b_staticpic'] = "true" if (
                    fpic or shared) else "false"

        self.build_dir = None
        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
Esempio n. 2
0
def vs_std_cpp(settings):
    cppstd = cppstd_from_settings(settings)
    if settings.get_safe("compiler") == "Visual Studio" and cppstd:
        flag = cppstd_flag(settings.get_safe("compiler"),
                           settings.get_safe("compiler.version"), cppstd)
        return flag
    return None
Esempio n. 3
0
    def _toolchain_content(self):
        sections = []
        sections.append("def configure(conf):")
        sections.append("    if not conf.env.CXXFLAGS:")
        sections.append("       conf.env.CXXFLAGS = []")
        sections.append("    if not conf.env.LINKFLAGS:")
        sections.append("       conf.env.LINKFLAGS = []")
        if "Visual Studio" in self._compiler:
            # first we set the options for the compiler, then load
            if self._compiler_version:
                sections.append("    conf.env.MSVC_VERSION = '{}.0'".format(
                    self._compiler_version))
            try:
                sections.append("    conf.env.MSVC_TARGETS = '{}'".format(
                    self._arch_conan2waf[self._arch]))
            except KeyError:
                raise ConanException("Architecture  '%s' not supported" %
                                     self._arch)

            sections.append("    conf.env.CXXFLAGS.append('/{}')".format(
                self._compiler_runtime))

            sections.append("    conf.env.CXXFLAGS.extend(['/EHsc'])")
            if self._build_type == "Debug":
                sections.append("    conf.env.CXXFLAGS.extend(['/Zi', '/FS'])")
                sections.append("    conf.env.LINKFLAGS.extend(['/DEBUG'])")
            elif self._build_type == "Release":
                sections.append(
                    "    conf.env.CXXFLAGS.extend(['/O2', '/Ob1', '/DNDEBUG'])"
                )
        else:
            sections.append("    conf.env.CC_VERSION = {}".format(
                self._gcc_ver_conan2waf(self._compiler_version)))

            cxxf = self._libcxx_flags(compiler=self._compiler,
                                      libcxx=self._compiler_libcxx)
            cppstd = cppstd_from_settings(self._conanfile.settings)
            cxxf.append(
                cppstd_flag(
                    self._conanfile.settings.get_safe("compiler"),
                    self._conanfile.settings.get_safe("compiler.version"),
                    cppstd))
            for flag in cxxf:
                sections.append(
                    "    conf.env.CXXFLAGS.append('{}')".format(flag))

            if self._compiler_cppstd:
                cppstdf = cppstd_flag(self._compiler, self._compiler_version,
                                      self._compiler_cppstd)
                sections.append(
                    "    conf.env.CXXFLAGS.append('{}')".format(cppstdf))

            if self._build_type == "Debug":
                sections.append("    conf.env.CXXFLAGS.extend(['-g'])")
            elif self._build_type == "Release":
                sections.append("    conf.env.CXXFLAGS.extend(['-O3'])")

        return "\n".join(sections)
Esempio n. 4
0
 def _cppstd_flag(self):
     if conan_version >= Version("1.24"):
         return tools.cppstd_flag(self._settings)
     else:
         from conans.client.build.cppstd_flags import cppstd_flag, cppstd_from_settings 
         compiler = self._settings.get_safe("compiler")
         compiler_version = self._settings.get_safe("compiler.version")
         cppstd = cppstd_from_settings(self._settings)
         return cppstd_flag(compiler, compiler_version, cppstd)
Esempio n. 5
0
    def __init__(self, conanfile):
        self._conanfile = conanfile
        self._build_type = self._conanfile.settings.get_safe("build_type")
        self._base_compiler = self._conanfile.settings.get_safe("compiler.base") or \
                              self._conanfile.settings.get_safe("compiler")
        self._vscrt = self._conanfile.settings.get_safe("compiler.base.runtime") or \
                      self._conanfile.settings.get_safe("compiler.runtime")
        self._cppstd = cppstd_from_settings(self._conanfile.settings)
        self._shared = self._conanfile.options.get_safe("shared")
        self._fpic = self._conanfile.options.get_safe("fPIC")
        self._build_env = VirtualBuildEnv(self._conanfile).environment()

        self.definitions = dict()
        self.preprocessor_definitions = dict()

        def from_build_env(name):
            return self._to_meson_value(self._build_env.get(name, None))

        self.c = from_build_env("CC")
        self.cpp = from_build_env("CXX")
        self.c_ld = from_build_env("CC_LD") or from_build_env("LD")
        self.cpp_ld = from_build_env("CXX_LD") or from_build_env("LD")
        self.ar = from_build_env("AR")
        self.strip = from_build_env("STRIP")
        self.as_ = from_build_env("AS")
        self.windres = from_build_env("WINDRES")
        self.pkgconfig = from_build_env("PKG_CONFIG")

        # https://mesonbuild.com/Builtin-options.html#core-options
        # Do not adjust "debug" if already adjusted "buildtype"
        self.buildtype = self._to_meson_build_type(
            self._build_type) if self._build_type else None
        self.default_library = self._to_meson_shared(self._shared) \
            if self._shared is not None else None

        # https://mesonbuild.com/Builtin-options.html#base-options
        self.b_vscrt = self._to_meson_vscrt(self._vscrt)
        self.b_staticpic = self._to_meson_value(self._fpic) \
            if (self._shared is False and self._fpic is not None) else None
        self.b_ndebug = self._to_meson_value(
            self._ndebug) if self._build_type else None

        # https://mesonbuild.com/Builtin-options.html#compiler-options
        self.cpp_std = self._to_meson_cppstd(
            self._cppstd) if self._cppstd else None
        self.c_args = self._to_meson_value(
            self._env_array('CPPFLAGS') + self._env_array('CFLAGS'))
        self.c_link_args = self._to_meson_value(self._env_array('LDFLAGS'))
        self.cpp_args = self._to_meson_value(
            self._env_array('CPPFLAGS') + self._env_array('CXXFLAGS'))
        self.cpp_link_args = self._to_meson_value(self._env_array('LDFLAGS'))
        self.pkg_config_path = "'%s'" % self._conanfile.generators_folder

        check_using_build_profile(self._conanfile)
Esempio n. 6
0
 def __init__(self, conanfile, env=os.environ):
     self._conanfile = conanfile
     self._build_type = self._conanfile.settings.get_safe("build_type")
     self._base_compiler = self._conanfile.settings.get_safe("compiler.base") or \
                           self._conanfile.settings.get_safe("compiler")
     self._vscrt = self._conanfile.settings.get_safe("compiler.base.runtime") or \
                   self._conanfile.settings.get_safe("compiler.runtime")
     self._cppstd = cppstd_from_settings(self._conanfile.settings)
     self._shared = self._conanfile.options.get_safe("shared")
     self._fpic = self._conanfile.options.get_safe("fPIC")
     self.definitions = dict()
     self._env = env
Esempio n. 7
0
    def content(self):
        """With compiler_args you can invoke your compiler:
        $ gcc main.c @conanbuildinfo.args -o main
        $ clang main.c @conanbuildinfo.args -o main
        $ cl /EHsc main.c @conanbuildinfo.args
        """
        flags = []
        flags.extend(format_defines(self._deps_build_info.defines))
        flags.extend(format_include_paths(self._deps_build_info.include_paths,
                                          compiler=self.compiler))

        flags.extend(self._deps_build_info.cxxflags)
        flags.extend(self._deps_build_info.cflags)

        arch_flag = architecture_flag(arch=self.conanfile.settings.get_safe("arch"),
                                      os=self.conanfile.settings.get_safe("os"),
                                      compiler=self.compiler)
        if arch_flag:
            flags.append(arch_flag)

        build_type = self.conanfile.settings.get_safe("build_type")
        btfs = build_type_flags(compiler=self.compiler, build_type=build_type,
                                vs_toolset=self.conanfile.settings.get_safe("compiler.toolset"))
        if btfs:
            flags.extend(btfs)
        btd = build_type_define(build_type=build_type)
        if btd:
            flags.extend(format_defines([btd]))

        if self.compiler == "Visual Studio":
            runtime = visual_runtime(self.conanfile.settings.get_safe("compiler.runtime"))
            if runtime:
                flags.append(runtime)
            # Necessary in the "cl" invocation before specify the rest of linker flags
            flags.append(visual_linker_option_separator)

        the_os = (self.conanfile.settings.get_safe("os_build") or
                  self.conanfile.settings.get_safe("os"))
        flags.extend(rpath_flags(the_os, self.compiler, self._deps_build_info.lib_paths))
        flags.extend(format_library_paths(self._deps_build_info.lib_paths, compiler=self.compiler))
        flags.extend(format_libraries(self._deps_build_info.libs, compiler=self.compiler))
        flags.extend(self._deps_build_info.sharedlinkflags)
        flags.extend(self._deps_build_info.exelinkflags)
        flags.extend(self._libcxx_flags())
        cppstd = cppstd_from_settings(self.conanfile.settings)
        flags.append(cppstd_flag(self.conanfile.settings.get_safe("compiler"),
                                 self.conanfile.settings.get_safe("compiler.version"),
                                 cppstd))
        sysrf = sysroot_flag(self._deps_build_info.sysroot, compiler=self.compiler)
        if sysrf:
            flags.append(sysrf)

        return " ".join(flag for flag in flags if flag)
Esempio n. 8
0
    def __init__(self, conanfile, win_bash=False, include_rpath_flags=False):
        """
        FIXME: include_rpath_flags CONAN 2.0 to default True? Could break many packages in center
        """
        self._conanfile = conanfile
        self._win_bash = win_bash
        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._os_version = conanfile.settings.get_safe("os.version")
        self._os_sdk = conanfile.settings.get_safe("os.sdk")
        self._os_subsystem = conanfile.settings.get_safe("os.subsystem")
        self._arch = conanfile.settings.get_safe("arch")
        self._os_target, self._arch_target = get_target_os_arch(conanfile)

        self._build_type = conanfile.settings.get_safe("build_type")

        self._compiler = conanfile.settings.get_safe("compiler")
        conan_v2_error("compiler setting should be defined.",
                       not self._compiler)

        self._compiler_version = conanfile.settings.get_safe(
            "compiler.version")
        self._compiler_runtime = conanfile.settings.get_safe(
            "compiler.runtime")
        self._libcxx = conanfile.settings.get_safe("compiler.libcxx")
        self._cppstd = cppstd_from_settings(conanfile.settings)

        # Set the generic objects before mapping to env vars to let the user
        # alter some value
        self.libs = list(self._deps_cpp_info.libs)
        self.libs.extend(list(self._deps_cpp_info.system_libs))
        self.include_paths = list(self._deps_cpp_info.include_paths)
        self.library_paths = list(self._deps_cpp_info.lib_paths)

        self.defines = self._configure_defines()
        # Will go to CFLAGS and CXXFLAGS ["-m64" "-m32", "-g", "-s"]
        self.flags = self._configure_flags()
        # Only c++ flags [-stdlib, -library], will go to CXXFLAGS
        self.cxx_flags = self._configure_cxx_flags()
        # cpp standard
        self.cppstd_flag = cppstd_flag(conanfile.settings)
        # Not -L flags, ["-m64" "-m32"]
        self.link_flags = self._configure_link_flags()  # TEST!
        # Precalculate -fPIC
        self.fpic = self._configure_fpic()

        # Precalculate build, host, target triplets
        self.build, self.host, self.target = self._get_host_build_target_flags(
        )
Esempio n. 9
0
    def _get_cpp_standard_vars(self):
        cppstd = cppstd_from_settings(self._conanfile.settings)

        if not cppstd:
            return {}

        definitions = {}
        if cppstd.startswith("gnu"):
            definitions["CONAN_CMAKE_CXX_STANDARD"] = cppstd[3:]
            definitions["CONAN_CMAKE_CXX_EXTENSIONS"] = "ON"
        else:
            definitions["CONAN_CMAKE_CXX_STANDARD"] = cppstd
            definitions["CONAN_CMAKE_CXX_EXTENSIONS"] = "OFF"

        definitions["CONAN_STD_CXX_FLAG"] = cppstd_flag(self._conanfile.settings)
        return definitions
Esempio n. 10
0
    def _get_cpp_standard_vars(self):
        cppstd = cppstd_from_settings(self._conanfile.settings)
        compiler = self._ss("compiler")
        compiler_version = self._ss("compiler.version")

        if not cppstd:
            return {}

        ret = {}
        if cppstd.startswith("gnu"):
            ret["CONAN_CMAKE_CXX_STANDARD"] = cppstd[3:]
            ret["CONAN_CMAKE_CXX_EXTENSIONS"] = "ON"
        else:
            ret["CONAN_CMAKE_CXX_STANDARD"] = cppstd
            ret["CONAN_CMAKE_CXX_EXTENSIONS"] = "OFF"

        ret["CONAN_STD_CXX_FLAG"] = cppstd_flag(compiler, compiler_version, cppstd)
        return ret
Esempio n. 11
0
    def __init__(self, conanfile):
        self._conanfile = conanfile

        self._set_libcxx = True
        self._set_cppstd = True
        self._set_arch = True
        self._set_shared = True if conanfile.options.get_safe(
            "shared") else False
        self._set_fpic = True if conanfile.options.get_safe("fPIC") else False

        self._compiler = conanfile.settings.get_safe("compiler")
        self._compiler_version = conanfile.settings.get_safe(
            "compiler.version")
        self._compiler_runtime = conanfile.settings.get_safe(
            "compiler.runtime")
        self._libcxx = conanfile.settings.get_safe("compiler.libcxx")

        # cpp standard
        self._cppstd = cppstd_from_settings(conanfile.settings)
        self._cppstd_flag = cppstd_flag(conanfile.settings)

        # arch_build in compiler flag format
        self._arch_flag = architecture_flag(self._conanfile.settings)

        # build_type information in compiler flag format
        self._build_type_flags = " ".join(
            build_type_flags(self._conanfile.settings))

        self._os_host = conanfile.settings.get_safe("os")
        self._arch_host = conanfile.settings.get_safe("arch")
        self._os_target, self._arch_target = get_target_os_arch(conanfile)
        self._arch_build, self._os_build = self._get_build_os_arch()
        self._build_type = conanfile.settings.get_safe("build_type")

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

        self.definitions = {}