示例#1
0
    def build_extension(self, ext):
        extdir = os.path.abspath(
            os.path.dirname(self.get_ext_fullpath(ext.name)))

        if not os.path.exists(self.build_temp):
            os.makedirs(self.build_temp)
        subprocess.check_call(
            [
                "cmake",
                "-DPYBIND11_PYTHON_VERSION={}.{}.{}".format(
                    sys.version_info.major, sys.version_info.minor,
                    sys.version_info.micro),
                "-Dpybind11_DIR={}".format(pybind11.get_cmake_dir()),
                "-DONNX_INCLUDE={}".format(
                    os.path.dirname(os.path.dirname(onnx.__file__))),
                "-DONNXRUNTIME_EXTERNAL_INCLUDE={}".format(
                    os.path.join(
                        os.path.join(os.path.dirname(onnxruntime.__file__),
                                     "external"), "include")),
                "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}".format(extdir),
                ext.sourcedir,
            ],
            cwd=self.build_temp,
        )
        subprocess.check_call(["cmake", "--build", "."], cwd=self.build_temp)
示例#2
0
    def build_extension(self, ext):
        extdir = os.path.abspath(
            os.path.dirname(self.get_ext_fullpath(ext.name)))
        cmake_args = [
            '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
            '-DPYTHON_EXECUTABLE=' + sys.executable
        ]

        cfg = 'Debug' if self.debug else 'Release'
        build_args = ['--config', cfg]

        cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
        build_args += ['--', '-j3']

        env = os.environ.copy()
        import pybind11
        env['pybind11_DIR'] = pybind11.get_cmake_dir()
        env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(
            env.get('CXXFLAGS', ''), self.distribution.get_version())

        if not os.path.exists(self.build_temp):
            os.makedirs(self.build_temp)
        subprocess.check_call(['cmake', ext.sourcedir] + cmake_args,
                              cwd=self.build_temp,
                              env=env)
        subprocess.check_call(['cmake', '--build', '.'] + build_args,
                              cwd=self.build_temp,
                              env=env)
示例#3
0
    def build_extensions(self):
        # First: configure CMake build
        import platform
        import sys
        import distutils.sysconfig

        import pybind11

        # Work out the relevant Python paths to pass to CMake, adapted from the
        # PyTorch build system
        if platform.system() == "Windows":
            cmake_python_library = "{}/libs/python{}.lib".format(
                distutils.sysconfig.get_config_var("prefix"),
                distutils.sysconfig.get_config_var("VERSION"),
            )
            if not os.path.exists(cmake_python_library):
                cmake_python_library = "{}/libs/python{}.lib".format(
                    sys.base_prefix,
                    distutils.sysconfig.get_config_var("VERSION"),
                )
        else:
            cmake_python_library = "{}/{}".format(
                distutils.sysconfig.get_config_var("LIBDIR"),
                distutils.sysconfig.get_config_var("INSTSONAME"),
            )
        cmake_python_include_dir = distutils.sysconfig.get_python_inc()

        install_dir = os.path.abspath(
            os.path.dirname(self.get_ext_fullpath("dummy"))
        )
        os.makedirs(install_dir, exist_ok=True)
        cmake_args = [
            "-DCMAKE_INSTALL_PREFIX={}".format(install_dir),
            "-DPython_EXECUTABLE={}".format(sys.executable),
            "-DPython_LIBRARIES={}".format(cmake_python_library),
            "-DPython_INCLUDE_DIRS={}".format(cmake_python_include_dir),
            "-DCMAKE_BUILD_TYPE={}".format(
                "Debug" if self.debug else "Release"
            ),
            "-DCMAKE_PREFIX_PATH={}".format(pybind11.get_cmake_dir()),
        ]
        if os.environ.get("KEPLER_JAX_CUDA", "no").lower() == "yes":
            cmake_args.append("-DKEPLER_JAX_CUDA=yes")

        os.makedirs(self.build_temp, exist_ok=True)
        subprocess.check_call(
            ["cmake", HERE] + cmake_args, cwd=self.build_temp
        )

        # Build all the extensions
        super().build_extensions()

        # Finally run install
        subprocess.check_call(
            ["cmake", "--build", ".", "--target", "install"],
            cwd=self.build_temp,
        )
