Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes uninitialized var, static libs, CLI options. #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 15 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ if(GEARSHIFFT_BACKEND_FFTW)
add_library(FFTW INTERFACE)
add_library(gearshifft::FFTW ALIAS FFTW)

set(GEARSHIFFT_BACKEND_FFTW_THREADS 0)
# set initial value to 0
set(GEARSHIFFT_INTERNAL_FFTWX_THREADED 0)

if(GEARSHIFFT_BACKEND_FFTW_OPENMP)

Expand All @@ -315,7 +316,7 @@ if(GEARSHIFFT_BACKEND_FFTW)
find_and_add_openmp(FFTW ${_QUIET})

if(TARGET OpenMP::OpenMP_CXX)
set(GEARSHIFFT_BACKEND_FFTW_THREADS 1)
set(GEARSHIFFT_INTERNAL_FFTWX_THREADED 1)
else()
message(WARNING "Could not find OpenMP")
set(GEARSHIFFT_BACKEND_FFTW_OPENMP OFF)
Expand All @@ -330,7 +331,7 @@ if(GEARSHIFFT_BACKEND_FFTW)
if(GEARSHIFFT_BACKEND_FFTW_PTHREADS)
if(FFTW_THREADS_LIBS)
find_package(Threads)
set(GEARSHIFFT_BACKEND_FFTW_THREADS 1)
set(GEARSHIFFT_INTERNAL_FFTWX_THREADED 1)
else()
message(WARNING "FFTW libraries for pthreads not found")
set(GEARSHIFFT_BACKEND_FFTW_PTHREADS OFF)
Expand All @@ -348,7 +349,7 @@ if(GEARSHIFFT_BACKEND_FFTW)
target_include_directories(FFTW INTERFACE ${FFTW_INCLUDE_DIR})
target_compile_definitions(FFTW INTERFACE
FFTW_ENABLED
GEARSHIFFT_BACKEND_FFTW_THREADS=${GEARSHIFFT_BACKEND_FFTW_THREADS})
GEARSHIFFT_INTERNAL_FFTWX_THREADED=${GEARSHIFFT_INTERNAL_FFTWX_THREADED})
target_link_libraries(FFTW INTERFACE
Common
$<$<STREQUAL:${GEARSHIFFT_BACKEND_FFTW_OPENMP},ON>:${FFTW_OPENMP_LIBS}>
Expand All @@ -366,7 +367,11 @@ endif()
#------------------------------------------------------------------------------

if(GEARSHIFFT_BACKEND_FFTWWRAPPERS)
if(GEARSHIFFT_USE_STATIC_LIBS)
set(FFTWWrappers_USE_STATIC_LIBS ON) # otherwise find libs automatically
endif()
find_package(FFTWWrappers ${_QUIET})

if(FFTWWrappers_FOUND) # found FFTWWrappers for GNU or Intel

if(FFTWWrappers_GNU_LIBRARIES AND NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU"
Expand All @@ -378,19 +383,22 @@ if(GEARSHIFFT_BACKEND_FFTWWRAPPERS)
add_library(gearshifft::FFTWWrappers ALIAS FFTWWrappers)

# if compiler supports OpenMP then add flag, as FFTWWrappers might need it
# set initial value to 0
set(GEARSHIFFT_INTERNAL_FFTWX_THREADED 0)

find_and_add_openmp(FFTWWrappers ${_QUIET})

if(TARGET OpenMP::OpenMP_CXX)
set(GEARSHIFFT_BACKEND_FFTW_THREADS 1)
set(GEARSHIFFT_INTERNAL_FFTWX_THREADED 1)
endif()

target_include_directories(FFTWWrappers INTERFACE ${FFTWWrappers_MKL_INCLUDE_DIR})
target_compile_definitions(FFTWWrappers INTERFACE
FFTW_ENABLED
GEARSHIFFT_BACKEND_FFTW_THREADS=${GEARSHIFFT_BACKEND_FFTW_THREADS})
GEARSHIFFT_INTERNAL_FFTWX_THREADED=${GEARSHIFFT_INTERNAL_FFTWX_THREADED})
target_link_libraries(FFTWWrappers INTERFACE
Common
# $<$<BOOL:${Threads_FOUND}>:Threads::Threads>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:m>
)

if(FFTWWrappers_GNU_LIBRARIES)
Expand Down
5 changes: 3 additions & 2 deletions cmake/gearshifft_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ set_property(CACHE GEARSHIFFT_CXX11_ABI PROPERTY STRINGS "0;1")
option(GEARSHIFFT_BACKEND_CUFFT "Compile gearshifft_cufft if possible" ON)
option(GEARSHIFFT_BACKEND_CLFFT "Compile gearshifft_clfft if possible" ON)
option(GEARSHIFFT_BACKEND_ROCFFT "Compile gearshifft_rocfft if possible (requires HCC as compiler)" ON)

option(GEARSHIFFT_BACKEND_FFTW "Compile gearshifft_fftw if possible" ON)
cmake_dependent_option(
GEARSHIFFT_BACKEND_FFTW_OPENMP "Use OpenMP parallel FFTW libraries if found" ON
"GEARSHIFFT_BACKEND_FFTW" ON)
cmake_dependent_option(
GEARSHIFFT_BACKEND_FFTW_PTHREADS "Use pthreads parallel FFTW libraries if found" OFF
"GEARSHIFFT_BACKEND_FFTW" ON
)
"GEARSHIFFT_BACKEND_FFTW" ON)

