<commit_before>cmake_minimum_required(VERSION 2.8)

project(gearshifft CXX)

list(APPEND CMAKE_MODULE_PATH "../cmake")

set(CMAKE_CXX_STANDARD 14)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  if (NOT (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0
        OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 5.0))
    message(FATAL_ERROR "${PROJECT_NAME} requires g++ 5.0 or greater.")
  endif()
  set(CMAKE_CXX_FLAGS "--std=gnu++14" ${CMAKE_CXX_FLAGS})
  #gcc4.8+ uses dwarf-4. If you have gdb <7.5 then use this line
  #set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -gdwarf-2")
  #gdb 7.0-7.5 may require
  #set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fvar-tracking-assignments")
endif()

find_package(Boost 1.56 QUIET COMPONENTS unit_test_framework program_options REQUIRED)
if(Boost_FOUND)
  include_directories(${Boost_INCLUDE_DIRS})
  link_directories(${Boost_LIBRARY_DIRS})
endif()

set(DEV_TESTS "" CACHE STRING "Tests for developing (No Benchmarks)")
if(DEV_TESTS)
  message(">> Test mode")
  add_definitions(-DDEV_TESTS)
  set(TESTS tests.cpp)
endif()

#------------------------------------------------------------------------------
# CUDA+CUFFT
#------------------------------------------------------------------------------
find_package(CUDA)
if(CUDA_FOUND)
  include(FindCUDA)
  include_directories(${CUDA_INCLUDE_DIRS})
  list(APPEND FFTLIBS "cufft")
  message(">> cuFFT -> " ${CUDA_CUFFT_LIBRARIES})
else()
  message("cuFFT benchmark disabled.")
endif()

#------------------------------------------------------------------------------
# OPENCL+CLFFT
#------------------------------------------------------------------------------
find_package(OpenCL)
if(OPENCL_FOUND)
  find_package(clFFT)
  if(CLFFT_FOUND)
    include_directories(${CLFFT_INCLUDE_DIRS})
    list(APPEND FFTLIBS "clfft")
    message(">> clFFT -> " ${CLFFT_LIBRARIES})
  endif()
endif()

if(NOT CLFFT_FOUND)
  message("clFFT benchmark disabled.")
endif()

#------------------------------------------------------------------------------
# ROCM+HCFFT
#------------------------------------------------------------------------------
find_package(hcFFT)
if(HCFFT_FOUND)
  include_directories(${HCFFT_INCLUDE_DIRS})
  list(APPEND FFTLIBS "hcfft")
  message(">> hcFFT -> " ${HCFFT_LIBRARIES} " " ${HCFFT_INCLUDE_DIRS})
  message(">> Warning: no runner for hcfft implemented yet")
endif()

if(NOT HCFFT_FOUND)
  message("hcFFT benchmark disabled.")
endif()

#------------------------------------------------------------------------------
# FFTW
#------------------------------------------------------------------------------
find_package(FFTW COMPONENTS float double)
if(FFTW_FOUND)
  include_directories(${FFTW_INCLUDE_DIR})
  link_directories(${FFTW_LIBRARY_DIR})
  list(APPEND FFTLIBS "fftw")
  find_package(OpenMP)

  foreach(_LIBSTEM IN LISTS FFTW_SERIAL_LIBS)
    list(APPEND FFTW_LIBS_TO_USE ${_LIBSTEM})
  endforeach()

  if(USE_FFTW_OPENMP AND OPENMP_FOUND AND "${FFTW_LIBRARIES}" MATCHES ".*_omp.*")
    foreach(_LIBSTEM IN LISTS FFTW_OPENMP_LIBS)
      list(APPEND FFTW_LIBS_TO_USE ${_LIBSTEM})
    endforeach()
  endif()

  if(USE_FFTW_PTHREADS AND "${FFTW_LIBRARIES}" MATCHES ".*_threads.*")
    foreach(_LIBSTEM IN LISTS FFTW_THREADS_LIBS)
      list(APPEND FFTW_LIBS_TO_USE ${_LIBSTEM})
    endforeach()

  endif()

  set(FFTW_LIBRARIES ${FFTW_LIBS_TO_USE})
  message(">> FFTW -> " ${FFTW_LIBRARIES} " " ${FFTW_INCLUDES})
