Skip to content

Commit

Permalink
create additional testing library if tests are enabled to avoid chang…
Browse files Browse the repository at this point in the history
…es to install target
  • Loading branch information
AdhocMan committed Aug 4, 2021
1 parent a2dd41a commit 6b90d30
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 69 deletions.
22 changes: 0 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ else()
set(SPFFT_LIBRARY_TYPE SHARED)
endif()

set(SPFFT_DEFINITIONS)
set(SPFFT_EXTERNAL_COMPILE_OPTIONS)
set(SPFFT_LIBS)
set(SPFFT_EXTERNAL_LIBS)
set(SPFFT_INTERFACE_INCLUDE_DIRS)
set(SPFFT_INCLUDE_DIRS)
set(SPFFT_EXTERNAL_INCLUDE_DIRS)
set(SPFFT_EXTERNAL_PKG_PACKAGES)
Expand All @@ -87,17 +83,6 @@ 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()

# Fortran
if(SPFFT_FORTRAN)
enable_language(Fortran)
Expand Down Expand Up @@ -155,7 +140,6 @@ endif()
if(SPFFT_MPI)
find_package(MPI COMPONENTS CXX REQUIRED)
list(APPEND SPFFT_EXTERNAL_LIBS MPI::MPI_CXX)
list(APPEND SPFFT_INTERFACE_INCLUDE_DIRS ${MPI_CXX_INCLUDE_DIRS})
endif()

if(SPFFT_OMP)
Expand Down Expand Up @@ -207,10 +191,6 @@ if(NOT TARGET MKL::Sequential)
list(APPEND SPFFT_EXTERNAL_PKG_PACKAGES fftw3)
endif()

if(SPFFT_BUILD_TESTS)
# enable timing with testing
set(SPFFT_TIMING ON)
endif()

# generate config.h
configure_file(include/spfft/config.h.in ${PROJECT_BINARY_DIR}/spfft/config.h)
Expand All @@ -225,8 +205,6 @@ list(APPEND SPFFT_EXTERNAL_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/ext)
#############################################################################
add_subdirectory(src)

list(APPEND SPFFT_LIBS spfft)

# add tests for developement
if(SPFFT_BUILD_TESTS)
add_subdirectory(tests)
Expand Down
1 change: 0 additions & 1 deletion include/spfft/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#cmakedefine SPFFT_ROCM
#cmakedefine SPFFT_MPI
#cmakedefine SPFFT_OMP
#cmakedefine SPFFT_TIMING
#cmakedefine SPFFT_SINGLE_PRECISION
#cmakedefine SPFFT_GPU_DIRECT

Expand Down
91 changes: 55 additions & 36 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,68 @@ if(SPFFT_ROCM)
if(CMAKE_CXX_STANDARD)
set(HIP_HCC_FLAGS ${HIP_HCC_FLAGS} -std=gnu++${CMAKE_CXX_STANDARD})
endif()

# macro from FindHIP package, which compiles all .cu files with hipcc and cpp files with the set c++ compiler
HIP_ADD_LIBRARY(spfft ${SPFFT_LIBRARY_TYPE} ${SPFFT_SOURCE_FILES})
else()
add_library(spfft ${SPFFT_LIBRARY_TYPE} ${SPFFT_SOURCE_FILES})
endif()

set_property(TARGET spfft PROPERTY VERSION ${SPFFT_VERSION})
set_property(TARGET spfft PROPERTY SOVERSION ${SPFFT_SO_VERSION})
# All .cu files are self-contained. Device linking can have issues with propageted linker flags of other targets like MPI.
if(SPFFT_CUDA)
set_property(TARGET spfft PROPERTY CUDA_RESOLVE_DEVICE_SYMBOLS OFF)
set_property(TARGET spfft PROPERTY CUDA_SEPARABLE_COMPILATION OFF)

