-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
231 lines (191 loc) · 6.93 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
cmake_minimum_required(VERSION 3.3)
set(chromaprint_VERSION_MAJOR 1)
set(chromaprint_VERSION_MINOR 5)
set(chromaprint_VERSION_PATCH 1)
set(chromaprint_VERSION "${chromaprint_VERSION_MAJOR}.${chromaprint_VERSION_MINOR}.${chromaprint_VERSION_PATCH}")
project(chromaprint LANGUAGES C CXX VERSION "${chromaprint_VERSION}")
set(chromaprint_SOVERSION 1)
set(AUDIO_PROCESSOR_LIB CACHE STRING "Library to use for audio processing")
set_property(CACHE AUDIO_PROCESSOR_LIB PROPERTY STRINGS avresample swresample)
set(FFT_LIB CACHE STRING "Library to use for FFT calculations")
set_property(CACHE FFT_LIB PROPERTY STRINGS avfft fftw3 fftw3f kissfft vdsp)
include(CMakePushCheckState)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckCXXCompilerFlag)
find_package(Threads)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
set(CMAKE_CXX_STANDARD 11)
if(BUILD_SHARED_LIBS)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
endif()
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-D_GLIBCXX_DEBUG)
endif()
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_LIBRARIES -lm)
check_symbol_exists(lrintf math.h HAVE_LRINTF)
check_symbol_exists(round math.h HAVE_ROUND)
cmake_pop_check_state()
add_definitions(
-DHAVE_CONFIG_H
-D_SCL_SECURE_NO_WARNINGS
-D_USE_MATH_DEFINES
-D__STDC_LIMIT_MACROS
-D__STDC_CONSTANT_MACROS
)
set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)")
set(EXEC_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Installation prefix for executables and object code libraries" FORCE)
set(BIN_INSTALL_DIR ${EXEC_INSTALL_PREFIX}/bin CACHE PATH "Installation prefix for user executables" FORCE)
set(LIB_INSTALL_DIR ${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX} CACHE PATH "Installation prefix for object code libraries" FORCE)
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include CACHE PATH "Installation prefix for C header files" FORCE)
if(APPLE)
option(BUILD_FRAMEWORK "Build an OS X framework" OFF)
set(FRAMEWORK_INSTALL_DIR "/Library/Frameworks" CACHE STRING "Directory to install frameworks to")
endif()
option(BUILD_TOOLS "Build command line tools" OFF)
option(BUILD_TESTS "Build test suite" ON)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
endif()
if(NOT BUILD_SHARED_LIBS)
add_definitions(-DCHROMAPRINT_NODLL)
endif()
set(TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests/)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
find_package(FFmpeg)
if(FFMPEG_LIBRARIES)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_LIBRARIES ${FFMPEG_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lm)
check_function_exists(av_packet_unref HAVE_AV_PACKET_UNREF)
check_function_exists(av_frame_alloc HAVE_AV_FRAME_ALLOC)
check_function_exists(av_frame_free HAVE_AV_FRAME_FREE)
cmake_pop_check_state()
endif()
if(NOT FFT_LIB OR FFT_LIB STREQUAL "fftw3" OR FFT_LIB STREQUAL "fftw3f")
find_package(FFTW3)
endif()
if(APPLE)
if(NOT FFT_LIB OR FFT_LIB STREQUAL "vdsp")
find_library(ACCELERATE_LIBRARIES Accelerate)
endif()
endif()
if(NOT FFT_LIB OR FFT_LIB STREQUAL "kissfft")
find_package(KissFFT)
endif()
set(USE_VDSP OFF)
set(USE_AVFFT OFF)
set(USE_FFTW3 OFF)
set(USE_FFTW3F OFF)
set(USE_KISSFFT OFF)
if(NOT FFT_LIB)
if(APPLE AND ACCELERATE_LIBRARIES)
set(FFT_LIB "vdsp")
elseif(FFMPEG_LIBAVCODEC_FFT_FOUND)
set(FFT_LIB "avfft")
elseif(FFTW3_LIBRARIES)
set(FFT_LIB "fftw3")
elseif(FFTW3_FFTWF_LIBRARY)
set(FFT_LIB "fftw3f")
elseif(KISSFFT_FOUND)
set(FFT_LIB "kissfft")
endif()
endif()
if(FFT_LIB STREQUAL "vdsp")
if(ACCELERATE_LIBRARIES)
set(USE_VDSP ON)
else()
message(FATAL_ERROR "Selected ${FFT_LIB} for FFT calculations, but the library is not found")
endif()
elseif(FFT_LIB STREQUAL "avfft")
if(FFMPEG_LIBAVCODEC_FFT_FOUND)
set(USE_AVFFT ON)
else()
message(FATAL_ERROR "Selected ${FFT_LIB} for FFT calculations, but the library is not found")
endif()
elseif(FFT_LIB STREQUAL "fftw3")
if(FFTW3_LIBRARIES)
set(USE_FFTW3 ON)
else()
message(FATAL_ERROR "Selected ${FFT_LIB} for FFT calculations, but the library is not found")
endif()
elseif(FFT_LIB STREQUAL "fftw3f")
if(FFTW3_FFTWF_LIBRARY)
set(USE_FFTW3F ON)
else()
message(FATAL_ERROR "Selected ${FFT_LIB} for FFT calculations, but the library is not found")
endif()
elseif(FFT_LIB STREQUAL "kissfft")
if(KISSFFT_FOUND)
set(USE_KISSFFT ON)
else()
message(FATAL_ERROR "Selected ${FFT_LIB} for FFT calculations, but the library is not found")
endif()
else()
message(FATAL_ERROR "No FFT library found")
endif()
message(STATUS "Using ${FFT_LIB} for FFT calculations")
if(NOT AUDIO_PROCESSOR_LIB)
if(FFMPEG_LIBSWRESAMPLE_FOUND)
set(AUDIO_PROCESSOR_LIB "swresample")
elseif(FFMPEG_LIBAVRESAMPLE_FOUND)
set(AUDIO_PROCESSOR_LIB "avresample")
endif()
endif()
if(AUDIO_PROCESSOR_LIB STREQUAL "swresample")
if(FFMPEG_LIBSWRESAMPLE_FOUND)
set(USE_AVRESAMPLE OFF)
set(USE_SWRESAMPLE ON)
set(AUDIO_PROCESSOR_LIBRARIES ${FFMPEG_LIBSWRESAMPLE_LIBRARIES})
set(AUDIO_PROCESSOR_INCLUDE_DIRS ${FFMPEG_LIBSWRESAMPLE_INCLUDE_DIRS})
else()
message(FATAL_ERROR "Selected ${AUDIO_PROCESSOR_LIB} for audio processing, but the library is not found")
endif()
message(STATUS "Using ${AUDIO_PROCESSOR_LIB} for audio conversion")
elseif(AUDIO_PROCESSOR_LIB STREQUAL "avresample")
if(FFMPEG_LIBAVRESAMPLE_FOUND)
set(USE_AVRESAMPLE ON)
set(USE_SWRESAMPLE OFF)
set(AUDIO_PROCESSOR_LIBRARIES ${FFMPEG_LIBAVRESAMPLE_LIBRARIES})
set(AUDIO_PROCESSOR_INCLUDE_DIRS ${FFMPEG_LIBAVRESAMPLE_INCLUDE_DIRS})
else()
message(FATAL_ERROR "Selected ${AUDIO_PROCESSOR_LIB} for audio processing, but the library is not found")
endif()
message(STATUS "Using ${AUDIO_PROCESSOR_LIB} for audio conversion")
else()
message(STATUS "Building without audio conversion support, please install FFmpeg with libswresample")
endif()
if(NOT BUILD_FRAMEWORK)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libchromaprint.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libchromaprint.pc)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/libchromaprint.pc
DESTINATION ${LIB_INSTALL_DIR}/pkgconfig
COMPONENT chromaprint)
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src)
add_definitions(
-DHAVE_CONFIG_H
-D_SCL_SECURE_NO_WARNINGS
-D_USE_MATH_DEFINES
-D__STDC_LIMIT_MACROS
-D__STDC_CONSTANT_MACROS
)
if(UNIX)
link_libraries(m)
endif()
add_subdirectory(src)
if(BUILD_TESTS)
add_subdirectory(tests)
endif(BUILD_TESTS)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.cmake" "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
add_custom_target(docs doxygen)