Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
7c85d0a
setup cmake
SteveBronder Jun 30, 2023
facce11
update github actions workflow to use cmake
SteveBronder Jun 30, 2023
a93bceb
...
SteveBronder Jun 30, 2023
893d3a4
Run python tests only once via cmake
SteveBronder Jun 30, 2023
ed44ecc
...
SteveBronder Jun 30, 2023
8ebe786
...
SteveBronder Jun 30, 2023
0c2a0fc
...
SteveBronder Jun 30, 2023
135b853
Merge remote-tracking branch 'upstream/master' into feature/cmake
SteveBronder Jun 30, 2023
17d2e3c
...
SteveBronder Jun 30, 2023
08cd33f
...
SteveBronder Jun 30, 2023
d8b1aa1
...
SteveBronder Jun 30, 2023
31bc719
...
SteveBronder Jun 30, 2023
de2e886
...
SteveBronder Jun 30, 2023
82ca2f2
...
SteveBronder Jun 30, 2023
223a47d
fix cmake to recompile the tests
SteveBronder Jul 7, 2023
ce364d1
fix cmake to recompile the tests
SteveBronder Jul 7, 2023
d249e52
update indents for cmake
SteveBronder Jul 7, 2023
14b6cbf
use python3
SteveBronder Jul 7, 2023
f0f442c
fix github action cmake so that it calls the right python version
SteveBronder Jul 7, 2023
ea7ecb5
fix the python version for cmake
SteveBronder Jul 7, 2023
f044708
set working directory for installing requirements
SteveBronder Jul 7, 2023
5753f41
set working directory for installing requirements
SteveBronder Jul 7, 2023
caafd88
...
SteveBronder Jul 7, 2023
2429c4e
...
SteveBronder Jul 7, 2023
2ab2b9d
...
SteveBronder Jul 7, 2023
2ca4537
...
SteveBronder Jul 7, 2023
ee48d1e
...
SteveBronder Jul 7, 2023
97d33de
...
SteveBronder Jul 7, 2023
6ff6ba3
...
SteveBronder Jul 7, 2023
494c2f4
...
SteveBronder Jul 7, 2023
c249f24
update version number to 1.3.0
SteveBronder Jul 10, 2023
f4796a8
...
SteveBronder Jul 10, 2023
bbbc6f5
add test for burst with actual expect tests
SteveBronder Jul 10, 2023
fe6dd5e
...
SteveBronder Jul 10, 2023
ea8b36d
add test for burst with actual expect tests
SteveBronder Jul 10, 2023
7d96436
fix test cmake
SteveBronder Jul 10, 2023
7e53eea
...
SteveBronder Jul 10, 2023
2f491a0
try to fix the windows bug where the iterator goes on past the list size
SteveBronder Jul 11, 2023
ad6a454
Adds clang sanitizers as cmake build types. Uses vectors instead of l…
SteveBronder Jul 11, 2023
caced66
update headers
SteveBronder Jul 11, 2023
7988526
remove . in python setup.py build
SteveBronder Jul 11, 2023
63fd9be
remove eigen submodule and instead use the Eigen from cmake in setup.py
SteveBronder Jul 11, 2023
da6ab1c
have github action only build with cmake
SteveBronder Jul 11, 2023
515c66d
Fix compiler flags for windows visual studio
SteveBronder Jul 11, 2023
9b2cabb
Fix compiler flags for windows visual studio
SteveBronder Jul 11, 2023
b6c69ef
windows fix
SteveBronder Jul 11, 2023
0c4db6d
update examples folder and fix cmake
SteveBronder Jul 11, 2023
0bfdbfb
...
SteveBronder Jul 11, 2023
8fdf78c
update setup.py to handle visual studio
SteveBronder Jul 11, 2023
f9fdb45
update docs for cmake compilation
SteveBronder Jul 11, 2023
5a496d5
...
SteveBronder Jul 11, 2023
5d7dbbb
...
SteveBronder Jul 11, 2023
bd67dc0
fix typo
SteveBronder Jul 11, 2023
fd04807
update near true answer check for burst test
SteveBronder Jul 11, 2023
cbe3ef4
Add airy test
SteveBronder Jul 19, 2023
75ad164
fix clang format
SteveBronder Jul 19, 2023
187c682
fix clang format
SteveBronder Jul 19, 2023
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
36 changes: 26 additions & 10 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Python package
name: Python and C++ package

