Skip to content

Commit 6d4d797

Browse files
Merge pull request #46 from kokarez/noexp
Allow xtensor-fftw to build with -fno-exceptions
2 parents 21f5e90 + 76dc964 commit 6d4d797

8 files changed

Lines changed: 64 additions & 17 deletions

File tree

.appveyor.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,10 @@ environment:
1414
- MINICONDA: C:\Miniconda36-x64
1515
FFTW_INSTALL_MODE: conda-forge
1616
FFTW_ROOT:
17-
- MINICONDA: C:\Miniconda36
18-
FFTW_INSTALL_MODE: conda-forge
19-
FFTW_ROOT:
2017
# fftw from the "official" fftw website build
2118
- MINICONDA: C:\Miniconda36-x64
2219
FFTW_INSTALL_MODE: official
2320
FFTW_ROOT: C:\fftw_download
24-
- MINICONDA: C:\Miniconda36
25-
FFTW_INSTALL_MODE: official
26-
FFTW_ROOT: C:\fftw_download
2721

2822
matrix:
2923
exclude:
@@ -42,7 +36,7 @@ install:
4236
- conda config --add channels conda-forge
4337
- conda update -q conda
4438
- conda info -a
45-
- conda install xtensor
39+
- conda install xtensor=0.21.2 -c conda-forge
4640
- IF "%FFTW_INSTALL_MODE%"=="official" ( Powershell.exe -File appveyor_install_fftw.ps1 ) ELSE IF "%FFTW_INSTALL_MODE%"=="conda-forge" ( conda install fftw )
4741
- cd %APPVEYOR_BUILD_FOLDER%
4842
- mkdir build

.travis.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ matrix:
5151
- g++-7
5252
- libfftw3-dev
5353
env: COMPILER=gcc GCC=7
54+
- os: linux
55+
addons:
56+
apt:
57+
sources:
58+
- ubuntu-toolchain-r-test
59+
packages:
60+
- g++-7
61+
- libfftw3-dev
62+
env: COMPILER=gcc GCC=7 DISABLE_EXCEPTION=1
5463
- os: linux
5564
addons:
5665
apt:
@@ -148,7 +157,7 @@ install:
148157
- export PATH="$HOME/miniconda/bin:$PATH"
149158
- hash -r
150159
- conda update -yq conda
151-
- conda install -y cmake xtl==0.6.7 xtensor=0.20.10 nlohmann_json=3.7.1 -c conda-forge
160+
- conda install -y cmake xtl==0.6.9 xtensor=0.21.2 nlohmann_json=3.7.1 -c conda-forge
152161
- |
153162
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
154163
conda install -y fftw -c conda-forge

CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ OPTION(BENCHMARK_ENABLE_TESTING "Build tests for Google Benchmark" OFF)
4545
OPTION(FIX_RPATH "Correctly set rpath for the linker" OFF)
4646
OPTION(DEFAULT_COLUMN_MAJOR "Set xtensor default layout to column major. This is currently not supported, since FFTW demands row major layout." OFF)
4747
OPTION(COVERAGE "Enable coverage compile flags (gcc only!)" OFF)
48+
OPTION(DISABLE_EXCEPTIONS "Disable C++ exceptions" OFF)
4849

4950
if (COVERAGE)
5051
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU")
@@ -65,12 +66,14 @@ set(CMAKE_CXX_EXTENSIONS NO)
6566
include_directories(${XTENSOR_FFTW_INCLUDE_DIR})
6667

6768
# .. xtensor
68-
find_package(xtensor REQUIRED)
69+
set(xtensor_REQUIRED_VERSION 0.21.2)
70+
find_package(xtensor ${xtensor_REQUIRED_VERSION} REQUIRED)
6971
message(STATUS "Found xtensor: ${xtensor_INCLUDE_DIRS}/xtensor")
7072
include_directories(${xtensor_INCLUDE_DIRS})
7173

7274
# .. xtl
73-
find_package(xtl REQUIRED)
75+
set(xtl_REQUIRED_VERSION 0.6.9)
76+
find_package(xtl ${xtl_REQUIRED_VERSION} REQUIRED)
7477
message(STATUS "Found xtl: ${xtl_INCLUDE_DIRS}/xtl")
7578
include_directories(${xtl_INCLUDE_DIRS})
7679