示例#4
0
def run_cmake(build_temp, install_dir, debug=False):
    import distutils.sysconfig
    from distutils import log

    # From PyTorch
    if platform.system() == "Windows":
        cmake_python_library = "{}/libs/python{}.lib".format(
            distutils.sysconfig.get_config_var("prefix"),
            distutils.sysconfig.get_config_var("VERSION"),
        )
        # Fix virtualenv builds
        if not os.path.exists(cmake_python_library):
            cmake_python_library = "{}/libs/python{}.lib".format(
                sys.base_prefix,
                distutils.sysconfig.get_config_var("VERSION"),
            )
    else:
        cmake_python_library = "{}/{}".format(
            distutils.sysconfig.get_config_var("LIBDIR"),
            distutils.sysconfig.get_config_var("INSTSONAME"),
        )
    cmake_python_include_dir = distutils.sysconfig.get_python_inc()

    cmake_args = [
        "-DCMAKE_INSTALL_PREFIX={}".format(os.path.dirname(install_dir)),
        "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}".format(install_dir),
        "-DPython_EXECUTABLE={}".format(sys.executable),
        "-DPython_LIBRARIES={}".format(cmake_python_library),
        "-DPython_INCLUDE_DIRS={}".format(cmake_python_include_dir),
        "-DCMAKE_BUILD_TYPE={}".format("Debug" if debug else "Release"),
        "-DCMAKE_PREFIX_PATH={}".format(pybind11.get_cmake_dir()),
    ]
    build_args = []

    if not os.path.exists(build_temp):
        os.makedirs(build_temp)
    log.info("cmake " + HERE + " " + " ".join(cmake_args))
    subprocess.check_call(["cmake", HERE] + cmake_args, cwd=build_temp)
    log.info("cmake --build . --target install " + " ".join(build_args))
    subprocess.check_call(
        ["cmake", "--build", ".", "--target", "install"] + build_args,
        cwd=build_temp,
    )
示例#5
0
文件: setup.py 项目: sthibaul/simgrid
    def build_extension(self, ext):
        from pybind11 import get_cmake_dir
        extdir = os.path.abspath(
            os.path.dirname(self.get_ext_fullpath(ext.name)))
        cmake_args = [
            '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
            '-DPYTHON_EXECUTABLE=' + sys.executable, '-Denable_smpi=OFF',
            '-Denable_java=OFF', '-Denable_python=ON', '-Dminimal-bindings=ON',
            '-Dpybind11_DIR=' + get_cmake_dir()
        ]

        cfg = 'Debug' if self.debug else 'Release'
        build_args = ['--config', cfg]

        if platform.system() == "Windows":
            cmake_args += [
                '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(
                    cfg.upper(), extdir)
            ]
            if sys.maxsize > 2**32:
                cmake_args += ['-A', 'x64']
            build_args += ['--', '/m']
        else:
            cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
            build_args += ['--', '-j4']

        env = os.environ.copy()
        env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(
            env.get('CXXFLAGS', ''), self.distribution.get_version())
        if not os.path.exists(self.build_temp):
            os.makedirs(self.build_temp)
        subprocess.check_call(['cmake', ext.sourcedir] + cmake_args,
                              cwd=self.build_temp,
                              env=env)
        subprocess.check_call(['cmake', '--build', '.'] + build_args,
                              cwd=self.build_temp)
示例#6
0
    def build_extension(self, ext):
        build_temp = Path(self.build_temp).resolve()
        build_temp.mkdir(parents=True, exist_ok=True)

        extdir = Path(self.get_ext_fullpath(ext.name)).resolve().parent
        extdir.mkdir(parents=True, exist_ok=True)

        config = 'Debug' if self.debug else 'Release'
        cmake_args = [
            '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + str(extdir.resolve()),
            '-DCMAKE_BUILD_TYPE=' + config,
            '-Dpybind11_DIR=' + pybind11.get_cmake_dir(),
        ]
        build_args = []

        if sys.platform.startswith("darwin"):
            # Cross-compile support for macOS - respect ARCHFLAGS if set
            archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
            if archs:
                cmake_args += [
                    "-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))
                ]

        # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
        # across all generators.
        if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
            # self.parallel is a Python 3 only way to set parallel jobs by hand
            # using -j in the build_ext call, not supported by pip or PyPA-build.
            if hasattr(self, "parallel") and self.parallel:
                # CMake 3.12+ only.
                build_args += [f"-j{self.parallel}"]

        subprocess.check_call(["cmake", ext.sourcedir] + cmake_args,
                              cwd=self.build_temp)
        subprocess.check_call(["cmake", "--build", "."] + build_args,
                              cwd=self.build_temp)
