🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1710 lines
58 KiB

  1. # CMake build file list for OpenAL
  2. cmake_minimum_required(VERSION 3.0.2)
  3. if(APPLE)
  4. # The workaround for try_compile failing with code signing
  5. # since cmake-3.18.2, not required
  6. set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
  7. ${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES}
  8. "CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED"
  9. "CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED")
  10. set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO)
  11. set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
  12. endif()
  13. if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
  14. # Fix compile failure with armv7 deployment target >= 11.0, xcode clang
  15. # will report:
  16. # error: invalid iOS deployment version '--target=armv7-apple-ios13.6',
  17. # iOS 10 is the maximum deployment target for 32-bit targets
  18. # If CMAKE_OSX_DEPLOYMENT_TARGET is not defined, cmake will choose latest
  19. # deployment target
  20. if("${CMAKE_OSX_ARCHITECTURES}" MATCHES ".*armv7.*")
  21. if(NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET
  22. OR NOT CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS "11.0")
  23. message(STATUS "Forcing iOS deployment target to 10.0 for armv7")
  24. set(CMAKE_OSX_DEPLOYMENT_TARGET "10.0" CACHE STRING "Minimum OS X deployment version"
  25. FORCE)
  26. endif()
  27. endif()
  28. endif()
  29. project(OpenAL)
  30. if(COMMAND CMAKE_POLICY)
  31. cmake_policy(SET CMP0003 NEW)
  32. cmake_policy(SET CMP0005 NEW)
  33. if(POLICY CMP0020)
  34. cmake_policy(SET CMP0020 NEW)
  35. endif(POLICY CMP0020)
  36. if(POLICY CMP0042)
  37. cmake_policy(SET CMP0042 NEW)
  38. endif(POLICY CMP0042)
  39. if(POLICY CMP0054)
  40. cmake_policy(SET CMP0054 NEW)
  41. endif(POLICY CMP0054)
  42. if(POLICY CMP0075)
  43. cmake_policy(SET CMP0075 NEW)
  44. endif(POLICY CMP0075)
  45. endif(COMMAND CMAKE_POLICY)
  46. if(NOT CMAKE_BUILD_TYPE)
  47. set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
  48. "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
  49. FORCE)
  50. endif()
  51. if(NOT CMAKE_DEBUG_POSTFIX)
  52. set(CMAKE_DEBUG_POSTFIX "" CACHE STRING
  53. "Library postfix for debug builds. Normally left blank."
  54. FORCE)
  55. endif()
  56. set(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
  57. include(CheckFunctionExists)
  58. include(CheckLibraryExists)
  59. include(CheckIncludeFile)
  60. include(CheckIncludeFiles)
  61. include(CheckSymbolExists)
  62. include(CheckCCompilerFlag)
  63. include(CheckCXXCompilerFlag)
  64. include(CheckCSourceCompiles)
  65. include(CheckCXXSourceCompiles)
  66. include(CheckStructHasMember)
  67. include(CMakePackageConfigHelpers)
  68. include(GNUInstallDirs)
  69. find_package(PkgConfig)
  70. option(ALSOFT_DLOPEN "Check for the dlopen API for loading optional libs" ON)
  71. option(ALSOFT_WERROR "Treat compile warnings as errors" OFF)
  72. option(ALSOFT_UTILS "Build utility programs" ON)
  73. option(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
  74. option(ALSOFT_EXAMPLES "Build example programs" ON)
  75. option(ALSOFT_INSTALL "Install main library" ON)
  76. option(ALSOFT_INSTALL_CONFIG "Install alsoft.conf sample configuration file" ON)
  77. option(ALSOFT_INSTALL_HRTF_DATA "Install HRTF data files" ON)
  78. option(ALSOFT_INSTALL_AMBDEC_PRESETS "Install AmbDec preset files" ON)
  79. option(ALSOFT_INSTALL_EXAMPLES "Install example programs (alplay, alstream, ...)" ON)
  80. option(ALSOFT_INSTALL_UTILS "Install utility programs (openal-info, alsoft-config, ...)" ON)
  81. option(ALSOFT_UPDATE_BUILD_VERSION "Update git build version info" ON)
  82. option(ALSOFT_EAX "Enable legacy EAX extensions" ${WIN32})
  83. if(DEFINED SHARE_INSTALL_DIR)
  84. message(WARNING "SHARE_INSTALL_DIR is deprecated. Use the variables provided by the GNUInstallDirs module instead")
  85. set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
  86. endif()
  87. if(DEFINED LIB_SUFFIX)
  88. message(WARNING "LIB_SUFFIX is deprecated. Use the variables provided by the GNUInstallDirs module instead")
  89. endif()
  90. if(DEFINED ALSOFT_CONFIG)
  91. message(WARNING "ALSOFT_CONFIG is deprecated. Use ALSOFT_INSTALL_CONFIG instead")
  92. endif()
  93. if(DEFINED ALSOFT_HRTF_DEFS)
  94. message(WARNING "ALSOFT_HRTF_DEFS is deprecated. Use ALSOFT_INSTALL_HRTF_DATA instead")
  95. endif()
  96. if(DEFINED ALSOFT_AMBDEC_PRESETS)
  97. message(WARNING "ALSOFT_AMBDEC_PRESETS is deprecated. Use ALSOFT_INSTALL_AMBDEC_PRESETS instead")
  98. endif()
  99. set(CPP_DEFS ) # C pre-processor, not C++
  100. set(INC_PATHS )
  101. set(C_FLAGS )
  102. set(LINKER_FLAGS )
  103. set(EXTRA_LIBS )
  104. if(WIN32)
  105. set(CPP_DEFS ${CPP_DEFS} _WIN32 NOMINMAX)
  106. if(MINGW)
  107. set(CPP_DEFS ${CPP_DEFS} __USE_MINGW_ANSI_STDIO)
  108. endif()
  109. option(ALSOFT_BUILD_ROUTER "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)" OFF)
  110. if(MINGW)
  111. option(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
  112. endif()
  113. elseif(APPLE)
  114. option(ALSOFT_OSX_FRAMEWORK "Build as macOS framework" OFF)
  115. endif()
  116. # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
  117. if("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
  118. set(INC_PATHS ${INC_PATHS} /usr/include)
  119. set(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
  120. endif()
  121. # When the library is built for static linking, apps should define
  122. # AL_LIBTYPE_STATIC when including the AL headers.
  123. if(NOT LIBTYPE)
  124. set(LIBTYPE SHARED)
  125. endif()
  126. set(LIB_MAJOR_VERSION "1")
  127. set(LIB_MINOR_VERSION "22")
  128. set(LIB_REVISION "0")
  129. set(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
  130. set(LIB_VERSION_NUM ${LIB_MAJOR_VERSION},${LIB_MINOR_VERSION},${LIB_REVISION},0)
  131. set(EXPORT_DECL "")
  132. # Require C++14
  133. set(CMAKE_CXX_STANDARD 14)
  134. set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
  135. # Prefer C11, but support C99 and C90 too.
  136. set(CMAKE_C_STANDARD 11)
  137. if(NOT WIN32)
  138. # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
  139. check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
  140. if(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
  141. set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
  142. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
  143. check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
  144. if(NOT HAVE_POSIX_MEMALIGN_POSIX)
  145. set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
  146. else()
  147. set(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
  148. endif()
  149. endif()
  150. unset(OLD_REQUIRED_FLAGS)
  151. endif()
  152. # C99 has restrict, but C++ does not, so we can only utilize __restrict.
  153. check_cxx_source_compiles("int *__restrict foo;
  154. int main() { return 0; }" HAVE___RESTRICT)
  155. if(HAVE___RESTRICT)
  156. set(CPP_DEFS ${CPP_DEFS} RESTRICT=__restrict)
  157. else()
  158. set(CPP_DEFS ${CPP_DEFS} "RESTRICT=")
  159. endif()
  160. # Some systems may need libatomic for atomic functions to work
  161. set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
  162. set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
  163. check_cxx_source_compiles("#include <atomic>
  164. std::atomic<int> foo{0};
  165. int main() { return foo.fetch_add(2); }"
  166. HAVE_LIBATOMIC)
  167. if(NOT HAVE_LIBATOMIC)
  168. set(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
  169. else()
  170. set(EXTRA_LIBS atomic ${EXTRA_LIBS})
  171. endif()
  172. unset(OLD_REQUIRED_LIBRARIES)
  173. if(ANDROID)
  174. # Include liblog for Android logging
  175. check_library_exists(log __android_log_print "" HAVE_LIBLOG)
  176. if(HAVE_LIBLOG)
  177. set(EXTRA_LIBS log ${EXTRA_LIBS})
  178. set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
  179. endif()
  180. endif()
  181. if(MSVC)
  182. set(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS)
  183. check_cxx_compiler_flag(/permissive- HAVE_PERMISSIVE_SWITCH)
  184. if(HAVE_PERMISSIVE_SWITCH)
  185. set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
  186. endif()
  187. set(C_FLAGS ${C_FLAGS} /W4 /w14640 /wd4065 /wd4127 /wd4268 /wd4324 /wd5030)
  188. # Remove /W3, which is added by default, since we set /W4. Some build
  189. # generators with MSVC complain about both /W3 and /W4 being specified.
  190. foreach(flag_var CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
  191. if(${flag_var} MATCHES "/W3")
  192. string(REGEX REPLACE "/W3" "" ${flag_var} "${${flag_var}}")
  193. endif()
  194. endforeach()
  195. if(NOT DXSDK_DIR)
  196. string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
  197. else()
  198. string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
  199. endif()
  200. if(DXSDK_DIR)
  201. message(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
  202. endif()
  203. option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
  204. if(FORCE_STATIC_VCRT)
  205. foreach(flag_var
  206. CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
  207. CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
  208. CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
  209. CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
  210. if(${flag_var} MATCHES "/MD")
  211. string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
  212. endif()
  213. endforeach(flag_var)
  214. endif()
  215. else()
  216. set(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align
  217. -Wpedantic
  218. $<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)
  219. if(ALSOFT_WERROR)
  220. set(C_FLAGS ${C_FLAGS} -Werror)
  221. endif()
  222. # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
  223. # instead of NDEBUG)
  224. foreach(flag_var CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
  225. if(${flag_var} MATCHES "-DNDEBUG")
  226. string(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
  227. endif()
  228. endforeach()
  229. check_c_compiler_flag(-fno-math-errno HAVE_FNO_MATH_ERRNO)
  230. if(HAVE_FNO_MATH_ERRNO)
  231. set(C_FLAGS ${C_FLAGS} -fno-math-errno)
  232. endif()
  233. option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
  234. if(ALSOFT_STATIC_LIBGCC)
  235. set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
  236. set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
  237. check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
  238. set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
  239. unset(OLD_REQUIRED_LIBRARIES)
  240. if(NOT HAVE_STATIC_LIBGCC_SWITCH)
  241. message(FATAL_ERROR "Cannot static link libgcc")
  242. endif()
  243. set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
  244. endif()
  245. option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
  246. if(ALSOFT_STATIC_STDCXX)
  247. set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
  248. set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
  249. check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
  250. set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
  251. unset(OLD_REQUIRED_LIBRARIES)
  252. if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
  253. message(FATAL_ERROR "Cannot static link libstdc++")
  254. endif()
  255. set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
  256. endif()
  257. if(WIN32)
  258. option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
  259. if(ALSOFT_STATIC_WINPTHREAD)
  260. set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
  261. set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
  262. check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
  263. set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
  264. unset(OLD_REQUIRED_LIBRARIES)
  265. if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
  266. message(FATAL_ERROR "Cannot static link libwinpthread")
  267. endif()
  268. set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
  269. endif()
  270. endif()
  271. endif()
  272. # Set visibility/export options if available
  273. if(WIN32)
  274. if(NOT LIBTYPE STREQUAL "STATIC")
  275. set(EXPORT_DECL "__declspec(dllexport)")
  276. endif()
  277. else()
  278. set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  279. # Yes GCC, really don't accept visibility modes you don't support
  280. set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
  281. check_c_source_compiles("int foo() __attribute__((visibility(\"protected\")));
  282. int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
  283. if(HAVE_GCC_PROTECTED_VISIBILITY)
  284. if(NOT LIBTYPE STREQUAL "STATIC")
  285. set(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
  286. endif()
  287. else()
  288. check_c_source_compiles("int foo() __attribute__((visibility(\"default\")));
  289. int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
  290. if(HAVE_GCC_DEFAULT_VISIBILITY)
  291. if(NOT LIBTYPE STREQUAL "STATIC")
  292. set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
  293. endif()
  294. endif()
  295. endif()
  296. if(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
  297. check_c_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
  298. if(HAVE_VISIBILITY_HIDDEN_SWITCH)
  299. set(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
  300. endif()
  301. endif()
  302. set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
  303. endif()
  304. set(SSE2_SWITCH "")
  305. if(NOT MSVC)
  306. set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
  307. # Yes GCC, really don't accept command line options you don't support
  308. set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
  309. check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
  310. if(HAVE_MSSE2_SWITCH)
  311. set(SSE2_SWITCH "-msse2")
  312. endif()
  313. set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
  314. unset(OLD_REQUIRED_FLAGS)
  315. endif()
  316. check_include_file(xmmintrin.h HAVE_XMMINTRIN_H)
  317. check_include_file(emmintrin.h HAVE_EMMINTRIN_H)
  318. check_include_file(pmmintrin.h HAVE_PMMINTRIN_H)
  319. check_include_file(smmintrin.h HAVE_SMMINTRIN_H)
  320. check_include_file(arm_neon.h HAVE_ARM_NEON_H)
  321. set(HAVE_SSE 0)
  322. set(HAVE_SSE2 0)
  323. set(HAVE_SSE3 0)
  324. set(HAVE_SSE4_1 0)
  325. set(HAVE_NEON 0)
  326. # Check for SSE support
  327. option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
  328. if(HAVE_XMMINTRIN_H)
  329. option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
  330. if(ALSOFT_CPUEXT_SSE)
  331. set(HAVE_SSE 1)
  332. endif()
  333. endif()
  334. if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
  335. message(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
  336. endif()
  337. option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
  338. if(HAVE_EMMINTRIN_H)
  339. option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
  340. if(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
  341. set(HAVE_SSE2 1)
  342. endif()
  343. endif()
  344. if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
  345. message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
  346. endif()
  347. option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
  348. if(HAVE_PMMINTRIN_H)
  349. option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
  350. if(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
  351. set(HAVE_SSE3 1)
  352. endif()
  353. endif()
  354. if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
  355. message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
  356. endif()
  357. option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
  358. if(HAVE_SMMINTRIN_H)
  359. option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
  360. if(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
  361. set(HAVE_SSE4_1 1)
  362. endif()
  363. endif()
  364. if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
  365. message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
  366. endif()
  367. # Check for ARM Neon support
  368. option(ALSOFT_REQUIRE_NEON "Require ARM NEON support" OFF)
  369. if(HAVE_ARM_NEON_H)
  370. option(ALSOFT_CPUEXT_NEON "Enable ARM NEON support" ON)
  371. if(ALSOFT_CPUEXT_NEON)
  372. check_c_source_compiles("#include <arm_neon.h>
  373. int main()
  374. {
  375. int32x4_t ret4 = vdupq_n_s32(0);
  376. return vgetq_lane_s32(ret4, 0);
  377. }" HAVE_NEON_INTRINSICS)
  378. if(HAVE_NEON_INTRINSICS)
  379. set(HAVE_NEON 1)
  380. endif()
  381. endif()
  382. endif()
  383. if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
  384. message(FATAL_ERROR "Failed to enabled required ARM NEON CPU extensions")
  385. endif()
  386. set(SSE_FLAGS )
  387. set(FPMATH_SET "0")
  388. if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND HAVE_SSE2)
  389. option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
  390. if(ALSOFT_ENABLE_SSE2_CODEGEN)
  391. if(MSVC)
  392. check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
  393. if(HAVE_ARCH_SSE2)
  394. set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
  395. set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
  396. set(FPMATH_SET 2)
  397. endif()
  398. elseif(SSE2_SWITCH)
  399. check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
  400. if(HAVE_MFPMATH_SSE_2)
  401. set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
  402. set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
  403. set(FPMATH_SET 2)
  404. endif()
  405. # SSE depends on a 16-byte aligned stack, and by default, GCC
  406. # assumes the stack is suitably aligned. Older Linux code or other
  407. # OSs don't guarantee this on 32-bit, so externally-callable
  408. # functions need to ensure an aligned stack.
  409. set(EXPORT_DECL "${EXPORT_DECL} __attribute__((force_align_arg_pointer))")
  410. endif()
  411. endif()
  412. endif()
  413. if(HAVE_SSE2)
  414. set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
  415. foreach(flag_var ${SSE_FLAGS})
  416. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
  417. endforeach()
  418. check_c_source_compiles("#include <emmintrin.h>
  419. int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
  420. set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
  421. endif()
  422. check_include_file(malloc.h HAVE_MALLOC_H)
  423. check_include_file(cpuid.h HAVE_CPUID_H)
  424. check_include_file(intrin.h HAVE_INTRIN_H)
  425. check_include_file(guiddef.h HAVE_GUIDDEF_H)
  426. if(NOT HAVE_GUIDDEF_H)
  427. check_include_file(initguid.h HAVE_INITGUID_H)
  428. endif()
  429. # Some systems need libm for some math functions to work
  430. set(MATH_LIB )
  431. check_library_exists(m pow "" HAVE_LIBM)
  432. if(HAVE_LIBM)
  433. set(MATH_LIB ${MATH_LIB} m)
  434. set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
  435. endif()
  436. # Some systems need to link with -lrt for clock_gettime as used by the common
  437. # eaxmple functions.
  438. set(RT_LIB )
  439. check_library_exists(rt clock_gettime "" HAVE_LIBRT)
  440. if(HAVE_LIBRT)
  441. set(RT_LIB rt)
  442. endif()
  443. # Check for the dlopen API (for dynamicly loading backend libs)
  444. if(ALSOFT_DLOPEN)
  445. check_include_file(dlfcn.h HAVE_DLFCN_H)
  446. check_library_exists(dl dlopen "" HAVE_LIBDL)
  447. if(HAVE_LIBDL)
  448. set(EXTRA_LIBS dl ${EXTRA_LIBS})
  449. set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
  450. endif()
  451. endif()
  452. # Check for a cpuid intrinsic
  453. if(HAVE_CPUID_H)
  454. check_c_source_compiles("#include <cpuid.h>
  455. int main()
  456. {
  457. unsigned int eax, ebx, ecx, edx;
  458. return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
  459. }" HAVE_GCC_GET_CPUID)
  460. endif()
  461. if(HAVE_INTRIN_H)
  462. check_c_source_compiles("#include <intrin.h>
  463. int main()
  464. {
  465. int regs[4];
  466. __cpuid(regs, 0);
  467. return regs[0];
  468. }" HAVE_CPUID_INTRINSIC)
  469. endif()
  470. check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
  471. check_symbol_exists(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
  472. check_symbol_exists(proc_pidpath libproc.h HAVE_PROC_PIDPATH)
  473. if(NOT WIN32)
  474. # We need pthreads outside of Windows, for semaphores. It's also used to
  475. # set the priority and name of threads, when possible.
  476. check_include_file(pthread.h HAVE_PTHREAD_H)
  477. if(NOT HAVE_PTHREAD_H)
  478. message(FATAL_ERROR "PThreads is required for non-Windows builds!")
  479. endif()
  480. check_c_compiler_flag(-pthread HAVE_PTHREAD)
  481. if(HAVE_PTHREAD)
  482. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
  483. set(C_FLAGS ${C_FLAGS} -pthread)
  484. set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
  485. endif()
  486. check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
  487. # Some systems need pthread_np.h to get pthread_setname_np
  488. check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
  489. if(HAVE_PTHREAD_NP_H)
  490. check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
  491. if(NOT HAVE_PTHREAD_SETNAME_NP)
  492. check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
  493. endif()
  494. else()
  495. check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
  496. if(NOT HAVE_PTHREAD_SETNAME_NP)
  497. check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
  498. endif()
  499. endif()
  500. endif()
  501. check_symbol_exists(getopt unistd.h HAVE_GETOPT)
  502. # Common sources used by both the OpenAL implementation library, the OpenAL
  503. # router, and certain tools and examples.
  504. set(COMMON_OBJS
  505. common/albit.h
  506. common/albyte.h
  507. common/alcomplex.cpp
  508. common/alcomplex.h
  509. common/aldeque.h
  510. common/alfstream.cpp
  511. common/alfstream.h
  512. common/almalloc.cpp
  513. common/almalloc.h
  514. common/alnumbers.h
  515. common/alnumeric.h
  516. common/aloptional.h
  517. common/alspan.h
  518. common/alstring.cpp
  519. common/alstring.h
  520. common/atomic.h
  521. common/comptr.h
  522. common/dynload.cpp
  523. common/dynload.h
  524. common/intrusive_ptr.h
  525. common/opthelpers.h
  526. common/phase_shifter.h
  527. common/polyphase_resampler.cpp
  528. common/polyphase_resampler.h
  529. common/pragmadefs.h
  530. common/ringbuffer.cpp
  531. common/ringbuffer.h
  532. common/strutils.cpp
  533. common/strutils.h
  534. common/threads.cpp
  535. common/threads.h
  536. common/vecmat.h
  537. common/vector.h)
  538. # Core library routines
  539. set(CORE_OBJS
  540. core/ambdec.cpp
  541. core/ambdec.h
  542. core/ambidefs.cpp
  543. core/ambidefs.h
  544. core/async_event.h
  545. core/bformatdec.cpp
  546. core/bformatdec.h
  547. core/bs2b.cpp
  548. core/bs2b.h
  549. core/bsinc_defs.h
  550. core/bsinc_tables.cpp
  551. core/bsinc_tables.h
  552. core/bufferline.h
  553. core/buffer_storage.cpp
  554. core/buffer_storage.h
  555. core/context.cpp
  556. core/context.h
  557. core/converter.cpp
  558. core/converter.h
  559. core/cpu_caps.cpp
  560. core/cpu_caps.h
  561. core/devformat.cpp
  562. core/devformat.h
  563. core/device.cpp
  564. core/device.h
  565. core/effects/base.h
  566. core/effectslot.cpp
  567. core/effectslot.h
  568. core/except.cpp
  569. core/except.h
  570. core/filters/biquad.h
  571. core/filters/biquad.cpp
  572. core/filters/nfc.cpp
  573. core/filters/nfc.h
  574. core/filters/splitter.cpp
  575. core/filters/splitter.h
  576. core/fmt_traits.cpp
  577. core/fmt_traits.h
  578. core/fpu_ctrl.cpp
  579. core/fpu_ctrl.h
  580. core/front_stablizer.h
  581. core/helpers.cpp
  582. core/helpers.h
  583. core/hrtf.cpp
  584. core/hrtf.h
  585. core/logging.cpp
  586. core/logging.h
  587. core/mastering.cpp
  588. core/mastering.h
  589. core/mixer.cpp
  590. core/mixer.h
  591. core/resampler_limits.h
  592. core/uhjfilter.cpp
  593. core/uhjfilter.h
  594. core/uiddefs.cpp
  595. core/voice.cpp
  596. core/voice.h
  597. core/voice_change.h)
  598. set(HAVE_RTKIT 0)
  599. option(ALSOFT_REQUIRE_RTKIT "Require RTKit/D-Bus support" FALSE)
  600. find_package(DBus1 QUIET)
  601. if(DBus1_FOUND)
  602. option(ALSOFT_RTKIT "Enable RTKit support" ON)
  603. if(ALSOFT_RTKIT)
  604. set(HAVE_RTKIT 1)
  605. set(CORE_OBJS ${CORE_OBJS} core/dbus_wrap.cpp core/dbus_wrap.h core/rtkit.cpp core/rtkit.h)
  606. if(WIN32 OR HAVE_DLFCN_H)
  607. set(INC_PATHS ${INC_PATHS} ${DBus1_INCLUDE_DIRS})
  608. set(CPP_DEFS ${CPP_DEFS} ${DBus1_DEFINITIONS})
  609. else()
  610. set(EXTRA_LIBS ${EXTRA_LIBS} ${DBus1_LIBRARIES})
  611. endif()
  612. endif()
  613. else()
  614. set(MISSING_VARS "")
  615. if(NOT DBus1_INCLUDE_DIRS)
  616. set(MISSING_VARS "${MISSING_VARS} DBus1_INCLUDE_DIRS")
  617. endif()
  618. if(NOT DBus1_LIBRARIES)
  619. set(MISSING_VARS "${MISSING_VARS} DBus1_LIBRARIES")
  620. endif()
  621. message(STATUS "Could NOT find DBus1 (missing:${MISSING_VARS})")
  622. unset(MISSING_VARS)
  623. endif()
  624. if(ALSOFT_REQUIRE_RTKIT AND NOT HAVE_RTKIT)
  625. message(FATAL_ERROR "Failed to enabled required RTKit support")
  626. endif()
  627. # Default mixers, always available
  628. set(CORE_OBJS ${CORE_OBJS}
  629. core/mixer/defs.h
  630. core/mixer/hrtfbase.h
  631. core/mixer/hrtfdefs.h
  632. core/mixer/mixer_c.cpp)
  633. # AL and related routines
  634. set(OPENAL_OBJS
  635. al/auxeffectslot.cpp
  636. al/auxeffectslot.h
  637. al/buffer.cpp
  638. al/buffer.h
  639. al/effect.cpp
  640. al/effect.h
  641. al/effects/autowah.cpp
  642. al/effects/chorus.cpp
  643. al/effects/compressor.cpp
  644. al/effects/convolution.cpp
  645. al/effects/dedicated.cpp
  646. al/effects/distortion.cpp
  647. al/effects/echo.cpp
  648. al/effects/effects.cpp
  649. al/effects/effects.h
  650. al/effects/equalizer.cpp
  651. al/effects/fshifter.cpp
  652. al/effects/modulator.cpp
  653. al/effects/null.cpp
  654. al/effects/pshifter.cpp
  655. al/effects/reverb.cpp
  656. al/effects/vmorpher.cpp
  657. al/error.cpp
  658. al/event.cpp
  659. al/event.h
  660. al/extension.cpp
  661. al/filter.cpp
  662. al/filter.h
  663. al/listener.cpp
  664. al/listener.h
  665. al/source.cpp
  666. al/source.h
  667. al/state.cpp)
  668. # ALC and related routines
  669. set(ALC_OBJS
  670. alc/alc.cpp
  671. alc/alu.cpp
  672. alc/alu.h
  673. alc/alconfig.cpp
  674. alc/alconfig.h
  675. alc/context.cpp
  676. alc/context.h
  677. alc/device.cpp
  678. alc/device.h
  679. alc/effects/base.h
  680. alc/effects/autowah.cpp
  681. alc/effects/chorus.cpp
  682. alc/effects/compressor.cpp
  683. alc/effects/convolution.cpp
  684. alc/effects/dedicated.cpp
  685. alc/effects/distortion.cpp
  686. alc/effects/echo.cpp
  687. alc/effects/equalizer.cpp
  688. alc/effects/fshifter.cpp
  689. alc/effects/modulator.cpp
  690. alc/effects/null.cpp
  691. alc/effects/pshifter.cpp
  692. alc/effects/reverb.cpp
  693. alc/effects/vmorpher.cpp
  694. alc/inprogext.h
  695. alc/panning.cpp)
  696. if (ALSOFT_EAX)
  697. set(OPENAL_OBJS
  698. ${OPENAL_OBJS}
  699. al/eax_api.cpp
  700. al/eax_api.h
  701. al/eax_eax_call.cpp
  702. al/eax_eax_call.h
  703. al/eax_effect.cpp
  704. al/eax_effect.h
  705. al/eax_exception.cpp
  706. al/eax_exception.h
  707. al/eax_fx_slot_index.cpp
  708. al/eax_fx_slot_index.h
  709. al/eax_fx_slots.cpp
  710. al/eax_fx_slots.h
  711. al/eax_globals.cpp
  712. al/eax_globals.h
  713. al/eax_utils.cpp
  714. al/eax_utils.h
  715. al/eax_x_ram.cpp
  716. al/eax_x_ram.h
  717. )
  718. endif ()
  719. # Include SIMD mixers
  720. set(CPU_EXTS "Default")
  721. if(HAVE_SSE)
  722. set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse.cpp)
  723. set(CPU_EXTS "${CPU_EXTS}, SSE")
  724. endif()
  725. if(HAVE_SSE2)
  726. set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse2.cpp)
  727. set(CPU_EXTS "${CPU_EXTS}, SSE2")
  728. endif()
  729. if(HAVE_SSE3)
  730. set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse3.cpp)
  731. set(CPU_EXTS "${CPU_EXTS}, SSE3")
  732. endif()
  733. if(HAVE_SSE4_1)
  734. set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse41.cpp)
  735. set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
  736. endif()
  737. if(HAVE_NEON)
  738. set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_neon.cpp)
  739. set(CPU_EXTS "${CPU_EXTS}, Neon")
  740. endif()
  741. set(HAVE_ALSA 0)
  742. set(HAVE_OSS 0)
  743. set(HAVE_PIPEWIRE 0)
  744. set(HAVE_SOLARIS 0)
  745. set(HAVE_SNDIO 0)
  746. set(HAVE_DSOUND 0)
  747. set(HAVE_WASAPI 0)
  748. set(HAVE_WINMM 0)
  749. set(HAVE_PORTAUDIO 0)
  750. set(HAVE_PULSEAUDIO 0)
  751. set(HAVE_COREAUDIO 0)
  752. set(HAVE_OPENSL 0)
  753. set(HAVE_OBOE 0)
  754. set(HAVE_WAVE 0)
  755. set(HAVE_SDL2 0)
  756. if(WIN32 OR HAVE_DLFCN_H)
  757. set(IS_LINKED "")
  758. macro(ADD_BACKEND_LIBS _LIBS)
  759. endmacro()
  760. else()
  761. set(IS_LINKED " (linked)")
  762. macro(ADD_BACKEND_LIBS _LIBS)
  763. set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
  764. endmacro()
  765. endif()
  766. set(BACKENDS "")
  767. set(ALC_OBJS ${ALC_OBJS}
  768. alc/backends/base.cpp
  769. alc/backends/base.h
  770. # Default backends, always available
  771. alc/backends/loopback.cpp
  772. alc/backends/loopback.h
  773. alc/backends/null.cpp
  774. alc/backends/null.h
  775. )
  776. # Check ALSA backend
  777. option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
  778. find_package(ALSA)
  779. if(ALSA_FOUND)
  780. option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
  781. if(ALSOFT_BACKEND_ALSA)
  782. set(HAVE_ALSA 1)
  783. set(BACKENDS "${BACKENDS} ALSA${IS_LINKED},")
  784. set(ALC_OBJS ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
  785. add_backend_libs(${ALSA_LIBRARIES})
  786. set(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
  787. endif()
  788. endif()
  789. if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
  790. message(FATAL_ERROR "Failed to enabled required ALSA backend")
  791. endif()
  792. # Check OSS backend
  793. option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
  794. find_package(OSS)
  795. if(OSS_FOUND)
  796. option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
  797. if(ALSOFT_BACKEND_OSS)
  798. set(HAVE_OSS 1)
  799. set(BACKENDS "${BACKENDS} OSS,")
  800. set(ALC_OBJS ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
  801. if(OSS_LIBRARIES)
  802. set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
  803. endif()
  804. set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
  805. endif()
  806. endif()
  807. if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
  808. message(FATAL_ERROR "Failed to enabled required OSS backend")
  809. endif()
  810. # Check PipeWire backend
  811. option(ALSOFT_REQUIRE_PIPEWIRE "Require PipeWire backend" OFF)
  812. if(PkgConfig_FOUND)
  813. pkg_check_modules(PIPEWIRE libpipewire-0.3)
  814. if(PIPEWIRE_FOUND)
  815. option(ALSOFT_BACKEND_PIPEWIRE "Enable PipeWire backend" ON)
  816. if(ALSOFT_BACKEND_PIPEWIRE)
  817. set(HAVE_PIPEWIRE 1)
  818. set(BACKENDS "${BACKENDS} PipeWire${IS_LINKED},")
  819. set(ALC_OBJS ${ALC_OBJS} alc/backends/pipewire.cpp alc/backends/pipewire.h)
  820. add_backend_libs(${PIPEWIRE_LIBRARIES})
  821. set(INC_PATHS ${INC_PATHS} ${PIPEWIRE_INCLUDE_DIRS})
  822. endif()
  823. endif()
  824. endif()
  825. if(ALSOFT_REQUIRE_PIPEWIRE AND NOT HAVE_PIPEWIRE)
  826. message(FATAL_ERROR "Failed to enabled required PipeWire backend")
  827. endif()
  828. # Check Solaris backend
  829. option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
  830. find_package(AudioIO)
  831. if(AUDIOIO_FOUND)
  832. option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
  833. if(ALSOFT_BACKEND_SOLARIS)
  834. set(HAVE_SOLARIS 1)
  835. set(BACKENDS "${BACKENDS} Solaris,")
  836. set(ALC_OBJS ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
  837. set(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
  838. endif()
  839. endif()
  840. if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
  841. message(FATAL_ERROR "Failed to enabled required Solaris backend")
  842. endif()
  843. # Check SndIO backend
  844. option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
  845. find_package(SoundIO)
  846. if(SOUNDIO_FOUND)
  847. option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
  848. if(ALSOFT_BACKEND_SNDIO)
  849. set(HAVE_SNDIO 1)
  850. set(BACKENDS "${BACKENDS} SndIO (linked),")
  851. set(ALC_OBJS ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
  852. set(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
  853. set(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
  854. endif()
  855. endif()
  856. if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
  857. message(FATAL_ERROR "Failed to enabled required SndIO backend")
  858. endif()
  859. # Check Windows-only backends
  860. option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
  861. option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
  862. option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
  863. if(WIN32)
  864. # Check MMSystem backend
  865. option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
  866. if(ALSOFT_BACKEND_WINMM)
  867. set(HAVE_WINMM 1)
  868. set(BACKENDS "${BACKENDS} WinMM,")
  869. set(ALC_OBJS ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
  870. # There doesn't seem to be good way to search for winmm.lib for MSVC.
  871. # find_library doesn't find it without being told to look in a specific
  872. # place in the WindowsSDK, but it links anyway. If there ends up being
  873. # Windows targets without this, another means to detect it is needed.
  874. set(EXTRA_LIBS winmm ${EXTRA_LIBS})
  875. endif()
  876. # Check DSound backend
  877. check_include_file(dsound.h HAVE_DSOUND_H)
  878. if(DXSDK_DIR)
  879. find_path(DSOUND_INCLUDE_DIR NAMES "dsound.h"
  880. PATHS "${DXSDK_DIR}" PATH_SUFFIXES include
  881. DOC "The DirectSound include directory")
  882. endif()
  883. if(HAVE_DSOUND_H OR DSOUND_INCLUDE_DIR)
  884. option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
  885. if(ALSOFT_BACKEND_DSOUND)
  886. set(HAVE_DSOUND 1)
  887. set(BACKENDS "${BACKENDS} DirectSound,")
  888. set(ALC_OBJS ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
  889. if(NOT HAVE_DSOUND_H)
  890. set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIR})
  891. endif()
  892. endif()
  893. endif()
  894. # Check for WASAPI backend
  895. check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
  896. if(HAVE_MMDEVICEAPI_H)
  897. option(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
  898. if(ALSOFT_BACKEND_WASAPI)
  899. set(HAVE_WASAPI 1)
  900. set(BACKENDS "${BACKENDS} WASAPI,")
  901. set(ALC_OBJS ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
  902. endif()
  903. endif()
  904. endif()
  905. if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
  906. message(FATAL_ERROR "Failed to enabled required WinMM backend")
  907. endif()
  908. if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
  909. message(FATAL_ERROR "Failed to enabled required DSound backend")
  910. endif()
  911. if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
  912. message(FATAL_ERROR "Failed to enabled required WASAPI backend")
  913. endif()
  914. # Check PortAudio backend
  915. option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
  916. find_package(PortAudio)
  917. if(PORTAUDIO_FOUND)
  918. option(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
  919. if(ALSOFT_BACKEND_PORTAUDIO)
  920. set(HAVE_PORTAUDIO 1)
  921. set(BACKENDS "${BACKENDS} PortAudio${IS_LINKED},")
  922. set(ALC_OBJS ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
  923. add_backend_libs(${PORTAUDIO_LIBRARIES})
  924. set(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
  925. endif()
  926. endif()
  927. if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
  928. message(FATAL_ERROR "Failed to enabled required PortAudio backend")
  929. endif()
  930. # Check PulseAudio backend
  931. option(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
  932. find_package(PulseAudio)
  933. if(PULSEAUDIO_FOUND)
  934. option(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
  935. if(ALSOFT_BACKEND_PULSEAUDIO)
  936. set(HAVE_PULSEAUDIO 1)
  937. set(BACKENDS "${BACKENDS} PulseAudio${IS_LINKED},")
  938. set(ALC_OBJS ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
  939. add_backend_libs(${PULSEAUDIO_LIBRARIES})
  940. set(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
  941. endif()
  942. endif()
  943. if(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
  944. message(FATAL_ERROR "Failed to enabled required PulseAudio backend")
  945. endif()
  946. # Check JACK backend
  947. option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
  948. find_package(JACK)
  949. if(JACK_FOUND)
  950. option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
  951. if(ALSOFT_BACKEND_JACK)
  952. set(HAVE_JACK 1)
  953. set(BACKENDS "${BACKENDS} JACK${IS_LINKED},")
  954. set(ALC_OBJS ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
  955. add_backend_libs(${JACK_LIBRARIES})
  956. set(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
  957. endif()
  958. endif()
  959. if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
  960. message(FATAL_ERROR "Failed to enabled required JACK backend")
  961. endif()
  962. # Check CoreAudio backend
  963. option(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
  964. find_library(COREAUDIO_FRAMEWORK NAMES CoreAudio)
  965. find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit/AudioUnit.h)
  966. if(COREAUDIO_FRAMEWORK AND AUDIOUNIT_INCLUDE_DIR)
  967. option(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
  968. if(ALSOFT_BACKEND_COREAUDIO)
  969. set(HAVE_COREAUDIO 1)
  970. set(ALC_OBJS ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
  971. set(BACKENDS "${BACKENDS} CoreAudio,")
  972. if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
  973. find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation)
  974. set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${COREFOUNDATION_FRAMEWORK} ${EXTRA_LIBS})
  975. else()
  976. set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} /System/Library/Frameworks/AudioUnit.framework
  977. /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
  978. endif()
  979. # Some versions of OSX may need the AudioToolbox framework. Add it if
  980. # it's found.
  981. find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
  982. if(AUDIOTOOLBOX_LIBRARY)
  983. set(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
  984. endif()
  985. set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
  986. endif()
  987. endif()
  988. if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
  989. message(FATAL_ERROR "Failed to enabled required CoreAudio backend")
  990. endif()
  991. # Check for OpenSL (Android) backend
  992. option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
  993. find_package(OpenSL)
  994. if(OPENSL_FOUND)
  995. option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
  996. if(ALSOFT_BACKEND_OPENSL)
  997. set(HAVE_OPENSL 1)
  998. set(ALC_OBJS ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
  999. set(BACKENDS "${BACKENDS} OpenSL,")
  1000. set(EXTRA_LIBS "OpenSL::OpenSLES" ${EXTRA_LIBS})
  1001. endif()
  1002. endif()
  1003. if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
  1004. message(FATAL_ERROR "Failed to enabled required OpenSL backend")
  1005. endif()
  1006. # Check for Oboe (Android) backend
  1007. set(OBOE_TARGET )
  1008. if(ANDROID)
  1009. set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
  1010. if(OBOE_SOURCE)
  1011. # Force Oboe to build with hidden symbols. Don't want to be exporting
  1012. # them from OpenAL.
  1013. set(OLD_CXX_FLAGS ${CMAKE_CXX_FLAGS})
  1014. check_cxx_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
  1015. if(HAVE_VISIBILITY_HIDDEN_SWITCH)
  1016. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
  1017. endif()
  1018. add_subdirectory(${OBOE_SOURCE} ./oboe)
  1019. set(CMAKE_CXX_FLAGS ${OLD_CXX_FLAGS})
  1020. unset(OLD_CXX_FLAGS)
  1021. set(OBOE_TARGET oboe)
  1022. else()
  1023. find_package(Oboe)
  1024. if(OBOE_FOUND)
  1025. set(OBOE_TARGET "oboe::oboe")
  1026. endif()
  1027. endif()
  1028. endif()
  1029. option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
  1030. if(OBOE_TARGET)
  1031. option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
  1032. if(ALSOFT_BACKEND_OBOE)
  1033. set(HAVE_OBOE 1)
  1034. set(ALC_OBJS ${ALC_OBJS} alc/backends/oboe.cpp alc/backends/oboe.h)
  1035. set(BACKENDS "${BACKENDS} Oboe,")
  1036. set(EXTRA_LIBS ${OBOE_TARGET} ${EXTRA_LIBS})
  1037. endif()
  1038. endif()
  1039. if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
  1040. message(FATAL_ERROR "Failed to enabled required Oboe backend")
  1041. endif()
  1042. # Check for SDL2 backend
  1043. option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
  1044. find_package(SDL2)
  1045. if(SDL2_FOUND)
  1046. # Off by default, since it adds a runtime dependency
  1047. option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
  1048. if(ALSOFT_BACKEND_SDL2)
  1049. set(HAVE_SDL2 1)
  1050. set(ALC_OBJS ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
  1051. set(BACKENDS "${BACKENDS} SDL2,")
  1052. set(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
  1053. set(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR})
  1054. endif()
  1055. endif()
  1056. if(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
  1057. message(FATAL_ERROR "Failed to enabled required SDL2 backend")
  1058. endif()
  1059. # Optionally enable the Wave Writer backend
  1060. option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
  1061. if(ALSOFT_BACKEND_WAVE)
  1062. set(HAVE_WAVE 1)
  1063. set(ALC_OBJS ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
  1064. set(BACKENDS "${BACKENDS} WaveFile,")
  1065. endif()
  1066. # This is always available
  1067. set(BACKENDS "${BACKENDS} Null")
  1068. find_package(Git)
  1069. if(ALSOFT_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
  1070. # Get the current working branch and its latest abbreviated commit hash
  1071. add_custom_target(build_version
  1072. ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
  1073. -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
  1074. -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
  1075. WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
  1076. VERBATIM
  1077. )
  1078. else()
  1079. set(GIT_BRANCH "UNKNOWN")
  1080. set(GIT_COMMIT_HASH "unknown")
  1081. configure_file(
  1082. "${OpenAL_SOURCE_DIR}/version.h.in"
  1083. "${OpenAL_BINARY_DIR}/version.h")
  1084. endif()
  1085. option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
  1086. if(ALSOFT_EMBED_HRTF_DATA)
  1087. macro(make_hrtf_header FILENAME VARNAME)
  1088. set(infile "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
  1089. set(outfile "${OpenAL_BINARY_DIR}/${VARNAME}.h")
  1090. add_custom_command(OUTPUT "${outfile}"
  1091. COMMAND ${CMAKE_COMMAND} -D "INPUT_FILE=${infile}" -D "OUTPUT_FILE=${outfile}"
  1092. -D "VARIABLE_NAME=${VARNAME}" -P "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
  1093. WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
  1094. DEPENDS "${infile}" "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
  1095. VERBATIM
  1096. )
  1097. set(ALC_OBJS ${ALC_OBJS} "${outfile}")
  1098. endmacro()
  1099. make_hrtf_header("Default HRTF.mhr" "hrtf_default")
  1100. endif()
  1101. if(ALSOFT_UTILS)
  1102. find_package(MySOFA)
  1103. if(NOT ALSOFT_NO_CONFIG_UTIL)
  1104. find_package(Qt5Widgets QUIET)
  1105. if(NOT Qt5Widgets_FOUND)
  1106. message(STATUS "Could NOT find Qt5Widgets")
  1107. endif()
  1108. endif()
  1109. endif()
  1110. if(ALSOFT_UTILS OR ALSOFT_EXAMPLES)
  1111. find_package(SndFile)
  1112. find_package(SDL2)
  1113. if(SDL2_FOUND)
  1114. find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
  1115. endif()
  1116. endif()
  1117. if(NOT WIN32)
  1118. set(LIBNAME "openal")
  1119. else()
  1120. set(LIBNAME "OpenAL32")
  1121. endif()
  1122. # Needed for openal.pc.in
  1123. set(prefix ${CMAKE_INSTALL_PREFIX})
  1124. set(exec_prefix "\${prefix}")
  1125. set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
  1126. set(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
  1127. set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
  1128. set(PACKAGE_VERSION "${LIB_VERSION}")
  1129. set(PKG_CONFIG_CFLAGS )
  1130. set(PKG_CONFIG_PRIVATE_LIBS )
  1131. if(LIBTYPE STREQUAL "STATIC")
  1132. set(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
  1133. foreach(FLAG ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
  1134. # If this is already a linker flag, or is a full path+file, add it
  1135. # as-is. Otherwise, it's a name intended to be dressed as -lname.
  1136. if(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
  1137. set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
  1138. else()
  1139. set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
  1140. endif()
  1141. endforeach()
  1142. endif()
  1143. # End configuration
  1144. configure_file(
  1145. "${OpenAL_SOURCE_DIR}/config.h.in"
  1146. "${OpenAL_BINARY_DIR}/config.h")
  1147. configure_file(
  1148. "${OpenAL_SOURCE_DIR}/openal.pc.in"
  1149. "${OpenAL_BINARY_DIR}/openal.pc"
  1150. @ONLY)
  1151. add_library(common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
  1152. target_include_directories(common PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include)
  1153. target_compile_definitions(common PRIVATE ${CPP_DEFS})
  1154. target_compile_options(common PRIVATE ${C_FLAGS})
  1155. set_target_properties(common PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
  1156. unset(HAS_ROUTER)
  1157. set(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
  1158. # Build main library
  1159. if(LIBTYPE STREQUAL "STATIC")
  1160. add_library(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS})
  1161. target_compile_definitions(${IMPL_TARGET} PUBLIC AL_LIBTYPE_STATIC)
  1162. target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
  1163. if(WIN32)
  1164. # This option is for static linking OpenAL Soft into another project
  1165. # that already defines the IDs. It is up to that project to ensure all
  1166. # required IDs are defined.
  1167. option(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
  1168. if(ALSOFT_NO_UID_DEFS)
  1169. target_compile_definitions(${IMPL_TARGET} PRIVATE AL_NO_UID_DEFS)
  1170. endif()
  1171. endif()
  1172. else()
  1173. set(RC_CONFIG resources/openal32.rc)
  1174. if(WIN32 AND ALSOFT_BUILD_ROUTER)
  1175. add_library(OpenAL SHARED
  1176. resources/router.rc
  1177. router/router.cpp
  1178. router/router.h
  1179. router/alc.cpp
  1180. router/al.cpp
  1181. )
  1182. target_compile_definitions(OpenAL
  1183. PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}"
  1184. "AL_API=${EXPORT_DECL}" ${CPP_DEFS})
  1185. target_compile_options(OpenAL PRIVATE ${C_FLAGS})
  1186. target_link_libraries(OpenAL PRIVATE common ${LINKER_FLAGS})
  1187. target_include_directories(OpenAL
  1188. PUBLIC
  1189. $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
  1190. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
  1191. PRIVATE
  1192. ${OpenAL_SOURCE_DIR}/common
  1193. ${OpenAL_BINARY_DIR}
  1194. )
  1195. set_target_properties(OpenAL PROPERTIES PREFIX "")
  1196. set_target_properties(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
  1197. if(TARGET build_version)
  1198. add_dependencies(OpenAL build_version)
  1199. endif()
  1200. set(HAS_ROUTER 1)
  1201. set(LIBNAME "soft_oal")
  1202. set(IMPL_TARGET soft_oal)
  1203. set(RC_CONFIG resources/soft_oal.rc)
  1204. endif()
  1205. # !important: for osx framework public header works, the headers must be in
  1206. # the project
  1207. set(TARGET_PUBLIC_HEADERS include/AL/al.h include/AL/alc.h include/AL/alext.h include/AL/efx.h)
  1208. add_library(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS} ${RC_CONFIG}
  1209. ${TARGET_PUBLIC_HEADERS})
  1210. if(WIN32)
  1211. set_target_properties(${IMPL_TARGET} PROPERTIES PREFIX "")
  1212. endif()
  1213. target_link_libraries(${IMPL_TARGET} PRIVATE common ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
  1214. if(APPLE AND ALSOFT_OSX_FRAMEWORK)
  1215. # Sets framework name to soft_oal to avoid ambiguity with the system OpenAL.framework
  1216. set(LIBNAME "soft_oal")
  1217. if(GIT_FOUND)
  1218. EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-list --count head
  1219. TIMEOUT 5
  1220. OUTPUT_VARIABLE BUNDLE_VERSION
  1221. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1222. else()
  1223. set(BUNDLE_VERSION 1)
  1224. endif()
  1225. # Build: Fix rpath in iOS shared libraries
  1226. # If this flag is not set, the final dylib binary ld path will be
  1227. # /User/xxx/*/soft_oal.framework/soft_oal, which can't be loaded by iOS devices.
  1228. # See also: https://github.com/libjpeg-turbo/libjpeg-turbo/commit/c80ddef7a4ce21ace9e3ca0fd190d320cc8cdaeb
  1229. if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
  1230. set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
  1231. endif()
  1232. set_target_properties(${IMPL_TARGET} PROPERTIES
  1233. FRAMEWORK TRUE
  1234. FRAMEWORK_VERSION C
  1235. MACOSX_FRAMEWORK_NAME "${IMPL_TARGET}"
  1236. MACOSX_FRAMEWORK_IDENTIFIER "org.openal-soft.openal"
  1237. MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${LIB_VERSION}
  1238. MACOSX_FRAMEWORK_BUNDLE_VERSION ${BUNDLE_VERSION}
  1239. XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
  1240. XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
  1241. XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
  1242. PUBLIC_HEADER "${TARGET_PUBLIC_HEADERS}"
  1243. MACOSX_RPATH TRUE)
  1244. endif()
  1245. endif()
  1246. target_include_directories(${IMPL_TARGET}
  1247. PUBLIC
  1248. $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
  1249. INTERFACE
  1250. $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include/AL>
  1251. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
  1252. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/AL>
  1253. PRIVATE
  1254. ${INC_PATHS}
  1255. ${OpenAL_BINARY_DIR}
  1256. ${OpenAL_SOURCE_DIR}
  1257. ${OpenAL_SOURCE_DIR}/common
  1258. )
  1259. set_target_properties(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
  1260. VERSION ${LIB_VERSION}
  1261. SOVERSION ${LIB_MAJOR_VERSION}
  1262. )
  1263. target_compile_definitions(${IMPL_TARGET}
  1264. PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}" "AL_API=${EXPORT_DECL}"
  1265. ${CPP_DEFS})
  1266. target_compile_options(${IMPL_TARGET} PRIVATE ${C_FLAGS})
  1267. if(TARGET build_version)
  1268. add_dependencies(${IMPL_TARGET} build_version)
  1269. endif()
  1270. if(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
  1271. find_program(SED_EXECUTABLE NAMES sed DOC "sed executable")
  1272. if(NOT SED_EXECUTABLE OR NOT CMAKE_DLLTOOL)
  1273. message(STATUS "")
  1274. if(NOT SED_EXECUTABLE)
  1275. message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
  1276. endif()
  1277. if(NOT CMAKE_DLLTOOL)
  1278. message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
  1279. endif()
  1280. else()
  1281. set_property(TARGET OpenAL APPEND_STRING PROPERTY
  1282. LINK_FLAGS " -Wl,--output-def,OpenAL32.def")
  1283. add_custom_command(TARGET OpenAL POST_BUILD
  1284. COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
  1285. COMMAND "${CMAKE_DLLTOOL}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
  1286. COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
  1287. VERBATIM
  1288. )
  1289. endif()
  1290. endif()
  1291. if(HAS_ROUTER)
  1292. message(STATUS "")
  1293. message(STATUS "Building DLL router")
  1294. endif()
  1295. message(STATUS "")
  1296. message(STATUS "Building OpenAL with support for the following backends:")
  1297. message(STATUS " ${BACKENDS}")
  1298. message(STATUS "")
  1299. message(STATUS "Building with support for CPU extensions:")
  1300. message(STATUS " ${CPU_EXTS}")
  1301. message(STATUS "")
  1302. if(FPMATH_SET)
  1303. message(STATUS "Building with SSE${FPMATH_SET} codegen")
  1304. message(STATUS "")
  1305. endif()
  1306. if(ALSOFT_EAX)
  1307. message(STATUS "Building with legacy EAX extension support")
  1308. message(STATUS "")
  1309. endif()
  1310. if(ALSOFT_EMBED_HRTF_DATA)
  1311. message(STATUS "Embedding HRTF datasets")
  1312. message(STATUS "")
  1313. endif()
  1314. # An alias for sub-project builds
  1315. add_library(OpenAL::OpenAL ALIAS OpenAL)
  1316. # Install main library
  1317. if(ALSOFT_INSTALL)
  1318. configure_package_config_file(OpenALConfig.cmake.in OpenALConfig.cmake
  1319. INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL)
  1320. install(TARGETS OpenAL EXPORT OpenAL
  1321. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  1322. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  1323. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  1324. FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
  1325. INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
  1326. export(TARGETS OpenAL
  1327. NAMESPACE OpenAL::
  1328. FILE OpenALTargets.cmake)
  1329. install(EXPORT OpenAL
  1330. DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
  1331. NAMESPACE OpenAL::
  1332. FILE OpenALTargets.cmake)
  1333. install(DIRECTORY include/AL
  1334. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  1335. install(FILES "${OpenAL_BINARY_DIR}/openal.pc"
  1336. DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
  1337. install(FILES "${OpenAL_BINARY_DIR}/OpenALConfig.cmake"
  1338. DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL")
  1339. if(TARGET soft_oal)
  1340. install(TARGETS soft_oal
  1341. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
  1342. endif()
  1343. message(STATUS "Installing library and headers")
  1344. else()
  1345. message(STATUS "NOT installing library and headers")
  1346. endif()
  1347. if(ALSOFT_INSTALL_CONFIG)
  1348. install(FILES alsoftrc.sample
  1349. DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
  1350. message(STATUS "Installing sample configuration")
  1351. endif()
  1352. if(ALSOFT_INSTALL_HRTF_DATA)
  1353. install(DIRECTORY hrtf
  1354. DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
  1355. message(STATUS "Installing HRTF data files")
  1356. endif()
  1357. if(ALSOFT_INSTALL_AMBDEC_PRESETS)
  1358. install(DIRECTORY presets
  1359. DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
  1360. message(STATUS "Installing AmbDec presets")
  1361. endif()
  1362. message(STATUS "")
  1363. set(UNICODE_FLAG )
  1364. if(MINGW)
  1365. set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
  1366. endif()
  1367. set(EXTRA_INSTALLS )
  1368. if(ALSOFT_UTILS)
  1369. add_executable(openal-info utils/openal-info.c)
  1370. target_include_directories(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
  1371. target_compile_options(openal-info PRIVATE ${C_FLAGS})
  1372. target_link_libraries(openal-info PRIVATE ${LINKER_FLAGS} OpenAL ${UNICODE_FLAG})
  1373. if(ALSOFT_INSTALL_EXAMPLES)
  1374. set(EXTRA_INSTALLS ${EXTRA_INSTALLS} openal-info)
  1375. endif()
  1376. if(SNDFILE_FOUND)
  1377. add_executable(uhjdecoder utils/uhjdecoder.cpp)
  1378. target_compile_definitions(uhjdecoder PRIVATE ${CPP_DEFS})
  1379. target_include_directories(uhjdecoder
  1380. PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
  1381. target_compile_options(uhjdecoder PRIVATE ${C_FLAGS})
  1382. target_link_libraries(uhjdecoder PUBLIC common
  1383. PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
  1384. add_executable(uhjencoder utils/uhjencoder.cpp)
  1385. target_compile_definitions(uhjencoder PRIVATE ${CPP_DEFS})
  1386. target_include_directories(uhjencoder
  1387. PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
  1388. target_compile_options(uhjencoder PRIVATE ${C_FLAGS})
  1389. target_link_libraries(uhjencoder PUBLIC common
  1390. PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
  1391. endif()
  1392. if(MYSOFA_FOUND)
  1393. set(SOFA_SUPPORT_SRCS
  1394. utils/sofa-support.cpp
  1395. utils/sofa-support.h)
  1396. add_library(sofa-support STATIC EXCLUDE_FROM_ALL ${SOFA_SUPPORT_SRCS})
  1397. target_compile_definitions(sofa-support PRIVATE ${CPP_DEFS})
  1398. target_include_directories(sofa-support PUBLIC ${OpenAL_SOURCE_DIR}/common)
  1399. target_compile_options(sofa-support PRIVATE ${C_FLAGS})
  1400. target_link_libraries(sofa-support PUBLIC common MySOFA::MySOFA PRIVATE ${LINKER_FLAGS})
  1401. set(MAKEMHR_SRCS
  1402. utils/makemhr/loaddef.cpp
  1403. utils/makemhr/loaddef.h
  1404. utils/makemhr/loadsofa.cpp
  1405. utils/makemhr/loadsofa.h
  1406. utils/makemhr/makemhr.cpp
  1407. utils/makemhr/makemhr.h)
  1408. if(NOT HAVE_GETOPT)
  1409. set(MAKEMHR_SRCS ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
  1410. endif()
  1411. add_executable(makemhr ${MAKEMHR_SRCS})
  1412. target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
  1413. target_include_directories(makemhr
  1414. PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/utils)
  1415. target_compile_options(makemhr PRIVATE ${C_FLAGS})
  1416. target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
  1417. if(ALSOFT_INSTALL_EXAMPLES)
  1418. set(EXTRA_INSTALLS ${EXTRA_INSTALLS} makemhr)
  1419. endif()
  1420. set(SOFAINFO_SRCS utils/sofa-info.cpp)
  1421. add_executable(sofa-info ${SOFAINFO_SRCS})
  1422. target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
  1423. target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/utils)
  1424. target_compile_options(sofa-info PRIVATE ${C_FLAGS})
  1425. target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
  1426. endif()
  1427. message(STATUS "Building utility programs")
  1428. if(NOT ALSOFT_NO_CONFIG_UTIL)
  1429. add_subdirectory(utils/alsoft-config)
  1430. endif()
  1431. message(STATUS "")
  1432. endif()
  1433. # Add a static library with common functions used by multiple example targets
  1434. add_library(ex-common STATIC EXCLUDE_FROM_ALL
  1435. examples/common/alhelpers.c
  1436. examples/common/alhelpers.h)
  1437. target_compile_definitions(ex-common PUBLIC ${CPP_DEFS})
  1438. target_include_directories(ex-common PUBLIC ${OpenAL_SOURCE_DIR}/common)
  1439. target_compile_options(ex-common PUBLIC ${C_FLAGS})
  1440. target_link_libraries(ex-common PUBLIC OpenAL PRIVATE ${RT_LIB})
  1441. if(ALSOFT_EXAMPLES)
  1442. add_executable(altonegen examples/altonegen.c)
  1443. target_link_libraries(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} ex-common ${UNICODE_FLAG})
  1444. add_executable(alrecord examples/alrecord.c)
  1445. target_link_libraries(alrecord PRIVATE ${LINKER_FLAGS} ex-common ${UNICODE_FLAG})
  1446. if(ALSOFT_INSTALL_EXAMPLES)
  1447. set(EXTRA_INSTALLS ${EXTRA_INSTALLS} altonegen alrecord)
  1448. endif()
  1449. message(STATUS "Building example programs")
  1450. if(SNDFILE_FOUND)
  1451. add_executable(alplay examples/alplay.c)
  1452. target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
  1453. ${UNICODE_FLAG})
  1454. add_executable(alstream examples/alstream.c)
  1455. target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
  1456. ${UNICODE_FLAG})
  1457. add_executable(alreverb examples/alreverb.c)
  1458. target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
  1459. ${UNICODE_FLAG})
  1460. add_executable(almultireverb examples/almultireverb.c)
  1461. target_link_libraries(almultireverb
  1462. PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
  1463. add_executable(allatency examples/allatency.c)
  1464. target_link_libraries(allatency PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
  1465. ${UNICODE_FLAG})
  1466. add_executable(alhrtf examples/alhrtf.c)
  1467. target_link_libraries(alhrtf
  1468. PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
  1469. add_executable(alstreamcb examples/alstreamcb.cpp)
  1470. target_link_libraries(alstreamcb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
  1471. ${UNICODE_FLAG})
  1472. add_executable(alconvolve examples/alconvolve.c)
  1473. target_link_libraries(alconvolve PRIVATE ${LINKER_FLAGS} common SndFile::SndFile ex-common
  1474. ${UNICODE_FLAG})
  1475. if(ALSOFT_INSTALL_EXAMPLES)
  1476. set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
  1477. alhrtf)
  1478. endif()
  1479. message(STATUS "Building SndFile example programs")
  1480. endif()
  1481. if(SDL2_FOUND)
  1482. add_executable(alloopback examples/alloopback.c)
  1483. target_include_directories(alloopback PRIVATE ${SDL2_INCLUDE_DIR})
  1484. target_link_libraries(alloopback
  1485. PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ex-common ${MATH_LIB})
  1486. if(ALSOFT_INSTALL_EXAMPLES)
  1487. set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alloopback)
  1488. endif()
  1489. message(STATUS "Building SDL example programs")
  1490. set(FFVER_OK FALSE)
  1491. if(FFMPEG_FOUND)
  1492. set(FFVER_OK TRUE)
  1493. if(AVFORMAT_VERSION VERSION_LESS "57.56.101")
  1494. message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
  1495. set(FFVER_OK FALSE)
  1496. endif()
  1497. if(AVCODEC_VERSION VERSION_LESS "57.64.101")
  1498. message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
  1499. set(FFVER_OK FALSE)
  1500. endif()
  1501. if(AVUTIL_VERSION VERSION_LESS "55.34.101")
  1502. message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
  1503. set(FFVER_OK FALSE)
  1504. endif()
  1505. if(SWSCALE_VERSION VERSION_LESS "4.2.100")
  1506. message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
  1507. set(FFVER_OK FALSE)
  1508. endif()
  1509. if(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
  1510. message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
  1511. set(FFVER_OK FALSE)
  1512. endif()
  1513. endif()
  1514. if(FFVER_OK)
  1515. add_executable(alffplay examples/alffplay.cpp)
  1516. target_include_directories(alffplay
  1517. PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
  1518. target_link_libraries(alffplay
  1519. PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common)
  1520. if(ALSOFT_INSTALL_EXAMPLES)
  1521. set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alffplay)
  1522. endif()
  1523. message(STATUS "Building SDL+FFmpeg example programs")
  1524. endif()
  1525. endif()
  1526. message(STATUS "")
  1527. endif()
  1528. if(EXTRA_INSTALLS)
  1529. install(TARGETS ${EXTRA_INSTALLS}
  1530. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  1531. BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
  1532. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  1533. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
  1534. endif()