Skip to content

Commit

Permalink
Build with cmake
Browse files Browse the repository at this point in the history
- Fix table of contents extraction bug for non-transient simulations
- Reconfigure build to use cmake - solves issues with libpsf.la builds
- Automate tests with ctest
- Use static libpsf.la for python bindings to prevent rpath issue and
make build wheels portable
  • Loading branch information
lekez2005 committed Jun 2, 2021
1 parent 262109b commit ede56b3
Show file tree
Hide file tree
Showing 42 changed files with 360 additions and 1,723 deletions.
23 changes: 2 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
*.lo
*.la
.vscode/
build/
*.o
*.so
.deps
.libs
aclocal.m4
autom4te.cache
configure
Makefile
Makefile.in
INSTALL
m4
py-compile
config.*
src/psftest
test/test_psfdataset
missing
ltmain.sh
libtool
libpsf.pc
libpsf-uninstalled.pc
depcomp
*~
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# https://stackoverflow.com/questions/17511496/how-to-create-a-shared-library-with-cmake
# https://github.com/giuliopaci/cmake-tutorial/blob/master/CMakeLists.txt

cmake_minimum_required(VERSION 3.12)

project(libpsf VERSION 0.3
DESCRIPTION "Load Cadence Spectre PSF simulation data"
LANGUAGES CXX)

option(WITH_PYTHON "Build python bindings" ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
endif()

add_subdirectory(src)
add_subdirectory(test)

if(WITH_PYTHON)
add_subdirectory(bindings)
endif()
Empty file removed ChangeLog
Empty file.
14 changes: 0 additions & 14 deletions Makefile.am

This file was deleted.

Empty file removed NEWS
Empty file.
60 changes: 29 additions & 31 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,44 @@ libpsf is a c++ library that reads Cadence PSF waveform files
Install
=======

Install prerequisits
Install prerequisites
--------------------
If building without python binding, only cmake and boost are required

On a debian based system you can run the following to install the
- On a debian based system you can run the following to install the
packages needed to build libpsf:

sudo apt-get install autoconf automake libtool libboost-all-dev python-numpy-dev
$ sudo apt-get install cmake libboost-all-dev python-numpy-dev cython cppunit

- Otherwise conda can be used to install the following packages:

$ conda install python numpy cython cmake

Then install boost libraries and set

$ export BOOST_LOC=<BOOST_LOCATION>

Build and install
-----------------
To build and install the library::
- From root directory, create build directory

./autogen.sh
make
sudo make install
$ mkdir build && cd build
- Run cmake configuration

To build the python extension with conda::
conda install python=3.7 numpy automake libtool cython
$ cmake .. -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DCMAKE_BUILD_TYPE=RELEASE -DWITH_PYTHON=ON

# link python3.7 to python3.7m
ln -s $CONDA_PREFIX/lib/libpython3.7m.so $CONDA_PREFIX/lib/libpython3.7.so
`CONDA_PREFIX` is the destination where you want libpsf to be installed
To build without the python binding, just set `-DWITH_PYTHON=OFF`
- Build

$ make
- To run tests, [cppunit](https://www.freedesktop.org/wiki/Software/cppunit) is required.

./autogen.sh
./configure --prefix=$CONDA_PREFIX --with-python
# make errors out with "cannot find the library 'libpsf.la'" so build libpsf.la first
cd src
make libpsf.la
cd ..
make install
cd bindings/python
python setup.py install


Running the tests
-----------------
Install cppunit, then compile and run the tests in the test dir::
$ ctest

`ctest --verbose` to see individual test result outputs

- Install

sudo apt-get install libcppunit-dev
cd test
make
./test_psfdataset
$ make install

6 changes: 0 additions & 6 deletions autogen.sh

This file was deleted.

1 change: 1 addition & 0 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(python)
6 changes: 0 additions & 6 deletions bindings/Makefile.am

This file was deleted.

3 changes: 3 additions & 0 deletions bindings/python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
libpsf.cpp
libpsf.h
*.pyc
46 changes: 46 additions & 0 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
find_package(Python COMPONENTS Interpreter Development)
find_program(CYTHON_EXECUTABLE NAMES cython cython3
HINTS ${_python_path})
# find_program(Python REQUIRED COMPONENTS Interpreter Development NumPy)
# https://bloerg.net/posts/cmake-and-distutils/
if( Python_EXECUTABLE AND CYTHON_EXECUTABLE)
MESSAGE( STATUS "numpy headers found at: ${Python_NumPy_INCLUDE_DIRS}")
MESSAGE( STATUS "cython found at: ${CYTHON_EXECUTABLE}")

# set variables for setup.py.in
get_target_property(LIBPSF_BUILD_DIR psf BINARY_DIR)
get_target_property(LIBPSF_INCLUDE psf INCLUDE_DIRECTORIES)

set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in")
set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
set(DEPS setup.py.in psfpython.h psfpython.cc libpsf.pyx cpp_defs.pxd)
set(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build/timestamp")
configure_file(${SETUP_PY_IN} ${SETUP_PY})
# build commands
add_custom_command(OUTPUT ${OUTPUT}
COMMAND ${Python_EXECUTABLE} ${SETUP_PY} build_ext --inplace
COMMAND ${Python_EXECUTABLE} ${SETUP_PY} bdist_wheel
COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT}
DEPENDS ${DEPS})

add_custom_target(python_binding ALL DEPENDS ${OUTPUT})
add_dependencies(python_binding psf)
# install binding
install(CODE "execute_process(COMMAND ${Python_EXECUTABLE} ${SETUP_PY} install)")


install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR})

