示例#1
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,
                 msbuild_verbosity=None,
                 cmake_program=None):
        """
        :param conanfile: Conanfile instance
        :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 coming 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)
        :param msbuild_verbosity: verbosity level for MSBuild (in case of Visual Studio generator)
        :param cmake_program: Path to the custom cmake executable
        """
        if not isinstance(conanfile, ConanFile):
            raise ConanException(
                "First argument of CMake() has to be ConanFile. Use CMake(self)"
            )

        self._conanfile = conanfile
        self._settings = conanfile.settings
        self._build_type = build_type or conanfile.settings.get_safe(
            "build_type")
        self._cmake_program = os.getenv(
            "CONAN_CMAKE_PROGRAM") or cmake_program or "cmake"

        self.generator = generator or get_generator(conanfile.settings)
        if not self.generator:
            self._conanfile.output.warn(
                "CMake generator could not be deduced from settings")
        self.parallel = parallel
        # Initialize definitions (won't be updated if conanfile or any of these variables change)
        builder = CMakeDefinitionsBuilder(self._conanfile,
                                          cmake_system_name=cmake_system_name,
                                          make_program=make_program,
                                          parallel=parallel,
                                          generator=self.generator,
                                          set_cmake_flags=set_cmake_flags,
                                          forced_build_type=build_type,
                                          output=self._conanfile.output)
        # FIXME CONAN 2.0: CMake() interface should be always the constructor and self.definitions.
        # FIXME CONAN 2.0: Avoid properties and attributes to make the user interface more clear

        self.definitions = builder.get_definitions()
        self.toolset = toolset or get_toolset(self._settings)
        self.build_dir = None
        self.msbuild_verbosity = (os.getenv("CONAN_MSBUILD_VERBOSITY")
                                  or msbuild_verbosity or "minimal")
示例#2
0
文件: cmake.py 项目: ninjayash/conan
    def __init__(self,
                 conanfile,
                 generator=None,
                 generator_platform=None,
                 build_type=None,
                 toolset=None,
                 parallel=True):
        self._conanfile = conanfile

        self.fpic = self._deduce_fpic()
        self.vs_static_runtime = self._deduce_vs_static_runtime()
        self.parallel = parallel

        # To find the generated cmake_find_package finders
        self.cmake_prefix_path = "${CMAKE_BINARY_DIR}"
        self.cmake_module_path = "${CMAKE_BINARY_DIR}"

        self.generator = generator or get_generator(self._conanfile)
        self.generator_platform = (generator_platform
                                   or get_generator_platform(
                                       self._conanfile.settings,
                                       self.generator))
        self.toolset = toolset or get_toolset(self._conanfile.settings,
                                              self.generator)

        self.variables = Variables()
        self.preprocessor_definitions = Variables()
        try:
            self._build_shared_libs = "ON" if self._conanfile.options.shared else "OFF"
        except ConanException:
            self._build_shared_libs = None

        self.set_libcxx, self.glibcxx = self._get_libcxx()

        self.parallel = None
        if parallel:
            if self.generator and "Visual Studio" in self.generator:
                self.parallel = "/MP%s" % cpu_count(
                    output=self._conanfile.output)

        self.cppstd, self.cppstd_extensions = self._cppstd()

        self.skip_rpath = True if self._conanfile.settings.get_safe(
            "os") == "Macos" else False
        self.architecture = self._get_architecture()

        # TODO: I would want to have here the path to the compiler too
        build_type = build_type or self._conanfile.settings.get_safe(
            "build_type")
        self.build_type = build_type if not is_multi_configuration(
            self.generator) else None
        try:
            # This is only defined in the cache, not in the local flow
            self.install_prefix = self._conanfile.package_folder.replace(
                "\\", "/")
        except AttributeError:
            # FIXME: In the local flow, we don't know the package_folder
            self.install_prefix = None
示例#3
0
    def __init__(
        self,
        conanfile,
        generator=None,
        generator_platform=None,
        build_type=None,
        cmake_system_name=True,
        toolset=None,
        parallel=True,
        make_program=None,
        # cmake_program=None,  # TODO: cmake program should be considered in the environment
    ):
        self._conanfile = conanfile

        self._fpic = self._deduce_fpic()
        self._vs_static_runtime = self._deduce_vs_static_runtime()

        self._set_rpath = True
        self._set_std = True
        self._set_libcxx = True

        # To find the generated cmake_find_package finders
        self._cmake_prefix_path = "${CMAKE_BINARY_DIR}"
        self._cmake_module_path = "${CMAKE_BINARY_DIR}"

        self._generator = generator or get_generator(self._conanfile)
        self._generator_platform = (generator_platform
                                    or get_generator_platform(
                                        self._conanfile.settings,
                                        self._generator))
        self._toolset = toolset or get_toolset(self._conanfile.settings,
                                               self._generator)
        self._build_type = build_type or self._conanfile.settings.get_safe(
            "build_type")

        builder = CMakeDefinitionsBuilder(self._conanfile,
                                          cmake_system_name=cmake_system_name,
                                          make_program=make_program,
                                          parallel=parallel,
                                          generator=self._generator,
                                          set_cmake_flags=False,
                                          output=self._conanfile.output)
        self.definitions = Definitions()
        self.definitions.update(builder.get_definitions())
        # FIXME: Removing too many things. We want to bring the new logic for the toolchain here
        # so we don't mess with the common code.
        self.definitions.pop("CMAKE_BUILD_TYPE", None)
        self.definitions.pop("CONAN_IN_LOCAL_CACHE", None)
        self.definitions.pop("CMAKE_PREFIX_PATH", None)
        self.definitions.pop("CMAKE_MODULE_PATH", None)
        self.definitions.pop("CONAN_LINK_RUNTIME", None)
        for install in ("PREFIX", "BINDIR", "SBINDIR", "LIBEXECDIR", "LIBDIR",
                        "INCLUDEDIR", "OLDINCLUDEDIR", "DATAROOTDIR"):
            self.definitions.pop("CMAKE_INSTALL_%s" % install, None)