on:
pull_request:
Expand All @@ -24,23 +24,39 @@ jobs:
uses: actions/checkout@v2
with:
submodules: recursive

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install .
python3 -m pip install --upgrade pip
pip3 install -r requirements.txt

- name: Install testing packages
run: |
# pip install flake8
# pip install pydocstyle
pip install pytest
pip install pytest-cov pytest-xdist codecov
- name: Test with pytest
pip3 install pytest
pip3 install pytest-cov pytest-xdist codecov


# Below are the added steps for CMake

- name: Setup CMake
uses: jwlawson/[email protected]
with:
cmake-version: 3.21.1

- name: Configure and run CMake
shell: bash
run: |
pytest --cov=pyoscode tests
mkdir test_build
cd test_build
PYTHON_PATH=$(which python)
cmake .. -DCMAKE_BUILD_TYPE=Debug -DPYTHON_EXECUTABLE=${PYTHON_PATH}
cmake --build . --target test

- name: Upload coverage to codecov
uses: codecov/codecov-action@v2

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
!/JOSS-paper/*
/examples/*
!/examples/*.cpp
/examples/*.txt
examples/output.txt
.eggs/*
.vscode/*
bin/*
build/*
test_build/*
dist/*
env/*
lib/*
Expand Down
4 changes: 0 additions & 4 deletions .gitmodules

This file was deleted.

140 changes: 140 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
cmake_minimum_required(VERSION 3.20.2)
project(
oscode
VERSION 1.3.0
LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
if(MSVC)
add_compile_options(/std:c++17)
endif()
set(CMAKE_CXX_EXTENSIONS NO)
if (CMAKE_BUILD_TYPE MATCHES Release)
set(CMAKE_VERBOSE_MAKEFILE NO)
else()
set(CMAKE_VERBOSE_MAKEFILE YES)
endif()

# Build Types
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}
CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel tsan asan lsan msan ubsan"
FORCE)

# ThreadSanitizer
set(CMAKE_C_FLAGS_TSAN
"-fsanitize=thread -g -O1 -march=native -mtune=native"
CACHE STRING "Flags used by the C compiler during ThreadSanitizer builds."
FORCE)
set(CMAKE_CXX_FLAGS_TSAN
"-fsanitize=thread -g -O1 -march=native -mtune=native"
CACHE STRING "Flags used by the C++ compiler during ThreadSanitizer builds."
FORCE)

# AddressSanitize
set(CMAKE_C_FLAGS_ASAN
"-fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer -g -Og -march=native -mtune=native"
CACHE STRING "Flags used by the C compiler during AddressSanitizer builds."
FORCE)
set(CMAKE_CXX_FLAGS_ASAN
"-fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer -g -Og -Wall -march=native -mtune=native"
CACHE STRING "Flags used by the C++ compiler during AddressSanitizer builds."
FORCE)

# LeakSanitizer
set(CMAKE_C_FLAGS_LSAN
"-fsanitize=leak -fno-omit-frame-pointer -g -O1"
CACHE STRING "Flags used by the C compiler during LeakSanitizer builds."
FORCE)
set(CMAKE_CXX_FLAGS_LSAN
"-fsanitize=leak -fno-omit-frame-pointer -g -O1"
CACHE STRING "Flags used by the C++ compiler during LeakSanitizer builds."
FORCE)



set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
include(FetchContent)
# Externally provided libraries
FetchContent_Declare(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG main)

FetchContent_MakeAvailable(googletest)

FetchContent_Declare(
Eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 3.4.0)
set(EIGEN_BUILD_DOC OFF)
# note: To disable eigen tests,
# you should put this code in a add_subdirectory to avoid to change
# BUILD_TESTING for your own project too since variables are directory
# scoped
set(BUILD_TESTING OFF)
set(EIGEN_BUILD_PKGCONFIG OFF)
FetchContent_MakeAvailable(Eigen)

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
set(BOOST_ENABLE_CMAKE ON)
FetchContent_Declare(
boost
URL https://boostorg.jfrog.io/artifactory/main/release/1.82.0/source/boost_1_82_0.tar.gz
)

FetchContent_GetProperties(boost)
if(NOT boost_POPULATED)
FetchContent_Populate(boost)
set(boost_INCLUDE_DIR ${boost_SOURCE_DIR})
endif()


if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_options(
-DNO_FPRINTF_OUTPUT
-Wall
-O3)
endif()

set(oscode_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")

set(PYTHON_EXECUTABLE "" CACHE FILEPATH "Python interpreter to use")

option(OSCODE_HEADER_ONLY "Whether the headers are only included or if the python package should be built. Default builds the python package" OFF)

if (NOT OSCODE_HEADER_ONLY)
if(NOT PYTHON_EXECUTABLE)
message(FATAL_ERROR "PYTHON_EXECUTABLE must be provided")
endif()
# Set the location of the eigen headers
#set(ENV{SOURCE_DIR} ${eigen_SOURCE_DIR})
if (CMAKE_BUILD_TYPE MATCHES Release)
add_custom_target(pyoscode ALL
COMMAND ${CMAKE_COMMAND} -E env "OSCODE_EIGEN_INCLUDE_DIR=${eigen_SOURCE_DIR}" ${PYTHON_EXECUTABLE} setup.py build
COMMAND ${CMAKE_COMMAND} -E env "OSCODE_EIGEN_INCLUDE_DIR=${eigen_SOURCE_DIR}" pip3 install -e .
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Building Python package using setup.py"
)
else()
add_custom_target(pyoscode ALL
COMMAND ${CMAKE_COMMAND} -E env "OSCODE_EIGEN_INCLUDE_DIR=${eigen_SOURCE_DIR}" ${PYTHON_EXECUTABLE} setup.py build_ext -i
COMMAND ${CMAKE_COMMAND} -E env "OSCODE_EIGEN_INCLUDE_DIR=${eigen_SOURCE_DIR}" pip3 install -e .
COMMAND ${CMAKE_COMMAND} -E env "OSCODE_EIGEN_INCLUDE_DIR=${eigen_SOURCE_DIR}" ${PYTHON_EXECUTABLE} setup.py build_ext -if
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Building Python package using setup.py"
)
endif()
endif()
unset(OSCODE_HEADER_ONLY CACHE)
# Allows upstream users to call fetch_content etc.
add_library(oscode INTERFACE)

target_include_directories(oscode PUBLIC INTERFACE
${oscode_INCLUDE_DIR}
)

target_link_libraries(oscode INTERFACE Eigen3::Eigen)

include_directories(tests)
add_subdirectory(tests)
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2020, Fruzsina Julia Agocs
Copyright (c) 2023, Fruzsina Julia Agocs
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
80 changes: 45 additions & 35 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,27 @@ Python

pip install pyoscode

or via the setup.py
Installing from source can be done via cmake with the following

.. code:: bash

git clone --recursive https://github.com/fruzsinaagocs/oscode
cd oscode
python setup.py install --user

or

.. code:: bash

git clone --recursive https://github.com/fruzsinaagocs/oscode
git clone https://github.com/fruzsinaagocs/oscode
cd oscode
pip install .
# For mac this will be $(which python3)
PYTHON_PATH=$(which python)
cmake -S . -B "build" -DCMAKE_BUILD_TYPE=Release -DPYTHON_EXECUTABLE=${PYTHON_PATH}
cd build
make oscode

You can then import ``pyoscode`` from anywhere. Omit the ``--user`` option if
you wish to install globally or in a virtual environment. If you have any
difficulties, check out the `FAQs - Installation
<https://github.com/fruzsinaagocs/oscode#installation-1>`__ section below.

You can check that things are working by running `tests/` (also ran by Travis continuous integration):
You can check that things are working by running the tests in `tests/` (also ran by github actions):

.. code:: bash

pytest tests/
make tests

C++
~~~
Expand All @@ -133,7 +128,7 @@ C++

.. code:: bash

git clone --recursive https://github.com/fruzsinaagocs/oscode
git clone https://github.com/fruzsinaagocs/oscode

and then include the relevant header files in your C++ code:

Expand Down Expand Up @@ -176,16 +171,18 @@ C++
:Introduction to oscode: `examples/burst.cpp`
:To plot results from `burst.cpp`: `examples/plot_burst.py`

To compile and run:
To compile and run the burst example you can use the following:

.. code:: bash

cd examples/
g++ -I../include/ -g -Wall -std=c++11 -c -o burst.o burst.cpp
g++ -I../include/ -g -Wall -std=c++11 -o burst burst.o
./burst
cmake -S . -B "build" -DCMAKE_BUILD_TYPE=Release -DOSCODE_HEADER_ONLY=YES
cd build && make burst_ex && ./burst_ex


The `OSCODE_HEADER_ONLY` flag tells cmake to not create the python package target.
You can use the `CMakeLists.txt` file in the examples folder as a reference point for including `oscode` into your own package.

Documentation
-------------

Expand Down Expand Up @@ -220,30 +217,41 @@ Further help

You can get help by submitting an issue or posting a message on `Gitter <https://gitter.im/oscode-help/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge>`__.

FAQs
----

Installation
~~~~~~~~~~~~
Development
-------------

1. Eigen import errors:
.. code:: bash
Run the following to setup an environment for development:

pyoscode/_pyoscode.hpp:6:10: fatal error: Eigen/Dense: No such file or directory
#include <Eigen/Dense>
^~~~~~~~~~~~~
.. code:: bash
python -m venv env
source ./env/bin/activate
pip install numpy scipy pytest
PYTHON_PATH=$(which python)
cmake -S . -B "build" -DCMAKE_BUILD_TYPE=Debug -DPYTHON_EXECUTABLE=${PYTHON_PATH}
cd build
make oscode
make -j4 test

Try explicitly including the location of your Eigen library via the
``CPLUS_INCLUDE_PATH`` environment variable, for example:
Tests for the C++ and python can be run via cmake with

.. code:: bash
# This can take a while the first time because of boost
cmake -S . -B "build" -DCMAKE_BUILD_TYPE=Debug -DPYTHON_EXECUTABLE=${PYTHON_PATH}
# If your already inside of the build folder then run
# cmake .. -DCMAKE_BUILD_TYPE=Debug -DPYTHON_EXECUTABLE=${PYTHON_PATH}
cd ./build
make -j4 test

CPLUS_INCLUDE_PATH=/usr/include/eigen3 python setup.py install --user
# or
CPLUS_INCLUDE_PATH=/usr/include/eigen3 pip install pyoscode
Valid `CMAKE_BUILD_TYPE`s are `Release` `Debug`, `LSAN`, `MSAN`, `ASAN`, and `TSAN`


Once in the build folder you can run the following to rebuild the cmake if you need to.

.. code:: bash
cmake .. -DCMAKE_BUILD_TYPE=Debug
make -j4 test

where ``/usr/include/eigen3`` should be replaced with your system-specific
eigen location.

Thanks
------
Expand All @@ -258,6 +266,8 @@ devs of `exhale <https://pypi.org/project/exhale/>`__ for making the beautiful C

Changelog
---------
- 1.3.0:
- Add support for cmake build and tests
- 1.2.0:
- Update the version of Eigen to 3.4.0
- 1.1.2:
Expand Down
1 change: 0 additions & 1 deletion deps/eigen
Submodule eigen deleted from e7248b
25 changes: 25 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.20.2)
project(
oscode_examples
VERSION 1.3.0
LANGUAGES C CXX)


set(CMAKE_VERBOSE_MAKEFILE YES)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)

include(FetchContent)
set(OSCODE_HEADER_ONLY ON)
FetchContent_Declare(
oscode
GIT_REPOSITORY https://github.com/SteveBronder/oscode
GIT_TAG feature/cmake
)

FetchContent_MakeAvailable(oscode)

add_executable(burst_ex burst.cpp)

target_link_libraries(burst_ex PRIVATE oscode)
Loading