# Creates library with given name. All common target modifications should be done here.
macro(spfft_create_library _TARGET_NAME)
# create target
if(SPFFT_ROCM)
# macro from FindHIP package, which compiles all .cu files with hipcc and cpp files with the set c++ compiler
HIP_ADD_LIBRARY(${_TARGET_NAME} ${SPFFT_LIBRARY_TYPE} ${SPFFT_SOURCE_FILES})
else()
add_library(${_TARGET_NAME} ${SPFFT_LIBRARY_TYPE} ${SPFFT_SOURCE_FILES})
endif()

# set version
set_property(TARGET ${_TARGET_NAME} PROPERTY VERSION ${SPFFT_VERSION})
set_property(TARGET ${_TARGET_NAME} PROPERTY SOVERSION ${SPFFT_SO_VERSION})

# All .cu files are self-contained. Device linking can have issues with propageted linker flags of other targets like MPI.
if(SPFFT_CUDA)
set_property(TARGET ${_TARGET_NAME} PROPERTY CUDA_RESOLVE_DEVICE_SYMBOLS OFF)
set_property(TARGET ${_TARGET_NAME} PROPERTY CUDA_SEPARABLE_COMPILATION OFF)
endif()

# Don't export any symbols of external static libaries. Only works on linux.
if(UNIX AND NOT APPLE)
if(${CMAKE_VERSION} VERSION_LESS "3.13.5")
target_link_libraries(${_TARGET_NAME} PRIVATE "-Wl,--exclude-libs,ALL")
else()
target_link_options(${_TARGET_NAME} PRIVATE "-Wl,--exclude-libs,ALL")
endif()
endif()

target_include_directories(${_TARGET_NAME} PRIVATE ${SPFFT_INCLUDE_DIRS} ${SPFFT_EXTERNAL_INCLUDE_DIRS})
target_link_libraries(${_TARGET_NAME} PRIVATE ${SPFFT_EXTERNAL_LIBS})

target_include_directories(${_TARGET_NAME} INTERFACE $<INSTALL_INTERFACE:include>) # for install(EXPORT ...)
target_include_directories(${_TARGET_NAME} INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>) # for export(...)
if(${SPFFT_FORTRAN}) # Add include directory for fortran module
target_include_directories(${_TARGET_NAME} INTERFACE $<INSTALL_INTERFACE:include/spfft>)
target_include_directories(${_TARGET_NAME} INTERFACE $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>)
endif()

endmacro()

# Create library
spfft_create_library(spfft)
set_target_properties(spfft PROPERTIES VISIBILITY_INLINES_HIDDEN TRUE CXX_VISIBILITY_PRESET hidden)

# Create library for testing, which allows linking to internal symbols and has timings enabled.
if(SPFFT_BUILD_TESTS)
spfft_create_library(spfft_test)
set_target_properties(spfft_test PROPERTIES VISIBILITY_INLINES_HIDDEN FALSE CXX_VISIBILITY_PRESET default)
target_compile_options(spfft_test PUBLIC -DSPFFT_STATIC_DEFINE) # disable properties of export header
# enable internal timings
target_compile_options(spfft_test PUBLIC -DSPFFT_TIMING)
endif()

# build fortran module
if(SPFFT_FORTRAN)
add_library(spfft_fortran OBJECT ${PROJECT_SOURCE_DIR}/include/spfft/spfft.f90)
endif()

# Don't export any symbols of external static libaries. Only works on linux.
if(UNIX AND NOT APPLE)
if(${CMAKE_VERSION} VERSION_LESS "3.13.5")
set(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} "-Wl,--exclude-libs,ALL")
else()
target_link_options(spfft PRIVATE "-Wl,--exclude-libs,ALL")
endif()
endif()

# generate export header to control symbol visibility
include(GenerateExportHeader)
generate_export_header(spfft)
Expand All @@ -94,23 +127,9 @@ configure_file("${CMAKE_CURRENT_BINARY_DIR}/spfft_export.h"
COPYONLY
)

