Handle the source latency as an explicit nanosecond type
[alure.git] / CMakeLists.txt
blobe1df98d3627c2d42293a587bd28878eefd9f3a13
1 cmake_minimum_required(VERSION 2.6)
2 project(alure)
4 IF(COMMAND CMAKE_POLICY)
5     CMAKE_POLICY(SET CMP0003 NEW)
6     CMAKE_POLICY(SET CMP0005 NEW)
7     IF(POLICY CMP0042)
8         CMAKE_POLICY(SET CMP0042 NEW)
9     ENDIF(POLICY CMP0042)
10 ENDIF(COMMAND CMAKE_POLICY)
12 set(CMAKE_MODULE_PATH "${alure_SOURCE_DIR}/cmake")
14 include(CheckCXXCompilerFlag)
15 include(CheckCXXSourceCompiles)
17 find_package(OpenAL REQUIRED)
19 include_directories(${alure_SOURCE_DIR}/include ${alure_SOURCE_DIR}/include/AL ${alure_SOURCE_DIR}/src ${alure_BINARY_DIR} ${OPENAL_INCLUDE_DIR})
21 option(ALURE_USE_RTTI  "Enable run-time type information"  OFF)
22 option(ALURE_STATIC_GCCRT "Static-link libgcc and libstdc++ runtimes" OFF)
24 check_cxx_compiler_flag(-std=c++11 HAVE_STD_CXX11)
25 if(HAVE_STD_CXX11)
26     set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
27 endif()
29 check_cxx_compiler_flag(-Wall HAVE_WALL_SWITCH)
30 if(HAVE_WALL_SWITCH)
31     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
32 endif()
33 check_cxx_compiler_flag(-Wextra HAVE_WEXTRA_SWITCH)
34 if(HAVE_WEXTRA_SWITCH)
35     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
36 endif()
38 if(NOT ALURE_USE_RTTI)
39     check_cxx_compiler_flag(-fno-rtti HAVE_NO_RTTI_SWITCH)
40     if(HAVE_NO_RTTI_SWITCH)
41         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
42     else()
43         check_cxx_compiler_flag(/GR- HAVE_GRX_SWITCH)
44         if(HAVE_GRX_SWITCH)
45             set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
46         endif()
47     endif()
48 endif()
50 set(LINKER_OPTS )
51 if(ALURE_STATIC_GCCRT)
52     set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
53     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc -static-libstdc++)
54     check_cxx_source_compiles(
55 "#include <vector>
56 int main()
58     std::vector<int> test;
59     return test.size();
61         HAVE_STATIC_GCCRT_SWITCHES
62     )
63     if(HAVE_STATIC_GCCRT_SWITCHES)
64         set(LINKER_OPTS -static-libgcc -static-libstdc++)
65     endif()
66     set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
67     unset(OLD_REQUIRED_LIBRARIES)
68 endif()
71 set(alure_srcs src/devicemanager.cpp
72                src/device.cpp
73                src/context.cpp
74                src/buffer.cpp
75                src/source.cpp
76                src/sourcegroup.cpp
77                src/auxeffectslot.cpp
78                src/effect.cpp
79                src/ringbuf.cpp
80                src/decoders/wave.cpp
82 set(alure_libs ${OPENAL_LIBRARY})
84 find_package(Ogg)
85 if(OGG_FOUND)
86     find_package(Vorbis)
87     if(VORBIS_FOUND)
88         include_directories(${OGG_INCLUDE_DIRS} ${VORBIS_INCLUDE_DIRS})
89         set(alure_libs ${alure_libs} ${VORBIS_LIBRARIES} ${OGG_LIBRARIES})
90         set(alure_srcs ${alure_srcs} src/decoders/vorbisfile.cpp)
91         set(HAVE_VORBISFILE 1)
92     endif()
94     find_package(FLAC)
95     if(FLAC_FOUND)
96         include_directories(${OGG_INCLUDE_DIRS} ${FLAC_INCLUDE_DIRS})
97         set(alure_libs ${alure_libs} ${FLAC_LIBRARIES} ${OGG_LIBRARIES})
98         set(alure_srcs ${alure_srcs} src/decoders/flac.cpp)
99         set(HAVE_LIBFLAC 1)
100     endif()
102     find_package(Opus)
103     if(OPUS_FOUND)
104         include_directories(${OGG_INCLUDE_DIRS} ${OPUS_INCLUDE_DIRS})
105         set(alure_libs ${alure_libs} ${OPUS_LIBRARIES} ${OGG_LIBRARIES})
106         set(alure_srcs ${alure_srcs} src/decoders/opusfile.cpp)
107         set(HAVE_OPUSFILE 1)
108     endif()
109 endif()
111 find_package(SndFile)
112 if(SNDFILE_FOUND)
113     include_directories(${SNDFILE_INCLUDE_DIRS})
114     set(alure_libs ${alure_libs} ${SNDFILE_LIBRARIES})
115     set(alure_srcs ${alure_srcs} src/decoders/sndfile.cpp)
116     set(HAVE_LIBSNDFILE 1)
117 endif()
119 find_package(MPG123)
120 if(MPG123_FOUND)
121     include_directories(${MPG123_INCLUDE_DIRS})
122     set(alure_libs ${alure_libs} ${MPG123_LIBRARIES})
123     set(alure_srcs ${alure_srcs} src/decoders/mpg123.cpp)
124     set(HAVE_MPG123 1)
125 endif()
128 CONFIGURE_FILE(
129     "${alure_SOURCE_DIR}/config.h.in"
130     "${alure_BINARY_DIR}/config.h")
133 add_library(alure2 SHARED ${alure_srcs})
134 target_link_libraries(alure2 ${alure_libs} ${LINKER_OPTS})
135 set_property(TARGET alure2 APPEND PROPERTY COMPILE_DEFINITIONS ALURE_BUILD_DLL)
137 add_library(alure2_s STATIC ${alure_srcs})
138 set_property(TARGET alure2_s APPEND PROPERTY COMPILE_DEFINITIONS ALURE_STATIC_LIB ALURE_BUILD_STATIC)
141 add_executable(alure-enum examples/alure-enum.cpp)
142 target_link_libraries(alure-enum alure2 ${LINKER_OPTS})
144 add_executable(alure-play examples/alure-play.cpp)
145 target_link_libraries(alure-play alure2 ${LINKER_OPTS})
147 add_executable(alure-stream examples/alure-stream.cpp)
148 target_link_libraries(alure-stream alure2 ${LINKER_OPTS})
150 add_executable(alure-reverb examples/alure-reverb.cpp)
151 target_link_libraries(alure-reverb alure2 ${LINKER_OPTS})
153 add_executable(alure-hrtf examples/alure-hrtf.cpp)
154 target_link_libraries(alure-hrtf alure2 ${LINKER_OPTS})
156 find_package(PhysFS)
157 if(PHYSFS_FOUND)
158     add_executable(alure-physfs examples/alure-physfs.cpp)
159     set_property(TARGET alure-physfs APPEND PROPERTY INCLUDE_DIRECTORIES "${PHYSFS_INCLUDE_DIR}")
160     target_link_libraries(alure-physfs alure2 "${PHYSFS_LIBRARY}" ${LINKER_OPTS})
161 endif()
163 find_package(DUMB)
164 if(DUMB_FOUND)
165     add_executable(alure-dumb examples/alure-dumb.cpp)
166     set_property(TARGET alure-dumb APPEND PROPERTY INCLUDE_DIRECTORIES "${DUMB_INCLUDE_DIRS}")
167     target_link_libraries(alure-dumb alure2 "${DUMB_LIBRARIES}" ${LINKER_OPTS})
168 endif()
171 if(NOT DEFINED LIB_SUFFIX)
172     set(LIB_SUFFIX "")
173 endif()
175 install(TARGETS alure2 alure2_s
176         RUNTIME DESTINATION bin
177         LIBRARY DESTINATION "lib${LIB_SUFFIX}"
178         ARCHIVE DESTINATION "lib${LIB_SUFFIX}"