Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ set (CMAKE_CXX_STANDARD 11)
cmake_minimum_required(VERSION 2.8.12)
project(nestpy)
# Set source directory
set(SOURCE_DIR "src/nestpy")
set(SOURCE_DIR "src/nestpy" CACHE PATH "NEST source directory")
# Tell CMake that headers are also in SOURCE_DIR
include_directories(${SOURCE_DIR})
set(INCLUDE_DIR ${SOURCE_DIR} CACHE PATH "NEST include directory")
include_directories(${INCLUDE_DIR} ${INCLUDE_DIR}/NEST ${INCLUDE_DIR}/Detectors)
set(SOURCES "${SOURCE_DIR}/NEST.cpp" "${SOURCE_DIR}/NEST.cpp" "${SOURCE_DIR}/RandomGen.cpp" "${SOURCE_DIR}/VDetector.cpp" "${SOURCE_DIR}/testNEST.cpp" "${SOURCE_DIR}/TestSpectra.cpp")
include_directories("${SOURCE_DIR}/include")


# Generate Python module
add_subdirectory(lib/pybind11)
pybind11_add_module(nestpy ${SOURCES} "${SOURCE_DIR}/bindings.cpp")
pybind11_add_module(nestpy ${SOURCES} "src/nestpy/bindings.cpp")
unset(SOURCE_DIR CACHE)
unset(INCLUDE_DIR CACHE)
39 changes: 35 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,40 @@
from distutils.version import LooseVersion
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext
from setuptools.command.install import install
from setuptools.command.develop import develop


class CommandMixin(object):
user_options = [
('nest-top-dir=', None, 'Directory holding external NEST code')
]
def initialize_options(self):
super().initialize_options()
# Initialize options
self.nest_top_dir = None

def finalize_options(self):
super().finalize_options()

def run(self):

global nest_top_dir
nest_top_dir = self.nest_top_dir
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=[])
self.sourcedir = os.path.abspath(sourcedir)


class CMakeBuild(build_ext):
def run(self):
try:
Expand All @@ -38,9 +65,9 @@ def build_extension(self, ext):
os.path.dirname(self.get_ext_fullpath(ext.name)))
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
'-DPYTHON_EXECUTABLE=' + sys.executable,
# '-DCMAKE_CXX_COMPILER=/software/gcc-4.9-el6-x86_64/bin/g++'
]

if nest_top_dir:
cmake_args+=[f'-DSOURCE_DIR={nest_top_dir}/src', f'-DINCLUDE_DIR={nest_top_dir}/include']
cfg = 'Debug' if self.debug else 'Release'
build_args = ['--config', cfg]

Expand Down Expand Up @@ -83,7 +110,11 @@ def build_extension(self, ext):
install_requires=requirements,
package_dir={'':'src'},
ext_modules=[CMakeExtension('nestpy/nestpy')],
cmdclass=dict(build_ext=CMakeBuild),
cmdclass={
'install': InstallCommand,
'develop': DevelopCommand,
'build_ext': CMakeBuild
},
test_suite='tests',
zip_safe=False,
include_package_data=True,
Expand Down