target_compile_options(spfft PRIVATE ${SPFFT_DEFINITIONS} ${SPFFT_EXTERNAL_COMPILE_OPTIONS})
target_include_directories(spfft PRIVATE ${SPFFT_EXTERNAL_INCLUDE_DIRS})
target_include_directories(spfft PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_include_directories(spfft PRIVATE ${PROJECT_SOURCE_DIR}/src)
target_include_directories(spfft PRIVATE ${PROJECT_BINARY_DIR})
target_link_libraries(spfft PRIVATE ${SPFFT_EXTERNAL_LIBS})

target_include_directories(spfft INTERFACE ${SPFFT_INTERFACE_INCLUDE_DIRS})
target_include_directories(spfft INTERFACE $<INSTALL_INTERFACE:include>) # for install(EXPORT ...)
target_include_directories(spfft INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>) # for export(...)
if(${SPFFT_FORTRAN}) # Add include directory for fortran module
target_include_directories(spfft INTERFACE $<INSTALL_INTERFACE:include/spfft>)
target_include_directories(spfft INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
endif()

# set packge config names
if(SPFFT_STATIC)
get_target_property(_LIB_TYPE spfft TYPE)
if(_LIB_TYPE STREQUAL "STATIC_LIBRARY")
set(SPFFT_VERSION_FILE "SpFFTStaticConfigVersion.cmake")
set(SPFFT_CONFIG_FILE "SpFFTStaticConfig.cmake")
set(SPFFT_TARGETS_FILE "SpFFTStaticTargets.cmake")
Expand Down
13 changes: 3 additions & 10 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,9 @@ if(SPFFT_BUILD_TESTS)

# benchmark executable
add_executable(benchmark programs/benchmark.cpp)
target_link_libraries(benchmark PRIVATE ${SPFFT_LIBS} ${SPFFT_EXTERNAL_LIBS})
target_compile_options(benchmark PRIVATE ${SPFFT_DEFINITIONS} ${SPFFT_EXTERNAL_COMPILE_OPTIONS})
target_link_libraries(benchmark PRIVATE spfft_test ${SPFFT_EXTERNAL_LIBS})
target_include_directories(benchmark PRIVATE ${SPFFT_INCLUDE_DIRS} ${SPFFT_EXTERNAL_INCLUDE_DIRS})

# if(SPFFT_CUDA)
# set_property(TARGET main PROPERTY CUDA_SEPARABLE_COMPILATION ON)
# endif()

# test executables
add_executable(run_local_tests
run_local_tests.cpp
Expand All @@ -82,8 +77,7 @@ if(SPFFT_BUILD_TESTS)
local_tests/test_local_transform.cpp
)
target_link_libraries(run_local_tests PRIVATE gtest_main gtest_mpi)
target_link_libraries(run_local_tests PRIVATE ${SPFFT_LIBS} ${SPFFT_EXTERNAL_LIBS})
target_compile_options(run_local_tests PRIVATE ${SPFFT_DEFINITIONS} ${SPFFT_EXTERNAL_COMPILE_OPTIONS})
target_link_libraries(run_local_tests PRIVATE spfft_test ${SPFFT_EXTERNAL_LIBS})
target_include_directories(run_local_tests PRIVATE ${SPFFT_INCLUDE_DIRS} ${SPFFT_EXTERNAL_INCLUDE_DIRS})

if(SPFFT_MPI)
Expand All @@ -95,8 +89,7 @@ if(SPFFT_BUILD_TESTS)
mpi_tests/test_transpose_gpu.cpp
)
target_link_libraries(run_mpi_tests PRIVATE gtest_main gtest_mpi)
target_link_libraries(run_mpi_tests PRIVATE ${SPFFT_LIBS} ${SPFFT_EXTERNAL_LIBS})
target_compile_options(run_mpi_tests PRIVATE ${SPFFT_DEFINITIONS} ${SPFFT_EXTERNAL_COMPILE_OPTIONS})
target_link_libraries(run_mpi_tests PRIVATE spfft_test ${SPFFT_EXTERNAL_LIBS})
target_include_directories(run_mpi_tests PRIVATE ${SPFFT_INCLUDE_DIRS} ${SPFFT_EXTERNAL_INCLUDE_DIRS})
endif()

Expand Down

0 comments on commit 6b90d30

Please sign in to comment.