Store the channel config with mpg123
[alure.git] / CMakeLists.txt
blobff4985c86b05a7a196a545df434634f1716b4b86
1 cmake_minimum_required(VERSION 3.0)
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 option(ALURE_STATIC_GCCRT "Static-link libgcc and libstdc++ runtimes" OFF)
21 set(CXX_FLAGS )
22 check_cxx_compiler_flag(-std=c++11 HAVE_STD_CXX11)
23 if(HAVE_STD_CXX11)
24     set(CXX_FLAGS -std=c++11 ${CXX_FLAGS})
25 endif()
27 check_cxx_compiler_flag(-Wall HAVE_WALL_SWITCH)
28 if(HAVE_WALL_SWITCH)
29     set(CXX_FLAGS ${CXX_FLAGS} -Wall)
30 endif()
31 check_cxx_compiler_flag(-Wextra HAVE_WEXTRA_SWITCH)
32 if(HAVE_WEXTRA_SWITCH)
33     set(CXX_FLAGS ${CXX_FLAGS} -Wextra)
34 endif()
36 check_cxx_compiler_flag(-fno-rtti HAVE_NO_RTTI_SWITCH)
37 if(HAVE_NO_RTTI_SWITCH)
38     set(CXX_FLAGS ${CXX_FLAGS} -fno-rtti)
39 else()
40     check_cxx_compiler_flag(/GR- HAVE_GRX_SWITCH)
41     if(HAVE_GRX_SWITCH)
42         set(CXX_FLAGS ${CXX_FLAGS} /GR-)
43     endif()
44 endif()
46 unset(EXPORT_DECL)
47 set(VISIBILITY_FLAGS )
48 if(WIN32)
49     set(EXPORT_DECL "__declspec(dllexport)")
50 else()
51     set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
52     # Yes GCC, really don't accept visibility modes you don't support
53     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
55     check_cxx_source_compiles("int foo() __attribute__((visibility(\"default\")));
56                                 int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
57     if(HAVE_GCC_DEFAULT_VISIBILITY)
58         set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
59     endif()
61     if(HAVE_GCC_DEFAULT_VISIBILITY)
62         check_cxx_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
63         if(HAVE_VISIBILITY_HIDDEN_SWITCH)
64             set(VISIBILITY_FLAGS ${VISIBILITY_FLAGS} -fvisibility=hidden)
65         endif()
66     endif()
68     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
69 endif()
72 set(LINKER_OPTS )
73 if(ALURE_STATIC_GCCRT)
74     set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
75     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc -static-libstdc++)
76     check_cxx_source_compiles(
77 "#include <vector>
78 int main()
80     std::vector<int> test;
81     return test.size();
83         HAVE_STATIC_GCCRT_SWITCHES
84     )
85     if(HAVE_STATIC_GCCRT_SWITCHES)
86         set(LINKER_OPTS ${LINKER_OPTS} -static-libgcc -static-libstdc++)
87     endif()
88     set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
89     unset(OLD_REQUIRED_LIBRARIES)
90 endif()
93 set(alure_srcs src/devicemanager.cpp
94                src/device.cpp
95                src/context.cpp
96                src/buffer.cpp
97                src/source.cpp
98                src/sourcegroup.cpp
99                src/auxeffectslot.cpp
100                src/effect.cpp
101                src/decoders/wave.cpp
103 set(alure_libs ${OPENAL_LIBRARY})
104 set(decoder_incls )
106 find_package(Ogg)
107 if(OGG_FOUND)
108     set(decoder_incls ${decoder_incls} ${OGG_INCLUDE_DIRS})
109     find_package(Vorbis)
110     if(VORBIS_FOUND)
111         set(decoder_incls ${decoder_incls} ${VORBIS_INCLUDE_DIRS})
112         set(alure_libs ${alure_libs} ${VORBIS_LIBRARIES})
113         set(alure_srcs ${alure_srcs} src/decoders/vorbisfile.cpp)
114         set(HAVE_VORBISFILE 1)
115     endif()
117     find_package(FLAC)
118     if(FLAC_FOUND)
119         set(decoder_incls ${decoder_incls} ${FLAC_INCLUDE_DIRS})
120         set(alure_libs ${alure_libs} ${FLAC_LIBRARIES})
121         set(alure_srcs ${alure_srcs} src/decoders/flac.cpp)
122         set(HAVE_LIBFLAC 1)
123     endif()
125     find_package(Opus)
126     if(OPUS_FOUND)
127         set(decoder_incls ${decoder_incls} ${OPUS_INCLUDE_DIRS})
128         set(alure_libs ${alure_libs} ${OPUS_LIBRARIES})
129         set(alure_srcs ${alure_srcs} src/decoders/opusfile.cpp)
130         set(HAVE_OPUSFILE 1)
131     endif()
132     set(alure_libs ${alure_libs} ${OGG_LIBRARIES})
133 endif()
135 find_package(SndFile)
136 if(SNDFILE_FOUND)
137     set(decoder_incls ${decoder_incls} ${SNDFILE_INCLUDE_DIRS})
138     set(alure_libs ${alure_libs} ${SNDFILE_LIBRARIES})
139     set(alure_srcs ${alure_srcs} src/decoders/sndfile.cpp)
140     set(HAVE_LIBSNDFILE 1)
141 endif()
143 find_package(MPG123)
144 if(MPG123_FOUND)
145     set(decoder_incls ${decoder_incls} ${MPG123_INCLUDE_DIRS})
146     set(alure_libs ${alure_libs} ${MPG123_LIBRARIES})
147     set(alure_srcs ${alure_srcs} src/decoders/mpg123.cpp)
148     set(HAVE_MPG123 1)
149 endif()
152 CONFIGURE_FILE(
153     "${alure_SOURCE_DIR}/config.h.in"
154     "${alure_BINARY_DIR}/config.h")
157 add_library(alure2 SHARED ${alure_srcs})
158 if(EXPORT_DECL)
159     target_compile_definitions(alure2 PRIVATE ALURE_API=${EXPORT_DECL})
160 endif()
161 target_include_directories(alure2
162     PUBLIC ${alure_SOURCE_DIR}/include/AL ${OPENAL_INCLUDE_DIR}
163     PRIVATE ${alure_SOURCE_DIR}/include ${alure_SOURCE_DIR}/src ${alure_BINARY_DIR}
164             ${decoder_incls}
166 target_compile_options(alure2 PRIVATE ${CXX_FLAGS} ${VISIBILITY_FLAGS})
167 target_link_libraries(alure2 PUBLIC ${alure_libs} PRIVATE ${LINKER_OPTS})
169 add_library(alure2_s STATIC ${alure_srcs})
170 target_compile_definitions(alure2_s PUBLIC ALURE_STATIC_LIB)
171 target_include_directories(alure2_s
172     PUBLIC ${alure_SOURCE_DIR}/include/AL ${OPENAL_INCLUDE_DIR}
173     PRIVATE ${alure_SOURCE_DIR}/include ${alure_SOURCE_DIR}/src ${alure_BINARY_DIR}
174             ${decoder_incls}
176 target_compile_options(alure2_s PRIVATE ${CXX_FLAGS} ${VISIBILITY_FLAGS})
177 target_link_libraries(alure2_s PUBLIC ${alure_libs})
179 if(NOT DEFINED LIB_SUFFIX)
180     set(LIB_SUFFIX "")
181 endif()
183 install(TARGETS alure2 alure2_s
184         RUNTIME DESTINATION bin
185         LIBRARY DESTINATION "lib${LIB_SUFFIX}"
186         ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
190 option(ALURE_BUILD_EXAMPLES "Build example programs" ON)
191 if(ALURE_BUILD_EXAMPLES)
192     add_executable(alure-enum examples/alure-enum.cpp)
193     target_compile_options(alure-enum PRIVATE ${CXX_FLAGS})
194     target_link_libraries(alure-enum PRIVATE alure2 ${LINKER_OPTS})
196     add_executable(alure-play examples/alure-play.cpp)
197     target_compile_options(alure-play PRIVATE ${CXX_FLAGS})
198     target_link_libraries(alure-play PRIVATE alure2 ${LINKER_OPTS})
200     add_executable(alure-stream examples/alure-stream.cpp)
201     target_compile_options(alure-stream PRIVATE ${CXX_FLAGS})
202     target_link_libraries(alure-stream PRIVATE alure2 ${LINKER_OPTS})
204     add_executable(alure-reverb examples/alure-reverb.cpp)
205     target_compile_options(alure-reverb PRIVATE ${CXX_FLAGS})
206     target_link_libraries(alure-reverb PRIVATE alure2 ${LINKER_OPTS})
208     add_executable(alure-hrtf examples/alure-hrtf.cpp)
209     target_compile_options(alure-hrtf PRIVATE ${CXX_FLAGS})
210     target_link_libraries(alure-hrtf PRIVATE alure2 ${LINKER_OPTS})
212     find_package(PhysFS)
213     if(PHYSFS_FOUND)
214         add_executable(alure-physfs examples/alure-physfs.cpp)
215         target_include_directories(alure-physfs PRIVATE ${PHYSFS_INCLUDE_DIR})
216         target_compile_options(alure-physfs PRIVATE ${CXX_FLAGS})
217         target_link_libraries(alure-physfs PRIVATE alure2 ${PHYSFS_LIBRARY} ${LINKER_OPTS})
218     endif()
220     find_package(DUMB)
221     if(DUMB_FOUND)
222         add_executable(alure-dumb examples/alure-dumb.cpp)
223         target_include_directories(alure-dumb PRIVATE ${DUMB_INCLUDE_DIRS})
224         target_compile_options(alure-dumb PRIVATE ${CXX_FLAGS})
225         target_link_libraries(alure-dumb PRIVATE alure2 ${DUMB_LIBRARIES} ${LINKER_OPTS})
226     endif()
227 endif()