Skip to content

Commit

Permalink
build native sources when calling pip install (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
markaren authored Nov 25, 2024
1 parent f8ea8e6 commit 6e4ac1e
Showing 1 changed file with 60 additions and 2 deletions.
62 changes: 60 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,62 @@
from setuptools import setup
import os
import subprocess
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext

cwd = os.getcwd()
WINDOWS = (os.name == 'nt')

buildFolder = "build"
nativeSources = os.path.join(cwd, "pythonfmu", "pythonfmu-export")


class CMakeExtension(Extension):

def __init__(self, name):
super().__init__(name, sources=[])


class CMakeBuild(build_ext):

def run(self):
for ext in self.extensions:
self.build_extension(ext)
super().run()

def build_extension(self, ext):
os.chdir(nativeSources)
if not os.path.exists(buildFolder):
os.mkdir(buildFolder)
build_type = 'Release'
# configure
cmake_args = [
'cmake',
'.',
'-B',
buildFolder,
'-DCMAKE_BUILD_TYPE={}'.format(build_type),
]
if WINDOWS:
cmake_args.extend(['-A', 'x64'])

subprocess.check_call(cmake_args)
cmake_args_build = [
'cmake',
'--build',
buildFolder
]
if WINDOWS:
cmake_args_build.extend(['--config', 'Release'])
subprocess.check_call(cmake_args_build)
os.chdir(cwd)


def binary_suffix():
return ".exe" if WINDOWS else ""


# See setup.cfg for Python package parameters
setup()
setup(
ext_modules=[CMakeExtension('.')],
cmdclass=dict(build_ext=CMakeBuild)
)

0 comments on commit 6e4ac1e

Please sign in to comment.