Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.1) |
Marcus Asteborg | a0e14e7 | 2020-04-13 15:51:48 -0700 | [diff] [blame] | 2 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 3 | |
Marcus Asteborg | 8ad827c | 2020-06-24 21:25:57 -0700 | [diff] [blame] | 4 | include(OpusPackageVersion) |
| 5 | get_package_version(PACKAGE_VERSION PROJECT_VERSION) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 6 | |
| 7 | project(Opus LANGUAGES C VERSION ${PROJECT_VERSION}) |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 8 | |
Marcus Asteborg | 8ad827c | 2020-06-24 21:25:57 -0700 | [diff] [blame] | 9 | include(OpusFunctions) |
Marcus Asteborg | 48055cc | 2020-04-22 22:06:11 -0700 | [diff] [blame] | 10 | include(OpusBuildtype) |
Marcus Asteborg | 48055cc | 2020-04-22 22:06:11 -0700 | [diff] [blame] | 11 | include(OpusConfig) |
| 12 | include(OpusSources) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 13 | include(GNUInstallDirs) |
| 14 | include(CMakeDependentOption) |
| 15 | include(FeatureSummary) |
| 16 | |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 17 | set(OPUS_BUILD_SHARED_LIBRARY_HELP_STR "build shared library.") |
| 18 | option(OPUS_BUILD_SHARED_LIBRARY ${OPUS_BUILD_SHARED_LIBRARY_HELP_STR} OFF) |
Simon Jackson | b254701 | 2020-04-15 17:58:55 +0100 | [diff] [blame] | 19 | if(OPUS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS OR OPUS_BUILD_FRAMEWORK) |
Davide Beatrici | c487f53 | 2019-10-01 06:08:04 +0200 | [diff] [blame] | 20 | # Global flag to cause add_library() to create shared libraries if on. |
| 21 | set(BUILD_SHARED_LIBS ON) |
Marcus Asteborg | 965a72e | 2019-12-17 10:21:21 -0800 | [diff] [blame] | 22 | set(OPUS_BUILD_SHARED_LIBRARY ON) |
Davide Beatrici | c487f53 | 2019-10-01 06:08:04 +0200 | [diff] [blame] | 23 | endif() |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 24 | add_feature_info(OPUS_BUILD_SHARED_LIBRARY OPUS_BUILD_SHARED_LIBRARY ${OPUS_BUILD_SHARED_LIBRARY_HELP_STR}) |
Davide Beatrici | c487f53 | 2019-10-01 06:08:04 +0200 | [diff] [blame] | 25 | |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 26 | set(OPUS_BUILD_TESTING_HELP_STR "build tests.") |
| 27 | option(OPUS_BUILD_TESTING ${OPUS_BUILD_TESTING_HELP_STR} OFF) |
Marcus Asteborg | c401f21 | 2020-03-13 15:51:10 -0700 | [diff] [blame] | 28 | if(OPUS_BUILD_TESTING OR BUILD_TESTING) |
| 29 | set(OPUS_BUILD_TESTING ON) |
| 30 | set(BUILD_TESTING ON) |
| 31 | endif() |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 32 | add_feature_info(OPUS_BUILD_TESTING OPUS_BUILD_TESTING ${OPUS_BUILD_TESTING_HELP_STR}) |
| 33 | |
| 34 | set(OPUS_CUSTOM_MODES_HELP_STR "enable non-Opus modes, e.g. 44.1 kHz & 2^n frames.") |
| 35 | option(OPUS_CUSTOM_MODES ${OPUS_CUSTOM_MODES_HELP_STR} OFF) |
| 36 | add_feature_info(OPUS_CUSTOM_MODES OPUS_CUSTOM_MODES ${OPUS_CUSTOM_MODES_HELP_STR}) |
| 37 | |
| 38 | set(OPUS_BUILD_PROGRAMS_HELP_STR "build programs.") |
| 39 | option(OPUS_BUILD_PROGRAMS ${OPUS_BUILD_PROGRAMS_HELP_STR} OFF) |
| 40 | add_feature_info(OPUS_BUILD_PROGRAMS OPUS_BUILD_PROGRAMS ${OPUS_BUILD_PROGRAMS_HELP_STR}) |
| 41 | |
| 42 | set(OPUS_DISABLE_INTRINSICS_HELP_STR "disable all intrinsics optimizations.") |
| 43 | option(OPUS_DISABLE_INTRINSICS ${OPUS_DISABLE_INTRINSICS_HELP_STR} OFF) |
| 44 | add_feature_info(OPUS_DISABLE_INTRINSICS OPUS_DISABLE_INTRINSICS ${OPUS_DISABLE_INTRINSICS_HELP_STR}) |
| 45 | |
| 46 | set(OPUS_FIXED_POINT_HELP_STR "compile as fixed-point (for machines without a fast enough FPU).") |
| 47 | option(OPUS_FIXED_POINT ${OPUS_FIXED_POINT_HELP_STR} OFF) |
| 48 | add_feature_info(OPUS_FIXED_POINT OPUS_FIXED_POINT ${OPUS_FIXED_POINT_HELP_STR}) |
| 49 | |
| 50 | set(OPUS_ENABLE_FLOAT_API_HELP_STR "compile with the floating point API (for machines with float library).") |
| 51 | option(OPUS_ENABLE_FLOAT_API ${OPUS_ENABLE_FLOAT_API_HELP_STR} ON) |
Marcus Asteborg | 5edb5aa | 2020-07-12 21:03:34 -0700 | [diff] [blame] | 52 | add_feature_info(OPUS_ENABLE_FLOAT_API OPUS_ENABLE_FLOAT_API ${OPUS_ENABLE_FLOAT_API_HELP_STR}) |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 53 | |
| 54 | set(OPUS_FLOAT_APPROX_HELP_STR "enable floating point approximations (Ensure your platform supports IEEE 754 before enabling).") |
| 55 | option(OPUS_FLOAT_APPROX ${OPUS_FLOAT_APPROX_HELP_STR} OFF) |
| 56 | add_feature_info(OPUS_FLOAT_APPROX OPUS_FLOAT_APPROX ${OPUS_FLOAT_APPROX_HELP_STR}) |
| 57 | |
Marcus Asteborg | 1d5c815 | 2020-11-20 21:12:56 -0800 | [diff] [blame] | 58 | set(OPUS_ASSERTIONS_HELP_STR "additional software error checking.") |
| 59 | option(OPUS_ASSERTIONS ${OPUS_ASSERTIONS_HELP_STR} OFF) |
| 60 | add_feature_info(OPUS_ASSERTIONS OPUS_ASSERTIONS ${OPUS_ASSERTIONS_HELP_STR}) |
| 61 | |
Marcus Asteborg | b459e4c | 2020-11-20 21:22:48 -0800 | [diff] [blame] | 62 | set(OPUS_HARDENING_HELP_STR "run-time checks that are cheap and safe for use in production.") |
| 63 | option(OPUS_HARDENING ${OPUS_HARDENING_HELP_STR} ON) |
| 64 | add_feature_info(OPUS_HARDENING OPUS_HARDENING ${OPUS_HARDENING_HELP_STR}) |
| 65 | |
Marcus Asteborg | 2f37feb | 2020-11-20 21:28:56 -0800 | [diff] [blame] | 66 | set(OPUS_FUZZING_HELP_STR "causes the encoder to make random decisions (do not use in production).") |
| 67 | option(OPUS_FUZZING ${OPUS_FUZZING_HELP_STR} OFF) |
| 68 | add_feature_info(OPUS_FUZZING OPUS_FUZZING ${OPUS_FUZZING_HELP_STR}) |
| 69 | |
Marcus Asteborg | 5bdb3a5 | 2020-11-20 21:38:21 -0800 | [diff] [blame] | 70 | set(OPUS_CHECK_ASM_HELP_STR "enable bit-exactness checks between optimized and c implementations.") |
| 71 | option(OPUS_CHECK_ASM ${OPUS_CHECK_ASM_HELP_STR} OFF) |
| 72 | add_feature_info(OPUS_CHECK_ASM OPUS_CHECK_ASM ${OPUS_CHECK_ASM_HELP_STR}) |
| 73 | |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 74 | set(OPUS_INSTALL_PKG_CONFIG_MODULE_HELP_STR "install pkg-config module.") |
| 75 | option(OPUS_INSTALL_PKG_CONFIG_MODULE ${OPUS_INSTALL_PKG_CONFIG_MODULE_HELP_STR} ON) |
| 76 | add_feature_info(OPUS_INSTALL_PKG_CONFIG_MODULE OPUS_INSTALL_PKG_CONFIG_MODULE ${OPUS_INSTALL_PKG_CONFIG_MODULE_HELP_STR}) |
| 77 | |
| 78 | set(OPUS_INSTALL_CMAKE_CONFIG_MODULE_HELP_STR "install CMake package config module.") |
| 79 | option(OPUS_INSTALL_CMAKE_CONFIG_MODULE ${OPUS_INSTALL_CMAKE_CONFIG_MODULE_HELP_STR} ON) |
| 80 | add_feature_info(OPUS_INSTALL_CMAKE_CONFIG_MODULE OPUS_INSTALL_CMAKE_CONFIG_MODULE ${OPUS_INSTALL_CMAKE_CONFIG_MODULE_HELP_STR}) |
| 81 | |
| 82 | if(APPLE) |
| 83 | set(OPUS_BUILD_FRAMEWORK_HELP_STR "build Framework bundle for Apple systems.") |
| 84 | option(OPUS_BUILD_FRAMEWORK ${OPUS_BUILD_FRAMEWORK_HELP_STR} OFF) |
| 85 | add_feature_info(OPUS_BUILD_FRAMEWORK OPUS_BUILD_FRAMEWORK ${OPUS_BUILD_FRAMEWORK_HELP_STR}) |
| 86 | endif() |
| 87 | |
Marcus Asteborg | 841d57b | 2020-07-31 22:17:49 -0700 | [diff] [blame] | 88 | set(OPUS_FIXED_POINT_DEBUG_HELP_STR "debug fixed-point implementation.") |
| 89 | cmake_dependent_option(OPUS_FIXED_POINT_DEBUG |
| 90 | ${OPUS_FIXED_POINT_DEBUG_HELP_STR} |
| 91 | ON |
| 92 | "OPUS_FIXED_POINT; OPUS_FIXED_POINT_DEBUG" |
| 93 | OFF) |
| 94 | add_feature_info(OPUS_FIXED_POINT_DEBUG OPUS_FIXED_POINT_DEBUG ${OPUS_FIXED_POINT_DEBUG_HELP_STR}) |
| 95 | |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 96 | set(OPUS_VAR_ARRAYS_HELP_STR "use variable length arrays for stack arrays.") |
| 97 | cmake_dependent_option(OPUS_VAR_ARRAYS |
| 98 | ${OPUS_VAR_ARRAYS_HELP_STR} |
| 99 | ON |
| 100 | "VLA_SUPPORTED; NOT OPUS_USE_ALLOCA; NOT OPUS_NONTHREADSAFE_PSEUDOSTACK" |
| 101 | OFF) |
| 102 | add_feature_info(OPUS_VAR_ARRAYS OPUS_VAR_ARRAYS ${OPUS_VAR_ARRAYS_HELP_STR}) |
| 103 | |
| 104 | set(OPUS_USE_ALLOCA_HELP_STR "use alloca for stack arrays (on non-C99 compilers).") |
| 105 | cmake_dependent_option(OPUS_USE_ALLOCA |
| 106 | ${OPUS_USE_ALLOCA_HELP_STR} |
| 107 | ON |
| 108 | "USE_ALLOCA_SUPPORTED; NOT OPUS_VAR_ARRAYS; NOT OPUS_NONTHREADSAFE_PSEUDOSTACK" |
| 109 | OFF) |
| 110 | add_feature_info(OPUS_USE_ALLOCA OPUS_USE_ALLOCA ${OPUS_USE_ALLOCA_HELP_STR}) |
| 111 | |
| 112 | set(OPUS_NONTHREADSAFE_PSEUDOSTACK_HELP_STR "use a non threadsafe pseudostack when neither variable length arrays or alloca is supported.") |
| 113 | cmake_dependent_option(OPUS_NONTHREADSAFE_PSEUDOSTACK |
| 114 | ${OPUS_NONTHREADSAFE_PSEUDOSTACK_HELP_STR} |
| 115 | ON |
| 116 | "NOT OPUS_VAR_ARRAYS; NOT OPUS_USE_ALLOCA" |
| 117 | OFF) |
| 118 | add_feature_info(OPUS_NONTHREADSAFE_PSEUDOSTACK OPUS_NONTHREADSAFE_PSEUDOSTACK ${OPUS_NONTHREADSAFE_PSEUDOSTACK_HELP_STR}) |
| 119 | |
| 120 | set(OPUS_FAST_MATH_HELP_STR "enable fast math (unsupported and discouraged use, as code is not well tested with this build option).") |
| 121 | cmake_dependent_option(OPUS_FAST_MATH |
| 122 | ${OPUS_FAST_MATH_HELP_STR} |
| 123 | ON |
| 124 | "OPUS_FLOAT_APPROX; OPUS_FAST_MATH; FAST_MATH_SUPPORTED" |
| 125 | OFF) |
| 126 | add_feature_info(OPUS_FAST_MATH OPUS_FAST_MATH ${OPUS_FAST_MATH_HELP_STR}) |
| 127 | |
| 128 | set(OPUS_STACK_PROTECTOR_HELP_STR "use stack protection.") |
| 129 | cmake_dependent_option(OPUS_STACK_PROTECTOR |
| 130 | ${OPUS_STACK_PROTECTOR_HELP_STR} |
| 131 | ON |
| 132 | "STACK_PROTECTOR_SUPPORTED" |
| 133 | OFF) |
| 134 | add_feature_info(OPUS_STACK_PROTECTOR OPUS_STACK_PROTECTOR ${OPUS_STACK_PROTECTOR_HELP_STR}) |
Marcus Asteborg | c401f21 | 2020-03-13 15:51:10 -0700 | [diff] [blame] | 135 | |
Marcus Asteborg | b83dd52 | 2020-07-16 22:40:08 -0700 | [diff] [blame] | 136 | if(NOT MSVC) |
| 137 | set(OPUS_FORTIFY_SOURCE_HELP_STR "add protection against buffer overflows.") |
| 138 | cmake_dependent_option(OPUS_FORTIFY_SOURCE |
| 139 | ${OPUS_FORTIFY_SOURCE_HELP_STR} |
| 140 | ON |
| 141 | "FORTIFY_SOURCE_SUPPORTED" |
| 142 | OFF) |
| 143 | add_feature_info(OPUS_FORTIFY_SOURCE OPUS_FORTIFY_SOURCE ${OPUS_FORTIFY_SOURCE_HELP_STR}) |
| 144 | endif() |
| 145 | |
| 146 | if(MINGW AND (OPUS_FORTIFY_SOURCE OR OPUS_STACK_PROTECTOR)) |
| 147 | # ssp lib is needed for security features for MINGW |
| 148 | list(APPEND OPUS_REQUIRED_LIBRARIES ssp) |
Zeno Endemann | d4b8707 | 2020-07-15 21:45:42 +0200 | [diff] [blame] | 149 | endif() |
| 150 | |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 151 | if(OPUS_CPU_X86 OR OPUS_CPU_X64) |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 152 | set(OPUS_X86_MAY_HAVE_SSE_HELP_STR "does runtime check for SSE1 support.") |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 153 | cmake_dependent_option(OPUS_X86_MAY_HAVE_SSE |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 154 | ${OPUS_X86_MAY_HAVE_SSE_HELP_STR} |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 155 | ON |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 156 | "SSE1_SUPPORTED; NOT OPUS_DISABLE_INTRINSICS" |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 157 | OFF) |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 158 | add_feature_info(OPUS_X86_MAY_HAVE_SSE OPUS_X86_MAY_HAVE_SSE ${OPUS_X86_MAY_HAVE_SSE_HELP_STR}) |
| 159 | |
| 160 | set(OPUS_X86_MAY_HAVE_SSE2_HELP_STR "does runtime check for SSE2 support.") |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 161 | cmake_dependent_option(OPUS_X86_MAY_HAVE_SSE2 |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 162 | ${OPUS_X86_MAY_HAVE_SSE2_HELP_STR} |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 163 | ON |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 164 | "SSE2_SUPPORTED; NOT OPUS_DISABLE_INTRINSICS" |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 165 | OFF) |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 166 | add_feature_info(OPUS_X86_MAY_HAVE_SSE2 OPUS_X86_MAY_HAVE_SSE2 ${OPUS_X86_MAY_HAVE_SSE2_HELP_STR}) |
| 167 | |
| 168 | set(OPUS_X86_MAY_HAVE_SSE4_1_HELP_STR "does runtime check for SSE4.1 support.") |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 169 | cmake_dependent_option(OPUS_X86_MAY_HAVE_SSE4_1 |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 170 | ${OPUS_X86_MAY_HAVE_SSE4_1_HELP_STR} |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 171 | ON |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 172 | "SSE4_1_SUPPORTED; NOT OPUS_DISABLE_INTRINSICS" |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 173 | OFF) |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 174 | add_feature_info(OPUS_X86_MAY_HAVE_SSE4_1 OPUS_X86_MAY_HAVE_SSE4_1 ${OPUS_X86_MAY_HAVE_SSE4_1_HELP_STR}) |
| 175 | |
| 176 | set(OPUS_X86_MAY_HAVE_AVX_HELP_STR "does runtime check for AVX support.") |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 177 | cmake_dependent_option(OPUS_X86_MAY_HAVE_AVX |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 178 | ${OPUS_X86_MAY_HAVE_AVX_HELP_STR} |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 179 | ON |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 180 | "AVX_SUPPORTED; NOT OPUS_DISABLE_INTRINSICS" |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 181 | OFF) |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 182 | add_feature_info(OPUS_X86_MAY_HAVE_AVX OPUS_X86_MAY_HAVE_AVX ${OPUS_X86_MAY_HAVE_AVX_HELP_STR}) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 183 | |
Marcus Asteborg | 927de84 | 2020-03-13 13:31:29 -0700 | [diff] [blame] | 184 | # PRESUME depends on MAY HAVE, but PRESUME will override runtime detection |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 185 | set(OPUS_X86_PRESUME_SSE_HELP_STR "assume target CPU has SSE1 support (override runtime check).") |
| 186 | set(OPUS_X86_PRESUME_SSE2_HELP_STR "assume target CPU has SSE2 support (override runtime check).") |
| 187 | if(OPUS_CPU_X64) # Assume x86_64 has up to SSE2 support |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 188 | cmake_dependent_option(OPUS_X86_PRESUME_SSE |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 189 | ${OPUS_X86_PRESUME_SSE_HELP_STR} |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 190 | ON |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 191 | "OPUS_X86_MAY_HAVE_SSE; NOT OPUS_DISABLE_INTRINSICS" |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 192 | OFF) |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 193 | |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 194 | cmake_dependent_option(OPUS_X86_PRESUME_SSE2 |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 195 | ${OPUS_X86_PRESUME_SSE2_HELP_STR} |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 196 | ON |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 197 | "OPUS_X86_MAY_HAVE_SSE2; NOT OPUS_DISABLE_INTRINSICS" |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 198 | OFF) |
| 199 | else() |
| 200 | cmake_dependent_option(OPUS_X86_PRESUME_SSE |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 201 | ${OPUS_X86_PRESUME_SSE_HELP_STR} |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 202 | OFF |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 203 | "OPUS_X86_MAY_HAVE_SSE; NOT OPUS_DISABLE_INTRINSICS" |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 204 | OFF) |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 205 | |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 206 | cmake_dependent_option(OPUS_X86_PRESUME_SSE2 |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 207 | ${OPUS_X86_PRESUME_SSE2_HELP_STR} |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 208 | OFF |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 209 | "OPUS_X86_MAY_HAVE_SSE2; NOT OPUS_DISABLE_INTRINSICS" |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 210 | OFF) |
| 211 | endif() |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 212 | add_feature_info(OPUS_X86_PRESUME_SSE OPUS_X86_PRESUME_SSE ${OPUS_X86_PRESUME_SSE_HELP_STR}) |
| 213 | add_feature_info(OPUS_X86_PRESUME_SSE2 OPUS_X86_PRESUME_SSE2 ${OPUS_X86_PRESUME_SSE2_HELP_STR}) |
| 214 | |
| 215 | set(OPUS_X86_PRESUME_SSE4_1_HELP_STR "assume target CPU has SSE4.1 support (override runtime check).") |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 216 | cmake_dependent_option(OPUS_X86_PRESUME_SSE4_1 |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 217 | ${OPUS_X86_PRESUME_SSE4_1_HELP_STR} |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 218 | OFF |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 219 | "OPUS_X86_MAY_HAVE_SSE4_1; NOT OPUS_DISABLE_INTRINSICS" |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 220 | OFF) |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 221 | add_feature_info(OPUS_X86_PRESUME_SSE4_1 OPUS_X86_PRESUME_SSE4_1 ${OPUS_X86_PRESUME_SSE4_1_HELP_STR}) |
| 222 | |
| 223 | set(OPUS_X86_PRESUME_AVX_HELP_STR "assume target CPU has AVX support (override runtime check).") |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 224 | cmake_dependent_option(OPUS_X86_PRESUME_AVX |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 225 | ${OPUS_X86_PRESUME_AVX_HELP_STR} |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 226 | OFF |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 227 | "OPUS_X86_MAY_HAVE_AVX; NOT OPUS_DISABLE_INTRINSICS" |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 228 | OFF) |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 229 | add_feature_info(OPUS_X86_PRESUME_AVX OPUS_X86_PRESUME_AVX ${OPUS_X86_PRESUME_AVX_HELP_STR}) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 230 | endif() |
| 231 | |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 232 | feature_summary(WHAT ALL) |
| 233 | |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 234 | set_package_properties(Git |
| 235 | PROPERTIES |
| 236 | TYPE |
| 237 | REQUIRED |
| 238 | DESCRIPTION |
| 239 | "fast, scalable, distributed revision control system" |
| 240 | URL |
| 241 | "https://git-scm.com/" |
| 242 | PURPOSE |
| 243 | "required to set up package version") |
| 244 | |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 245 | set(Opus_PUBLIC_HEADER |
| 246 | ${CMAKE_CURRENT_SOURCE_DIR}/include/opus.h |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 247 | ${CMAKE_CURRENT_SOURCE_DIR}/include/opus_defines.h |
| 248 | ${CMAKE_CURRENT_SOURCE_DIR}/include/opus_multistream.h |
| 249 | ${CMAKE_CURRENT_SOURCE_DIR}/include/opus_projection.h |
| 250 | ${CMAKE_CURRENT_SOURCE_DIR}/include/opus_types.h) |
| 251 | |
Marcus Asteborg | f2f8f33 | 2020-04-22 20:29:37 -0700 | [diff] [blame] | 252 | if(OPUS_CUSTOM_MODES) |
| 253 | list(APPEND Opus_PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include/opus_custom.h) |
| 254 | endif() |
| 255 | |
Marcus Asteborg | 7f01183 | 2020-04-22 20:17:57 -0700 | [diff] [blame] | 256 | add_library(opus ${opus_headers} ${opus_sources} ${opus_sources_float} ${Opus_PUBLIC_HEADER}) |
Simon Jackson | b254701 | 2020-04-15 17:58:55 +0100 | [diff] [blame] | 257 | add_library(Opus::opus ALIAS opus) |
| 258 | |
Marcus Asteborg | 8ad827c | 2020-06-24 21:25:57 -0700 | [diff] [blame] | 259 | get_library_version(OPUS_LIBRARY_VERSION OPUS_LIBRARY_VERSION_MAJOR) |
Marcus Asteborg | 93fe345 | 2020-08-28 16:17:50 -0700 | [diff] [blame] | 260 | message(DEBUG "Opus library version: ${OPUS_LIBRARY_VERSION}") |
Marcus Asteborg | 8ad827c | 2020-06-24 21:25:57 -0700 | [diff] [blame] | 261 | |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 262 | set_target_properties(opus |
| 263 | PROPERTIES SOVERSION |
| 264 | ${OPUS_LIBRARY_VERSION_MAJOR} |
| 265 | VERSION |
| 266 | ${OPUS_LIBRARY_VERSION} |
| 267 | PUBLIC_HEADER |
| 268 | "${Opus_PUBLIC_HEADER}") |
| 269 | |
| 270 | target_include_directories( |
| 271 | opus |
| 272 | PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 273 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
evpobr | d637b90 | 2020-01-26 18:11:01 +0500 | [diff] [blame] | 274 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/opus> |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 275 | PRIVATE ${CMAKE_CURRENT_BINARY_DIR} |
| 276 | ${CMAKE_CURRENT_SOURCE_DIR} |
| 277 | celt |
| 278 | silk) |
| 279 | |
| 280 | target_link_libraries(opus PRIVATE ${OPUS_REQUIRED_LIBRARIES}) |
Marcus Asteborg | b459e4c | 2020-11-20 21:22:48 -0800 | [diff] [blame] | 281 | target_compile_definitions(opus PRIVATE OPUS_BUILD) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 282 | |
Marcus Asteborg | 841d57b | 2020-07-31 22:17:49 -0700 | [diff] [blame] | 283 | if(OPUS_FIXED_POINT_DEBUG) |
| 284 | target_compile_definitions(opus PRIVATE FIXED_DEBUG) |
| 285 | endif() |
| 286 | |
Marcus Asteborg | b83dd52 | 2020-07-16 22:40:08 -0700 | [diff] [blame] | 287 | if(OPUS_FORTIFY_SOURCE AND NOT MSVC) |
| 288 | target_compile_definitions(opus PRIVATE |
| 289 | $<$<NOT:$<CONFIG:debug>>:_FORTIFY_SOURCE=2>) |
Marcus Asteborg | 268780f | 2019-04-10 16:34:01 -0700 | [diff] [blame] | 290 | endif() |
| 291 | |
Marcus Asteborg | c5c986a | 2020-04-13 15:59:50 -0700 | [diff] [blame] | 292 | if(OPUS_FLOAT_APPROX) |
| 293 | target_compile_definitions(opus PRIVATE FLOAT_APPROX) |
| 294 | endif() |
| 295 | |
Marcus Asteborg | 1d5c815 | 2020-11-20 21:12:56 -0800 | [diff] [blame] | 296 | if(OPUS_ASSERTIONS) |
| 297 | target_compile_definitions(opus PRIVATE ENABLE_ASSERTIONS) |
| 298 | endif() |
| 299 | |
Marcus Asteborg | b459e4c | 2020-11-20 21:22:48 -0800 | [diff] [blame] | 300 | if(OPUS_HARDENING) |
| 301 | target_compile_definitions(opus PRIVATE ENABLE_HARDENING) |
| 302 | endif() |
| 303 | |
Marcus Asteborg | 2f37feb | 2020-11-20 21:28:56 -0800 | [diff] [blame] | 304 | if(OPUS_FUZZING) |
| 305 | target_compile_definitions(opus PRIVATE FUZZING) |
| 306 | endif() |
| 307 | |
Marcus Asteborg | 5bdb3a5 | 2020-11-20 21:38:21 -0800 | [diff] [blame] | 308 | if(OPUS_CHECK_ASM) |
| 309 | target_compile_definitions(opus PRIVATE OPUS_CHECK_ASM) |
| 310 | endif() |
| 311 | |
Marcus Asteborg | a0e14e7 | 2020-04-13 15:51:48 -0700 | [diff] [blame] | 312 | if(OPUS_VAR_ARRAYS) |
Marcus Asteborg | 268780f | 2019-04-10 16:34:01 -0700 | [diff] [blame] | 313 | target_compile_definitions(opus PRIVATE VAR_ARRAYS) |
Marcus Asteborg | a0e14e7 | 2020-04-13 15:51:48 -0700 | [diff] [blame] | 314 | elseif(OPUS_USE_ALLOCA) |
| 315 | target_compile_definitions(opus PRIVATE USE_ALLOCA) |
| 316 | elseif(OPUS_NONTHREADSAFE_PSEUDOSTACK) |
| 317 | target_compile_definitions(opus PRIVATE NONTHREADSAFE_PSEUDOSTACK) |
| 318 | else() |
Marcus Asteborg | 87cdaae | 2020-06-04 17:35:13 -0700 | [diff] [blame] | 319 | message(ERROR "Need to set a define for stack allocation") |
Marcus Asteborg | 268780f | 2019-04-10 16:34:01 -0700 | [diff] [blame] | 320 | endif() |
| 321 | |
| 322 | if(OPUS_CUSTOM_MODES) |
| 323 | target_compile_definitions(opus PRIVATE CUSTOM_MODES) |
| 324 | endif() |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 325 | |
Marcus Asteborg | c350cec | 2020-04-27 08:52:57 -0700 | [diff] [blame] | 326 | if(OPUS_FAST_MATH) |
| 327 | if(MSVC) |
| 328 | target_compile_options(opus PRIVATE /fp:fast) |
| 329 | else() |
| 330 | target_compile_options(opus PRIVATE -ffast-math) |
| 331 | endif() |
| 332 | endif() |
| 333 | |
| 334 | if(OPUS_STACK_PROTECTOR) |
| 335 | if(MSVC) |
| 336 | target_compile_options(opus PRIVATE /GS) |
| 337 | else() |
| 338 | target_compile_options(opus PRIVATE -fstack-protector-strong) |
| 339 | endif() |
| 340 | elseif(STACK_PROTECTOR_DISABLED_SUPPORTED) |
| 341 | target_compile_options(opus PRIVATE /GS-) |
| 342 | endif() |
| 343 | |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 344 | if(BUILD_SHARED_LIBS) |
| 345 | if(WIN32) |
| 346 | target_compile_definitions(opus PRIVATE DLL_EXPORT) |
Marcus Asteborg | c350cec | 2020-04-27 08:52:57 -0700 | [diff] [blame] | 347 | elseif(HIDDEN_VISIBILITY_SUPPORTED) |
| 348 | set_target_properties(opus PROPERTIES C_VISIBILITY_PRESET hidden) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 349 | endif() |
| 350 | endif() |
| 351 | |
Marcus Asteborg | 7f01183 | 2020-04-22 20:17:57 -0700 | [diff] [blame] | 352 | add_sources_group(opus silk ${silk_headers} ${silk_sources}) |
| 353 | add_sources_group(opus celt ${celt_headers} ${celt_sources}) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 354 | |
| 355 | if(OPUS_FIXED_POINT) |
| 356 | add_sources_group(opus silk ${silk_sources_fixed}) |
| 357 | target_include_directories(opus PRIVATE silk/fixed) |
| 358 | target_compile_definitions(opus PRIVATE FIXED_POINT=1) |
| 359 | else() |
| 360 | add_sources_group(opus silk ${silk_sources_float}) |
| 361 | target_include_directories(opus PRIVATE silk/float) |
| 362 | endif() |
| 363 | |
| 364 | if(NOT OPUS_ENABLE_FLOAT_API) |
| 365 | target_compile_definitions(opus PRIVATE DISABLE_FLOAT_API) |
| 366 | endif() |
| 367 | |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 368 | if(NOT OPUS_DISABLE_INTRINSICS) |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 369 | if((OPUS_X86_MAY_HAVE_SSE AND NOT OPUS_X86_PRESUME_SSE) OR |
| 370 | (OPUS_X86_MAY_HAVE_SSE2 AND NOT OPUS_X86_PRESUME_SSE2) OR |
| 371 | (OPUS_X86_MAY_HAVE_SSE4_1 AND NOT OPUS_X86_PRESUME_SSE4_1) OR |
| 372 | (OPUS_X86_MAY_HAVE_AVX AND NOT OPUS_X86_PRESUME_AVX)) |
| 373 | target_compile_definitions(opus PRIVATE OPUS_HAVE_RTCD) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 374 | endif() |
Marcus Asteborg | 927de84 | 2020-03-13 13:31:29 -0700 | [diff] [blame] | 375 | |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 376 | if(SSE1_SUPPORTED) |
| 377 | if(OPUS_X86_MAY_HAVE_SSE) |
| 378 | add_sources_group(opus celt ${celt_sources_sse}) |
| 379 | target_compile_definitions(opus PRIVATE OPUS_X86_MAY_HAVE_SSE) |
Marcus Asteborg | 927de84 | 2020-03-13 13:31:29 -0700 | [diff] [blame] | 380 | if(NOT MSVC) |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 381 | set_source_files_properties(${celt_sources_sse} PROPERTIES COMPILE_FLAGS -msse) |
| 382 | endif() |
| 383 | endif() |
| 384 | if(OPUS_X86_PRESUME_SSE) |
| 385 | target_compile_definitions(opus PRIVATE OPUS_X86_PRESUME_SSE) |
| 386 | if(NOT MSVC) |
| 387 | target_compile_options(opus PRIVATE -msse) |
Marcus Asteborg | 927de84 | 2020-03-13 13:31:29 -0700 | [diff] [blame] | 388 | endif() |
| 389 | endif() |
| 390 | endif() |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 391 | |
| 392 | if(SSE2_SUPPORTED) |
| 393 | if(OPUS_X86_MAY_HAVE_SSE2) |
| 394 | add_sources_group(opus celt ${celt_sources_sse2}) |
| 395 | target_compile_definitions(opus PRIVATE OPUS_X86_MAY_HAVE_SSE2) |
| 396 | if(NOT MSVC) |
| 397 | set_source_files_properties(${celt_sources_sse2} PROPERTIES COMPILE_FLAGS -msse2) |
| 398 | endif() |
| 399 | endif() |
| 400 | if(OPUS_X86_PRESUME_SSE2) |
| 401 | target_compile_definitions(opus PRIVATE OPUS_X86_PRESUME_SSE2) |
| 402 | if(NOT MSVC) |
| 403 | target_compile_options(opus PRIVATE -msse2) |
| 404 | endif() |
Marcus Asteborg | 927de84 | 2020-03-13 13:31:29 -0700 | [diff] [blame] | 405 | endif() |
| 406 | endif() |
Marcus Asteborg | 927de84 | 2020-03-13 13:31:29 -0700 | [diff] [blame] | 407 | |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 408 | if(SSE4_1_SUPPORTED) |
| 409 | if(OPUS_X86_MAY_HAVE_SSE4_1) |
| 410 | add_sources_group(opus celt ${celt_sources_sse4_1}) |
| 411 | add_sources_group(opus silk ${silk_sources_sse4_1}) |
| 412 | target_compile_definitions(opus PRIVATE OPUS_X86_MAY_HAVE_SSE4_1) |
| 413 | if(NOT MSVC) |
| 414 | set_source_files_properties(${celt_sources_sse4_1} ${silk_sources_sse4_1} PROPERTIES COMPILE_FLAGS -msse4.1) |
| 415 | endif() |
| 416 | |
| 417 | if(OPUS_FIXED_POINT) |
| 418 | add_sources_group(opus silk ${silk_sources_fixed_sse4_1}) |
| 419 | if(NOT MSVC) |
| 420 | set_source_files_properties(${silk_sources_fixed_sse4_1} PROPERTIES COMPILE_FLAGS -msse4.1) |
| 421 | endif() |
| 422 | endif() |
| 423 | endif() |
| 424 | if(OPUS_X86_PRESUME_SSE4_1) |
| 425 | target_compile_definitions(opus PRIVATE OPUS_X86_PRESUME_SSE4_1) |
| 426 | if(NOT MSVC) |
| 427 | target_compile_options(opus PRIVATE -msse4.1) |
| 428 | endif() |
Marcus Asteborg | 927de84 | 2020-03-13 13:31:29 -0700 | [diff] [blame] | 429 | endif() |
| 430 | endif() |
Marcus Asteborg | 927de84 | 2020-03-13 13:31:29 -0700 | [diff] [blame] | 431 | |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 432 | if(AVX_SUPPORTED) |
| 433 | # mostly placeholder in case of avx intrinsics is added |
| 434 | if(OPUS_X86_MAY_HAVE_AVX) |
| 435 | target_compile_definitions(opus PRIVATE OPUS_X86_MAY_HAVE_AVX) |
| 436 | endif() |
| 437 | if(OPUS_X86_PRESUME_AVX) |
| 438 | target_compile_definitions(opus PRIVATE OPUS_X86_PRESUME_AVX) |
| 439 | if(NOT MSVC) |
| 440 | target_compile_options(opus PRIVATE -mavx) |
| 441 | endif() |
Marcus Asteborg | 927de84 | 2020-03-13 13:31:29 -0700 | [diff] [blame] | 442 | endif() |
| 443 | endif() |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 444 | |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 445 | if(MSVC) |
| 446 | if(AVX_SUPPORTED AND OPUS_X86_PRESUME_AVX) # on 64 bit and 32 bits |
| 447 | add_definitions(/arch:AVX) |
| 448 | elseif(OPUS_CPU_X86) # if AVX not supported then set SSE flag |
| 449 | if((SSE4_1_SUPPORTED AND OPUS_X86_PRESUME_SSE4_1) |
| 450 | OR (SSE2_SUPPORTED AND OPUS_X86_PRESUME_SSE2)) |
| 451 | target_compile_definitions(opus PRIVATE /arch:SSE2) |
| 452 | elseif(SSE1_SUPPORTED AND OPUS_X86_PRESUME_SSE) |
| 453 | target_compile_definitions(opus PRIVATE /arch:SSE) |
| 454 | endif() |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 455 | endif() |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 456 | endif() |
| 457 | |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 458 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm|aarch64)") |
| 459 | add_sources_group(opus celt ${celt_sources_arm}) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 460 | endif() |
| 461 | |
Marcus Asteborg | 97fca1b | 2020-04-27 12:19:59 -0700 | [diff] [blame] | 462 | if(COMPILER_SUPPORT_NEON) |
| 463 | if(OPUS_MAY_HAVE_NEON) |
| 464 | if(RUNTIME_CPU_CAPABILITY_DETECTION) |
| 465 | message(STATUS "OPUS_MAY_HAVE_NEON enabling runtime detection") |
| 466 | target_compile_definitions(opus PRIVATE OPUS_HAVE_RTCD) |
| 467 | else() |
| 468 | message(ERROR "Runtime cpu capability detection needed for MAY_HAVE_NEON") |
| 469 | endif() |
| 470 | # Do runtime check for NEON |
| 471 | target_compile_definitions(opus |
| 472 | PRIVATE |
| 473 | OPUS_ARM_MAY_HAVE_NEON |
| 474 | OPUS_ARM_MAY_HAVE_NEON_INTR) |
| 475 | endif() |
| 476 | |
| 477 | add_sources_group(opus celt ${celt_sources_arm_neon_intr}) |
| 478 | add_sources_group(opus silk ${silk_sources_arm_neon_intr}) |
| 479 | |
| 480 | # silk arm neon depends on main_Fix.h |
| 481 | target_include_directories(opus PRIVATE silk/fixed) |
| 482 | |
| 483 | if(OPUS_FIXED_POINT) |
| 484 | add_sources_group(opus silk ${silk_sources_fixed_arm_neon_intr}) |
| 485 | endif() |
| 486 | |
| 487 | if(OPUS_PRESUME_NEON) |
| 488 | target_compile_definitions(opus |
| 489 | PRIVATE |
| 490 | OPUS_ARM_PRESUME_NEON |
| 491 | OPUS_ARM_PRESUME_NEON_INTR) |
| 492 | endif() |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 493 | endif() |
| 494 | endif() |
| 495 | |
Nathaniel R. Lewis | 94b68f3 | 2019-05-09 21:38:14 -0700 | [diff] [blame] | 496 | target_compile_definitions(opus |
| 497 | PRIVATE |
| 498 | $<$<BOOL:${HAVE_LRINT}>:HAVE_LRINT> |
| 499 | $<$<BOOL:${HAVE_LRINTF}>:HAVE_LRINTF>) |
| 500 | |
Simon Jackson | b254701 | 2020-04-15 17:58:55 +0100 | [diff] [blame] | 501 | if(OPUS_BUILD_FRAMEWORK) |
| 502 | set_target_properties(opus PROPERTIES |
| 503 | FRAMEWORK TRUE |
| 504 | FRAMEWORK_VERSION ${PROJECT_VERSION} |
| 505 | MACOSX_FRAMEWORK_IDENTIFIER org.xiph.opus |
| 506 | MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PROJECT_VERSION} |
| 507 | MACOSX_FRAMEWORK_BUNDLE_VERSION ${PROJECT_VERSION} |
| 508 | XCODE_ATTRIBUTE_INSTALL_PATH "@rpath" |
| 509 | OUTPUT_NAME Opus) |
| 510 | endif() |
| 511 | |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 512 | install(TARGETS opus |
| 513 | EXPORT OpusTargets |
| 514 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 515 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 516 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
Simon Jackson | b254701 | 2020-04-15 17:58:55 +0100 | [diff] [blame] | 517 | FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX} |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 518 | PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/opus) |
| 519 | |
| 520 | if(OPUS_INSTALL_PKG_CONFIG_MODULE) |
| 521 | set(prefix ${CMAKE_INSTALL_PREFIX}) |
| 522 | set(exec_prefix ${CMAKE_INSTALL_PREFIX}) |
| 523 | set(libdir ${CMAKE_INSTALL_FULL_LIBDIR}) |
| 524 | set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR}) |
DeadSix27 | 6d29f51 | 2019-12-05 06:00:58 +0100 | [diff] [blame] | 525 | set(VERSION ${PACKAGE_VERSION}) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 526 | if(HAVE_LIBM) |
| 527 | set(LIBM "-lm") |
| 528 | endif() |
| 529 | configure_file(opus.pc.in opus.pc) |
| 530 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/opus.pc |
| 531 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) |
| 532 | endif() |
| 533 | |
| 534 | if(OPUS_INSTALL_CMAKE_CONFIG_MODULE) |
Marcus Asteborg | e780645 | 2020-03-26 23:13:04 -0700 | [diff] [blame] | 535 | set(CPACK_GENERATOR TGZ) |
| 536 | include(CPack) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 537 | set(CMAKE_INSTALL_PACKAGEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) |
| 538 | install(EXPORT OpusTargets |
| 539 | NAMESPACE Opus:: |
| 540 | DESTINATION ${CMAKE_INSTALL_PACKAGEDIR}) |
| 541 | |
| 542 | include(CMakePackageConfigHelpers) |
| 543 | |
| 544 | set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}) |
Marcus Asteborg | 8ad827c | 2020-06-24 21:25:57 -0700 | [diff] [blame] | 545 | configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/OpusConfig.cmake.in |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 546 | OpusConfig.cmake |
| 547 | INSTALL_DESTINATION |
| 548 | ${CMAKE_INSTALL_PACKAGEDIR} |
| 549 | PATH_VARS |
| 550 | INCLUDE_INSTALL_DIR |
| 551 | INSTALL_PREFIX |
| 552 | ${CMAKE_INSTALL_PREFIX}) |
| 553 | write_basic_package_version_file(OpusConfigVersion.cmake |
| 554 | VERSION ${PROJECT_VERSION} |
| 555 | COMPATIBILITY SameMajorVersion) |
| 556 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/OpusConfig.cmake |
| 557 | ${CMAKE_CURRENT_BINARY_DIR}/OpusConfigVersion.cmake |
| 558 | DESTINATION ${CMAKE_INSTALL_PACKAGEDIR}) |
| 559 | endif() |
| 560 | |
Marcus Asteborg | 268780f | 2019-04-10 16:34:01 -0700 | [diff] [blame] | 561 | if(OPUS_BUILD_PROGRAMS) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 562 | # demo |
Marcus Asteborg | 268780f | 2019-04-10 16:34:01 -0700 | [diff] [blame] | 563 | if(OPUS_CUSTOM_MODES) |
| 564 | add_executable(opus_custom_demo ${opus_custom_demo_sources}) |
| 565 | target_include_directories(opus_custom_demo |
| 566 | PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
| 567 | target_link_libraries(opus_custom_demo PRIVATE opus) |
| 568 | endif() |
| 569 | |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 570 | add_executable(opus_demo ${opus_demo_sources}) |
| 571 | target_include_directories(opus_demo PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
Marcus Asteborg | 268780f | 2019-04-10 16:34:01 -0700 | [diff] [blame] | 572 | target_include_directories(opus_demo PRIVATE silk) # debug.h |
| 573 | target_include_directories(opus_demo PRIVATE celt) # arch.h |
willson-chen | ddb2c97 | 2019-12-19 16:59:32 +0800 | [diff] [blame] | 574 | target_link_libraries(opus_demo PRIVATE opus ${OPUS_REQUIRED_LIBRARIES}) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 575 | |
| 576 | # compare |
| 577 | add_executable(opus_compare ${opus_compare_sources}) |
| 578 | target_include_directories(opus_compare PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
willson-chen | ddb2c97 | 2019-12-19 16:59:32 +0800 | [diff] [blame] | 579 | target_link_libraries(opus_compare PRIVATE opus ${OPUS_REQUIRED_LIBRARIES}) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 580 | endif() |
| 581 | |
| 582 | if(BUILD_TESTING) |
| 583 | enable_testing() |
| 584 | |
| 585 | # tests |
| 586 | add_executable(test_opus_decode ${test_opus_decode_sources}) |
| 587 | target_include_directories(test_opus_decode |
| 588 | PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
| 589 | target_link_libraries(test_opus_decode PRIVATE opus) |
| 590 | if(OPUS_FIXED_POINT) |
| 591 | target_compile_definitions(test_opus_decode PRIVATE DISABLE_FLOAT_API) |
| 592 | endif() |
Davide Beatrici | f040fb0 | 2020-06-05 01:19:21 +0200 | [diff] [blame] | 593 | add_test(NAME test_opus_decode COMMAND $<TARGET_FILE:test_opus_decode> WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 594 | |
| 595 | add_executable(test_opus_padding ${test_opus_padding_sources}) |
| 596 | target_include_directories(test_opus_padding |
| 597 | PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
| 598 | target_link_libraries(test_opus_padding PRIVATE opus) |
Davide Beatrici | f040fb0 | 2020-06-05 01:19:21 +0200 | [diff] [blame] | 599 | add_test(NAME test_opus_padding COMMAND $<TARGET_FILE:test_opus_padding> WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 600 | |
| 601 | if(NOT BUILD_SHARED_LIBS) |
| 602 | # disable tests that depends on private API when building shared lib |
| 603 | add_executable(test_opus_api ${test_opus_api_sources}) |
| 604 | target_include_directories(test_opus_api |
| 605 | PRIVATE ${CMAKE_CURRENT_BINARY_DIR} celt) |
| 606 | target_link_libraries(test_opus_api PRIVATE opus) |
| 607 | if(OPUS_FIXED_POINT) |
| 608 | target_compile_definitions(test_opus_api PRIVATE DISABLE_FLOAT_API) |
| 609 | endif() |
Davide Beatrici | f040fb0 | 2020-06-05 01:19:21 +0200 | [diff] [blame] | 610 | add_test(NAME test_opus_api COMMAND $<TARGET_FILE:test_opus_api> WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 611 | |
| 612 | add_executable(test_opus_encode ${test_opus_encode_sources}) |
| 613 | target_include_directories(test_opus_encode |
| 614 | PRIVATE ${CMAKE_CURRENT_BINARY_DIR} celt) |
| 615 | target_link_libraries(test_opus_encode PRIVATE opus) |
Davide Beatrici | f040fb0 | 2020-06-05 01:19:21 +0200 | [diff] [blame] | 616 | add_test(NAME test_opus_encode COMMAND $<TARGET_FILE:test_opus_encode> WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) |
Marcus Asteborg | f9d3d43 | 2018-11-15 19:48:38 -0800 | [diff] [blame] | 617 | endif() |
| 618 | endif() |