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)
17 find_package(OpenAL REQUIRED)
19 option(ALURE_STATIC_GCCRT "Static-link libgcc and libstdc++ runtimes" OFF)
22 check_cxx_compiler_flag(-std=c++11 HAVE_STD_CXX11)
24 set(CXX_FLAGS -std=c++11 ${CXX_FLAGS})
27 check_cxx_compiler_flag(-Wall HAVE_WALL_SWITCH)
29 set(CXX_FLAGS ${CXX_FLAGS} -Wall)
31 check_cxx_compiler_flag(-Wextra HAVE_WEXTRA_SWITCH)
32 if(HAVE_WEXTRA_SWITCH)
33 set(CXX_FLAGS ${CXX_FLAGS} -Wextra)
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)
40 check_cxx_compiler_flag(/GR- HAVE_GRX_SWITCH)
42 set(CXX_FLAGS ${CXX_FLAGS} /GR-)
47 set(VISIBILITY_FLAGS )
49 set(EXPORT_DECL "__declspec(dllexport)")
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\")))")
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)
68 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
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(
80 std::vector<int> test;
83 HAVE_STATIC_GCCRT_SWITCHES
85 if(HAVE_STATIC_GCCRT_SWITCHES)
86 set(LINKER_OPTS ${LINKER_OPTS} -static-libgcc -static-libstdc++)
88 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
89 unset(OLD_REQUIRED_LIBRARIES)
93 set(alure_srcs src/devicemanager.cpp
101 src/decoders/wave.cpp
103 set(alure_libs ${OPENAL_LIBRARY})
108 set(decoder_incls ${decoder_incls} ${OGG_INCLUDE_DIRS})
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)
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)
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)
132 set(alure_libs ${alure_libs} ${OGG_LIBRARIES})
135 find_package(SndFile)
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)
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)
153 "${alure_SOURCE_DIR}/config.h.in"
154 "${alure_BINARY_DIR}/config.h")
157 add_library(alure2 SHARED ${alure_srcs})
159 target_compile_definitions(alure2 PRIVATE ALURE_API=${EXPORT_DECL})
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}
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}
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)
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})
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})
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})