Exemplo n.º 1
0
def ext_modules(static_include_dirs, static_library_dirs, static_cflags,
                static_binaries):
    from get_libxpdf import get_prebuilt_libxpdf
    get_prebuilt_libxpdf(OPTION_DOWNLOAD_DIR, static_include_dirs,
                         static_library_dirs)

    modules = EXT_MODULES + COMPILED_MODULES

    module_files = list(
        os.path.join(SOURCE_PATH, *module.split('.')) for module in modules)
    cpp_files_exist = [
        os.path.exists(module + '.cpp') for module in module_files
    ]

    use_cython = True
    if CYTHON_INSTALLED and (OPTION_WITH_CYTHON or not all(cpp_files_exist)):
        print("Building with Cython %s." % Cython.Compiler.Version.version)
        # generate module cleanup code
        from Cython.Compiler import Options
        Options.generate_cleanup_code = 3
        Options.clear_to_none = False
    elif not OPTION_WITHOUT_CYTHON and not all(cpp_files_exist):
        for exists, module in zip(cpp_files_exist, module_files):
            if not exists:
                raise RuntimeError(
                    "ERROR: Trying to build without Cython, but pre-generated '%s.cpp' "
                    "is not available (pass --without-cython to ignore this error)."
                    % module)
    else:
        if not all(cpp_files_exist):
            for exists, module in zip(cpp_files_exist, module_files):
                if not exists:
                    print(
                        "WARNING: Trying to build without Cython, but pre-generated "
                        "'%s.cpp' is not available." % module)
        use_cython = False
        print("Building without Cython.")

    base_dir = get_base_dir()
    _include_dirs = _prefer_reldirs(
        base_dir,
        include_dirs(static_include_dirs) + [
            SOURCE_PATH,
            INCLUDE_PACKAGE_PATH,
        ])
    _library_dirs = _prefer_reldirs(base_dir,
                                    library_dirs(static_library_dirs))
    _cflags = cflags(static_cflags)
    _ldflags = ['-isysroot', get_xcode_isysroot()
                ] if sys.platform == 'darwin' else None
    _define_macros = define_macros()
    _libraries = libraries()

    if _library_dirs:
        message = "Building against libxpdf in "
        print(message + "the following directory: " + _library_dirs[0])

    if OPTION_AUTO_RPATH:
        runtime_library_dirs = _library_dirs
    else:
        runtime_library_dirs = []

    if CYTHON_INSTALLED and OPTION_SHOW_WARNINGS:
        from Cython.Compiler import Errors
        Errors.LEVEL = 0

    cythonize_directives = {
        'binding': True,
    }
    if OPTION_WITH_COVERAGE:
        cythonize_directives['linetrace'] = True

    result = []
    for module, src_file in zip(modules, module_files):
        is_py = module in COMPILED_MODULES
        main_module_source = src_file + ('.cpp' if not use_cython else
                                         '.py' if is_py else '.pyx')
        result.append(
            Extension(
                module,
                sources=[main_module_source],
                depends=find_dependencies(module),
                extra_compile_args=_cflags,
                extra_link_args=None if is_py else _ldflags,
                extra_objects=None if is_py else static_binaries,
                define_macros=_define_macros,
                include_dirs=_include_dirs,
                library_dirs=None if is_py else _library_dirs,
                runtime_library_dirs=None if is_py else runtime_library_dirs,
                libraries=None if is_py else _libraries,
            ))
    if CYTHON_INSTALLED and OPTION_WITH_CYTHON_GDB:
        for ext in result:
            ext.cython_gdb = True

    if CYTHON_INSTALLED and use_cython:
        # build .cpp files right now and convert Extension() objects
        from Cython.Build import cythonize
        result = cythonize(result, compiler_directives=cythonize_directives)

    return result
