#!/usr/bin/env python # imports: import setuptools from distutils.core import setup, Extension import os import sysconfig import subprocess # basic variables: libname = "cnorxz" author = "Christian Zimmermann" author_email = "chizeta@f3l.de" path_to_cnorxz = "" if 'CNORXZ' in os.environ: path_to_cnorxz = os.environ['CNORXZ'] version = "0.0.0" have_numpy = True # flags: config_bin = path_to_cnorxz+"/bin/cnorxz-config" extra_compile_args = sysconfig.get_config_var('CFLAGS').split() cnorxz_version = subprocess.run([config_bin,'--version'],stdout=subprocess.PIPE).stdout.decode('ascii')[:-1] cnorxz_flags = subprocess.run([config_bin,'--flags'],stdout=subprocess.PIPE).stdout.decode('ascii').split() cnorxz_definitions = subprocess.run([config_bin,'--definitions'],stdout=subprocess.PIPE).stdout.decode('ascii').split() cnorxz_flags.remove("-Werror") cnorxz_flags.append("-Wno-write-strings") extra_compile_args += cnorxz_flags # includes: inc_dirs = list() if path_to_cnorxz != "": inc_dirs.append( path_to_cnorxz + "/include/cnorxz" ) inc_dirs.append( "cnorxz/core/include" ) # library dirs: lib_dirs = list() lib_dirs.append( "/usr/lib" ) lib_dirs.append( "/usr/local/lib" ) if path_to_cnorxz != "": lib_dirs.append( path_to_cnorxz + "/lib" ) # optional dependencies: if have_numpy: import numpy inc_dirs.append( numpy.get_include() ) # main default_extension_args = dict( language = "c++", include_dirs = inc_dirs, libraries = [libname], library_dirs = lib_dirs, extra_compile_args = extra_compile_args, define_macros = [(mac,None) for mac in cnorxz_definitions] ) if __name__ == "__main__": print("Include directories:") for d in inc_dirs: print("\t",d) print("Library directories:") for d in lib_dirs: print("\t",d) setup( name = libname, packages = setuptools.find_packages(), version = version, include_dirs = inc_dirs, ext_modules = [Extension( 'cnorxz', ['cnorxz/core/core.cpp','cnorxz/core/lib/array_wrapper.cpp','cnorxz/core/lib/range_wrapper.cpp'], **default_extension_args )], author = author, author_email = author_email, )