🛠️🐜 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.

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