示例#7
0
文件: setup.py 项目: ENCCS/gromacs
    def build_extension(self, ext):
        # The pybind11 package is only needed for `build_ext`, and may not be installed
        # in the caller's environment. By the time this function is called, though,
        # build dependencies will have been checked.
        import pybind11

        extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))

        # required for auto-detection & inclusion of auxiliary "native" libs
        if not extdir.endswith(os.path.sep):
            extdir += os.path.sep

        debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug
        cfg = "Debug" if debug else "Release"

        # CMake lets you override the generator - we need to check this.
        # Can be set with Conda-Build, for example.
        cmake_generator = os.environ.get("CMAKE_GENERATOR", "")

        cmake_args = [
            "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}".format(extdir),
            "-DCMAKE_BUILD_TYPE={}".format(cfg),  # not used on MSVC, but no harm
        ]
        build_args = []
        # Adding CMake arguments set as environment variable
        # (needed e.g. to build for ARM OSx on conda-forge)
        if "CMAKE_ARGS" in os.environ:
            cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]

        if self.compiler.compiler_type != "msvc":
            # Using Ninja-build since it a) is available as a wheel and b)
            # multithreads automatically. MSVC would require all variables be
            # exported for Ninja to pick it up, which is a little tricky to do.
            # Users can override the generator with CMAKE_GENERATOR in CMake
            # 3.15+.
            if not cmake_generator:
                try:
                    import ninja  # noqa: F401

                    cmake_args += ["-GNinja"]
                except ImportError:
                    pass

        else:

            # Single config generators are handled "normally"
            single_config = any(x in cmake_generator for x in {"NMake", "Ninja"})

            # CMake allows an arch-in-generator style for backward compatibility
            contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"})

            # Specify the arch if using MSVC generator, but only if it doesn't
            # contain a backward-compatibility arch spec already in the
            # generator name.
            if not single_config and not contains_arch:
                cmake_args += ["-A", PLAT_TO_CMAKE[self.plat_name]]

            # Multi-config generators have a different way to specify configs
            if not single_config:
                cmake_args += [
                    "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format(cfg.upper(), extdir)
                ]
                build_args += ["--config", cfg]

        if sys.platform.startswith("darwin"):
            # Cross-compile support for macOS - respect ARCHFLAGS if set
            archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
            if archs:
                cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))]

        # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
        # across all generators.
        if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
            # self.parallel is a Python 3 only way to set parallel jobs by hand
            # using -j in the build_ext call, not supported by pip or PyPA-build.
            if hasattr(self, "parallel") and self.parallel:
                # CMake 3.12+ only.
                build_args += ["-j{}".format(self.parallel)]

        if not os.path.exists(self.build_temp):
            os.makedirs(self.build_temp)

        cmake_args = update_gromacs_client_cmake_args(cmake_args)

        has_pybind = False
        for arg in cmake_args:
            if arg.upper().startswith('-DPYBIND11_ROOT'):
                has_pybind = True
        if not has_pybind:
            pybind_root = pybind11.get_cmake_dir()
            if pybind_root:
                cmake_args.append(f'-Dpybind11_ROOT={pybind_root}')

        subprocess.check_call(
            ["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp
        )
        subprocess.check_call(
            ["cmake", "--build", "."] + build_args, cwd=self.build_temp
        )
示例#8
0
    def run(self):
        nddshome = get_nddshome()
        arch = get_arch()
        lib_dir = os.path.join(get_script_dir(), 'platform', arch)

        # CMake will find same Python major version as the one used for setup
        major_version = sys.version_info.major

        cfg = 'Debug' if (self.debug or get_debug()) else 'Release'
        cmake_args = [
            '-DBUILD_SHARED_LIBS=ON', '-DCONNEXTDDS_DIR=' + nddshome,
            '-DCONNEXTDDS_ARCH=' + arch, '-DCMAKE_BUILD_TYPE=' + cfg,
            '-Dpybind11_DIR=' + pybind11.get_cmake_dir(),
            '-DRTI_PYTHON_MAJOR_VERSION=' + str(major_version),
            '-DRTI_PLATFORM_DIR=' + lib_dir
        ]

        cmake_toolchain = get_cmake_toolchain()
        python_root = get_python_root()

        if cmake_toolchain:
            cmake_args += ['-DCMAKE_TOOLCHAIN_FILE=' + cmake_toolchain]
        else:
            cmake_args += ['-DCMAKE_PREFIX_PATH=' + lib_dir]

        if python_root:
            cmake_args += ['-DPython_ROOT_DIR=' + python_root]

        for ext in self.extensions:
            extdir = os.path.abspath(
                os.path.dirname(self.get_ext_fullpath(ext.name)))
            cmake_args += [
                '-D' + ext.name.replace('.', '_').upper() +
                '_LIBRARY_OUTPUT_DIRECTORY=' + extdir
            ]
            self.copy_extension_libs(ext, extdir, arch)

        build_args = ['--config', cfg]

        if 'Win' in arch:
            cmake_args += ['-A', get_cpu(arch)]
            build_args += ['--', '/p:CL_MPcount={}'.format(get_job_count())]
        else:
            cmake_args += ['-DRTI_LINK_OPTIMIZATIONS_ON=1']
            build_args += ['--parallel', str(get_job_count())]

        # handle possible ABI issues when targeting gcc 4.x platforms
        if 'Linux' in arch and 'gcc4' in arch:
            abi_flag = '-D_GLIBCXX_USE_CXX11_ABI=0'
        else:
            abi_flag = ''

        env = os.environ.copy()
        env['CXXFLAGS'] = '{} {} -DVERSION_INFO=\\"{}\\"'.format(
            env.get('CXXFLAGS', ''), abi_flag, self.distribution.get_version())

        module_build_dir = os.path.join(self.build_temp, 'connext-py')
        if not os.path.exists(module_build_dir):
            os.makedirs(module_build_dir)
        cmake_cmd = os.path.join(cmake.CMAKE_BIN_DIR, 'cmake')
        subprocess.check_call([
            cmake_cmd,
            os.path.abspath(os.path.join(get_script_dir(), 'modules'))
        ] + cmake_args,
                              cwd=module_build_dir,
                              env=env)
        subprocess.check_call([cmake_cmd, '--build', '.'] + build_args,
                              cwd=module_build_dir,
                              env=env)

        # attempt to create interface files for type hinting; failure is not a fatal error
        python_cmd = sys.executable
        stubgen = os.path.join(get_script_dir(), 'resources', 'scripts',
                               'stubgen.py')
        stubgen_args = [
            '--split-overload-docs', '--no-setup-py', '--root-module-suffix',
            ''
        ]
        extdirs = set()
        for ext in self.extensions:
            extdir = os.path.abspath(
                os.path.dirname(self.get_ext_fullpath(ext.name)))
            extdirs.add(extdir)
            pkg_components = ext.name.split('.')[:-1]
            builddir = os.path.abspath(
                os.path.join(extdir,
                             os.sep.join(['..'] * len(pkg_components))))
            stubs_env = os.environ.copy()
            stubs_env['PYTHONPATH'] = builddir
            try:
                with open(os.devnull, 'w') as devnull:
                    subprocess.check_call([python_cmd, stubgen] +
                                          stubgen_args +
                                          ['-o', extdir, ext.name],
                                          env=stubs_env,
                                          stderr=devnull)
            except Exception:
                print('Could not generate stub file for {}'.format(ext.name))

        for extdir in extdirs:
            if os.path.isdir(os.path.join(extdir, '__pycache__')):
                shutil.rmtree(os.path.join(extdir, '__pycache__'))
示例#9
0
    '-DUSE_QT:BOOL=FALSE',
    '-DUSE_MMTF:BOOL=FALSE',
    '-DUSE_PYTHON:BOOL=TRUE',
    '-DUSE_MOLEQUEUE:BOOL=FALSE',
    '-DUSE_HDF5:BOOL=FALSE',
    '-DUSE_LIBARCHIVE:BOOL=FALSE',
    '-DUSE_LIBMSYM:BOOL=FALSE',
] + extra_cmake_args() + wheel_args()