@@ -163,4 +166,4 @@ configure_file(${PROJECT_NAME}.pc.in
163166
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
164167
@ONLY)
165168
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
166-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")
169+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ make install
4646
* [FFTW](http://www.fftw.org/) version 3
4747
* A compiler supporting C++14
4848

49+
| `xtensor-fftw` | `xtensor` | `xtl` | `fftw` |
50+
|----------------|-----------|---------|---------|
51+
| master | ^0.20.10 | ^0.6.7 | ^3.3.8 |
52+
4953
## Usage
5054

5155
_xtensor-fftw_ is a header-only library.

include/xtensor-fftw/basic.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
#include <fftw3.h>
3434

35+
#include "xtensor-fftw_config.hpp"
36+
3537
#ifdef __CLING__
3638
#pragma cling load("fftw3")
3739
#endif
@@ -386,7 +388,8 @@ namespace xt {
386388

387389
auto plan = fftw_plan_dft_caller<dim, fftw_direction, fftw_123dim, input_t, output_t, fftw_plan_dft, half_plus_one_out, half_plus_one_in>(input, output, FFTW_ESTIMATE, odd_last_dim);
388390
if (plan == nullptr) {
389-
throw std::runtime_error("Plan creation returned nullptr. This usually means FFTW cannot create a plan for the given arguments (e.g. a non-destructive multi-dimensional real FFT is impossible in FFTW).");
391+
XTENSOR_FFTW_THROW(std::runtime_error,
392+
"Plan creation returned nullptr. This usually means FFTW cannot create a plan for the given arguments (e.g. a non-destructive multi-dimensional real FFT is impossible in FFTW).");
390393
}
391394

392395
fftw_execute(plan);
@@ -414,7 +417,8 @@ namespace xt {
414417

415418
auto plan = fftw_plan_dft_caller<dim, fftw_direction, fftw_123dim, input_t, output_t, fftw_plan_dft, half_plus_one_out, half_plus_one_in>(input, output, FFTW_ESTIMATE, odd_last_dim);
416419
if (plan == nullptr) {
417-
throw std::runtime_error("Plan creation returned nullptr. This usually means FFTW cannot create a plan for the given arguments (e.g. a non-destructive multi-dimensional real FFT is impossible in FFTW).");
420+
XTENSOR_FFTW_THROW(std::runtime_error,
421+
"Plan creation returned nullptr. This usually means FFTW cannot create a plan for the given arguments (e.g. a non-destructive multi-dimensional real FFT is impossible in FFTW).");
418422
}
419423

420424
fftw_execute(plan);
@@ -446,7 +450,8 @@ namespace xt {
446450

447451
auto plan = fftw_plan_dft_caller<dim, fftw_direction, fftw_123dim, input_t, output_t, fftw_plan_dft, half_plus_one_out, half_plus_one_in>(input_conj, output, FFTW_ESTIMATE);
448452
if (plan == nullptr) {
449-
throw std::runtime_error("Plan creation returned nullptr. This usually means FFTW cannot create a plan for the given arguments (e.g. a non-destructive multi-dimensional real FFT is impossible in FFTW).");
453+
XTENSOR_FFTW_THROW(std::runtime_error,
454+
"Plan creation returned nullptr. This usually means FFTW cannot create a plan for the given arguments (e.g. a non-destructive multi-dimensional real FFT is impossible in FFTW).");
450455
}
451456

452457
fftw_execute(plan);
@@ -474,7 +479,8 @@ namespace xt {
474479

475480
auto plan = fftw_plan_dft_caller<dim, fftw_direction, fftw_123dim, input_t, output_t, fftw_plan_dft, half_plus_one_out, half_plus_one_in>(input, output, FFTW_ESTIMATE);
476481
if (plan == nullptr) {
477-
throw std::runtime_error("Plan creation returned nullptr. This usually means FFTW cannot create a plan for the given arguments (e.g. a non-destructive multi-dimensional real FFT is impossible in FFTW).");
482+
XTENSOR_FFTW_THROW(std::runtime_error,
483+
"Plan creation returned nullptr. This usually means FFTW cannot create a plan for the given arguments (e.g. a non-destructive multi-dimensional real FFT is impossible in FFTW).");
478484
}
479485

480486
fftw_execute(plan);

include/xtensor-fftw/xtensor-fftw_config.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,22 @@
1313
#define XTENSOR_FFTW_VERSION_MINOR 2
1414
#define XTENSOR_FFTW_VERSION_PATCH 5
1515

16+
// Define if the library is going to be using exceptions.
17+
#if (!defined(__cpp_exceptions) && !defined(__EXCEPTIONS) && !defined(_CPPUNWIND))
18+
#undef XTENSOR_FFTW_DISABLE_EXCEPTIONS
19+
#define XTENSOR_FFTW_DISABLE_EXCEPTIONS
20+
#endif
21+
22+
// Exception support.
23+
#if defined(XTENSOR_FFTW_DISABLE_EXCEPTIONS)
24+
#include <iostream>
25+
#define XTENSOR_FFTW_THROW(_, msg) \
26+
{ \
27+
std::cerr << msg << std::endl; \
28+
std::abort(); \
29+
}
30+
#else
31+
#define XTENSOR_FFTW_THROW(exception, msg) throw exception(msg)
32+
#endif
33+
1634
#endif //XTENSOR_FFTW_CONFIG_HPP

test/CMakeLists.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,25 @@ string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
3333

3434
set(CMAKE_CXX_STANDARD 14)
3535

36+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT WIN32))
37+
if (DISABLE_EXCEPTIONS)
38+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
39+
endif()
40+
endif()
41+
3642
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
3743
add_compile_options(-ftemplate-backtrace-limit=0)
44+
if (DISABLE_EXCEPTIONS)
45+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
46+
endif()
3847
endif()
3948

4049
if(MSVC)
41-
add_compile_options(/EHsc /MP /bigobj)
50+
if (DISABLE_EXCEPTIONS)
51+
add_compile_options(/EHs-c- /MP /bigobj)
52+
else()
53+
add_compile_options(/EHsc /MP /bigobj)
54+
endif()
4255
set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
4356
foreach(flag_var
4457
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE

test/basic_interface_fft.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,4 @@ TYPED_TEST(TransformAndInvert_FFT, FFT_4D_xtensor) {
106106
assert_results_complex(a, a_fourier, should_be_a);
107107
}
108108
109-
*/
109+
*/

0 commit comments

Comments
 (0)