option(GEARSHIFFT_BACKEND_FFTWWRAPPERS "Compile gearshifft_fftwwrappers if possible" ON)

# backend-disabler
Expand Down
50 changes: 24 additions & 26 deletions cmake/modules/FindFFTW.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
#
# Usage:
# find_package(FFTW [REQUIRED] [QUIET] [COMPONENTS ...])
#
#
# It sets the following variables:
# FFTW_FOUND ... true if fftw is found on the system
# FFTW_LIBRARIES ... list of library identifiers that were found (will be filled with serial/openmp/pthreads enabled file names if present, only stubs will be filled in not full paths)
# FFTW_INCLUDES ... fftw include directory
# FFTW_SERIAL_LIBS ... list of full path(s) to serial fftw library(ies)
# FFTW_THREADS_LIBS ... list of full path(s) to pthreads fftw library(ies)
# FFTW_OPENMP_LIBS ... list of full path(s) to openmp fftw library(ies)
# FFTW_INCLUDE_DIR ... fftw include directory
# FFTW_LIBRARY_DIR ... fftw library directory
# FFTW_SERIAL_LIBS ... list of full path(s) to serial fftw library(ies)
# FFTW_THREADS_LIBS ... list of full path(s) to pthreads fftw library(ies)
# FFTW_OPENMP_LIBS ... list of full path(s) to openmp fftw library(ies)
# FFTW_INCLUDE_DIR ... fftw include directory
# FFTW_LIBRARY_DIR ... fftw library directory
#
# The following variables will be checked by the function
# FFTW_USE_STATIC_LIBS ... if true, only static libraries are found
Expand Down Expand Up @@ -60,12 +60,12 @@ endforeach()

#If environment variable FFTWDIR is specified, it has same effect as FFTW_ROOT
if( NOT FFTW_ROOT AND (DEFINED ENV{FFTWDIR} OR DEFINED ENV{FFTW_ROOT}))
if(EXISTS "$ENV{FFTWDIR}/")
set( FFTW_ROOT $ENV{FFTWDIR} )
endif()
if( EXISTS "$ENV{FFTW_ROOT}/" )
set( FFTW_ROOT $ENV{FFTW_ROOT} )
endif()
if(EXISTS "$ENV{FFTWDIR}/")
set( FFTW_ROOT $ENV{FFTWDIR} )
endif()
if( EXISTS "$ENV{FFTW_ROOT}/" )
set( FFTW_ROOT $ENV{FFTW_ROOT} )
endif()
endif()

# Check if we can use PkgConfig
Expand All @@ -79,17 +79,15 @@ endif()
#Check whether to search static or dynamic libs
set( CMAKE_FIND_LIBRARY_SUFFIXES_SAV ${CMAKE_FIND_LIBRARY_SUFFIXES} )

