Merge branch 'master' into blender2.8
[blender.git] / extern / audaspace / CMakeLists.txt
1 ################################################################################
2 # Copyright 2009-2016 Jörg Müller
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #   http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 ################################################################################
16
17 cmake_minimum_required(VERSION 3.0)
18 include(CMakeDependentOption)
19
20 if(POLICY CMP0054)
21         cmake_policy(SET CMP0054 NEW)
22 endif()
23
24 project(audaspace)
25
26 set(AUDASPACE_VERSION 1.3)
27 set(AUDASPACE_LONG_VERSION ${AUDASPACE_VERSION}.0)
28
29 if(DEFINED AUDASPACE_CMAKE_CFG)
30         include(${AUDASPACE_CMAKE_CFG})
31 endif()
32
33 if(NOT DEFINED AUDASPACE_STANDALONE)
34         set(AUDASPACE_STANDALONE TRUE)
35 endif()
36
37 # sources
38
39 set(SRC
40         src/devices/DefaultSynchronizer.cpp
41         src/devices/DeviceManager.cpp
42         src/devices/NULLDevice.cpp
43         src/devices/ReadDevice.cpp
44         src/devices/SoftwareDevice.cpp
45         src/Exception.cpp
46         src/file/File.cpp
47         src/file/FileManager.cpp
48         src/file/FileWriter.cpp
49         src/fx/Accumulator.cpp
50         src/fx/ADSR.cpp
51         src/fx/ADSRReader.cpp
52         src/fx/BaseIIRFilterReader.cpp
53         src/fx/ButterworthCalculator.cpp
54         src/fx/Butterworth.cpp
55         src/fx/CallbackIIRFilterReader.cpp
56         src/fx/Delay.cpp
57         src/fx/DelayReader.cpp
58         src/fx/DynamicIIRFilter.cpp
59         src/fx/DynamicIIRFilterReader.cpp
60         src/fx/DynamicMusic.cpp
61         src/fx/Effect.cpp
62         src/fx/EffectReader.cpp
63         src/fx/Envelope.cpp
64         src/fx/Fader.cpp
65         src/fx/FaderReader.cpp
66         src/fx/HighpassCalculator.cpp
67         src/fx/Highpass.cpp
68         src/fx/IIRFilter.cpp
69         src/fx/IIRFilterReader.cpp
70         src/fx/Limiter.cpp
71         src/fx/LimiterReader.cpp
72         src/fx/Loop.cpp
73         src/fx/LoopReader.cpp
74         src/fx/LowpassCalculator.cpp
75         src/fx/Lowpass.cpp
76         src/fx/MutableReader.cpp
77         src/fx/MutableSound.cpp
78         src/fx/Pitch.cpp
79         src/fx/PitchReader.cpp
80         src/fx/PlaybackManager.cpp
81         src/fx/PlaybackCategory.cpp
82         src/fx/Reverse.cpp
83         src/fx/ReverseReader.cpp
84         src/fx/SoundList.cpp
85         src/fx/Source.cpp
86         src/fx/Sum.cpp
87         src/fx/Threshold.cpp
88         src/fx/Volume.cpp
89         src/fx/VolumeReader.cpp
90         src/fx/VolumeSound.cpp
91         src/fx/VolumeStorage.cpp
92         src/generator/Sawtooth.cpp
93         src/generator/SawtoothReader.cpp
94         src/generator/Silence.cpp
95         src/generator/SilenceReader.cpp
96         src/generator/Sine.cpp
97         src/generator/SineReader.cpp
98         src/generator/Square.cpp
99         src/generator/SquareReader.cpp
100         src/generator/Triangle.cpp
101         src/generator/TriangleReader.cpp
102         src/respec/ChannelMapper.cpp
103         src/respec/ChannelMapperReader.cpp
104         src/respec/Converter.cpp
105         src/respec/ConverterFunctions.cpp
106         src/respec/ConverterReader.cpp
107         src/respec/JOSResample.cpp
108         src/respec/JOSResampleReaderCoeff.cpp
109         src/respec/JOSResampleReader.cpp
110         src/respec/LinearResample.cpp
111         src/respec/LinearResampleReader.cpp
112         src/respec/Mixer.cpp
113         src/respec/ResampleReader.cpp
114         src/respec/SpecsChanger.cpp
115         src/sequence/AnimateableProperty.cpp
116         src/sequence/Double.cpp
117         src/sequence/DoubleReader.cpp
118         src/sequence/PingPong.cpp
119         src/sequence/Sequence.cpp
120         src/sequence/SequenceData.cpp
121         src/sequence/SequenceEntry.cpp
122         src/sequence/SequenceHandle.cpp
123         src/sequence/SequenceReader.cpp
124         src/sequence/Superpose.cpp
125         src/sequence/SuperposeReader.cpp
126         src/util/Barrier.cpp
127         src/util/Buffer.cpp
128         src/util/BufferReader.cpp
129         src/util/StreamBuffer.cpp
130         src/util/ThreadPool.cpp
131 )
132
133 set(PRIVATE_HDR
134         src/sequence/SequenceHandle.h
135 )
136
137 set(PUBLIC_HDR
138         include/devices/DefaultSynchronizer.h
139         include/devices/DeviceManager.h
140         include/devices/I3DDevice.h
141         include/devices/I3DHandle.h
142         include/devices/IDeviceFactory.h
143         include/devices/IDevice.h
144         include/devices/IHandle.h
145         include/devices/ISynchronizer.h
146         include/devices/NULLDevice.h
147         include/devices/ReadDevice.h
148         include/devices/SoftwareDevice.h
149         include/Exception.h
150         include/file/File.h
151         include/file/FileManager.h
152         include/file/FileWriter.h
153         include/file/IFileInput.h
154         include/file/IFileOutput.h
155         include/file/IWriter.h
156         include/fx/Accumulator.h
157         include/fx/ADSR.h
158         include/fx/ADSRReader.h
159         include/fx/BaseIIRFilterReader.h
160         include/fx/ButterworthCalculator.h
161         include/fx/Butterworth.h
162         include/fx/CallbackIIRFilterReader.h
163         include/fx/Delay.h
164         include/fx/DelayReader.h
165         include/fx/DynamicIIRFilter.h
166         include/fx/DynamicIIRFilterReader.h
167         include/fx/DynamicMusic.h
168         include/fx/Effect.h
169         include/fx/EffectReader.h
170         include/fx/Envelope.h
171         include/fx/Fader.h
172         include/fx/FaderReader.h
173         include/fx/HighpassCalculator.h
174         include/fx/Highpass.h
175         include/fx/IDynamicIIRFilterCalculator.h
176         include/fx/IIRFilter.h
177         include/fx/IIRFilterReader.h
178         include/fx/Limiter.h
179         include/fx/LimiterReader.h
180         include/fx/Loop.h
181         include/fx/LoopReader.h
182         include/fx/LowpassCalculator.h
183         include/fx/Lowpass.h
184         include/fx/MutableReader.h
185         include/fx/MutableSound.h
186         include/fx/Pitch.h
187         include/fx/PitchReader.h
188         include/fx/PlaybackManager.h
189         include/fx/PlaybackCategory.h
190         include/fx/Reverse.h
191         include/fx/ReverseReader.h
192         include/fx/SoundList.h
193         include/fx/Source.h
194         include/fx/Sum.h
195         include/fx/Threshold.h
196         include/fx/Volume.h
197         include/fx/VolumeReader.h
198         include/fx/VolumeSound.h
199         include/fx/VolumeStorage.h
200         include/generator/Sawtooth.h
201         include/generator/SawtoothReader.h
202         include/generator/Silence.h
203         include/generator/SilenceReader.h
204         include/generator/Sine.h
205         include/generator/SineReader.h
206         include/generator/Square.h
207         include/generator/SquareReader.h
208         include/generator/Triangle.h
209         include/generator/TriangleReader.h
210         include/IReader.h
211         include/ISound.h
212         include/plugin/PluginManager.h
213         include/respec/ChannelMapper.h
214         include/respec/ChannelMapperReader.h
215         include/respec/ConverterFunctions.h
216         include/respec/Converter.h
217         include/respec/ConverterReader.h
218         include/respec/JOSResample.h
219         include/respec/JOSResampleReader.h
220         include/respec/LinearResample.h
221         include/respec/LinearResampleReader.h
222         include/respec/Mixer.h
223         include/respec/ResampleReader.h
224         include/respec/Specification.h
225         include/respec/SpecsChanger.h
226         include/sequence/AnimateableProperty.h
227         include/sequence/Double.h
228         include/sequence/DoubleReader.h
229         include/sequence/PingPong.h
230         include/sequence/SequenceData.h
231         include/sequence/SequenceEntry.h
232         include/sequence/Sequence.h
233         include/sequence/SequenceReader.h
234         include/sequence/Superpose.h
235         include/sequence/SuperposeReader.h
236         include/util/Barrier.h
237         include/util/Buffer.h
238         include/util/BufferReader.h
239         include/util/ILockable.h
240         include/util/Math3D.h
241         include/util/StreamBuffer.h
242         include/util/ThreadPool.h
243 )
244
245 set(HDR ${PRIVATE_HDR} ${PUBLIC_HDR})
246
247 set(INCLUDE ${CMAKE_CURRENT_BINARY_DIR} include)
248
249 if(WIN32)
250         set(LIBRARIES)
251         if(AUDASPACE_STANDALONE)
252                 set(DLLS)
253                 set(LIBRARY_PATH "../lib" CACHE PATH "Path which contains the libraries.")
254                 file(GLOB LIBRARY_DIRS ${LIBRARY_PATH}/*)
255                 list(APPEND CMAKE_PREFIX_PATH ${LIBRARY_DIRS})
256         endif()
257 else()
258         set(LIBRARIES ${CMAKE_DL_LIBS} -lpthread)
259 endif()
260
261 set(STATIC_PLUGINS "")
262
263 # dependencies
264
265 if(AUDASPACE_STANDALONE)
266         set(PACKAGE_OPTION QUIET)
267         list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
268
269         option(BUILD_DEMOS "Build and install demos" TRUE)
270
271         option(SHARED_LIBRARY "Build Shared Library" TRUE)
272
273         option(WITH_C "Build C Module" TRUE)
274         option(WITH_DOCS "Build C++ HTML Documentation with Doxygen" TRUE)
275         option(WITH_FFMPEG "Build With FFMPEG" TRUE)
276         option(WITH_FFTW "Build With FFTW" TRUE)
277         option(WITH_JACK "Build With Plugin" TRUE)
278         option(WITH_LIBSNDFILE "Build With LibSndFile" TRUE)
279         option(WITH_OPENAL "Build With OpenAL" TRUE)
280         option(WITH_PYTHON "Build With Python Library" TRUE)
281         option(WITH_SDL "Build With SDL" TRUE)
282         option(WITH_STRICT_DEPENDENCIES "Error and abort instead of warning if a library is not found." FALSE)
283
284         if(WITH_STRICT_DEPENDENCIES)
285                 set(PACKAGE_OPTION REQUIRED)
286         endif()
287 endif()
288
289 if(WIN32)
290         set(DEFAULT_PLUGIN_PATH "." CACHE STRING "Default plugin installation and loading path.")
291         set(DOCUMENTATION_INSTALL_PATH "doc" CACHE PATH "Path where the documentation is installed.")
292 else()
293         set(DEFAULT_PLUGIN_PATH "${CMAKE_INSTALL_PREFIX}/share/audaspace/plugins" CACHE STRING "Default plugin installation and loading path.")
294         set(DOCUMENTATION_INSTALL_PATH "share/doc/audaspace" CACHE PATH "Path where the documentation is installed.")
295 endif()
296
297 if(AUDASPACE_STANDALONE)
298         cmake_dependent_option(SEPARATE_C "Build C Binding as separate library" TRUE "WITH_C" FALSE)
299         cmake_dependent_option(PLUGIN_FFMPEG "Build FFMPEG Plugin" TRUE "WITH_FFMPEG;SHARED_LIBRARY" FALSE)
300         cmake_dependent_option(PLUGIN_JACK "Build JACK Plugin" TRUE "WITH_JACK;SHARED_LIBRARY" FALSE)
301         cmake_dependent_option(PLUGIN_LIBSNDFILE "Build LibSndFile Plugin" TRUE "WITH_LIBSNDFILE;SHARED_LIBRARY" FALSE)
302         cmake_dependent_option(PLUGIN_OPENAL "Build OpenAL Plugin" TRUE "WITH_OPENAL;SHARED_LIBRARY" FALSE)
303         cmake_dependent_option(PLUGIN_SDL "Build SDL Plugin" TRUE "WITH_SDL;SHARED_LIBRARY" FALSE)
304         cmake_dependent_option(WITH_PYTHON_MODULE "Build Python Module" TRUE "WITH_PYTHON" FALSE)
305         cmake_dependent_option(USE_SDL2 "Use SDL2 instead of 1 if available" TRUE "WITH_SDL" FALSE)
306         cmake_dependent_option(DYNLOAD_JACK "Dynamically load JACK" FALSE "WITH_JACK" FALSE)
307         cmake_dependent_option(WITH_BINDING_DOCS "Build C/Python HTML Documentation with Sphinx" TRUE "WITH_PYTHON_MODULE" FALSE)
308 endif()
309
310 # compiler options
311
312 if(AUDASPACE_STANDALONE)
313         if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
314                 add_definitions(-std=c++11)
315                 list(APPEND CMAKE_C_COMPILER_FLAGS "-fvisibility=hidden")
316                 list(APPEND CMAKE_CXX_COMPILER_FLAGS "-fvisibility=hidden")
317         endif()
318
319         if(MSVC)
320                 list(APPEND CMAKE_C_FLAGS_DEBUG "/Zi /Od")
321                 list(APPEND CMAKE_CXX_FLAGS_DEBUG "/Zi /Od")
322                 list(APPEND CMAKE_SHARED_LINKER_FLAGS_DEBUG "/DEBUG")
323                 list(APPEND CMAKE_STATIC_LINKER_FLAGS_DEBUG "/DEBUG")
324                 list(APPEND CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG")
325
326                 if(SHARED_LIBRARY)
327                         include(GenerateExportHeader)
328                 endif()
329         endif()
330
331         if(APPLE AND NOT CMAKE_OSX_DEPLOYMENT_TARGET)
332                 set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "" FORCE)
333         endif()
334 endif()
335
336 if(MSVC)
337         add_definitions(
338                 /D_USE_MATH_DEFINES
339                 /EHsc
340                 /DNOMINMAX
341                 /D_STDINT_H
342         )
343 endif()
344
345 # platform specific options
346
347 if(MSYS OR MINGW)
348         add_definitions(-D_USE_MATH_DEFINES)
349 endif()
350
351 # C
352 if(WITH_C)
353         set(C_SRC
354                 bindings/C/AUD_ThreadPool.cpp
355                 bindings/C/AUD_Source.cpp
356                 bindings/C/AUD_Device.cpp
357                 bindings/C/AUD_DynamicMusic.cpp
358                 bindings/C/AUD_Handle.cpp
359                 bindings/C/AUD_PlaybackManager.cpp
360                 bindings/C/AUD_Sequence.cpp
361                 bindings/C/AUD_Sound.cpp
362                 bindings/C/AUD_Special.cpp
363         )
364         set(C_HDR
365                 bindings/C/AUD_ThreadPool.h
366                 bindings/C/AUD_Source.h
367                 bindings/C/AUD_Device.h
368                 bindings/C/AUD_DynamicMusic.h
369                 bindings/C/AUD_Handle.h
370                 bindings/C/AUD_PlaybackManager.h
371                 bindings/C/AUD_Sequence.h
372                 bindings/C/AUD_Sound.h
373                 bindings/C/AUD_Special.h
374                 bindings/C/AUD_Types.h
375         )
376
377 if(WITH_FFTW)
378         list(APPEND C_SRC
379                         bindings/C/AUD_HRTF.cpp
380                         bindings/C/AUD_ImpulseResponse.cpp
381                         )
382
383                 list(APPEND C_HDR
384                         bindings/C/AUD_HRTF.h
385                         bindings/C/AUD_ImpulseResponse.h
386                         )
387         endif()
388
389         if(NOT SEPARATE_C)
390                 list(APPEND SRC ${C_SRC})
391                 list(APPEND HDR ${C_HDR})
392         else()
393                 set(AUDASPACE_C_LIBRARY -laudaspace-c)
394         endif()
395 endif()
396
397 # FFMPEG
398 if(WITH_FFMPEG)
399         if(AUDASPACE_STANDALONE)
400                 find_package(FFMPEG ${PACKAGE_OPTION})
401         endif()
402
403         if(FFMPEG_FOUND)
404                 set(FFMPEG_SRC
405                         plugins/ffmpeg/FFMPEG.cpp
406                         plugins/ffmpeg/FFMPEGReader.cpp
407                         plugins/ffmpeg/FFMPEGWriter.cpp
408                 )
409                 set(FFMPEG_HDR
410                         plugins/ffmpeg/FFMPEG.h
411                         plugins/ffmpeg/FFMPEGReader.h
412                         plugins/ffmpeg/FFMPEGWriter.h
413                 )
414
415                 if(NOT PLUGIN_FFMPEG)
416                         list(APPEND INCLUDE ${FFMPEG_INCLUDE_DIRS})
417                         list(APPEND LIBRARIES ${FFMPEG_LIBRARIES})
418                         list(APPEND SRC ${FFMPEG_SRC})
419                         list(APPEND HDR ${FFMPEG_HDR})
420                         list(APPEND STATIC_PLUGINS FFMPEG)
421                 endif()
422
423                 if(WIN32 AND AUDASPACE_STANDALONE)
424                         file(GLOB FFMPEG_DLLS ${LIBRARY_PATH}/ffmpeg/bin/*.dll)
425                         list(APPEND DLLS ${FFMPEG_DLLS})
426                 endif()
427         else()
428                 set(WITH_FFMPEG FALSE CACHE BOOL "Build With FFMPEG" FORCE)
429                 message(WARNING "FFMPEG not found, plugin will not be built.")
430         endif()
431 endif()
432
433 # FFTW
434 if(WITH_FFTW)
435         if(AUDASPACE_STANDALONE)
436                 find_package(FFTW ${PACKAGE_OPTION})
437         endif()
438
439         if(FFTW_FOUND)
440                 set(FFTW_SRC
441                         src/fx/BinauralSound.cpp
442                         src/fx/BinauralReader.cpp
443                         src/fx/Convolver.cpp
444                         src/fx/ConvolverReader.cpp
445                         src/fx/ConvolverSound.cpp
446                         src/fx/FFTConvolver.cpp
447                         src/fx/HRTF.cpp
448                         src/fx/ImpulseResponse.cpp
449                         src/util/FFTPlan.cpp
450                 )
451         set(FFTW_HDR
452                 include/fx/BinauralSound.h
453                         include/fx/BinauralReader.h
454                         include/fx/Convolver.h
455                         include/fx/ConvolverReader.h
456                         include/fx/ConvolverSound.h
457                         include/fx/FFTConvolver.h
458                         include/fx/HRTF.h
459                         include/fx/HRTFLoader.h
460                         include/fx/ImpulseResponse.h
461                         include/util/FFTPlan.h
462                 )
463
464                 add_definitions(-DWITH_CONVOLUTION)
465
466                 list(APPEND INCLUDE ${FFTW_INCLUDE_DIR})
467                 list(APPEND LIBRARIES ${FFTW_LIBRARY})
468
469                 list(APPEND SRC ${FFTW_SRC})
470                 list(APPEND HDR ${FFTW_HDR})
471
472                 if(WIN32 AND AUDASPACE_STANDALONE)
473                         file(GLOB FFTW_DLLS ${LIBRARY_PATH}/fftw/bin/*.dll)
474                         list(APPEND DLLS ${FFTW_DLLS})
475                 endif()
476         else()
477                 set(WITH_FFTW FALSE CACHE BOOL "Build With FFTW" FORCE)
478                 message(WARNING "FFTW not found, convolution functionality will not be built.")
479         endif()
480 endif()
481
482 # JACK
483 if(WITH_JACK)
484         if(AUDASPACE_STANDALONE)
485                 find_package(Jack ${PACKAGE_OPTION})
486         endif()
487
488         if(JACK_FOUND)
489                 set(JACK_SRC
490                         plugins/jack/JackDevice.cpp
491                         plugins/jack/JackSynchronizer.cpp
492                         plugins/jack/JackLibrary.cpp
493                 )
494                 set(JACK_HDR
495                         plugins/jack/JackDevice.h
496                         plugins/jack/JackSynchronizer.h
497                         plugins/jack/JackLibrary.h
498                         plugins/jack/JackSymbols.h
499                 )
500
501         if(DYNLOAD_JACK)
502                         add_definitions(-DDYNLOAD_JACK)
503                 endif()
504
505                 if(NOT PLUGIN_JACK)
506                         list(APPEND INCLUDE ${JACK_INCLUDE_DIRS})
507                         if(NOT DYNLOAD_JACK)
508                                 list(APPEND LIBRARIES ${JACK_LIBRARIES})
509                         endif()
510                         list(APPEND SRC ${JACK_SRC})
511                         list(APPEND HDR ${JACK_HDR})
512                         list(APPEND STATIC_PLUGINS JackDevice)
513                 endif()
514
515                 if(WIN32 AND AUDASPACE_STANDALONE)
516                         file(GLOB JACK_DLLS ${LIBRARY_PATH}/jack/bin/*.dll)
517                         list(APPEND DLLS ${JACK_DLLS})
518                 endif()
519         else()
520                 set(WITH_JACK FALSE CACHE BOOL "Build With JACK" FORCE)
521                 message(WARNING "JACK not found, plugin will not be built.")
522         endif()
523 endif()
524
525 # LibSndFile
526 if(WITH_LIBSNDFILE)
527         if(AUDASPACE_STANDALONE)
528                 find_package(LibSndFile ${PACKAGE_OPTION})
529         endif()
530
531         if(LIBSNDFILE_FOUND)
532                 set(LIBSNDFILE_SRC
533                         plugins/libsndfile/SndFile.cpp
534                         plugins/libsndfile/SndFileReader.cpp
535                         plugins/libsndfile/SndFileWriter.cpp
536                 )
537                 set(LIBSNDFILE_HDR
538                         plugins/libsndfile/SndFile.h
539                         plugins/libsndfile/SndFileReader.h
540                         plugins/libsndfile/SndFileWriter.h
541                 )
542
543                 if(NOT PLUGIN_LIBSNDFILE)
544                         list(APPEND INCLUDE ${LIBSNDFILE_INCLUDE_DIRS})
545                         list(APPEND LIBRARIES ${LIBSNDFILE_LIBRARIES})
546                         list(APPEND SRC ${LIBSNDFILE_SRC})
547                         list(APPEND HDR ${LIBSNDFILE_HDR})
548                         list(APPEND STATIC_PLUGINS SndFile)
549                 endif()
550
551                 if(WIN32 AND AUDASPACE_STANDALONE)
552                         file(GLOB LIBSNDFILE_DLLS ${LIBRARY_PATH}/libsndfile/bin/*.dll)
553                         list(APPEND DLLS ${LIBSNDFILE_DLLS})
554                 endif()
555         else()
556                 set(WITH_LIBSNDFILE FALSE CACHE BOOL "Build With LibSndFile" FORCE)
557                 message(WARNING "LibSndFile not found, plugin will not be built.")
558         endif()
559 endif()
560
561 # OpenAL
562 if(WITH_OPENAL)
563         if(AUDASPACE_STANDALONE)
564                 find_package(OpenAL ${PACKAGE_OPTION})
565         endif()
566
567         if(OPENAL_FOUND)
568                 set(OPENAL_SRC
569                         plugins/openal/OpenALDevice.cpp
570                         plugins/openal/OpenALReader.cpp
571                 )
572                 set(OPENAL_HDR
573                         plugins/openal/OpenALDevice.h
574                         plugins/openal/OpenALReader.h
575                 )
576
577                 if(NOT PLUGIN_OPENAL)
578                         list(APPEND INCLUDE ${OPENAL_INCLUDE_DIR})
579                         list(APPEND LIBRARIES ${OPENAL_LIBRARY})
580                         list(APPEND SRC ${OPENAL_SRC})
581                         list(APPEND HDR ${OPENAL_HDR})
582                         list(APPEND STATIC_PLUGINS OpenALDevice)
583                 endif()
584
585                 if(WIN32 AND AUDASPACE_STANDALONE)
586                         file(GLOB OPENAL_DLLS ${LIBRARY_PATH}/OpenAL/bin/*.dll)
587                         list(APPEND DLLS ${OPENAL_DLLS})
588                 endif()
589         else()
590                 set(WITH_OPENAL FALSE CACHE BOOL "Build With OpenAL" FORCE)
591                 message(WARNING "OpenAL not found, plugin will not be built.")
592         endif()
593 endif()
594
595 # Python
596 if(WITH_PYTHON)
597         if(AUDASPACE_STANDALONE)
598                 find_package(PythonLibs 3.2 ${PACKAGE_OPTION})
599                 find_package(NumPy ${PACKAGE_OPTION})
600         endif()
601
602         if(PYTHONLIBS_FOUND AND NUMPY_FOUND)
603                 list(APPEND INCLUDE ${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIRS})
604
605                 if(WITH_PYTHON_MODULE)
606                         find_package(PythonInterp 3.2 ${PACKAGE_OPTION})
607
608                         if(NOT PYTHONINTERP_FOUND)
609                                 set(WITH_PYTHON_MODULE FALSE)
610                                 message(WARNING "Python interpreter not found, module will not be built.")
611                         endif()
612                 endif()
613
614                 set(AUDASPACE_PY_LIBRARY -laudaspace-py)
615
616                 if(WIN32 AND AUDASPACE_STANDALONE)
617                         file(GLOB PYTHON_DLLS ${LIBRARY_PATH}/Python/bin/*.dll)
618                         list(APPEND DLLS ${PYTHON_DLLS})
619                 endif()
620         else()
621                 set(WITH_PYTHON FALSE CACHE BOOL "Build With Python Library" FORCE)
622                 message(WARNING "Python libraries not found, language binding will not be built.")
623         endif()
624 endif()
625
626 # SDL
627 if(WITH_SDL)
628         if(AUDASPACE_STANDALONE)
629                 if(USE_SDL2)
630                         find_package(SDL2)
631                         if(SDL2_FOUND)
632                                 set(SDL_INCLUDE_DIR ${SDL2_INCLUDE_DIR})
633                                 set(SDL_LIBRARY ${SDL2_LIBRARY})
634                                 set(SDL_FOUND TRUE)
635                         else()
636                                 find_package(SDL ${PACKAGE_OPTION})
637                         endif()
638                 else()
639                         find_package(SDL ${PACKAGE_OPTION})
640                 endif()
641         endif()
642
643         if(SDL_FOUND)
644                 set(SDL_SRC
645                         plugins/sdl/SDLDevice.cpp
646                 )
647                 set(SDL_HDR
648                         plugins/sdl/SDLDevice.h
649                 )
650
651                 if(NOT PLUGIN_SDL)
652                         list(APPEND INCLUDE ${SDL_INCLUDE_DIR})
653                         list(APPEND LIBRARIES ${SDL_LIBRARY})
654                         list(APPEND SRC ${SDL_SRC})
655                         list(APPEND HDR ${SDL_HDR})
656                         list(APPEND STATIC_PLUGINS SDLDevice)
657                 endif()
658
659                 if(WIN32 AND AUDASPACE_STANDALONE)
660                         file(GLOB SDL_DLLS ${LIBRARY_PATH}/sdl/bin/*.dll)
661                         list(APPEND DLLS ${SDL_DLLS})
662                 endif()
663         else()
664                 set(WITH_SDL FALSE CACHE BOOL "Build With SDL" FORCE)
665                 message(WARNING "SDL not found, plugin will not be built.")
666         endif()
667 endif()
668
669 # library configuration
670
671 if(SHARED_LIBRARY)
672         set(AUD_LIBRARY_TYPE AUD_SHARED_LIBRARY)
673         set(LIBRARY_TYPE SHARED)
674         add_definitions(-DAUD_BUILD_SHARED_LIBRARY)
675 else()
676         set(AUD_LIBRARY_TYPE AUD_STATIC_LIBRARY)
677         set(LIBRARY_TYPE STATIC)
678 endif()
679
680 # file configuration
681
682 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config/Audaspace.h.in ${CMAKE_CURRENT_BINARY_DIR}/Audaspace.h ESCAPE_QUOTES @ONLY)
683
684 list(APPEND HDR ${CMAKE_CURRENT_BINARY_DIR}/Audaspace.h)
685
686 set(STATIC_PLUGIN_CLASSES "")
687 set(STATIC_PLUGIN_REGISTERS "")
688
689 foreach(PLUGIN ${STATIC_PLUGINS})
690         list(APPEND STATIC_PLUGIN_CLASSES "STATIC_PLUGIN_CLASS(" ${PLUGIN} ")\n")
691         list(APPEND STATIC_PLUGIN_REGISTERS "\tSTATIC_PLUGIN_REGISTER(" ${PLUGIN} ")\n")
692 endforeach()
693
694 string(CONCAT STATIC_PLUGIN_CLASSES ${STATIC_PLUGIN_CLASSES})
695 string(CONCAT STATIC_PLUGIN_REGISTERS ${STATIC_PLUGIN_REGISTERS})
696
697 if(WIN32)
698         configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/plugin/PluginManagerWindows.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/PluginManager.cpp ESCAPE_QUOTES @ONLY)
699         if(WITH_FFTW)
700                 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/fx/HRTFLoaderWindows.cpp ${CMAKE_CURRENT_BINARY_DIR}/HRTFLoader.cpp COPYONLY)
701         endif()
702 else()
703         configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/plugin/PluginManagerUnix.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/PluginManager.cpp ESCAPE_QUOTES @ONLY)
704         if(WITH_FFTW)
705                 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/fx/HRTFLoaderUnix.cpp ${CMAKE_CURRENT_BINARY_DIR}/HRTFLoader.cpp COPYONLY)
706         endif()
707 endif()
708
709 list(APPEND SRC ${CMAKE_CURRENT_BINARY_DIR}/PluginManager.cpp)
710 if(WITH_FFTW)
711         list(APPEND SRC ${CMAKE_CURRENT_BINARY_DIR}/HRTFLoader.cpp)
712 endif()
713
714 # directories
715
716 include_directories(${INCLUDE})
717 link_directories()
718
719 # install configuration
720
721 if(WIN32)
722         set(BIN_DESTINATION ".")
723 else()
724         set(BIN_DESTINATION "bin")
725 endif()
726
727 set(LIB_DESTINATION "lib${LIB_SUFFIX}")
728
729 # library
730
731 add_library(audaspace ${LIBRARY_TYPE} ${SRC} ${HDR})
732 target_link_libraries(audaspace ${LIBRARIES})
733 set_target_properties(audaspace PROPERTIES SOVERSION ${AUDASPACE_VERSION})
734
735 if(AUDASPACE_STANDALONE)
736         install(TARGETS audaspace
737                 RUNTIME DESTINATION ${BIN_DESTINATION}
738                 LIBRARY DESTINATION ${LIB_DESTINATION}
739                 ARCHIVE DESTINATION ${LIB_DESTINATION}
740         )
741
742         install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION include/audaspace)
743         install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Audaspace.h DESTINATION include/audaspace)
744
745         configure_file(${CMAKE_CURRENT_SOURCE_DIR}/packages/pkgconfig/audaspace.pc.in ${CMAKE_CURRENT_BINARY_DIR}/audaspace.pc @ONLY)
746
747         if(NOT WIN32 AND NOT APPLE)
748                 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/audaspace.pc DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
749         endif()
750 endif()
751
752 # plugins
753
754 if(WITH_FFMPEG AND PLUGIN_FFMPEG)
755         add_definitions(-DFFMPEG_PLUGIN)
756         include_directories(${INCLUDE} ${FFMPEG_INCLUDE_DIRS})
757         add_library(audffmpeg SHARED ${FFMPEG_SRC} ${FFMPEG_HDR} ${HDR})
758         target_link_libraries(audffmpeg audaspace ${FFMPEG_LIBRARIES})
759         set_target_properties(audffmpeg PROPERTIES SOVERSION ${AUDASPACE_VERSION})
760         install(TARGETS audffmpeg DESTINATION ${DEFAULT_PLUGIN_PATH})
761 endif()
762
763 if(WITH_JACK AND PLUGIN_JACK)
764         add_definitions(-DJACK_PLUGIN)
765         include_directories(${INCLUDE} ${JACK_INCLUDE_DIRS})
766         add_library(audjack SHARED ${JACK_SRC} ${JACK_HDR} ${HDR})
767         if(DYNLOAD_JACK)
768                 target_link_libraries(audjack audaspace)
769         else()
770                 target_link_libraries(audjack audaspace ${JACK_LIBRARIES})
771         endif()
772         set_target_properties(audjack PROPERTIES SOVERSION ${AUDASPACE_VERSION})
773         install(TARGETS audjack DESTINATION ${DEFAULT_PLUGIN_PATH})
774 endif()
775
776 if(WITH_LIBSNDFILE AND PLUGIN_LIBSNDFILE)
777         add_definitions(-DLIBSNDFILE_PLUGIN)
778         include_directories(${INCLUDE} ${LIBSNDFILE_INCLUDE_DIRS})
779         add_library(audlibsndfile SHARED ${LIBSNDFILE_SRC} ${LIBSNDFILE_HDR} ${HDR})
780         set_target_properties(audlibsndfile PROPERTIES SOVERSION ${AUDASPACE_VERSION})
781         target_link_libraries(audlibsndfile audaspace ${LIBSNDFILE_LIBRARIES})
782         install(TARGETS audlibsndfile DESTINATION ${DEFAULT_PLUGIN_PATH})
783 endif()
784
785 if(WITH_OPENAL AND PLUGIN_OPENAL)
786         add_definitions(-DOPENAL_PLUGIN)
787         include_directories(${INCLUDE} ${OPENAL_INCLUDE_DIR})
788         add_library(audopenal SHARED ${OPENAL_SRC} ${OPENAL_HDR} ${HDR})
789         set_target_properties(audopenal PROPERTIES SOVERSION ${AUDASPACE_VERSION})
790         target_link_libraries(audopenal audaspace ${OPENAL_LIBRARY})
791         install(TARGETS audopenal DESTINATION ${DEFAULT_PLUGIN_PATH})
792 endif()
793
794 if(WITH_SDL AND PLUGIN_SDL)
795         add_definitions(-DSDL_PLUGIN)
796         include_directories(${INCLUDE} ${SDL_INCLUDE_DIR})
797         add_library(audsdl SHARED ${SDL_SRC} ${SDL_HDR} ${HDR})
798         set_target_properties(audsdl PROPERTIES SOVERSION ${AUDASPACE_VERSION})
799         target_link_libraries(audsdl audaspace ${SDL_LIBRARY})
800         install(TARGETS audsdl DESTINATION ${DEFAULT_PLUGIN_PATH})
801 endif()
802
803 # dlls
804
805 if(WIN32)
806         if(DLLS)
807                 install(FILES ${DLLS} DESTINATION ${BIN_DESTINATION})
808         endif()
809 endif()
810
811 # demos
812
813 if(BUILD_DEMOS)
814         include_directories(${INCLUDE})
815
816         set(DEMOS audaplay audaconvert audaremap signalgen randsounds dynamicmusic playbackmanager)
817
818         add_executable(audaplay demos/audaplay.cpp)
819         target_link_libraries(audaplay audaspace)
820
821         add_executable(audaconvert demos/audaconvert.cpp)
822         target_link_libraries(audaconvert audaspace)
823
824         add_executable(audaremap demos/audaremap.cpp)
825         target_link_libraries(audaremap audaspace)
826
827         add_executable(signalgen demos/signalgen.cpp)
828         target_link_libraries(signalgen audaspace)
829
830         add_executable(randsounds demos/randsounds.cpp)
831         target_link_libraries(randsounds audaspace)
832
833         add_executable(dynamicmusic demos/dynamicmusic.cpp)
834         target_link_libraries(dynamicmusic audaspace)
835
836         add_executable(playbackmanager demos/playbackmanager.cpp)
837         target_link_libraries(playbackmanager audaspace)
838
839         if(WITH_FFTW)
840                 list(APPEND DEMOS convolution binaural)
841
842                 add_executable(convolution demos/convolution.cpp)
843                 target_link_libraries(convolution audaspace)
844
845                 add_executable(binaural demos/binaural.cpp)
846                 target_link_libraries(binaural audaspace)
847         endif()
848
849         if(WITH_OPENAL)
850                 list(APPEND DEMOS openaldevices)
851
852                 add_executable(openaldevices demos/openaldevices.cpp)
853                 if(PLUGIN_OPENAL)
854                         target_link_libraries(openaldevices audaspace audopenal)
855                 else()
856                         target_link_libraries(openaldevices audaspace)
857                 endif()
858         endif()
859
860         install(TARGETS ${DEMOS}
861                 RUNTIME DESTINATION ${BIN_DESTINATION}
862                 LIBRARY DESTINATION ${LIB_DESTINATION}
863                 ARCHIVE DESTINATION ${LIB_DESTINATION}
864         )
865 endif()
866
867 # bindings
868
869 if(WITH_C)
870         if(SEPARATE_C)
871                 add_library(audaspace-c ${LIBRARY_TYPE} ${C_SRC} ${C_HDR})
872                 target_link_libraries(audaspace-c audaspace)
873                 set_target_properties(audaspace-c PROPERTIES SOVERSION ${AUDASPACE_VERSION})
874                 install(TARGETS audaspace-c
875                         RUNTIME DESTINATION ${BIN_DESTINATION}
876                         LIBRARY DESTINATION ${LIB_DESTINATION}
877                         ARCHIVE DESTINATION ${LIB_DESTINATION}
878                 )
879         endif()
880
881         if(AUDASPACE_STANDALONE)
882                 install(FILES ${C_HDR} DESTINATION include/audaspace)
883         endif()
884 endif()
885
886 if(WITH_PYTHON)
887         set(PYTHON_SRC
888                 bindings/python/PyAPI.cpp
889                 bindings/python/PyDevice.cpp
890                 bindings/python/PyDynamicMusic.cpp
891                 bindings/python/PyHandle.cpp
892                 bindings/python/PyPlaybackManager.cpp
893                 bindings/python/PySequence.cpp
894                 bindings/python/PySequenceEntry.cpp
895                 bindings/python/PySound.cpp
896                 bindings/python/PySource.cpp
897                 bindings/python/PyThreadPool.cpp
898         )
899         set(PYTHON_HDR
900                 bindings/python/PyAPI.h
901                 bindings/python/PyDevice.h
902                 bindings/python/PyDynamicMusic.h
903                 bindings/python/PyHandle.h
904                 bindings/python/PyPlaybackManager.h
905                 bindings/python/PySequence.h
906                 bindings/python/PySequenceEntry.h
907                 bindings/python/PySound.h
908                 bindings/python/PySource.h
909                 bindings/python/PyThreadPool.h
910         )
911
912         if(WITH_FFTW)
913                 list(APPEND PYTHON_SRC
914                         bindings/python/PyHRTF.cpp
915                         bindings/python/PyImpulseResponse.cpp
916                         )
917                 list(APPEND PYTHON_HDR
918                         bindings/python/PyHRTF.h
919                         bindings/python/PyImpulseResponse.h
920                         )
921         endif()
922
923         add_library(audaspace-py ${LIBRARY_TYPE} ${PYTHON_SRC} ${PYTHON_HDR})
924         target_link_libraries(audaspace-py audaspace ${PYTHON_LIBRARIES})
925         set_target_properties(audaspace-py PROPERTIES SOVERSION ${AUDASPACE_VERSION})
926
927         if(AUDASPACE_STANDALONE)
928                 install(TARGETS audaspace-py
929                         RUNTIME DESTINATION ${BIN_DESTINATION}
930                         LIBRARY DESTINATION ${LIB_DESTINATION}
931                         ARCHIVE DESTINATION ${LIB_DESTINATION}
932                 )
933
934                 install(FILES ${PYTHON_HDR} DESTINATION include/audaspace/python)
935         endif()
936
937         if(WITH_PYTHON_MODULE)
938                 set(PYTHON_SOURCE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bindings/python)
939                 configure_file(${PYTHON_SOURCE_DIRECTORY}/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup.py ESCAPE_QUOTES @ONLY)
940
941                 if(APPLE)
942                         add_custom_command(OUTPUT build COMMAND MACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} ${PYTHON_EXECUTABLE} setup.py build DEPENDS ${PYTHON_SRC} ${PYTHON_HDR})
943                 elseif(WIN32)
944                         set(ENV{VS100COMNTOOLS} $ENV{VS120COMNTOOLS})
945                         add_custom_command(OUTPUT build COMMAND ${PYTHON_EXECUTABLE} setup.py build DEPENDS ${PYTHON_SRC} ${PYTHON_HDR})
946                 else()
947                         add_custom_command(OUTPUT build COMMAND ${PYTHON_EXECUTABLE} setup.py build DEPENDS ${PYTHON_SRC} ${PYTHON_HDR})
948                 endif()
949                 add_custom_target(pythonmodule ALL DEPENDS build SOURCES ${PYTHON_SOURCE_DIRECTORY}/setup.py.in ${PYTHON_SRC} ${PYTHON_HDR})
950                 add_dependencies(pythonmodule audaspace)
951
952                 install(CODE "EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} setup.py install --root=\$ENV{DESTDIR} --prefix=${CMAKE_INSTALL_PREFIX})")
953         endif()
954 endif()
955
956 # docs
957
958 if(WITH_DOCS)
959         find_package(Doxygen ${PACKAGE_OPTION})
960
961         if(DOXYGEN_FOUND AND DOXYGEN_DOT_FOUND)
962                 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
963
964                 add_custom_target(audaspace_doc ALL ${DOXYGEN_EXECUTABLE} Doxyfile COMMENT "Building C++ HTML documentation with Doxygen.")
965         else()
966                 set(WITH_DOCS FALSE CACHE BOOL "Build C++ HTML Documentation with Doxygen" FORCE)
967                 message(WARNING "Doxygen (and/or dot) not found, documentation will not be built.")
968         endif()
969 endif()
970
971 if(WITH_BINDING_DOCS)
972         find_package(Sphinx ${PACKAGE_OPTION})
973
974         if(SPHINX_FOUND)
975                 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/bindings/doc/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/conf.py @ONLY)
976
977                 add_custom_target(bindings_doc ALL COMMAND ${PYTHON_EXECUTABLE} setup.py --build-docs ${SPHINX_EXECUTABLE} -q -b html -c "${CMAKE_CURRENT_BINARY_DIR}" -d "${CMAKE_CURRENT_BINARY_DIR}/_doctrees" "${CMAKE_CURRENT_SOURCE_DIR}/bindings/doc" "${CMAKE_CURRENT_BINARY_DIR}/doc/bindings" DEPENDS pythonmodule COMMENT "Building C/Python HTML documentation with Sphinx.")
978         else()
979                 set(WITH_BINDING_DOCS FALSE CACHE BOOL "Build C/Python HTML Documentation with Sphinx" FORCE)
980                 message(WARNING "Sphinx not found, binding documentation will not be built.")
981         endif()
982 endif()
983
984 if(WITH_DOCS OR WITH_BINDING_DOCS)
985         install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/ DESTINATION ${DOCUMENTATION_INSTALL_PATH})
986 endif()