Beispiel #1
0
 def test_is_apple_os(self):
     self.assertTrue(tools.is_apple_os('iOS'))
     self.assertTrue(tools.is_apple_os('tvOS'))
     self.assertTrue(tools.is_apple_os('watchOS'))
     self.assertTrue(tools.is_apple_os('Macos'))
     self.assertFalse(tools.is_apple_os('Windows'))
     self.assertFalse(tools.is_apple_os('Linux'))
     self.assertFalse(tools.is_apple_os('Android'))
Beispiel #2
0
    def _get_vars(self):
        def append(*args):
            ret = []
            for arg in args:
                if arg:
                    if isinstance(arg, list):
                        ret.extend(arg)
                    else:
                        ret.append(arg)
            return ret

        lib_paths = format_library_paths(self.library_paths,
                                         self._conanfile.settings,
                                         win_bash=self._win_bash,
                                         subsystem=self.subsystem)
        include_paths = format_include_paths(self.include_paths,
                                             self._conanfile.settings,
                                             win_bash=self._win_bash,
                                             subsystem=self.subsystem)

        ld_flags = append(self.link_flags, lib_paths)
        cpp_flags = append(include_paths, format_defines(self.defines))
        libs = format_libraries(self.libs, self._conanfile.settings)

        tmp_compilation_flags = copy.copy(self.flags)
        if self.fpic:
            tmp_compilation_flags.append(pic_flag(self._conanfile.settings))
        if tools.is_apple_os(self._os):
            concat = " ".join(tmp_compilation_flags)
            if os.environ.get("CFLAGS", None):
                concat += " " + os.environ.get("CFLAGS", None)
            if os.environ.get("CXXFLAGS", None):
                concat += " " + os.environ.get("CXXFLAGS", None)
            if (self._os_version and "-version-min" not in concat and "-target" not in concat) or \
                    self._os_subsystem:
                tmp_compilation_flags.append(
                    tools.apple_deployment_target_flag(self._os,
                                                       self._os_version,
                                                       self._os_sdk,
                                                       self._os_subsystem,
                                                       self._arch))
            if "-isysroot" not in concat and platform.system() == "Darwin":
                isysroot = tools.XCRun(self._conanfile.settings).sdk_path
                if isysroot:
                    tmp_compilation_flags.extend(["-isysroot", isysroot])
            if "-arch" not in concat and self._arch:
                apple_arch = tools.to_apple_arch(self._arch)
                if apple_arch:
                    tmp_compilation_flags.extend(["-arch", apple_arch])

        cxx_flags = append(tmp_compilation_flags, self.cxx_flags,
                           self.cppstd_flag)
        c_flags = tmp_compilation_flags

        return ld_flags, cpp_flags, libs, cxx_flags, c_flags
Beispiel #3
0
    def _get_vars(self):
        def append(*args):
            ret = []
            for arg in args:
                if arg:
                    if isinstance(arg, list):
                        ret.extend(arg)
                    else:
                        ret.append(arg)
            return ret

        lib_paths = format_library_paths(self.library_paths,
                                         self._conanfile.settings,
                                         win_bash=self._win_bash,
                                         subsystem=self.subsystem)
        include_paths = format_include_paths(self.include_paths,
                                             self._conanfile.settings,
                                             win_bash=self._win_bash,
                                             subsystem=self.subsystem)

        ld_flags = append(self.link_flags, lib_paths)
        cpp_flags = append(include_paths, format_defines(self.defines))
        libs = format_libraries(self.libs, self._conanfile.settings)

        tmp_compilation_flags = copy.copy(self.flags)
        if self.fpic:
            tmp_compilation_flags.append(pic_flag(self._conanfile.settings))
        if tools.is_apple_os(self._os):
            concat = " ".join(tmp_compilation_flags)
            if os.environ.get("CFLAGS", None):
                concat += " " + os.environ.get("CFLAGS", None)
            if os.environ.get("CXXFLAGS", None):
                concat += " " + os.environ.get("CXXFLAGS", None)
            if self._os_version and "-version-min" not in concat and "-target" not in concat:
                tmp_compilation_flags.append(
                    tools.apple_deployment_target_flag(self._os,
                                                       self._os_version))

        cxx_flags = append(tmp_compilation_flags, self.cxx_flags,
                           self.cppstd_flag)
        c_flags = tmp_compilation_flags

        return ld_flags, cpp_flags, libs, cxx_flags, c_flags