示例#4
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.generator = generator or get_generator(self._settings)
        self.toolset = toolset or get_toolset(self._settings)
        self.build_dir = None
        self.parallel = parallel

        self._set_cmake_flags = set_cmake_flags
        self._cmake_system_name = cmake_system_name
        self._make_program = make_program

        # Initialize definitions (won't be updated if conanfile or any of these variables change)
        builder = CMakeDefinitionsBuilder(
            self._conanfile,
            cmake_system_name=self._cmake_system_name,
            make_program=self._make_program,
            parallel=self.parallel,
            generator=self.generator,
            set_cmake_flags=self._set_cmake_flags)
        self.definitions = builder.get_definitions()

        if build_type is None:
            self.build_type = self._settings.get_safe("build_type")
        else:
            self.build_type = build_type
示例#5
0
    def __init__(self,
                 conanfile,
                 generator=None,
                 generator_platform=None,
                 build_type=None,
                 toolset=None,
                 parallel=True):
        super(CMakeGenericToolchain, self).__init__(conanfile)

        self.fpic = self._deduce_fpic()
        self.vs_static_runtime = self._deduce_vs_static_runtime()
        self.parallel = parallel

        self.generator = generator or get_generator(self._conanfile)
        self.generator_platform = (generator_platform
                                   or get_generator_platform(
                                       self._conanfile.settings,
                                       self.generator))
        self.toolset = toolset or get_toolset(self._conanfile.settings,
                                              self.generator)
        if (self.generator is not None and "Ninja" in self.generator
                and "Visual" in self._conanfile.settings.compiler):
            self.compiler = "cl"
        else:
            self.compiler = None  # compiler defined by default

        try:
            self._build_shared_libs = "ON" if self._conanfile.options.shared else "OFF"
        except ConanException:
            self._build_shared_libs = None

        self.set_libcxx, self.glibcxx = self._get_libcxx()

        self.parallel = None
        if parallel:
            if self.generator and "Visual Studio" in self.generator:
                self.parallel = "/MP%s" % cpu_count(
                    output=self._conanfile.output)

        self.cppstd, self.cppstd_extensions = self._cppstd()

        self.skip_rpath = True if self._conanfile.settings.get_safe(
            "os") == "Macos" else False
        self.architecture = self._get_architecture()

        # TODO: I would want to have here the path to the compiler too
        build_type = build_type or self._conanfile.settings.get_safe(
            "build_type")
        self.build_type = build_type if not is_multi_configuration(
            self.generator) else None
示例#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,
                 msbuild_verbosity="minimal",
                 cmake_program=None,
                 generator_platform=None,
                 append_vcvars=False):
        """
        :param conanfile: Conanfile instance
        :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 coming 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)
        :param msbuild_verbosity: verbosity level for MSBuild (in case of Visual Studio generator)
        :param cmake_program: Path to the custom cmake executable
        :param generator_platform: Generator platform name or none to autodetect (-A cmake option)
        """
        self._append_vcvars = append_vcvars
        self._conanfile = conanfile
        self._settings = conanfile.settings
        self._build_type = build_type or conanfile.settings.get_safe(
            "build_type")
        self._cmake_program = os.getenv(
            "CONAN_CMAKE_PROGRAM") or cmake_program or "cmake"

        self.generator_platform = generator_platform
        self.generator = generator or get_generator(conanfile)

        if not self.generator:
            self._conanfile.output.warn(
                "CMake generator could not be deduced from settings")
        self.parallel = parallel
        # Initialize definitions (won't be updated if conanfile or any of these variables change)
        builder = CMakeDefinitionsBuilder(self._conanfile,
                                          cmake_system_name=cmake_system_name,
                                          make_program=make_program,
                                          parallel=parallel,
                                          generator=self.generator,
                                          set_cmake_flags=set_cmake_flags,
                                          forced_build_type=build_type,
                                          output=self._conanfile.output)
        # FIXME CONAN 2.0: CMake() interface should be always the constructor and self.definitions.
        # FIXME CONAN 2.0: Avoid properties and attributes to make the user interface more clear

        try:
            cmake_version = self.get_version()
            self.definitions = builder.get_definitions(cmake_version)
        except ConanException:
            self.definitions = builder.get_definitions(None)

        self.definitions["CONAN_EXPORTED"] = "1"

        if hasattr(self._conanfile, 'settings_build'):
            # https://github.com/conan-io/conan/issues/9202
            if self._conanfile.settings_build.get_safe("os") == "Macos" and \
               self._conanfile.settings.get_safe("os") == "iOS":
                self.definitions["CMAKE_FIND_ROOT_PATH_MODE_INCLUDE"] = "BOTH"
                self.definitions["CMAKE_FIND_ROOT_PATH_MODE_LIBRARY"] = "BOTH"
                self.definitions["CMAKE_FIND_ROOT_PATH_MODE_PACKAGE"] = "BOTH"

        self.toolset = toolset or get_toolset(self._settings, self.generator)
        self.build_dir = None
        self.msbuild_verbosity = os.getenv(
            "CONAN_MSBUILD_VERBOSITY") or msbuild_verbosity