else()
  message("fftw benchmark disabled.")
endif()


if(NOT (CLFFT_FOUND OR CUDA_FOUND OR HCFFT_FOUND OR FFTW_FOUND))
  message(FATAL_ERROR "-> No FFT library for benchmark found !!!")
endif()

#------------------------------------------------------------------------------
# Helper function to add specific FFT library benchmark
#------------------------------------------------------------------------------
function(add_exec Tlib)
  message(">> Target: ${Tlib}")
  set(PROJECT_EXEC gearshifft_${Tlib})
  add_executable(${PROJECT_EXEC} ${SOURCES})
  if (Tlib STREQUAL "cufft")
    target_compile_definitions(${PROJECT_EXEC} PUBLIC -DCUDA_ENABLED)
    set(LIBS ${CUDA_LIBRARIES} ${CUDA_CUFFT_LIBRARIES})
  elseif(Tlib STREQUAL "clfft" OR Tlib STREQUAL "test")
    target_compile_definitions(${PROJECT_EXEC} PUBLIC -DOPENCL_ENABLED)
    set(LIBS ${CLFFT_LIBRARIES} ${OPENCL_LIBRARIES})
  endif()
  if (Tlib STREQUAL "fftw")
    set_target_properties(${PROJECT_EXEC}
      PROPERTIES COMPILE_FLAGS "-DFFTW_ENABLED ${PROJECT_EXEC_FLAGS}")
    
    set(LIBS ${LIBS} ${FFTW_LIBRARIES})
  endif()
  message("BOOST LIB: ${Boost_LIBRARIES}")
  target_link_libraries(${PROJECT_EXEC} ${Boost_LIBRARIES} ${LIBS})
  add_test(NAME ${PROJECT_EXEC} COMMAND ${PROJECT_EXEC})
endfunction()

#------------------------------------------------------------------------------
#
#------------------------------------------------------------------------------
include_directories(../inc)

enable_testing()
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose)

if(DEV_TESTS)<commit_msg>removed obsolete cmake message statements<commit_after>cmake_minimum_required(VERSION 2.8)

project(gearshifft CXX)

list(APPEND CMAKE_MODULE_PATH "../cmake")

set(CMAKE_CXX_STANDARD 14)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  if (NOT (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0
        OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 5.0))
    message(FATAL_ERROR "${PROJECT_NAME} requires g++ 5.0 or greater.")
  endif()
  set(CMAKE_CXX_FLAGS "--std=gnu++14" ${CMAKE_CXX_FLAGS})
  #gcc4.8+ uses dwarf-4. If you have gdb <7.5 then use this line
  #set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -gdwarf-2")
  #gdb 7.0-7.5 may require
  #set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fvar-tracking-assignments")
endif()

find_package(Boost 1.56 QUIET COMPONENTS unit_test_framework program_options REQUIRED)
if(Boost_FOUND)
  include_directories(${Boost_INCLUDE_DIRS})
  link_directories(${Boost_LIBRARY_DIRS})
endif()

set(DEV_TESTS "" CACHE STRING "Tests for developing (No Benchmarks)")
if(DEV_TESTS)
  message(">> Test mode")
  add_definitions(-DDEV_TESTS)
  set(TESTS tests.cpp)
endif()

#------------------------------------------------------------------------------
# CUDA+CUFFT
#------------------------------------------------------------------------------
find_package(CUDA)
if(CUDA_FOUND)
  include(FindCUDA)
  include_directories(${CUDA_INCLUDE_DIRS})
  list(APPEND FFTLIBS "cufft")
  message(">> cuFFT -> " ${CUDA_CUFFT_LIBRARIES})
else()
  message("<< cuFFT benchmark disabled.")
endif()

#------------------------------------------------------------------------------
# OPENCL+CLFFT
#------------------------------------------------------------------------------
find_package(OpenCL)
if(OPENCL_FOUND)
  find_package(clFFT)
  if(CLFFT_FOUND)
    include_directories(${CLFFT_INCLUDE_DIRS})
    list(APPEND FFTLIBS "clfft")
    message(">> clFFT -> " ${CLFFT_LIBRARIES})
  endif()
endif()

if(NOT CLFFT_FOUND)
  message("<< clFFT benchmark disabled.")