if( ${FFTW_USE_STATIC_LIBS} )
if( FFTW_USE_STATIC_LIBS ) # find static libs only
set( CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX} )
else()
set( CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX} )
endif()

#initialize library variables
foreach(_LIBSTUB IN LISTS FFTW_LIBRARY_STUBS)

if( FFTW_ROOT )

find_library(
FFTW_SERIAL_STUBLIB
NAMES ${_LIBSTUB} lib${_LIBSTUB}
Expand All @@ -113,7 +111,7 @@ foreach(_LIBSTUB IN LISTS FFTW_LIBRARY_STUBS)
PATH_SUFFIXES "lib" "lib64"
NO_DEFAULT_PATH
)

else( FFTW_ROOT )
find_library(
FFTW_SERIAL_STUBLIB
Expand All @@ -133,9 +131,10 @@ foreach(_LIBSTUB IN LISTS FFTW_LIBRARY_STUBS)
NAMES ${_LIBSTUB}_threads lib${_LIBSTUB}_threads
PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR}
)

endif( FFTW_ROOT )

# manually build shared libs from static libs (if only static libs were found)
if(EXISTS ${FFTW_SERIAL_STUBLIB})

if( NOT CMAKE_FIND_LIBRARY_SUFFIXES MATCHES ${CMAKE_STATIC_LIBRARY_SUFFIX} )
Expand Down Expand Up @@ -168,7 +167,7 @@ foreach(_LIBSTUB IN LISTS FFTW_LIBRARY_STUBS)

list(APPEND FFTW_OPENMP_LIBS_ABSPATH ${FFTW_OPENMP_STUBLIB})
list(APPEND FFTW_OPENMP_LIBS ${_LIBSTUB}_omp)

list(APPEND FFTW_LIBRARIES ${_LIBSTUB}_omp)

else()
Expand All @@ -187,7 +186,7 @@ foreach(_LIBSTUB IN LISTS FFTW_LIBRARY_STUBS)

list(APPEND FFTW_THREADS_LIBS_ABSPATH ${FFTW_THREADS_STUBLIB})
list(APPEND FFTW_THREADS_LIBS ${_LIBSTUB}_threads)

list(APPEND FFTW_LIBRARIES ${_LIBSTUB}_threads)
else()
if(NOT FFTW_FIND_QUIETLY)
Expand All @@ -198,12 +197,12 @@ foreach(_LIBSTUB IN LISTS FFTW_LIBRARY_STUBS)
unset(FFTW_SERIAL_STUBLIB CACHE)
unset(FFTW_THREADS_STUBLIB CACHE)
unset(FFTW_OPENMP_STUBLIB CACHE)

endforeach()

#find includes
if( FFTW_ROOT )

find_path(
FFTW_INCLUDES
NAMES "fftw3.h"
Expand Down Expand Up @@ -247,15 +246,15 @@ include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FFTW DEFAULT_MSG
FFTW_INCLUDES
FFTW_LIBRARIES
# HANDLE_COMPONENTS
# HANDLE_COMPONENTS
)

if(NOT FFTW_FIND_QUIETLY)
message("++ FindFFTW")
message("++ FFTW_INCLUDES : ${FFTW_INCLUDES}")
message("++ FFTW_LIBRARIES : ${FFTW_LIBRARIES}")
message("++ FFTW_SERIAL_LIBS : ${FFTW_SERIAL_LIBS_ABSPATH}")
message("++ FFTW_THREADS_LIBS: ${FFTW_THREADS_LIBS_ABSPATH}")
message("++ FFTW_THREADS_LIBS: ${FFTW_THREADS_LIBS_ABSPATH}")
message("++ FFTW_OPENMP_LIBS : ${FFTW_OPENMP_LIBS_ABSPATH}")
message("++ FFTW_INCLUDE_DIR : ${FFTW_INCLUDE_DIR}")
message("++ FFTW_LIBRARY_DIR : ${FFTW_LIBRARY_DIR}")
Expand All @@ -270,4 +269,3 @@ mark_as_advanced(
FFTW_INCLUDE_DIR
FFTW_LIBRARY_DIR
)

Loading