1 cmake_minimum_required(VERSION 3.0)
4 IF(COMMAND CMAKE_POLICY)
5 CMAKE_POLICY(SET CMP0003 NEW)
6 CMAKE_POLICY(SET CMP0005 NEW)
8 CMAKE_POLICY(SET CMP0042 NEW)
10 ENDIF(COMMAND CMAKE_POLICY)
12 set(CMAKE_MODULE_PATH "${alure_SOURCE_DIR}/cmake")
14 include(CheckCXXCompilerFlag)
15 include(CheckCXXSourceCompiles)
16 include(GNUInstallDirs)
18 find_package(OpenAL REQUIRED)
22 set(CMAKE_CXX_STANDARD 14)
23 set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
27 option(ALURE_DISABLE_RTTI "Disable run-time type information" OFF)
29 if(ALURE_DISABLE_RTTI)
30 check_cxx_compiler_flag(/GR- HAVE_GRX_SWITCH)
32 set(CXX_FLAGS ${CXX_FLAGS} /GR-)
36 check_cxx_compiler_flag(-Wall HAVE_WALL_SWITCH)
38 set(CXX_FLAGS ${CXX_FLAGS} -Wall)
40 check_cxx_compiler_flag(-Wextra HAVE_WEXTRA_SWITCH)
41 if(HAVE_WEXTRA_SWITCH)
42 set(CXX_FLAGS ${CXX_FLAGS} -Wextra)
45 if(ALURE_DISABLE_RTTI)
46 check_cxx_compiler_flag(-fno-rtti HAVE_NO_RTTI_SWITCH)
47 if(HAVE_NO_RTTI_SWITCH)
48 set(CXX_FLAGS ${CXX_FLAGS} -fno-rtti)
54 set(VISIBILITY_FLAGS )
56 set(EXPORT_DECL "__declspec(dllexport)")
58 set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
59 # Yes GCC, really don't accept visibility modes you don't support
60 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
62 check_cxx_source_compiles("int foo() __attribute__((visibility(\"default\")));
63 int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
64 if(HAVE_GCC_DEFAULT_VISIBILITY)
65 set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
68 if(HAVE_GCC_DEFAULT_VISIBILITY)
69 check_cxx_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
70 if(HAVE_VISIBILITY_HIDDEN_SWITCH)
71 set(VISIBILITY_FLAGS ${VISIBILITY_FLAGS} -fvisibility=hidden)
75 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
81 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
82 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
83 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")
85 option(ALURE_STATIC_GCCRT "Static-link libgcc and libstdc++ runtimes" OFF)
86 if(ALURE_STATIC_GCCRT)
87 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
88 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc -static-libstdc++)
89 check_cxx_source_compiles(
93 std::vector<int> test;
96 HAVE_STATIC_GCCRT_SWITCHES
98 if(HAVE_STATIC_GCCRT_SWITCHES)
99 set(LINKER_OPTS ${LINKER_OPTS} -static-libgcc -static-libstdc++)
101 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
102 unset(OLD_REQUIRED_LIBRARIES)
107 set(alure_srcs src/devicemanager.cpp
113 src/auxeffectslot.cpp
116 set(alure_libs ${OPENAL_LIBRARY})
120 unset(HAVE_VORBISFILE)
123 unset(HAVE_LIBSNDFILE)
126 option(ALURE_INSTALL "Install library and import module" ON)
127 option(ALURE_BUILD_SHARED "Build shared library" ON)
128 option(ALURE_BUILD_STATIC "Build static library" ON)
130 if(NOT ALURE_BUILD_SHARED AND NOT ALURE_BUILD_STATIC)
131 message(FATAL_ERROR "Neither shared or static libraries are enabled!")
134 option(ALURE_ENABLE_WAVE "Enables the built-in wave file decoder" ON)
135 option(ALURE_ENABLE_VORBIS "Enables the built-in libvorbisfile decoder" ON)
136 option(ALURE_ENABLE_FLAC "Enables the built-in FLAC decoder" ON)
137 option(ALURE_ENABLE_OPUS "Enables the built-in libopusfile decoder" ON)
138 option(ALURE_ENABLE_SNDFILE "Enables the built-in libsndfile decoder" ON)
139 option(ALURE_ENABLE_MINIMP3 "Enables the built-in MINIMP3 decoder" ON)
141 if(ALURE_ENABLE_WAVE)
142 set(alure_srcs ${alure_srcs} src/decoders/wave.cpp)
148 set(decoder_incls ${decoder_incls} ${OGG_INCLUDE_DIRS})
150 if(VORBIS_FOUND AND ALURE_ENABLE_VORBIS)
151 set(decoder_incls ${decoder_incls} ${VORBIS_INCLUDE_DIRS})
152 set(alure_libs ${alure_libs} ${VORBIS_LIBRARIES})
153 set(alure_srcs ${alure_srcs} src/decoders/vorbisfile.cpp)
154 set(HAVE_VORBISFILE 1)
158 if(OPUS_FOUND AND ALURE_ENABLE_OPUS)
159 set(decoder_incls ${decoder_incls} ${OPUS_INCLUDE_DIRS})
160 set(alure_libs ${alure_libs} ${OPUS_LIBRARIES})
161 set(alure_srcs ${alure_srcs} src/decoders/opusfile.cpp)
164 set(alure_libs ${alure_libs} ${OGG_LIBRARIES})
167 if(ALURE_ENABLE_FLAC)
168 set(alure_srcs ${alure_srcs} src/decoders/dr_flac.h src/decoders/flac.cpp)
172 find_package(SndFile)
173 if(SNDFILE_FOUND AND ALURE_ENABLE_SNDFILE)
174 set(decoder_incls ${decoder_incls} ${SNDFILE_INCLUDE_DIRS})
175 set(alure_libs ${alure_libs} ${SNDFILE_LIBRARIES})
176 set(alure_srcs ${alure_srcs} src/decoders/sndfile.cpp)
177 set(HAVE_LIBSNDFILE 1)
180 if(ALURE_ENABLE_MINIMP3)
181 set(alure_srcs ${alure_srcs} src/decoders/minimp3.h src/decoders/mp3.hpp src/decoders/mp3.cpp)
187 "${alure_SOURCE_DIR}/config.h.in"
188 "${alure_BINARY_DIR}/config.h")
194 if(ALURE_BUILD_SHARED)
195 add_library(alure2 SHARED ${alure_srcs})
197 target_compile_definitions(alure2 PRIVATE ALURE_API=${EXPORT_DECL} ALURE_TEMPLATE=template
200 target_include_directories(alure2
201 PUBLIC $<BUILD_INTERFACE:${alure_SOURCE_DIR}/include/AL> ${OPENAL_INCLUDE_DIR}
202 PRIVATE ${alure_SOURCE_DIR}/include ${alure_SOURCE_DIR}/src ${alure_BINARY_DIR}
205 target_compile_options(alure2 PRIVATE ${CXX_FLAGS} ${VISIBILITY_FLAGS})
206 target_link_libraries(alure2 PUBLIC ${alure_libs} PRIVATE Threads::Threads ${LINKER_OPTS})
208 set(TARGET_NAMES ${TARGET_NAMES} alure2)
210 set(MAIN_TARGET alure2)
214 if(ALURE_BUILD_STATIC)
215 add_library(alure2_s STATIC ${alure_srcs})
216 target_compile_definitions(alure2_s PUBLIC ALURE_STATIC_LIB PRIVATE NOMINMAX)
217 target_include_directories(alure2_s
218 PUBLIC $<BUILD_INTERFACE:${alure_SOURCE_DIR}/include/AL> ${OPENAL_INCLUDE_DIR}
219 PRIVATE ${alure_SOURCE_DIR}/include ${alure_SOURCE_DIR}/src ${alure_BINARY_DIR}
222 target_compile_options(alure2_s PRIVATE ${CXX_FLAGS} ${VISIBILITY_FLAGS})
223 target_link_libraries(alure2_s PUBLIC ${alure_libs} PRIVATE Threads::Threads)
225 set(TARGET_NAMES ${TARGET_NAMES} alure2_s)
227 set(MAIN_TARGET alure2_s)
232 TARGETS ${TARGET_NAMES}
234 FILE Alure2Config.cmake
237 install(TARGETS ${TARGET_NAMES} EXPORT alure2
238 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
239 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
240 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
241 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL
245 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Alure2
247 FILE Alure2Config.cmake
251 include/AL/alure2-aliases.h
252 include/AL/alure2-typeviews.h
253 include/AL/alure2-alext.h
255 include/AL/efx-presets.h
256 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
261 option(ALURE_BUILD_EXAMPLES "Build example programs" ON)
262 if(ALURE_BUILD_EXAMPLES)
263 add_executable(alure-enum examples/alure-enum.cpp)
264 target_compile_options(alure-enum PRIVATE ${CXX_FLAGS})
265 target_link_libraries(alure-enum PRIVATE ${MAIN_TARGET} ${LINKER_OPTS})
267 add_executable(alure-play examples/alure-play.cpp)
268 target_compile_options(alure-play PRIVATE ${CXX_FLAGS})
269 target_link_libraries(alure-play PRIVATE ${MAIN_TARGET} ${LINKER_OPTS})
271 add_executable(alure-play3d examples/alure-play3d.cpp)
272 target_compile_options(alure-play3d PRIVATE ${CXX_FLAGS})
273 target_link_libraries(alure-play3d PRIVATE ${MAIN_TARGET} ${LINKER_OPTS})
275 add_executable(alure-stream examples/alure-stream.cpp)
276 target_compile_options(alure-stream PRIVATE ${CXX_FLAGS})
277 target_link_libraries(alure-stream PRIVATE ${MAIN_TARGET} ${LINKER_OPTS})
279 add_executable(alure-reverb examples/alure-reverb.cpp)
280 target_compile_options(alure-reverb PRIVATE ${CXX_FLAGS})
281 target_link_libraries(alure-reverb PRIVATE ${MAIN_TARGET} ${LINKER_OPTS})
283 add_executable(alure-hrtf examples/alure-hrtf.cpp)
284 target_compile_options(alure-hrtf PRIVATE ${CXX_FLAGS})
285 target_link_libraries(alure-hrtf PRIVATE ${MAIN_TARGET} ${LINKER_OPTS})
289 add_executable(alure-physfs examples/alure-physfs.cpp)
290 target_include_directories(alure-physfs PRIVATE ${PHYSFS_INCLUDE_DIR})
291 target_compile_options(alure-physfs PRIVATE ${CXX_FLAGS})
292 target_link_libraries(alure-physfs PRIVATE ${MAIN_TARGET} ${PHYSFS_LIBRARY} ${LINKER_OPTS})
297 add_executable(alure-dumb examples/alure-dumb.cpp)
298 target_include_directories(alure-dumb PRIVATE ${DUMB_INCLUDE_DIRS})
299 target_compile_options(alure-dumb PRIVATE ${CXX_FLAGS})
300 target_link_libraries(alure-dumb PRIVATE ${MAIN_TARGET} ${DUMB_LIBRARIES} ${LINKER_OPTS})