# tests
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
add_test(NAME python_test
COMMAND ${Python_EXECUTABLE} -m unittest test_psfdataset.py -v
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tests")
set_tests_properties(python_test PROPERTIES
ENVIRONMENT PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}:$ENV{PYTHONPATH})
endif()

else()
MESSAGE( WARNING "python/numpy/cython include not found, skipping python bindings")
endif()
17 changes: 0 additions & 17 deletions bindings/python/Makefile.am

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
37 changes: 19 additions & 18 deletions bindings/python/setup.py → bindings/python/setup.py.in
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/usr/bin/env python

import os, sys
import os
import numpy
from sysconfig import get_paths

# BEFORE importing setuptools, remove MANIFEST. Otherwise it may not be
# properly updated when the contents of directories change (true for distutils,
# not sure about setuptools).
if os.path.exists('MANIFEST'):
os.remove('MANIFEST')
os.remove('MANIFEST')

from setuptools import setup, Extension
from Cython.Build import cythonize
Expand All @@ -19,31 +18,33 @@
except:
long_description = ''

root_include = os.path.abspath(os.path.join(get_paths()['include'], '..'))
numpy_includes = [numpy.get_include()]
python_includes = "${Python_INCLUDE_DIRS}".split(":")
psf_includes = "${LIBPSF_INCLUDE}".split()
psf_lib_dir = "${LIBPSF_BUILD_DIR}"

# https://stackoverflow.com/questions/4597228/how-to-statically-link-a-library-when-compiling-a-python-module-extension
lib_dir = os.path.abspath(os.path.join(get_paths()['stdlib'], '..'))
if 'bdist_wheel' in sys.argv:
static_libraries = ['psf']
extra_objects = ['{}/lib{}.a'.format(lib_dir, l) for l in static_libraries]
libraries = []
else:
extra_objects = []
libraries = ['psf']
static_libraries = ['psf']
extra_objects = [
'{}/lib{}_static.a'.format(psf_lib_dir, l) for l in static_libraries]
libraries = []
extra_link_args=[]


libpsf_ext = Extension(
name="libpsf",
sources = ["libpsf.pyx", "psfpython.cc"],
extra_objects = extra_objects,
libraries = ["psf"],
include_dirs = [root_include, numpy.get_include() ],
sources=["${CMAKE_CURRENT_SOURCE_DIR}/libpsf.pyx",
"${CMAKE_CURRENT_SOURCE_DIR}/psfpython.cc"],
extra_objects=extra_objects,
libraries=libraries,
include_dirs=psf_includes + numpy_includes + python_includes,
extra_link_args=extra_link_args,
)

setup(
name="libpsf",
ext_modules=cythonize([libpsf_ext]),
version="0.0.1",
version="${CMAKE_PROJECT_VERSION}",
description="library to read Cadence PSF output",
install_requires=['numpy>=1.10.0'],
test_suite="tests",
Expand All @@ -52,7 +53,7 @@
long_description=long_description,
long_description_content_type="text/markdown",
license="GNU Lesser General Public License v3.0",
keywords=["cadence","spectre","virtuoso","circtuit", "simulation",
keywords=["cadence", "spectre", "virtuoso", "circtuit", "simulation",
"waveform", "circuit simulation"],
zip_safe=False
)
Empty file removed bindings/python/tests/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion bindings/python/tests/test_psfdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ def test_is_swept(self):


def test_get_signal_properties(self):
with self.assertRaises(libpsf.NotFound) as context:
with self.assertRaises(libpsf.NotFound):
self.psf.get_signal_properties("PSUP")

Loading

0 comments on commit ede56b3

Please sign in to comment.