endif()

#------------------------------------------------------------------------------
# ROCM+HCFFT
#------------------------------------------------------------------------------
find_package(hcFFT)
if(HCFFT_FOUND)
  include_directories(${HCFFT_INCLUDE_DIRS})
  list(APPEND FFTLIBS "hcfft")
  message(">> hcFFT -> " ${HCFFT_LIBRARIES} " " ${HCFFT_INCLUDE_DIRS})
  message(">> Warning: no runner for hcfft implemented yet")
endif()

if(NOT HCFFT_FOUND)
  message("<< hcFFT benchmark disabled.")
endif()

#------------------------------------------------------------------------------
# FFTW
#------------------------------------------------------------------------------
find_package(FFTW COMPONENTS float double)
if(FFTW_FOUND)
  include_directories(${FFTW_INCLUDE_DIR})
  link_directories(${FFTW_LIBRARY_DIR})
  list(APPEND FFTLIBS "fftw")
  find_package(OpenMP)

  foreach(_LIBSTEM IN LISTS FFTW_SERIAL_LIBS)
    list(APPEND FFTW_LIBS_TO_USE ${_LIBSTEM})
  endforeach()

  if(USE_FFTW_OPENMP AND OPENMP_FOUND AND "${FFTW_LIBRARIES}" MATCHES ".*_omp.*")
    foreach(_LIBSTEM IN LISTS FFTW_OPENMP_LIBS)
      list(APPEND FFTW_LIBS_TO_USE ${_LIBSTEM})
    endforeach()
  endif()

  if(USE_FFTW_PTHREADS AND "${FFTW_LIBRARIES}" MATCHES ".*_threads.*")
    foreach(_LIBSTEM IN LISTS FFTW_THREADS_LIBS)
      list(APPEND FFTW_LIBS_TO_USE ${_LIBSTEM})
    endforeach()

  endif()

  set(FFTW_LIBRARIES ${FFTW_LIBS_TO_USE})
  message(">> FFTW -> " ${FFTW_LIBRARIES} " " ${FFTW_INCLUDES})
else()
  message("<< FFTW benchmark disabled.")
endif()


if(NOT (CLFFT_FOUND OR CUDA_FOUND OR HCFFT_FOUND OR FFTW_FOUND))
  message(FATAL_ERROR ">> No FFT library for benchmark found !!!")
endif()

#------------------------------------------------------------------------------
# Helper function to add specific FFT library benchmark
#------------------------------------------------------------------------------
function(add_exec Tlib)
  set(PROJECT_EXEC gearshifft_${Tlib})
  add_executable(${PROJECT_EXEC} ${SOURCES})
  if (Tlib STREQUAL "cufft")
    target_compile_definitions(${PROJECT_EXEC} PUBLIC -DCUDA_ENABLED)
    set(LIBS ${CUDA_LIBRARIES} ${CUDA_CUFFT_LIBRARIES})
  elseif(Tlib STREQUAL "clfft" OR Tlib STREQUAL "test")
    target_compile_definitions(${PROJECT_EXEC} PUBLIC -DOPENCL_ENABLED)
    set(LIBS ${CLFFT_LIBRARIES} ${OPENCL_LIBRARIES})
  endif()
  if (Tlib STREQUAL "fftw")
    set_target_properties(${PROJECT_EXEC}
      PROPERTIES COMPILE_FLAGS "-DFFTW_ENABLED ${PROJECT_EXEC_FLAGS}")
    
    set(LIBS ${LIBS} ${FFTW_LIBRARIES})
  endif()

  target_link_libraries(${PROJECT_EXEC} ${Boost_LIBRARIES} ${LIBS})
  add_test(NAME ${PROJECT_EXEC} COMMAND ${PROJECT_EXEC})
endfunction()

#------------------------------------------------------------------------------
#
#------------------------------------------------------------------------------
include_directories(../inc)

enable_testing()
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose)

if(DEV_TESTS)
{'fraction_non_alphanumeric': 0.29391688415980727, 'fraction_numerical': 0.005019072475406545, 'mean_word_length': 2.2719211822660097, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3469011', 'n_tokens_mistral': 3521, 'n_tokens_neox': 3286, 'n_words': 587}