# Add pybind11 if it is installed
try:
    from pybind11 import get_cmake_dir
except ImportError:
    pass
else:
    cmake_args.append('-Dpybind11_DIR:PATH=' + get_cmake_dir())

setup(
    name='avogadro',
    use_scm_version=True,
    setup_requires=['setuptools_scm'],
    description=
    'Avogadro provides analysis and data processing useful in computational chemistry, molecular modeling, bioinformatics, materials science, and related areas.',
    author='Kitware',
    license='BSD',
    url='https://github.com/OpenChemistry/avogadrolibs',
    classifiers=[
        'License :: OSI Approved :: BSD License',
        'Programming Language :: Python', 'Programming Language :: C++',
        'Development Status :: 4 - Beta', 'Intended Audience :: Developers',
        'Intended Audience :: Education',
示例#10
0
    def build_extension(self, ext):
        extdir = os.path.abspath(
            os.path.dirname(self.get_ext_fullpath(ext.name)))

        # required for auto-detection of auxiliary "native" libs
        if not extdir.endswith(os.path.sep):
            extdir += os.path.sep

        cfg = "Debug" if self.debug else "Release"

        # CMake lets you override the generator - we need to check this.
        # Can be set with Conda-Build, for example.
        cmake_generator = os.environ.get("CMAKE_GENERATOR", "")

        # Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON
        # EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code
        # from Python.
        cmake_args = [
            "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}".format(extdir),
            "-DPYTHON_EXECUTABLE={}".format(sys.executable),
            "-DPYDICAL_VERSION_INFO={}".format(
                self.distribution.get_version()),
            "-Dpybind11_ROOT={}".format(get_cmake_dir()),
            "-DCMAKE_BUILD_TYPE={}".format(
                cfg),  # not used on MSVC, but no harm
        ]
        build_args = []

        if self.compiler.compiler_type != "msvc":
            # Using Ninja-build since it a) is available as a wheel and b)
            # multithreads automatically. MSVC would require all variables be
            # exported for Ninja to pick it up, which is a little tricky to do.
            # Users can override the generator with CMAKE_GENERATOR in CMake
            # 3.15+.
            if not cmake_generator:
                cmake_args += ["-GNinja"]

        else:

            # Single config generators are handled "normally"
            single_config = any(x in cmake_generator
                                for x in {"NMake", "Ninja"})

            # CMake allows an arch-in-generator style for backward compatibility
            contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"})

            # Specify the arch if using MSVC generator, but only if it doesn't
            # contain a backward-compatibility arch spec already in the
            # generator name.
            if not single_config and not contains_arch:
                cmake_args += ["-A", PLAT_TO_CMAKE[self.plat_name]]

            # Multi-config generators have a different way to specify configs
            if not single_config:
                cmake_args += [
                    "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format(
                        cfg.upper(), extdir)
                ]
                build_args += ["--config", cfg]

        # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
        # across all generators.
        if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
            # self.parallel is a Python 3 only way to set parallel jobs by hand
            # using -j in the build_ext call, not supported by pip or PyPA-build.
            if hasattr(self, "parallel") and self.parallel:
                # CMake 3.12+ only.
                build_args += ["-j{}".format(self.parallel)]

        if not os.path.exists(self.build_temp):
            os.makedirs(self.build_temp)

        subprocess.check_call(["cmake", ext.sourcedir] + cmake_args,
                              cwd=self.build_temp)
        subprocess.check_call(["cmake", "--build", "."] + build_args,
                              cwd=self.build_temp)
示例#11
0
import subprocess
import sys
import pathlib
import pybind11

lib_name = sys.argv[1]
tag_name = sys.argv[2]

pybind11.get_cmake_dir()

repo_url = 'https://github.com/xtensor-stack/' + lib_name

home = pathlib.Path.home()

subprocess.check_call(['git', 'clone', repo_url], cwd=home)
subprocess.check_call(['git', 'checkout', f'tags/{tag_name}', '-b', tag_name], cwd=home / lib_name)
build = home / lib_name / "build"
build.mkdir()
subprocess.check_call(['cmake', '..'], cwd=build)
subprocess.check_call(['make', 'install'], cwd=build)