Update alure2.h comments
[alure.git] / CMakeLists.txt
blobf1a59f8980b16c773a3bd83b137e5693619d1ef0
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 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 set(LINKER_OPTS )
47 if(ALURE_STATIC_GCCRT)
48     set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
49     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc -static-libstdc++)
50     check_cxx_source_compiles(
51 "#include <vector>
52 int main()
54     std::vector<int> test;
55     return test.size();
57         HAVE_STATIC_GCCRT_SWITCHES
58     )
59     if(HAVE_STATIC_GCCRT_SWITCHES)
60         set(LINKER_OPTS -static-libgcc -static-libstdc++)
61     endif()
62     set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
63     unset(OLD_REQUIRED_LIBRARIES)
64 endif()
67 set(alure_srcs src/devicemanager.cpp
68                src/device.cpp
69                src/context.cpp
70                src/buffer.cpp
71                src/source.cpp
72                src/sourcegroup.cpp
73                src/auxeffectslot.cpp
74                src/effect.cpp
75                src/ringbuf.cpp
76                src/decoders/wave.cpp
78 set(alure_libs ${OPENAL_LIBRARY})
79 set(decoder_incls )
81 find_package(Ogg)
82 if(OGG_FOUND)
83     set(decoder_incls ${decoder_incls} ${OGG_INCLUDE_DIRS})
84     find_package(Vorbis)
85     if(VORBIS_FOUND)
86         set(decoder_incls ${decoder_incls} ${VORBIS_INCLUDE_DIRS})
87         set(alure_libs ${alure_libs} ${VORBIS_LIBRARIES})
88         set(alure_srcs ${alure_srcs} src/decoders/vorbisfile.cpp)
89         set(HAVE_VORBISFILE 1)
90     endif()
92     find_package(FLAC)
93     if(FLAC_FOUND)
94         set(decoder_incls ${decoder_incls} ${FLAC_INCLUDE_DIRS})
95         set(alure_libs ${alure_libs} ${FLAC_LIBRARIES})
96         set(alure_srcs ${alure_srcs} src/decoders/flac.cpp)
97         set(HAVE_LIBFLAC 1)
98     endif()
100     find_package(Opus)
101     if(OPUS_FOUND)
102         set(decoder_incls ${decoder_incls} ${OPUS_INCLUDE_DIRS})
103         set(alure_libs ${alure_libs} ${OPUS_LIBRARIES})
104         set(alure_srcs ${alure_srcs} src/decoders/opusfile.cpp)
105         set(HAVE_OPUSFILE 1)
106     endif()
107     set(alure_libs ${alure_libs} ${OGG_LIBRARIES})
108 endif()
110 find_package(SndFile)
111 if(SNDFILE_FOUND)
112     set(decoder_incls ${decoder_incls} ${SNDFILE_INCLUDE_DIRS})
113     set(alure_libs ${alure_libs} ${SNDFILE_LIBRARIES})
114     set(alure_srcs ${alure_srcs} src/decoders/sndfile.cpp)
115     set(HAVE_LIBSNDFILE 1)
116 endif()
118 find_package(MPG123)
119 if(MPG123_FOUND)
120     set(decoder_incls ${decoder_incls} ${MPG123_INCLUDE_DIRS})
121     set(alure_libs ${alure_libs} ${MPG123_LIBRARIES})
122     set(alure_srcs ${alure_srcs} src/decoders/mpg123.cpp)
123     set(HAVE_MPG123 1)
124 endif()
127 CONFIGURE_FILE(
128     "${alure_SOURCE_DIR}/config.h.in"
129     "${alure_BINARY_DIR}/config.h")
132 add_library(alure2 SHARED ${alure_srcs})
133 target_compile_definitions(alure2 PRIVATE ALURE_BUILD_DLL)
134 target_include_directories(alure2
135     PUBLIC ${alure_SOURCE_DIR}/include/AL ${OPENAL_INCLUDE_DIR}
136     PRIVATE ${alure_SOURCE_DIR}/include ${alure_SOURCE_DIR}/src ${alure_BINARY_DIR}
137             ${decoder_incls}
139 target_compile_options(alure2 PRIVATE ${CXX_FLAGS})
140 target_link_libraries(alure2 PUBLIC ${alure_libs} PRIVATE ${LINKER_OPTS})
142 add_library(alure2_s STATIC ${alure_srcs})
143 target_compile_definitions(alure2_s PUBLIC ALURE_STATIC_LIB PRIVATE ALURE_BUILD_STATIC)
144 target_include_directories(alure2_s
145     PUBLIC ${alure_SOURCE_DIR}/include/AL ${OPENAL_INCLUDE_DIR}
146     PRIVATE ${alure_SOURCE_DIR}/include ${alure_SOURCE_DIR}/src ${alure_BINARY_DIR}
147             ${decoder_incls}
149 target_compile_options(alure2_s PRIVATE ${CXX_FLAGS})
150 target_link_libraries(alure2_s PUBLIC ${alure_libs})
153 add_executable(alure-enum examples/alure-enum.cpp)
154 target_compile_options(alure-enum PRIVATE ${CXX_FLAGS})
155 target_link_libraries(alure-enum PRIVATE alure2)
157 add_executable(alure-play examples/alure-play.cpp)
158 target_compile_options(alure-play PRIVATE ${CXX_FLAGS})
159 target_link_libraries(alure-play PRIVATE alure2)
161 add_executable(alure-stream examples/alure-stream.cpp)
162 target_compile_options(alure-stream PRIVATE ${CXX_FLAGS})
163 target_link_libraries(alure-stream PRIVATE alure2)
165 add_executable(alure-reverb examples/alure-reverb.cpp)
166 target_compile_options(alure-reverb PRIVATE ${CXX_FLAGS})
167 target_link_libraries(alure-reverb PRIVATE alure2)
169 add_executable(alure-hrtf examples/alure-hrtf.cpp)
170 target_compile_options(alure-hrtf PRIVATE ${CXX_FLAGS})
171 target_link_libraries(alure-hrtf PRIVATE alure2)
173 find_package(PhysFS)
174 if(PHYSFS_FOUND)
175     add_executable(alure-physfs examples/alure-physfs.cpp)
176     target_include_directories(alure-physfs PRIVATE ${PHYSFS_INCLUDE_DIR})
177     target_compile_options(alure-physfs PRIVATE ${CXX_FLAGS})
178     target_link_libraries(alure-physfs PRIVATE alure2 ${PHYSFS_LIBRARY} ${LINKER_OPTS})
179 endif()
181 find_package(DUMB)
182 if(DUMB_FOUND)
183     add_executable(alure-dumb examples/alure-dumb.cpp)
184     target_include_directories(alure-dumb PRIVATE ${DUMB_INCLUDE_DIRS})
185     target_compile_options(alure-dumb PRIVATE ${CXX_FLAGS})
186     target_link_libraries(alure-dumb PRIVATE alure2 ${DUMB_LIBRARIES} ${LINKER_OPTS})
187 endif()
190 if(NOT DEFINED LIB_SUFFIX)
191     set(LIB_SUFFIX "")
192 endif()
194 install(TARGETS alure2 alure2_s
195         RUNTIME DESTINATION bin
196         LIBRARY DESTINATION "lib${LIB_SUFFIX}"
197         ARCHIVE DESTINATION "lib${LIB_SUFFIX}"