diff --git a/setup.py b/setup.py index 5840793e5d70c346cfb7230cd267bfa3b7e86e54..b26e1c13d09447d17f8e9fd6e2cd0d0671595bf3 100644 --- a/setup.py +++ b/setup.py @@ -10,8 +10,11 @@ from setuptools.command.install import install from setuptools.command.develop import develop from distutils.version import LooseVersion -# Installation via pip: pip install -e . -# If GPU backend: pip install -e . --install-option="--GPU" +""" +Install python wrapper of virtual fluids +Install GPU backend with option --GPU +(pass to pip via --install-option="--GPU") +""" vf_cmake_args = [ "-DBUILD_VF_PYTHON_BINDINGS=ON", @@ -36,6 +39,7 @@ vf_gpu_cmake_args = [ "-DBUILD_VF_UNIT_TESTS:BOOL=OFF", ] +GPU = False class CommandMixin: user_options = [ @@ -46,12 +50,23 @@ class CommandMixin: super().initialize_options() self.GPU = False + def finalize_options(self): + super().finalize_options() + + def run(self): + global GPU + GPU = GPU or self.GPU + super().run() + + class InstallCommand(CommandMixin, install): user_options = getattr(install, 'user_options', []) + CommandMixin.user_options + class DevelopCommand(CommandMixin, develop): user_options = getattr(develop, 'user_options', []) + CommandMixin.user_options + class CMakeExtension(Extension): def __init__(self, name, sourcedir=''): Extension.__init__(self, name, sources=[]) @@ -99,7 +114,7 @@ class CMakeBuild(CommandMixin, build_ext): build_args += ['--', '-j2'] cmake_args.extend(vf_cmake_args) - cmake_args.extend(vf_gpu_cmake_args if self.GPU else vf_cpu_cmake_args) + cmake_args.extend(vf_gpu_cmake_args if GPU else vf_cpu_cmake_args) env = os.environ.copy() env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''), @@ -117,6 +132,6 @@ setup( name='pyfluids', version='0.0.1', ext_modules=[CMakeExtension('pyfluids')], - cmdclass={"install": InstallCommand, "develop": DevelopCommand, "build_ext":CMakeBuild}, + cmdclass={"install": InstallCommand, "develop": DevelopCommand, "build_ext": CMakeBuild}, zip_safe=False, )