Skip to content

Commit

Permalink
Updated CMake package with namespace and config file and only export …
Browse files Browse the repository at this point in the history
…public symbols (#9)

* reduced number of interface libraries to smallest subset

* added separate CMake config files for shared and static library

* only public symbols are now exported

* added SpFFTConfigVersion file

* fortran functions are now exported
  • Loading branch information
AdhocMan authored Sep 20, 2019
1 parent 9831345 commit 4a9daf6
Show file tree
Hide file tree
Showing 25 changed files with 323 additions and 199 deletions.
27 changes: 23 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ set_property(CACHE SPFFT_GPU_BACKEND PROPERTY STRINGS
"OFF" "CUDA" "ROCM"
)


# set preferred library type
if (SPFFT_STATIC)
# prefer static over dynamic libraries with the find_library() command by changing the order
Expand All @@ -59,6 +58,7 @@ set(SPFFT_EXTERNAL_COMPILE_OPTIONS)
set(SPFFT_LIBS)
set(SPFFT_EXTERNAL_LIBS)
set(SPFFT_INTERFACE_LIBS)
set(SPFFT_INTERFACE_INCLUDE_DIRS)
set(SPFFT_INCLUDE_DIRS)
set(SPFFT_EXTERNAL_INCLUDE_DIRS)

Expand All @@ -76,6 +76,17 @@ if(SPFFT_GPU_BACKEND)
endif()
mark_as_advanced(SPFFT_CUDA SPFFT_ROCM)

# Hide symbols by default if tests are not build
if(NOT SPFFT_BUILD_TESTS)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
else()
# disable visibility macros if tests are build
list(APPEND SPFFT_DEFINITIONS -DSPFFT_STATIC_DEFINE)
set(CMAKE_CXX_VISIBILITY_PRESET default)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 0)
endif()

# CUDA
if(SPFFT_CUDA)
enable_language(CUDA)
Expand All @@ -98,13 +109,17 @@ endif()
if(SPFFT_MPI)
find_package(MPI REQUIRED)
list(APPEND SPFFT_EXTERNAL_LIBS MPI::MPI_CXX)
# always add MPI to interface libraries, because mpi.h is included in public header files
list(APPEND SPFFT_INTERFACE_LIBS ${MPI_CXX_LIBRARIES})
list(APPEND SPFFT_INTERFACE_INCLUDE_DIRS ${MPI_CXX_INCLUDE_DIRS})
endif()

if(SPFFT_OMP)
find_package(OpenMP REQUIRED)
list(APPEND SPFFT_EXTERNAL_LIBS OpenMP::OpenMP_CXX)
list(APPEND SPFFT_INTERFACE_LIBS ${OpenMP_CXX_LIBRARIES})
if(SPFFT_STATIC)
list(APPEND SPFFT_INTERFACE_LIBS ${OpenMP_CXX_LIBRARIES})
endif()
endif()

if(SPFFT_GPU_DIRECT)
Expand All @@ -117,11 +132,15 @@ endif()
find_package(MKLSequential)
if(MKLSequential_FOUND)
list(APPEND SPFFT_EXTERNAL_LIBS MKL::Sequential)
list(APPEND SPFFT_INTERFACE_LIBS ${MKLSequential_LIBRARIES})
if(SPFFT_STATIC)
list(APPEND SPFFT_INTERFACE_LIBS ${MKLSequential_LIBRARIES})
endif()
else()
find_package(FFTW REQUIRED)
list(APPEND SPFFT_EXTERNAL_LIBS FFTW::FFTW)
list(APPEND SPFFT_INTERFACE_LIBS ${FFTW_LIBRARIES})
if(SPFFT_STATIC)
list(APPEND SPFFT_INTERFACE_LIBS ${FFTW_LIBRARIES})
endif()
if(SPFFT_SINGLE_PRECISION AND NOT FFTW_FLOAT_FOUND)
message(FATAL_ERROR "FFTW library with single precision support NOT FOUND. Disable SPFFT_SINGLE_PRECISION or provide path to library.")
endif()
Expand Down
10 changes: 0 additions & 10 deletions cmake/SpFFTConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
# options used for building library
set(SPFFT_OMP @SPFFT_OMP@)
set(SPFFT_MPI @SPFFT_MPI@)
set(SPFFT_STATIC @SPFFT_STATIC@)
set(SPFFT_GPU_DIRECT @SPFFT_GPU_DIRECT@)
set(SPFFT_SINGLE_PRECISION @SPFFT_SINGLE_PRECISION@)
set(SPFFT_GPU_BACKEND @SPFFT_GPU_BACKEND@)

# add version of package
include("${CMAKE_CURRENT_LIST_DIR}/SpFFTConfigVersion.cmake")

# add library target
include("${CMAKE_CURRENT_LIST_DIR}/SpFFTTargets.cmake")