Exemplo n.º 2
0
def ext_modules(static_include_dirs, static_library_dirs, static_cflags,
                static_binaries):
    from get_libxpdf import build_libxpdf, get_prebuilt_libxpdf

    if OPTION_BUILD_LIBXPDF:
        btype = "Release"
        if OPTION_DEBUG_GCC:
            btype = "Debug"
        libs = build_libxpdf(
            OPTION_DOWNLOAD_DIR,
            "build/tmp",
            static_include_dirs,
            static_library_dirs,
            static_cflags,
            static_binaries,
            libxpdf_version=OPTION_LIBXPDF_VERSION,
            build_type=btype,
            multicore=OPTION_MULTICORE,
        )
        if not libs:
            sys.exit(1)
    else:
        get_prebuilt_libxpdf(OPTION_DOWNLOAD_DIR, static_include_dirs,
                             static_library_dirs)

    modules = EXT_MODULES + COMPILED_MODULES

    module_files = list(
        os.path.join(SOURCE_PATH, *module.split(".")) for module in modules)
    cpp_files_exist = [
        os.path.exists(module + ".cpp") for module in module_files
    ]

    use_cython = True
    if CYTHON_INSTALLED and (OPTION_WITH_CYTHON or not all(cpp_files_exist)):
        print("Building with Cython %s." % Cython.Compiler.Version.version)
        # generate module cleanup code
        from Cython.Compiler import Options

        Options.generate_cleanup_code = 3
        Options.clear_to_none = False
    elif not OPTION_WITHOUT_CYTHON and not all(cpp_files_exist):
        for exists, module in zip(cpp_files_exist, module_files):
            if not exists:
                raise RuntimeError(
                    "ERROR: Trying to build without Cython, but pre-generated '%s.cpp' "
                    "is not available (pass --without-cython to ignore this error)."
                    % module)
    else:
        if not all(cpp_files_exist):
            for exists, module in zip(cpp_files_exist, module_files):
                if not exists:
                    print(
                        "WARNING: Trying to build without Cython, but pre-generated "
                        "'%s.cpp' is not available." % module)
        use_cython = False
        print("Building without Cython.")

    base_dir = get_base_dir()
    _include_dirs = _prefer_reldirs(
        base_dir,
        include_dirs(static_include_dirs) + [
            SOURCE_PATH,
            INCLUDE_PACKAGE_PATH,
            EXT_CXX_INCLUDE,
        ],
    )
    _library_dirs = _prefer_reldirs(base_dir,
                                    library_dirs(static_library_dirs))
    _cflags = cflags(static_cflags)
    _ldflags = ["-isysroot", get_xcode_isysroot()
                ] if sys.platform == "darwin" else None
    _define_macros = define_macros()
    _libraries = libraries()

    if _library_dirs:
        message = "Building against libxpdf in "
        print(message + "the following directory: " + _library_dirs[0])

    if OPTION_AUTO_RPATH:
        runtime_library_dirs = _library_dirs
    else:
        runtime_library_dirs = []

    if CYTHON_INSTALLED and OPTION_SHOW_WARNINGS:
        from Cython.Compiler import Errors

        Errors.LEVEL = 0

    cythonize_directives = {
        "binding": True,
    }
    if OPTION_WITH_COVERAGE:
        cythonize_directives["linetrace"] = True
    if OPTION_WITH_SIGNATURE:
        cythonize_directives["embedsignature"] = True

    result = []
    for module, src_file in zip(modules, module_files):
        is_py = module in COMPILED_MODULES
        main_module_source = src_file + (".cpp" if not use_cython else
                                         ".py" if is_py else ".pyx")
        result.append(
            Extension(
                module,
                sources=[main_module_source] +
                EXT_MODULES_EXTRA_SRC.get(module, []),
                depends=find_dependencies(module),
                extra_compile_args=_cflags,
                extra_link_args=None if is_py else _ldflags,
                extra_objects=None if is_py else static_binaries,
                define_macros=_define_macros,
                include_dirs=_include_dirs,
                library_dirs=None if is_py else _library_dirs,
                runtime_library_dirs=None if is_py else runtime_library_dirs,
                libraries=None if is_py else _libraries,
            ))

    gdb = False
    if CYTHON_INSTALLED and OPTION_WITH_CYTHON_GDB:
        gdb = True

    if CYTHON_INSTALLED and use_cython:
        # build .cpp files right now and convert Extension() objects
        from Cython.Build import cythonize

        result = cythonize(result,
                           compiler_directives=cythonize_directives,
                           gdb_debug=gdb)

    return result