CMakeLists.txt 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. cmake_minimum_required(VERSION 3.1)
  2. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
  3. include(opus_functions.cmake)
  4. get_library_version(OPUS_LIBRARY_VERSION OPUS_LIBRARY_VERSION_MAJOR)
  5. message(STATUS "Opus library version: ${OPUS_LIBRARY_VERSION}")
  6. get_package_version(PACKAGE_VERSION)
  7. message(STATUS "Opus package version: ${PACKAGE_VERSION}")
  8. string(REGEX
  9. REPLACE "^([0-9]+.[0-9]+\\.?([0-9]+)?).*"
  10. "\\1"
  11. PROJECT_VERSION
  12. ${PACKAGE_VERSION})
  13. message(STATUS "Opus project version: ${PROJECT_VERSION}")
  14. project(Opus LANGUAGES C VERSION ${PROJECT_VERSION})
  15. include(opus_buildtype.cmake)
  16. option(OPUS_BUILD_SHARED_LIBRARY "Build shared library" OFF)
  17. option(OPUS_STACK_PROTECTOR "Use stack protection" ON)
  18. option(OPUS_CUSTOM_MODES "Enable non-Opus modes, e.g. 44.1 kHz & 2^n frames"
  19. OFF)
  20. option(OPUS_BUILD_PROGRAMS "Build programs" OFF)
  21. option(OPUS_BUILD_TESTING "Build tests" OFF)
  22. option(OPUS_FIXED_POINT
  23. "Compile as fixed-point (for machines without a fast enough FPU)" OFF)
  24. option(OPUS_ENABLE_FLOAT_API
  25. "Compile with the floating point API (for machines with float library"
  26. ON)
  27. option(OPUS_FLOAT_APPROX
  28. "Enable floating point approximations (Ensure your platform supports IEEE 754 before enabling)"
  29. OFF)
  30. option(OPUS_INSTALL_PKG_CONFIG_MODULE "Install PkgConfig module" ON)
  31. option(OPUS_INSTALL_CMAKE_CONFIG_MODULE "Install CMake package config module"
  32. ON)
  33. include(opus_config.cmake)
  34. include(opus_sources.cmake)
  35. include(GNUInstallDirs)
  36. include(CMakeDependentOption)
  37. include(FeatureSummary)
  38. cmake_dependent_option(OPUS_VAR_ARRAYS
  39. "Use variable length arrays for stack arrays"
  40. ON
  41. "VLA_SUPPORTED; NOT OPUS_USE_ALLOCA; NOT OPUS_NONTHREADSAFE_PSEUDOSTACK"
  42. OFF)
  43. cmake_dependent_option(OPUS_USE_ALLOCA
  44. "Use alloca for stack arrays (on non-C99 compilers)"
  45. ON
  46. "USE_ALLOCA_SUPPORTED; NOT OPUS_VAR_ARRAYS; NOT OPUS_NONTHREADSAFE_PSEUDOSTACK"
  47. OFF)
  48. cmake_dependent_option(OPUS_NONTHREADSAFE_PSEUDOSTACK
  49. "Use a non threadsafe pseudostack when neither variable length arrays or alloca is supported"
  50. ON
  51. "NOT OPUS_VAR_ARRAYS; NOT OPUS_USE_ALLOCA"
  52. OFF)
  53. cmake_dependent_option(OPUS_FAST_MATH
  54. "Enable fast math"
  55. ON
  56. "OPUS_FLOAT_APPROX; OPUS_FAST_MATH"
  57. OFF)
  58. if(OPUS_FAST_MATH)
  59. if(MSVC)
  60. check_and_set_flag(FAST_MATH /fp:fast)
  61. else()
  62. check_and_set_flag(FAST_MATH -ffast-math)
  63. endif()
  64. endif()
  65. if(OPUS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS)
  66. # Global flag to cause add_library() to create shared libraries if on.
  67. set(BUILD_SHARED_LIBS ON)
  68. set(OPUS_BUILD_SHARED_LIBRARY ON)
  69. endif()
  70. if(OPUS_BUILD_TESTING OR BUILD_TESTING)
  71. set(OPUS_BUILD_TESTING ON)
  72. set(BUILD_TESTING ON)
  73. endif()
  74. if(OPUS_STACK_PROTECTOR)
  75. if(MSVC) # GC on by default on MSVC
  76. check_and_set_flag(STACK_PROTECTOR /GS)
  77. else()
  78. check_and_set_flag(STACK_PROTECTOR -fstack-protector-strong)
  79. endif()
  80. else()
  81. if(MSVC)
  82. check_and_set_flag(STACK_PROTECTOR_DISABLED /GS-)
  83. if (STACK_PROTECTOR_DISABLED_SUPPORTED)
  84. set(STACK_PROTECTOR_SUPPORTED OFF)
  85. endif()
  86. else()
  87. set(STACK_PROTECTOR_SUPPORTED OFF)
  88. endif()
  89. endif()
  90. if(OPUS_CPU_X86 OR OPUS_CPU_X64)
  91. cmake_dependent_option(OPUS_X86_MAY_HAVE_SSE
  92. "Does runtime check for SSE1 support"
  93. ON
  94. "SSE1_SUPPORTED"
  95. OFF)
  96. cmake_dependent_option(OPUS_X86_MAY_HAVE_SSE2
  97. "Does runtime check for SSE2 support"
  98. ON
  99. "SSE2_SUPPORTED"
  100. OFF)
  101. cmake_dependent_option(OPUS_X86_MAY_HAVE_SSE4_1
  102. "Does runtime check for SSE4.1 support"
  103. ON
  104. "SSE4_1_SUPPORTED"
  105. OFF)
  106. cmake_dependent_option(OPUS_X86_MAY_HAVE_AVX
  107. "Does runtime check for AVX support"
  108. ON
  109. "AVX_SUPPORTED"
  110. OFF)
  111. # PRESUME depends on MAY HAVE, but PRESUME will override runtime detection
  112. if(OPUS_CPU_X64) # Assume 64 bit has SSE2 support
  113. cmake_dependent_option(OPUS_X86_PRESUME_SSE
  114. "Assume target CPU has SSE1 support"
  115. ON
  116. "OPUS_X86_MAY_HAVE_SSE"
  117. OFF)
  118. cmake_dependent_option(OPUS_X86_PRESUME_SSE2
  119. "Assume target CPU has SSE2 support"
  120. ON
  121. "OPUS_X86_MAY_HAVE_SSE2"
  122. OFF)
  123. else()
  124. cmake_dependent_option(OPUS_X86_PRESUME_SSE
  125. "Assume target CPU has SSE1 support"
  126. OFF
  127. "OPUS_X86_MAY_HAVE_SSE"
  128. OFF)
  129. cmake_dependent_option(OPUS_X86_PRESUME_SSE2
  130. "Assume target CPU has SSE2 support"
  131. OFF
  132. "OPUS_X86_MAY_HAVE_SSE2"
  133. OFF)
  134. endif()
  135. cmake_dependent_option(OPUS_X86_PRESUME_SSE4_1
  136. "Assume target CPU has SSE4.1 support"
  137. OFF
  138. "OPUS_X86_MAY_HAVE_SSE4_1"
  139. OFF)
  140. cmake_dependent_option(OPUS_X86_PRESUME_AVX
  141. "Assume target CPU has AVX support"
  142. OFF
  143. "OPUS_X86_MAY_HAVE_AVX"
  144. OFF)
  145. endif()
  146. set_package_properties(Git
  147. PROPERTIES
  148. TYPE
  149. REQUIRED
  150. DESCRIPTION
  151. "fast, scalable, distributed revision control system"
  152. URL
  153. "https://git-scm.com/"
  154. PURPOSE
  155. "required to set up package version")
  156. add_feature_info(OPUS_BUILD_SHARED_LIBRARY OPUS_BUILD_SHARED_LIBRARY "Build shared library")
  157. add_feature_info(OPUS_STACK_PROTECTOR STACK_PROTECTOR_SUPPORTED "Use stack protection")
  158. add_feature_info(OPUS_VAR_ARRAYS OPUS_VAR_ARRAYS
  159. "Use variable length arrays for stack arrays")
  160. add_feature_info(OPUS_USE_ALLOCA OPUS_USE_ALLOCA
  161. "Use alloca for stack arrays (on non-C99 compilers)")
  162. add_feature_info(OPUS_NONTHREADSAFE_PSEUDOSTACK OPUS_NONTHREADSAFE_PSEUDOSTACK
  163. "Use a non threadsafe pseudostack when neither variable length arrays or alloca is supported")
  164. add_feature_info(OPUS_CUSTOM_MODES OPUS_CUSTOM_MODES
  165. "Enable non-Opus modes, e.g. 44.1 kHz & 2^n frames")
  166. add_feature_info(OPUS_BUILD_TESTING OPUS_BUILD_TESTING "Build test programs")
  167. add_feature_info(OPUS_BUILD_PROGRAMS OPUS_BUILD_PROGRAMS "Build programs")
  168. add_feature_info(
  169. OPUS_FIXED_POINT OPUS_FIXED_POINT
  170. "compile as fixed-point (for machines without a fast enough FPU)")
  171. add_feature_info(
  172. OPUS_FLOAT_API OPUS_ENABLE_FLOAT_API
  173. "compile with the floating point API (for machines with float library)")
  174. add_feature_info(OPUS_FLOAT_APPROX OPUS_FLOAT_APPROX
  175. "Enable floating point approximations (Ensure your platform supports IEEE 754 before enabling)")
  176. add_feature_info(OPUS_FAST_MATH FAST_MATH_SUPPORTED "Enable fast math, (depending on OPUS_FLOAT_APPROX to be enabled)")
  177. add_feature_info(OPUS_INSTALL_PKG_CONFIG_MODULE OPUS_INSTALL_PKG_CONFIG_MODULE
  178. "install PkgConfig module")
  179. add_feature_info(OPUS_INSTALL_CMAKE_CONFIG_MODULE OPUS_INSTALL_CMAKE_CONFIG_MODULE
  180. "install CMake package config module")
  181. if(OPUS_CPU_X86 OR OPUS_CPU_X64)
  182. add_feature_info(OPUS_X86_MAY_HAVE_SSE OPUS_X86_MAY_HAVE_SSE
  183. "does runtime check for SSE1 support")
  184. add_feature_info(OPUS_X86_MAY_HAVE_SSE2 OPUS_X86_MAY_HAVE_SSE2
  185. "does runtime check for SSE2 support")
  186. add_feature_info(OPUS_X86_MAY_HAVE_SSE4_1 OPUS_X86_MAY_HAVE_SSE4_1
  187. "does runtime check for SSE4_1 support")
  188. add_feature_info(OPUS_X86_MAY_HAVE_AVX OPUS_X86_MAY_HAVE_AVX
  189. "does runtime check for AVX support")
  190. add_feature_info(OPUS_X86_PRESUME_SSE OPUS_X86_PRESUME_SSE
  191. "assume target CPU has SSE1 support will override the runtime check")
  192. add_feature_info(OPUS_X86_PRESUME_SSE2 OPUS_X86_PRESUME_SSE2
  193. "assume target CPU has SSE2 support will override the runtime check")
  194. add_feature_info(OPUS_X86_PRESUME_SSE4_1 OPUS_X86_PRESUME_SSE4_1
  195. "assume target CPU has SSE4_1 support will override the runtime check")
  196. add_feature_info(OPUS_X86_PRESUME_AVX OPUS_X86_PRESUME_AVX
  197. "assume target CPU has AVX support will override the runtime check")
  198. endif()
  199. feature_summary(WHAT ALL)
  200. add_library(opus ${opus_sources} ${opus_sources_float})
  201. add_library(Opus::opus ALIAS opus)
  202. set(Opus_PUBLIC_HEADER
  203. ${CMAKE_CURRENT_SOURCE_DIR}/include/opus.h
  204. ${CMAKE_CURRENT_SOURCE_DIR}/include/opus_custom.h
  205. ${CMAKE_CURRENT_SOURCE_DIR}/include/opus_defines.h
  206. ${CMAKE_CURRENT_SOURCE_DIR}/include/opus_multistream.h
  207. ${CMAKE_CURRENT_SOURCE_DIR}/include/opus_projection.h
  208. ${CMAKE_CURRENT_SOURCE_DIR}/include/opus_types.h)
  209. set_target_properties(opus
  210. PROPERTIES SOVERSION
  211. ${OPUS_LIBRARY_VERSION_MAJOR}
  212. VERSION
  213. ${OPUS_LIBRARY_VERSION}
  214. PUBLIC_HEADER
  215. "${Opus_PUBLIC_HEADER}")
  216. target_include_directories(
  217. opus
  218. PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  219. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
  220. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/opus>
  221. PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
  222. ${CMAKE_CURRENT_SOURCE_DIR}
  223. celt
  224. silk)
  225. target_link_libraries(opus PRIVATE ${OPUS_REQUIRED_LIBRARIES})
  226. target_compile_definitions(opus PRIVATE OPUS_BUILD ENABLE_HARDENING)
  227. if(NOT MSVC)
  228. target_compile_definitions(opus PRIVATE _FORTIFY_SOURCE=2)
  229. endif()
  230. if(OPUS_FLOAT_APPROX)
  231. target_compile_definitions(opus PRIVATE FLOAT_APPROX)
  232. endif()
  233. if(OPUS_VAR_ARRAYS)
  234. target_compile_definitions(opus PRIVATE VAR_ARRAYS)
  235. elseif(OPUS_USE_ALLOCA)
  236. target_compile_definitions(opus PRIVATE USE_ALLOCA)
  237. elseif(OPUS_NONTHREADSAFE_PSEUDOSTACK)
  238. target_compile_definitions(opus PRIVATE NONTHREADSAFE_PSEUDOSTACK)
  239. else()
  240. message(ERROR Neet to set a define for stack allocation)
  241. endif()
  242. if(OPUS_CUSTOM_MODES)
  243. target_compile_definitions(opus PRIVATE CUSTOM_MODES)
  244. endif()
  245. if(BUILD_SHARED_LIBS)
  246. if(WIN32)
  247. target_compile_definitions(opus PRIVATE DLL_EXPORT)
  248. else()
  249. include(CheckCCompilerFlag)
  250. check_c_compiler_flag(-fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY)
  251. if(COMPILER_HAS_HIDDEN_VISIBILITY)
  252. set_target_properties(opus PROPERTIES C_VISIBILITY_PRESET hidden)
  253. endif()
  254. endif()
  255. endif()
  256. add_sources_group(opus silk ${silk_sources})
  257. add_sources_group(opus celt ${celt_sources})
  258. if(OPUS_FIXED_POINT)
  259. add_sources_group(opus silk ${silk_sources_fixed})
  260. target_include_directories(opus PRIVATE silk/fixed)
  261. target_compile_definitions(opus PRIVATE FIXED_POINT=1)
  262. else()
  263. add_sources_group(opus silk ${silk_sources_float})
  264. target_include_directories(opus PRIVATE silk/float)
  265. endif()
  266. if(NOT OPUS_ENABLE_FLOAT_API)
  267. target_compile_definitions(opus PRIVATE DISABLE_FLOAT_API)
  268. endif()
  269. #[[Build flags for SSE will be set the following way:
  270. MSVC: If OPUS_X86_PRESUME_X is set then we will set the highest possible /arch:X
  271. we won't set any ARCH flag for OPUS_X86_MAY_HAVE_SSE due to:
  272. https://randomascii.wordpress.com/2016/12/05/vc-archavx-option-unsafe-at-any-speed/
  273. For non MSVC: we will set the compiler flags on per file basis for OPUS_X86_MAY_HAVE_SSE
  274. for OPUS_X86_PRESUME_X we will set it for the target]]
  275. if((OPUS_X86_MAY_HAVE_SSE AND NOT OPUS_X86_PRESUME_SSE) OR
  276. (OPUS_X86_MAY_HAVE_SSE2 AND NOT OPUS_X86_PRESUME_SSE2) OR
  277. (OPUS_X86_MAY_HAVE_SSE4_1 AND NOT OPUS_X86_PRESUME_SSE4_1) OR
  278. (OPUS_X86_MAY_HAVE_AVX AND NOT OPUS_X86_PRESUME_AVX))
  279. target_compile_definitions(opus PRIVATE OPUS_HAVE_RTCD)
  280. endif()
  281. if(SSE1_SUPPORTED)
  282. if(OPUS_X86_MAY_HAVE_SSE)
  283. add_sources_group(opus celt ${celt_sources_sse})
  284. target_compile_definitions(opus PRIVATE OPUS_X86_MAY_HAVE_SSE)
  285. if(NOT MSVC)
  286. set_source_files_properties(${celt_sources_sse} PROPERTIES COMPILE_FLAGS -msse)
  287. endif()
  288. endif()
  289. if(OPUS_X86_PRESUME_SSE)
  290. target_compile_definitions(opus PRIVATE OPUS_X86_PRESUME_SSE)
  291. if(NOT MSVC)
  292. target_compile_options(opus PRIVATE -msse)
  293. endif()
  294. endif()
  295. endif()
  296. if(SSE2_SUPPORTED)
  297. if(OPUS_X86_MAY_HAVE_SSE2)
  298. add_sources_group(opus celt ${celt_sources_sse2})
  299. target_compile_definitions(opus PRIVATE OPUS_X86_MAY_HAVE_SSE2)
  300. if(NOT MSVC)
  301. set_source_files_properties(${celt_sources_sse2} PROPERTIES COMPILE_FLAGS -msse2)
  302. endif()
  303. endif()
  304. if(OPUS_X86_PRESUME_SSE2)
  305. target_compile_definitions(opus PRIVATE OPUS_X86_PRESUME_SSE2)
  306. if(NOT MSVC)
  307. target_compile_options(opus PRIVATE -msse2)
  308. endif()
  309. endif()
  310. endif()
  311. if(SSE4_1_SUPPORTED)
  312. if(OPUS_X86_MAY_HAVE_SSE4_1)
  313. add_sources_group(opus celt ${celt_sources_sse4_1})
  314. add_sources_group(opus silk ${silk_sources_sse4_1})
  315. target_compile_definitions(opus PRIVATE OPUS_X86_MAY_HAVE_SSE4_1)
  316. if(NOT MSVC)
  317. set_source_files_properties(${celt_sources_sse4_1} ${silk_sources_sse4_1} PROPERTIES COMPILE_FLAGS -msse4.1)
  318. endif()
  319. if(OPUS_FIXED_POINT)
  320. add_sources_group(opus silk ${silk_sources_fixed_sse4_1})
  321. if(NOT MSVC)
  322. set_source_files_properties(${silk_sources_fixed_sse4_1} PROPERTIES COMPILE_FLAGS -msse4.1)
  323. endif()
  324. endif()
  325. endif()
  326. if(OPUS_X86_PRESUME_SSE4_1)
  327. target_compile_definitions(opus PRIVATE OPUS_X86_PRESUME_SSE4_1)
  328. if(NOT MSVC)
  329. target_compile_options(opus PRIVATE -msse4.1)
  330. endif()
  331. endif()
  332. endif()
  333. if(AVX_SUPPORTED)
  334. # mostly placeholder in case of avx intrinsics is added
  335. if(OPUS_X86_MAY_HAVE_AVX)
  336. target_compile_definitions(opus PRIVATE OPUS_X86_MAY_HAVE_AVX)
  337. endif()
  338. if(OPUS_X86_PRESUME_AVX)
  339. target_compile_definitions(opus PRIVATE OPUS_X86_PRESUME_AVX)
  340. if(NOT MSVC)
  341. target_compile_options(opus PRIVATE -mavx)
  342. endif()
  343. endif()
  344. endif()
  345. if(MSVC)
  346. if(AVX_SUPPORTED AND OPUS_X86_PRESUME_AVX) # on 64 bit and 32 bits
  347. add_definitions(/arch:AVX)
  348. elseif(OPUS_CPU_X86) # if AVX not supported then set SSE flag
  349. if((SSE4_1_SUPPORTED AND OPUS_X86_PRESUME_SSE4_1)
  350. OR (SSE2_SUPPORTED AND OPUS_X86_PRESUME_SSE2))
  351. target_compile_definitions(opus PRIVATE /arch:SSE2)
  352. elseif(SSE1_SUPPORTED AND OPUS_X86_PRESUME_SSE)
  353. target_compile_definitions(opus PRIVATE /arch:SSE)
  354. endif()
  355. endif()
  356. endif()
  357. if(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm|aarch64)")
  358. add_sources_group(opus celt ${celt_sources_arm})
  359. endif()
  360. if(COMPILER_SUPPORT_NEON AND OPUS_USE_NEON)
  361. if(OPUS_MAY_HAVE_NEON)
  362. if(RUNTIME_CPU_CAPABILITY_DETECTION)
  363. message(STATUS "OPUS_MAY_HAVE_NEON enabling runtime detection")
  364. target_compile_definitions(opus PRIVATE OPUS_HAVE_RTCD)
  365. else()
  366. message(ERROR "Runtime cpu capability detection needed for MAY_HAVE_NEON")
  367. endif()
  368. # Do runtime check for NEON
  369. target_compile_definitions(opus
  370. PRIVATE
  371. OPUS_ARM_MAY_HAVE_NEON
  372. OPUS_ARM_MAY_HAVE_NEON_INTR)
  373. endif()
  374. add_sources_group(opus celt ${celt_sources_arm_neon_intr})
  375. add_sources_group(opus silk ${silk_sources_arm_neon_intr})
  376. # silk arm neon depends on main_Fix.h
  377. target_include_directories(opus PRIVATE silk/fixed)
  378. if(OPUS_FIXED_POINT)
  379. add_sources_group(opus silk ${silk_sources_fixed_arm_neon_intr})
  380. endif()
  381. if(OPUS_PRESUME_NEON)
  382. target_compile_definitions(opus
  383. PRIVATE
  384. OPUS_ARM_PRESUME_NEON
  385. OPUS_ARM_PRESUME_NEON_INTR)
  386. endif()
  387. endif()
  388. target_compile_definitions(opus
  389. PRIVATE
  390. $<$<BOOL:${HAVE_LRINT}>:HAVE_LRINT>
  391. $<$<BOOL:${HAVE_LRINTF}>:HAVE_LRINTF>)
  392. install(TARGETS opus
  393. EXPORT OpusTargets
  394. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  395. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  396. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  397. PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/opus)
  398. if(OPUS_INSTALL_PKG_CONFIG_MODULE)
  399. set(prefix ${CMAKE_INSTALL_PREFIX})
  400. set(exec_prefix ${CMAKE_INSTALL_PREFIX})
  401. set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
  402. set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
  403. set(VERSION ${PACKAGE_VERSION})
  404. if(HAVE_LIBM)
  405. set(LIBM "-lm")
  406. endif()
  407. configure_file(opus.pc.in opus.pc)
  408. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/opus.pc
  409. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  410. endif()
  411. if(OPUS_INSTALL_CMAKE_CONFIG_MODULE)
  412. set(CPACK_GENERATOR TGZ)
  413. include(CPack)
  414. set(CMAKE_INSTALL_PACKAGEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
  415. install(EXPORT OpusTargets
  416. NAMESPACE Opus::
  417. DESTINATION ${CMAKE_INSTALL_PACKAGEDIR})
  418. include(CMakePackageConfigHelpers)
  419. set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR})
  420. configure_package_config_file(OpusConfig.cmake.in
  421. OpusConfig.cmake
  422. INSTALL_DESTINATION
  423. ${CMAKE_INSTALL_PACKAGEDIR}
  424. PATH_VARS
  425. INCLUDE_INSTALL_DIR
  426. INSTALL_PREFIX
  427. ${CMAKE_INSTALL_PREFIX})
  428. write_basic_package_version_file(OpusConfigVersion.cmake
  429. VERSION ${PROJECT_VERSION}
  430. COMPATIBILITY SameMajorVersion)
  431. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/OpusConfig.cmake
  432. ${CMAKE_CURRENT_BINARY_DIR}/OpusConfigVersion.cmake
  433. DESTINATION ${CMAKE_INSTALL_PACKAGEDIR})
  434. endif()
  435. if(OPUS_BUILD_PROGRAMS)
  436. # demo
  437. if(OPUS_CUSTOM_MODES)
  438. add_executable(opus_custom_demo ${opus_custom_demo_sources})
  439. target_include_directories(opus_custom_demo
  440. PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
  441. target_link_libraries(opus_custom_demo PRIVATE opus)
  442. endif()
  443. add_executable(opus_demo ${opus_demo_sources})
  444. target_include_directories(opus_demo PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
  445. target_include_directories(opus_demo PRIVATE silk) # debug.h
  446. target_include_directories(opus_demo PRIVATE celt) # arch.h
  447. target_link_libraries(opus_demo PRIVATE opus ${OPUS_REQUIRED_LIBRARIES})
  448. # compare
  449. add_executable(opus_compare ${opus_compare_sources})
  450. target_include_directories(opus_compare PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
  451. target_link_libraries(opus_compare PRIVATE opus ${OPUS_REQUIRED_LIBRARIES})
  452. endif()
  453. if(BUILD_TESTING)
  454. enable_testing()
  455. # tests
  456. add_executable(test_opus_decode ${test_opus_decode_sources})
  457. target_include_directories(test_opus_decode
  458. PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
  459. target_link_libraries(test_opus_decode PRIVATE opus)
  460. if(OPUS_FIXED_POINT)
  461. target_compile_definitions(test_opus_decode PRIVATE DISABLE_FLOAT_API)
  462. endif()
  463. add_test(test_opus_decode test_opus_decode)
  464. add_executable(test_opus_padding ${test_opus_padding_sources})
  465. target_include_directories(test_opus_padding
  466. PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
  467. target_link_libraries(test_opus_padding PRIVATE opus)
  468. add_test(test_opus_padding test_opus_padding)
  469. if(NOT BUILD_SHARED_LIBS)
  470. # disable tests that depends on private API when building shared lib
  471. add_executable(test_opus_api ${test_opus_api_sources})
  472. target_include_directories(test_opus_api
  473. PRIVATE ${CMAKE_CURRENT_BINARY_DIR} celt)
  474. target_link_libraries(test_opus_api PRIVATE opus)
  475. if(OPUS_FIXED_POINT)
  476. target_compile_definitions(test_opus_api PRIVATE DISABLE_FLOAT_API)
  477. endif()
  478. add_test(test_opus_api test_opus_api)
  479. add_executable(test_opus_encode ${test_opus_encode_sources})
  480. target_include_directories(test_opus_encode
  481. PRIVATE ${CMAKE_CURRENT_BINARY_DIR} celt)
  482. target_link_libraries(test_opus_encode PRIVATE opus)
  483. add_test(test_opus_encode test_opus_encode)
  484. endif()
  485. endif()