7 changes: 7 additions & 0 deletions cmake/SpFFTConfigVersion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# Prefer shared library
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SpFFTSharedConfigVersion.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/SpFFTSharedConfigVersion.cmake")
else()
include("${CMAKE_CURRENT_LIST_DIR}/SpFFTStaticConfigVersion.cmake")
endif()
14 changes: 14 additions & 0 deletions cmake/SpFFTSharedConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# options used for building library
set(SPFFT_OMP @SPFFT_OMP@)
set(SPFFT_MPI @SPFFT_MPI@)
set(SPFFT_STATIC @SPFFT_STATIC@)
set(SPFFT_GPU_DIRECT @SPFFT_GPU_DIRECT@)
set(SPFFT_SINGLE_PRECISION @SPFFT_SINGLE_PRECISION@)
set(SPFFT_GPU_BACKEND @SPFFT_GPU_BACKEND@)

# add version of package
include("${CMAKE_CURRENT_LIST_DIR}/SpFFTSharedConfigVersion.cmake")

# add library target
include("${CMAKE_CURRENT_LIST_DIR}/SpFFTSharedTargets.cmake")

14 changes: 14 additions & 0 deletions cmake/SpFFTStaticConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# options used for building library
set(SPFFT_OMP @SPFFT_OMP@)
set(SPFFT_MPI @SPFFT_MPI@)
set(SPFFT_STATIC @SPFFT_STATIC@)
set(SPFFT_GPU_DIRECT @SPFFT_GPU_DIRECT@)
set(SPFFT_SINGLE_PRECISION @SPFFT_SINGLE_PRECISION@)
set(SPFFT_GPU_BACKEND @SPFFT_GPU_BACKEND@)

# add version of package
include("${CMAKE_CURRENT_LIST_DIR}/SpFFTStaticConfigVersion.cmake")

# add library target
include("${CMAKE_CURRENT_LIST_DIR}/SpFFTStaticTargets.cmake")

7 changes: 7 additions & 0 deletions cmake/SpFFTTargets.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# Prefer shared library
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SpFFTSharedTargets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/SpFFTSharedTargets.cmake")
else()
include("${CMAKE_CURRENT_LIST_DIR}/SpFFTStaticTargets.cmake")
endif()
2 changes: 2 additions & 0 deletions include/spfft/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@
#cmakedefine SPFFT_SINGLE_PRECISION
#cmakedefine SPFFT_GPU_DIRECT

#include "spfft/spfft_export.h"