Beispiel #4
0
    def get_definitions(self, cmake_version):

        compiler = self._ss("compiler")
        compiler_base = self._ss("compiler.base")
        compiler_version = self._ss("compiler.version")
        arch = self._ss("arch")
        os_ = self._ss("os")
        libcxx = self._ss("compiler.libcxx")
        runtime = self._ss("compiler.runtime")
        build_type = self._ss("build_type")

        definitions = OrderedDict()
        definitions.update(runtime_definition(runtime))
        definitions.update(build_type_definition(self._forced_build_type, build_type,
                                                 self._generator, self._output))

        # don't attempt to override variables set within toolchain
        if (tools.is_apple_os(os_) and "CONAN_CMAKE_TOOLCHAIN_FILE" not in os.environ
                and "CMAKE_TOOLCHAIN_FILE" not in definitions):
            apple_arch = tools.to_apple_arch(arch)
            if apple_arch:
                definitions["CMAKE_OSX_ARCHITECTURES"] = apple_arch
            # xcrun is only available on macOS, otherwise it's cross-compiling and it needs to be
            # set within CMake toolchain. also, if SDKROOT is set, CMake will use it, and it's not
            # needed to run xcrun.
            if platform.system() == "Darwin" and "SDKROOT" not in os.environ:
                sdk_path = tools.XCRun(self._conanfile.settings).sdk_path
                if sdk_path:
                    definitions["CMAKE_OSX_SYSROOT"] = sdk_path

        definitions.update(self._cmake_cross_build_defines(cmake_version))
        definitions.update(self._get_cpp_standard_vars())

        definitions.update(in_local_cache_definition(self._conanfile.in_local_cache))

        if compiler:
            definitions["CONAN_COMPILER"] = compiler
        if compiler_version:
            definitions["CONAN_COMPILER_VERSION"] = str(compiler_version)

        # C, CXX, LINK FLAGS
        if compiler == "Visual Studio" or compiler_base == "Visual Studio":
            if self._parallel:
                flag = parallel_compiler_cl_flag(output=self._output)
                definitions['CONAN_CXX_FLAGS'] = flag
                definitions['CONAN_C_FLAGS'] = flag
        else:  # arch_flag is only set for non Visual Studio
            arch_flag = architecture_flag(self._conanfile.settings)
            if arch_flag:
                definitions['CONAN_CXX_FLAGS'] = arch_flag
                definitions['CONAN_SHARED_LINKER_FLAGS'] = arch_flag
                definitions['CONAN_C_FLAGS'] = arch_flag
                if self._set_cmake_flags:
                    definitions['CMAKE_CXX_FLAGS'] = arch_flag
                    definitions['CMAKE_SHARED_LINKER_FLAGS'] = arch_flag
                    definitions['CMAKE_C_FLAGS'] = arch_flag

        if libcxx:
            definitions["CONAN_LIBCXX"] = libcxx

        # Shared library
        try:
            definitions["BUILD_SHARED_LIBS"] = "ON" if self._conanfile.options.shared else "OFF"
        except ConanException:
            pass

        # Install to package folder
        try:
            if self._conanfile.package_folder:
                definitions["CMAKE_INSTALL_PREFIX"] = self._conanfile.package_folder
                definitions["CMAKE_INSTALL_BINDIR"] = DEFAULT_BIN
                definitions["CMAKE_INSTALL_SBINDIR"] = DEFAULT_BIN
                definitions["CMAKE_INSTALL_LIBEXECDIR"] = DEFAULT_BIN
                definitions["CMAKE_INSTALL_LIBDIR"] = DEFAULT_LIB
                definitions["CMAKE_INSTALL_INCLUDEDIR"] = DEFAULT_INCLUDE
                definitions["CMAKE_INSTALL_OLDINCLUDEDIR"] = DEFAULT_INCLUDE
                definitions["CMAKE_INSTALL_DATAROOTDIR"] = DEFAULT_SHARE
        except AttributeError:
            pass

        # fpic
        if not str(os_).startswith("Windows"):
            fpic = self._conanfile.options.get_safe("fPIC")
            if fpic is not None:
                shared = self._conanfile.options.get_safe("shared")
                fpic_value = "ON" if (fpic or shared) else "OFF"
                definitions["CONAN_CMAKE_POSITION_INDEPENDENT_CODE"] = fpic_value

        # Adjust automatically the module path in case the conanfile is using the
        # cmake_find_package or cmake_find_package_multi
        install_folder = self._conanfile.install_folder.replace("\\", "/")
        if "cmake_find_package" in self._conanfile.generators:
            definitions["CMAKE_MODULE_PATH"] = install_folder

        if "cmake_find_package_multi" in self._conanfile.generators:
            # The cmake_find_package_multi only works with targets and generates XXXConfig.cmake
            # that require the prefix path and the module path
            definitions["CMAKE_PREFIX_PATH"] = install_folder
            definitions["CMAKE_MODULE_PATH"] = install_folder

        definitions.update(self._get_make_program_definition())

        # Disable CMake export registry #3070 (CMake installing modules in user home's)
        definitions["CMAKE_EXPORT_NO_PACKAGE_REGISTRY"] = "ON"
        return definitions