|
| 1 | +import os |
| 2 | +import sys |
| 3 | +import struct |
| 4 | +import platform |
| 5 | +from setuptools import setup, Extension |
| 6 | +from ext_targets import build_ext, StaticLib |
| 7 | + |
| 8 | +COMPILE_FLAGS = ['-flto', '-std=gnu++11', '-g', '-Wall', |
| 9 | + '-Werror'] |
| 10 | + |
| 11 | +LINK_FLAGS = ['-flto', '-Wl,-rpath,.'] |
| 12 | + |
| 13 | +if len(sys.argv) > 1 and "--fast" in sys.argv: |
| 14 | + sys.argv.remove("--fast") |
| 15 | + # Fast mode disables optimization flags |
| 16 | + FAST = True |
| 17 | + print("FAST mode On") |
| 18 | +else: |
| 19 | + FAST = False |
| 20 | + # Fix "ImportError ... undefined symbol ..." caused by CEF's include/base/ |
| 21 | + # headers by adding the -flto flag (Issue #230). Unfortunately -flto |
| 22 | + # prolongs compilation time significantly. |
| 23 | + # More on the other flags: https://stackoverflow.com/questions/6687630/ |
| 24 | + COMPILE_FLAGS += ['-fdata-sections', '-ffunction-sections'] |
| 25 | + LINK_FLAGS += ['-Wl,--gc-sections'] |
| 26 | + |
| 27 | + |
| 28 | +# Architecture and OS postfixes |
| 29 | +ARCH32 = (8 * struct.calcsize('P') == 32) |
| 30 | +ARCH64 = (8 * struct.calcsize('P') == 64) |
| 31 | +OS_POSTFIX = ("win" if platform.system() == "Windows" else |
| 32 | + "linux" if platform.system() == "Linux" else |
| 33 | + "mac" if platform.system() == "Darwin" else "unknown") |
| 34 | +OS_POSTFIX2 = "unknown" |
| 35 | +if OS_POSTFIX == "win": |
| 36 | + OS_POSTFIX2 = "win32" if ARCH32 else "win64" |
| 37 | +elif OS_POSTFIX == "mac": |
| 38 | + OS_POSTFIX2 = "mac32" if ARCH32 else "mac64" |
| 39 | +elif OS_POSTFIX == "linux": |
| 40 | + OS_POSTFIX2 = "linux32" if ARCH32 else "linux64" |
| 41 | + |
| 42 | +# Directories |
| 43 | +CPP_UTILS_DIR = os.path.abspath(os.path.dirname(__file__)) |
| 44 | +SRC_DIR = os.path.abspath(os.path.join(CPP_UTILS_DIR, "..")) |
| 45 | +CEFPYTHON_DIR = os.path.abspath(os.path.join(SRC_DIR, "..")) |
| 46 | +BUILD_DIR = os.path.abspath(os.path.join(CEFPYTHON_DIR, "build")) |
| 47 | +CEFPYTHON_BINARY = os.path.abspath(os.path.join(BUILD_DIR, |
| 48 | + "cefpython_"+OS_POSTFIX2)) |
| 49 | + |
| 50 | +CEF_BINARY = os.environ.get('CEF_BINARY') |
| 51 | +if not CEF_BINARY or not os.path.exists(CEF_BINARY): |
| 52 | + CEF_BINARY = os.path.abspath(os.path.join(BUILD_DIR, "cef_"+OS_POSTFIX2)) |
| 53 | + |
| 54 | + |
| 55 | +UPSTREAM_BUILD = (os.path.exists(os.path.join(CEF_BINARY, 'bin')) and |
| 56 | + os.path.exists(os.path.join(CEF_BINARY, 'lib'))) |
| 57 | + |
| 58 | +# Python version string: "27" or "32". |
| 59 | +PYTHON_VERSION = str(sys.version_info.major) + str(sys.version_info.minor) |
| 60 | + |
| 61 | + |
| 62 | +libcpp_utils_src = [ |
| 63 | + 'PaintBuffer.cpp' |
| 64 | +] |
| 65 | + |
| 66 | +setup( |
| 67 | + name='libcpp_utils', |
| 68 | + cmdclass={'build_ext': build_ext}, |
| 69 | + ext_modules=[ |
| 70 | + StaticLib( |
| 71 | + name="cpp_utils", |
| 72 | + sources=[os.path.join(CPP_UTILS_DIR, src) for src in libcpp_utils_src], |
| 73 | + include_dirs=[ |
| 74 | + r'./../', |
| 75 | + r'./../common/', |
| 76 | + r'/usr/include/python2.7', |
| 77 | + r'/usr/include/gtk-2.0', |
| 78 | + r'/usr/include/gtk-unix-print-2.0', |
| 79 | + r'/usr/include/glib-2.0', |
| 80 | + r'/usr/include/cairo', |
| 81 | + r'/usr/include/pango-1.0', |
| 82 | + r'/usr/include/gdk-pixbuf-2.0', |
| 83 | + r'/usr/include/atk-1.0', |
| 84 | + r'/usr/lib/x86_64-linux-gnu/gtk-2.0/include', |
| 85 | + r'/usr/lib/x86_64-linux-gnu/gtk-unix-print-2.0', |
| 86 | + r'/usr/lib/x86_64-linux-gnu/glib-2.0/include', |
| 87 | + r'/usr/lib/i386-linux-gnu/gtk-2.0/include', |
| 88 | + r'/usr/lib/i386-linux-gnu/gtk-unix-print-2.0', |
| 89 | + r'/usr/lib/i386-linux-gnu/glib-2.0/include', |
| 90 | + r'/usr/lib64/gtk-2.0/include', |
| 91 | + r'/usr/lib64/gtk-unix-print-2.0', |
| 92 | + r'/usr/lib64/glib-2.0/include', |
| 93 | + r'/usr/lib/gtk-2.0/include', |
| 94 | + r'/usr/lib/gtk-2.0/gtk-unix-print-2.0', |
| 95 | + r'/usr/lib/glib-2.0/include', |
| 96 | + ], |
| 97 | + |
| 98 | + # library_dirs=library_dirs, |
| 99 | + |
| 100 | + # Static libraries only. Order is important, if library A depends on B, |
| 101 | + # then B must be included before A. |
| 102 | + # libraries=libs, |
| 103 | + |
| 104 | + extra_compile_args=COMPILE_FLAGS, |
| 105 | + extra_link_args=LINK_FLAGS, |
| 106 | + ) |
| 107 | + ], |
| 108 | + setup_requires = ['setuptools_bin_targets'] |
| 109 | +) |
0 commit comments