#endif
44 changes: 22 additions & 22 deletions include/spfft/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace spfft {
/**
* A generic error. Base type for all other exceptions.
*/
class GenericError : public std::exception {
class SPFFT_EXPORT GenericError : public std::exception {
public:
auto what() const noexcept -> const char* override { return "SpFFT: Generic error"; }

Expand All @@ -47,7 +47,7 @@ class GenericError : public std::exception {
/**
* Overflow of integer values.
*/
class OverflowError : public GenericError {
class SPFFT_EXPORT OverflowError : public GenericError {
public:
auto what() const noexcept -> const char* override { return "SpFFT: Overflow error"; }

Expand All @@ -59,7 +59,7 @@ class OverflowError : public GenericError {
/**
* Failed allocation on host.
*/
class HostAllocationError : public GenericError {
class SPFFT_EXPORT HostAllocationError : public GenericError {
public:
auto what() const noexcept -> const char* override { return "SpFFT: Host allocation error"; }

Expand All @@ -71,7 +71,7 @@ class HostAllocationError : public GenericError {
/**
* Invalid parameter.
*/
class InvalidParameterError : public GenericError {
class SPFFT_EXPORT InvalidParameterError : public GenericError {
public:
auto what() const noexcept -> const char* override { return "SpFFT: Invalid parameter error"; }

Expand All @@ -83,7 +83,7 @@ class InvalidParameterError : public GenericError {
/**
* Duplicate indices given to transform. May indicate non-local z-coloumn between MPI ranks.
*/
class DuplicateIndicesError : public GenericError {
class SPFFT_EXPORT DuplicateIndicesError : public GenericError {
public:
auto what() const noexcept -> const char* override { return "SpFFT: Duplicate indices error"; }

Expand All @@ -95,7 +95,7 @@ class DuplicateIndicesError : public GenericError {
/**
* Invalid indices given to transform.
*/
class InvalidIndicesError : public GenericError {
class SPFFT_EXPORT InvalidIndicesError : public GenericError {
public:
auto what() const noexcept -> const char* override { return "SpFFT: Invalid indices error"; }

Expand All @@ -107,7 +107,7 @@ class InvalidIndicesError : public GenericError {
/**
* Library not compiled with MPI support.
*/
class MPISupportError : public GenericError {
class SPFFT_EXPORT MPISupportError : public GenericError {
public:
auto what() const noexcept -> const char* override {
return "SpFFT: Not compiled with MPI support error";
Expand All @@ -121,7 +121,7 @@ class MPISupportError : public GenericError {
/**
* MPI error. Only thrown if error code of MPI API calls is non-zero.
*/
class MPIError : public GenericError {
class SPFFT_EXPORT MPIError : public GenericError {
public:
auto what() const noexcept -> const char* override { return "SpFFT: MPI error"; }

Expand All @@ -131,7 +131,7 @@ class MPIError : public GenericError {
/**
* Parameters differ between MPI ranks.
*/
class MPIParameterMismatchError : public GenericError {
class SPFFT_EXPORT MPIParameterMismatchError : public GenericError {
public:
auto what() const noexcept -> const char* override {
return "SpFFT: Mismatched parameters between MPI ranks";
Expand All @@ -145,7 +145,7 @@ class MPIParameterMismatchError : public GenericError {
/**
* Failed execution on host.
*/
class HostExecutionError : public GenericError {
class SPFFT_EXPORT HostExecutionError : public GenericError {
public:
auto what() const noexcept -> const char* override { return "SpFFT: Host execution error"; }

Expand All @@ -157,7 +157,7 @@ class HostExecutionError : public GenericError {
/**
* FFTW library error.
*/
class FFTWError : public GenericError {
class SPFFT_EXPORT FFTWError : public GenericError {
public:
auto what() const noexcept -> const char* override { return "SpFFT: FFTW error"; }

Expand All @@ -167,7 +167,7 @@ class FFTWError : public GenericError {
/**
* Unknown internal error.
*/
class InternalError : public GenericError {
class SPFFT_EXPORT InternalError : public GenericError {
public:
auto what() const noexcept -> const char* override { return "SpFFT: Internal error"; }

Expand All @@ -180,7 +180,7 @@ class InternalError : public GenericError {
/**
* Generic GPU error. Base type for all GPU related exceptions.
*/
class GPUError : public GenericError {
class SPFFT_EXPORT GPUError : public GenericError {
public:
auto what() const noexcept -> const char* override { return "SpFFT: GPU error"; }

Expand All @@ -190,7 +190,7 @@ class GPUError : public GenericError {
/**
* Library not compiled with GPU support.
*/
class GPUSupportError : public GPUError {
class SPFFT_EXPORT GPUSupportError : public GPUError {
public:
auto what() const noexcept -> const char* override {
return "SpFFT: Not compiled with GPU support";
Expand All @@ -204,7 +204,7 @@ class GPUSupportError : public GPUError {
/**
* Detected error on GPU from previous GPU API / kernel calls.
*/
class GPUPrecedingError : public GPUError {
class SPFFT_EXPORT GPUPrecedingError : public GPUError {
public:
auto what() const noexcept -> const char* override {
return "SpFFT: Detected error from preceding gpu calls.";
Expand All @@ -218,7 +218,7 @@ class GPUPrecedingError : public GPUError {
/**
* Failed allocation on GPU.
*/
class GPUAllocationError : public GPUError {
class SPFFT_EXPORT GPUAllocationError : public GPUError {
public:
auto what() const noexcept -> const char* override { return "SpFFT: GPU allocation error"; }

Expand All @@ -230,7 +230,7 @@ class GPUAllocationError : public GPUError {
/**
* Failed to launch kernel on GPU.
*/
class GPULaunchError : public GPUError {
class SPFFT_EXPORT GPULaunchError : public GPUError {
public:
auto what() const noexcept -> const char* override { return "SpFFT: GPU launch error"; }

Expand All @@ -242,7 +242,7 @@ class GPULaunchError : public GPUError {
/**
* No GPU device detected.
*/
class GPUNoDeviceError : public GPUError {
class SPFFT_EXPORT GPUNoDeviceError : public GPUError {
public:
auto what() const noexcept -> const char* override { return "SpFFT: no GPU available"; }

Expand All @@ -254,7 +254,7 @@ class GPUNoDeviceError : public GPUError {
/**
* Invalid value passed to GPU API.
*/
class GPUInvalidValueError : public GPUError {
class SPFFT_EXPORT GPUInvalidValueError : public GPUError {
public:
auto what() const noexcept -> const char* override {
return "SpFFT: GPU call with invalid value";
Expand All @@ -268,7 +268,7 @@ class GPUInvalidValueError : public GPUError {
/**
* Invalid device pointer used.
*/
class GPUInvalidDevicePointerError : public GPUError {
class SPFFT_EXPORT GPUInvalidDevicePointerError : public GPUError {
public:
auto what() const noexcept -> const char* override { return "SpFFT: Invalid GPU pointer"; }

Expand All @@ -280,7 +280,7 @@ class GPUInvalidDevicePointerError : public GPUError {
/**
* Failed to copy from / to GPU.
*/
class GPUCopyError : public GPUError {
class SPFFT_EXPORT GPUCopyError : public GPUError {
public:
auto what() const noexcept -> const char* override { return "SpFFT: GPU Memory copy error"; }

Expand All @@ -292,7 +292,7 @@ class GPUCopyError : public GPUError {
/**
* Failure in GPU FFT library call.
*/
class GPUFFTError : public GPUError {
class SPFFT_EXPORT GPUFFTError : public GPUError {
public:
auto what() const noexcept -> const char* override { return "SpFFT: GPU FFT error"; }

Expand Down
Loading

0 comments on commit 4a9daf6

Please sign in to comment.