Skip to content

Commit

Permalink
Merge pull request #12 from joeydumont/feature-ScaledBesselFunctions
Browse files Browse the repository at this point in the history
This PR adds multiple features:
  * build a static library with the `BUILD_STATIC_LIBS` CMake build option
  * implemented a testing framework based on GTest and GitHub Actions
  * added the scaled Bessel functions, which limit overflow for large arguments. Example call: `double scaled = besselJ(order, z, true)`. The exact scaling depends on the Bessel functions and is documented in the zbesh.for file (more user-friendly docs coming in the near™ future)
  • Loading branch information
joeydumont authored Mar 25, 2020
2 parents e3a7c47 + e376f59 commit ec021ed
Show file tree
Hide file tree
Showing 12 changed files with 501 additions and 85 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This is a basic workflow to help you get started with Actions

name: Run Google Tests

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on: [push, pull_request]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Install dependencies, and Google Test
run: |
sudo apt-get update
sudo apt-get install -y apt-utils build-essential wget git cmake clang ninja-build curl gfortran libgtest-dev libhdf5-dev libboost-all-dev
sudo mkdir -p "/usr/src/googletest/build/" && cd "/usr/src/googletest/build"
sudo cmake -G Ninja .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib -DBUILD_SHARED_LIBS=ON
sudo cmake --build .
sudo cmake --build . --target install
# Runs a set of commands using the runners shell
- name: Compile the package and run the tests
run: |
cd $GITHUB_WORKSPACE
bash build.sh
cd build && make test
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
tests/
build/
*.hdf5
*.h5
*.dat
*.png
*.pdf

# http://www.gnu.org/software/automake

Expand Down
88 changes: 70 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# ----------------------------------------------------------------- #
project(complex_bessel)
set (complex_bessel_VERSION_MAJOR 0)
set (complex_bessel_VERSION_MINOR 6)
set (complex_bessel_VERSION_MINOR 7)
set (complex_bessel_VERSION_RELEASE 0)

# ----------------------------------------------------------------- #
Expand All @@ -22,10 +22,48 @@ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX /usr)
endif()

option(BUILD_STATIC_LIBS "Builds static libraries as well as shared libraries" OFF)
option(BUILD_TESTING "Build the testing tree" OFF)

# ----------------------------------------------------------------- #
# -- Compiler Configuration -- #
# ----------------------------------------------------------------- #

# -- Compiler config (flags and such)
enable_language (Fortran)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wall -march=native")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall -march=native -std=c++11")

# -- Default build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)

# C++14 Standard required
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Configuration for the GCC compiler.
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Wall -Wextra -pedantic -march=native -mtune=native")
set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -Wall -Wextra -pedantic -march=native -mtune=native")

set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -pg -g -Wall -DNDEBUG")
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -pg -g -Wall -DNDEBUG")

set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -Wall -pg -O3 -DNDEBUG")
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -Wall -pg -O3 -DNDEBUG")

# Configuration for the Intel compiler.
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")

set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -debug all")
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g -debug all")

set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O3 -g -debug all")
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O3 -g -debug all")
endif()

# ----------------------------------------------------------------- #
# -- Compilation Instructions -- #
Expand All @@ -37,7 +75,7 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
aux_source_directory (${CMAKE_CURRENT_SOURCE_DIR}/src SRC_LIST)

# -- Build a shared library
add_library(${PROJECT_NAME} SHARED
add_library(${PROJECT_NAME} SHARED
${SRC_LIST}
"${CMAKE_CURRENT_SOURCE_DIR}/src/amos_iso_c_fortran_wrapper.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/src/zbesh.for"
Expand All @@ -52,23 +90,37 @@ set_target_properties (
SOVERSION ${complex_bessel_VERSION_MAJOR}.${complex_bessel_VERSION_MINOR}.${complex_bessel_VERSION_RELEASE}
)

# Link dependencies
target_link_libraries (${PROJECT_NAME} ${LIBS})

# Install directories
install (TARGETS ${PROJECT_NAME} DESTINATION lib)

if (BUILD_STATIC_LIBS)
add_library(${PROJECT_NAME}_static STATIC
${SRC_LIST}
"${CMAKE_CURRENT_SOURCE_DIR}/src/amos_iso_c_fortran_wrapper.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/src/zbesh.for"
"${CMAKE_CURRENT_SOURCE_DIR}/src/machine.for")

set_target_properties(
${PROJECT_NAME}_static
PROPERTIES
VERSION ${complex_bessel_VERSION_MAJOR}.${complex_bessel_VERSION_MINOR}.${complex_bessel_VERSION_RELEASE}
)

# Link dependencies
target_link_libraries (${PROJECT_NAME}_static ${LIBS})

install (TARGETS ${PROJECT_NAME}_static DESTINATION lib)

endif()

# Install includes
install (DIRECTORY include/ DESTINATION include)

# ----------------------------------------------------------------- #
# -- Generate Documentation -- #
# -- Testing Infrastructure -- #
# ----------------------------------------------------------------- #
# add a target to generate API documentation with Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(
doc ALL ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif(DOXYGEN_FOUND)

if (BUILD_TESTING)
include(CTest)
add_subdirectory(tests)
endif()
15 changes: 8 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
# Usage: bash build.sh {make_arg} #
# -----------------------------------------#

# Change to file directory.
# Change to file directory.
cd "$(dirname "$(readlink "$0")")";

# Check if build/ dir exists.
if [ -d build ]; then
# Check if build/ dir exists.
if [ ! -d build ]; then
mkdir build
else
rm -rf build
fi

mkdir build
mkdir build
fi

# Change to build dir and compile the library.
cd build
cmake ..
cmake -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_TESTING=ON ..
make $1
Loading

0 comments on commit ec021ed

Please sign in to comment.