]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blob - src/CMakeLists.txt
Modified parallel version of Fftw use POSIX threads only when the sequential version...
[hercules2020/kcf.git] / src / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8)
2
3 set(KCF_LIB_SRC kcf.cpp kcf.h fft.cpp)
4
5 SET(FFT "OpenCV" CACHE STRING "Select FFT implementation")
6 SET_PROPERTY(CACHE FFT PROPERTY STRINGS OpenCV OpenCV_cuFFT fftw cuFFTW cuFFT)
7 MESSAGE(STATUS "FFT implementation: ${FFT}")
8
9 option(OPENMP "Use OpenMP library. Works with FFTW and OpenCV implementation." OFF)
10 option(ASYNC "Works only if OPENCV_CUFFT is not ON. Will enable C++ async directive." OFF)
11 option(CUDA_DEBUG "Enables error cheking for cuda and cufft. " OFF)
12 option(BIG_BATCH "Enable transforming all features from all scales together." OFF)
13
14 IF(PROFILING)
15   add_definitions(-DPROFILING )
16   MESSAGE(STATUS "Profiling mode")
17 ENDIF()
18
19 IF(BIG_BATCH)
20   add_definitions(-DBIG_BATCH )
21   MESSAGE(STATUS "Big_batch mode")
22 ENDIF()
23
24 SET(use_cuda OFF)
25
26 IF(FFT STREQUAL "OpenCV")
27   list(APPEND KCF_LIB_SRC fft_opencv.cpp complexmat.hpp)
28 ELSEIF(FFT STREQUAL "OpenCV_cuFFT")
29   list(APPEND KCF_LIB_SRC fft_opencv_cuda.cpp complexmat.hpp)
30   add_definitions(-DOPENCV_CUFFT)
31   set(use_cuda ON)
32 ELSEIF(FFT STREQUAL "fftw")
33   list(APPEND KCF_LIB_SRC fft_fftw.cpp complexmat.hpp)
34   add_definitions(-DFFTW)
35 ELSEIF(FFT STREQUAL "cuFFTW")
36   list(APPEND KCF_LIB_SRC fft_fftw.cpp complexmat.hpp)
37   add_definitions(-DFFTW -DCUFFTW)
38   set(use_cuda ON)
39 ELSEIF(FFT STREQUAL "cuFFT")
40     list(APPEND KCF_LIB_SRC fft_cufft.cpp complexmat.cuh cuda_functions.cuh)
41     add_definitions(-DCUFFT)
42     set(use_cuda ON)
43     iF(CUDA_DEBUG)
44       add_definitions(-DCUDA_DEBUG)
45       MESSAGE(STATUS "CUDA debug mode")
46     ENDIF()
47 ELSE()
48   MESSAGE(FATAL_ERROR "Invalid FFT implementation selected")
49 ENDIF()
50
51 IF((FFT STREQUAL "OpenCV") AND BIG_BATCH)
52   message(SEND_ERROR "OpenCV version does not support big batch mode.")
53 ENDIF()
54
55 IF((FFT STREQUAL "cuFFT") AND (ASYNC OR (OPENMP AND NOT BIG_BATCH)))
56   message(SEND_ERROR "cuFFT version does not support ASYNC and OpenMP only if used with big batch mode.")
57 ENDIF()
58
59 IF(ASYNC AND NOT OPENMP)
60   add_definitions(-DASYNC)
61   MESSAGE(STATUS "ASYNC")
62 ENDIF() #ASYNC
63
64 FIND_PACKAGE( OpenCV REQUIRED )
65
66 IF(use_cuda)
67   find_package(CUDA REQUIRED)
68
69   if (NOT ${OpenCV_USE_CUFFT})
70     message(SEND_ERROR "OpenCV was not built with cuFFT")
71   endif()
72
73   include_directories ( ${CUDA_INCLUDE_DIRS} )
74   set(CUDA_SEPARABLE_COMPILATION ON)
75   set(CUDA_PROPAGATE_HOST_FLAGS OFF)
76   set(CUDA_HOST_COMPILER /usr/bin/g++)
77   list( APPEND CUDA_NVCC_FLAGS -O3 --gpu-architecture sm_62 -std=c++11 -default-stream per-thread)
78   find_cuda_helper_libs(cufftw)
79   IF(FFT STREQUAL "cuFFT")
80   add_subdirectory(cuda)
81   cuda_add_library(complexmat complexmat.cu)
82   cuda_add_library(cuda_func cuda_functions.cu)
83   ENDIF()
84   
85 ENDIF()
86
87 add_subdirectory(piotr_fhog)
88 add_subdirectory(cn)
89
90 add_library(kcf STATIC ${KCF_LIB_SRC})
91 target_link_libraries(kcf fhog cndata  ${OpenCV_LIBS})
92 set_target_properties(kcf PROPERTIES VERSION 1.0.0 SOVERSION 1)
93
94 IF(FFT STREQUAL "fftw")
95   target_link_libraries(kcf fftw3f)
96   IF(OPENMP)
97     target_link_libraries(kcf fftw3_omp)
98   ELSEIF(NOT ASYNC)
99     target_link_libraries(kcf fftw3_threads)
100   ENDIF()
101 ENDIF() #FFTW
102
103 IF(FFT STREQUAL "cuFFTW")
104   target_link_libraries(kcf ${CUDA_cufft_LIBRARY} ${CUDA_cufftw_LIBRARY})
105 ENDIF() #cuFFTW
106
107 IF(FFT STREQUAL "cuFFT")
108     target_link_libraries(kcf ${CUDA_cufft_LIBRARY} ${CUDA_LIBRARIES} complexmat cuda_func)
109 ENDIF()
110
111 IF(PROFILING)
112   target_link_libraries(kcf pfm)
113 ENDIF()