Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.xiph.org/xiph/opus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorMarcus Asteborg <maastebo@microsoft.com>2020-04-23 08:06:11 +0300
committerMark Harris <mark.hsj@gmail.com>2020-06-13 10:20:56 +0300
commit48055ccc235a287c2ccf143a7196281a78a7746d (patch)
tree7eac98462a67dc99a252393c735a82dfc514c630 /cmake
parentf2f8f338731787962971106654273aaa8b912a53 (diff)
cmake - move cmake related files to cmake folder to make root dir less busy
Signed-off-by: Mark Harris <mark.hsj@gmail.com>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/OpusBuildtype.cmake23
-rw-r--r--cmake/OpusConfig.cmake63
-rw-r--r--cmake/OpusConfig.cmake.in20
-rw-r--r--cmake/OpusFunctions.cmake275
-rw-r--r--cmake/OpusSources.cmake41
-rw-r--r--cmake/config.h.cmake.in1
6 files changed, 423 insertions, 0 deletions
diff --git a/cmake/OpusBuildtype.cmake b/cmake/OpusBuildtype.cmake
new file mode 100644
index 00000000..aaee9eff
--- /dev/null
+++ b/cmake/OpusBuildtype.cmake
@@ -0,0 +1,23 @@
+# Set a default build type if none was specified
+
+if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+ if(CMAKE_C_FLAGS)
+ message(STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS})
+ else()
+ set(default_build_type "Release")
+ message(
+ STATUS
+ "Setting build type to '${default_build_type}' as none was specified and no CFLAGS was exported."
+ )
+ set(CMAKE_BUILD_TYPE "${default_build_type}"
+ CACHE STRING "Choose the type of build."
+ FORCE)
+ # Set the possible values of build type for cmake-gui
+ set_property(CACHE CMAKE_BUILD_TYPE
+ PROPERTY STRINGS
+ "Debug"
+ "Release"
+ "MinSizeRel"
+ "RelWithDebInfo")
+ endif()
+endif()
diff --git a/cmake/OpusConfig.cmake b/cmake/OpusConfig.cmake
new file mode 100644
index 00000000..cb20e7fc
--- /dev/null
+++ b/cmake/OpusConfig.cmake
@@ -0,0 +1,63 @@
+include(OpusFunctions)
+
+configure_file(${CMAKE_SOURCE_DIR}/cmake/config.h.cmake.in config.h @ONLY)
+add_definitions(-DHAVE_CONFIG_H)
+
+set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+set_property(GLOBAL PROPERTY C_STANDARD 99)
+
+if(MSVC)
+ add_definitions(-D_CRT_SECURE_NO_WARNINGS)
+endif()
+
+include(CheckLibraryExists)
+check_library_exists(m floor "" HAVE_LIBM)
+if(HAVE_LIBM)
+ list(APPEND OPUS_REQUIRED_LIBRARIES m)
+endif()
+
+include(CFeatureCheck)
+c_feature_check(VLA)
+
+include(CheckIncludeFile)
+check_include_file(alloca.h HAVE_ALLOCA_H)
+
+include(CheckSymbolExists)
+if(HAVE_ALLOCA_H)
+ add_definitions(-DHAVE_ALLOCA_H)
+ check_symbol_exists(alloca "alloca.h" USE_ALLOCA_SUPPORTED)
+else()
+ check_symbol_exists(alloca "stdlib.h;malloc.h" USE_ALLOCA_SUPPORTED)
+endif()
+
+include(CheckFunctionExists)
+check_function_exists(lrintf HAVE_LRINTF)
+check_function_exists(lrint HAVE_LRINT)
+
+if(CMAKE_SYSTEM_PROCESSOR MATCHES "(i[0-9]86|x86|X86|amd64|AMD64|x86_64)")
+ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(OPUS_CPU_X64 1)
+ else()
+ set(OPUS_CPU_X86 1)
+ endif()
+elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm|aarch64)")
+ set(OPUS_CPU_ARM 1)
+endif()
+
+opus_supports_cpu_detection(RUNTIME_CPU_CAPABILITY_DETECTION)
+
+if(OPUS_CPU_X86 OR OPUS_CPU_X64)
+ opus_detect_sse(COMPILER_SUPPORT_SIMD)
+elseif(OPUS_CPU_ARM)
+ opus_detect_neon(COMPILER_SUPPORT_NEON)
+ if(COMPILER_SUPPORT_NEON)
+ option(OPUS_USE_NEON "Option to enable NEON" ON)
+ option(OPUS_MAY_HAVE_NEON "Does runtime check for neon support" ON)
+ option(OPUS_PRESUME_NEON "Assume target CPU has NEON support" OFF)
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
+ set(OPUS_PRESUME_NEON ON)
+ elseif(CMAKE_SYSTEM_NAME MATCHES "iOS")
+ set(OPUS_PRESUME_NEON ON)
+ endif()
+ endif()
+endif()
diff --git a/cmake/OpusConfig.cmake.in b/cmake/OpusConfig.cmake.in
new file mode 100644
index 00000000..0b21231d
--- /dev/null
+++ b/cmake/OpusConfig.cmake.in
@@ -0,0 +1,20 @@
+set(OPUS_VERSION @PROJECT_VERSION@)
+set(OPUS_VERSION_STRING @PROJECT_VERSION@)
+set(OPUS_VERSION_MAJOR @PROJECT_VERSION_MAJOR@)
+set(OPUS_VERSION_MINOR @PROJECT_VERSION_MINOR@)
+set(OPUS_VERSION_PATCH @PROJECT_VERSION_PATCH@)
+
+@PACKAGE_INIT@
+
+set_and_check(OPUS_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
+set(OPUS_INCLUDE_DIR ${OPUS_INCLUDE_DIR};${OPUS_INCLUDE_DIR}/opus)
+set(OPUS_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@;@PACKAGE_INCLUDE_INSTALL_DIR@/opus")
+
+include(${CMAKE_CURRENT_LIST_DIR}/OpusTargets.cmake)
+
+set(OPUS_LIBRARY Opus::opus)
+set(OPUS_LIBRARIES Opus::opus)
+
+check_required_components(Opus)
+
+set(OPUS_FOUND 1)
diff --git a/cmake/OpusFunctions.cmake b/cmake/OpusFunctions.cmake
new file mode 100644
index 00000000..a3ac1c09
--- /dev/null
+++ b/cmake/OpusFunctions.cmake
@@ -0,0 +1,275 @@
+#[[Cmake helper function to parse source files from make files
+this is to avoid breaking existing make and auto make support
+but still have the option to use CMake with only lists at one place]]
+
+cmake_minimum_required(VERSION 3.1)
+
+function(get_library_version OPUS_LIBRARY_VERSION OPUS_LIBRARY_VERSION_MAJOR)
+ file(STRINGS configure.ac opus_lt_current_string
+ LIMIT_COUNT 1
+ REGEX "OPUS_LT_CURRENT=")
+ string(REGEX MATCH
+ "OPUS_LT_CURRENT=([0-9]*)"
+ _
+ ${opus_lt_current_string})
+ set(OPUS_LT_CURRENT ${CMAKE_MATCH_1})
+
+ file(STRINGS configure.ac opus_lt_revision_string
+ LIMIT_COUNT 1
+ REGEX "OPUS_LT_REVISION=")
+ string(REGEX MATCH
+ "OPUS_LT_REVISION=([0-9]*)"
+ _
+ ${opus_lt_revision_string})
+ set(OPUS_LT_REVISION ${CMAKE_MATCH_1})
+
+ file(STRINGS configure.ac opus_lt_age_string
+ LIMIT_COUNT 1
+ REGEX "OPUS_LT_AGE=")
+ string(REGEX MATCH
+ "OPUS_LT_AGE=([0-9]*)"
+ _
+ ${opus_lt_age_string})
+ set(OPUS_LT_AGE ${CMAKE_MATCH_1})
+
+ math(EXPR OPUS_LIBRARY_VERSION_MAJOR "${OPUS_LT_CURRENT} - ${OPUS_LT_AGE}")
+ set(OPUS_LIBRARY_VERSION_MINOR ${OPUS_LT_AGE})
+ set(OPUS_LIBRARY_VERSION_PATCH ${OPUS_LT_REVISION})
+ set(
+ OPUS_LIBRARY_VERSION
+ "${OPUS_LIBRARY_VERSION_MAJOR}.${OPUS_LIBRARY_VERSION_MINOR}.${OPUS_LIBRARY_VERSION_PATCH}"
+ PARENT_SCOPE)
+ set(OPUS_LIBRARY_VERSION_MAJOR ${OPUS_LIBRARY_VERSION_MAJOR} PARENT_SCOPE)
+endfunction()
+
+function(get_package_version PACKAGE_VERSION)
+ find_package(Git)
+ if(Git_FOUND AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git")
+ execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --match "v*"
+ OUTPUT_VARIABLE OPUS_PACKAGE_VERSION)
+ if(OPUS_PACKAGE_VERSION)
+ string(STRIP ${OPUS_PACKAGE_VERSION}, OPUS_PACKAGE_VERSION)
+ string(REPLACE \n
+ ""
+ OPUS_PACKAGE_VERSION
+ ${OPUS_PACKAGE_VERSION})
+ string(REPLACE ,
+ ""
+ OPUS_PACKAGE_VERSION
+ ${OPUS_PACKAGE_VERSION})
+
+ string(SUBSTRING ${OPUS_PACKAGE_VERSION}
+ 1
+ -1
+ OPUS_PACKAGE_VERSION)
+ set(PACKAGE_VERSION ${OPUS_PACKAGE_VERSION} PARENT_SCOPE)
+ return()
+ endif()
+ endif()
+
+ if(EXISTS "${CMAKE_SOURCE_DIR}/package_version")
+ # Not a git repo, lets' try to parse it from package_version file if exists
+ file(STRINGS package_version opus_package_version_string
+ LIMIT_COUNT 1
+ REGEX "PACKAGE_VERSION=")
+ string(REPLACE "PACKAGE_VERSION="
+ ""
+ opus_package_version_string
+ ${opus_package_version_string})
+ string(REPLACE "\""
+ ""
+ opus_package_version_string
+ ${opus_package_version_string})
+ # In case we have a unknown dist here we just replace it with 0
+ string(REPLACE "unknown"
+ "0"
+ opus_package_version_string
+ ${opus_package_version_string})
+ set(PACKAGE_VERSION ${opus_package_version_string} PARENT_SCOPE)
+ return()
+ endif()
+
+ # if all else fails set to 0
+ set(PACKAGE_VERSION 0 PARENT_SCOPE)
+endfunction()
+
+function(check_and_set_flag NAME FLAG)
+ include(CheckCCompilerFlag)
+ check_c_compiler_flag(${FLAG} ${NAME}_SUPPORTED)
+ if(${NAME}_SUPPORTED)
+ add_definitions(${FLAG})
+ endif()
+endfunction()
+
+function(check_flag NAME FLAG)
+ include(CheckCCompilerFlag)
+ check_c_compiler_flag(${FLAG} ${NAME}_SUPPORTED)
+endfunction()
+
+include(CheckIncludeFile)
+# function to check if compiler supports SSE, SSE2, SSE4.1 and AVX if target
+# systems may not have SSE support then use OPUS_MAY_HAVE_SSE option if target
+# system is guaranteed to have SSE support then OPUS_PRESUME_SSE can be used to
+# skip SSE runtime check
+function(opus_detect_sse COMPILER_SUPPORT_SIMD)
+ message(STATUS "Check SIMD support by compiler")
+ check_include_file(xmmintrin.h HAVE_XMMINTRIN_H) # SSE1
+ if(HAVE_XMMINTRIN_H)
+ if(MSVC)
+ # different arch options for 32 and 64 bit target for MSVC
+ if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+ check_flag(SSE1 /arch:SSE)
+ else()
+ set(SSE1_SUPPORTED
+ 1
+ PARENT_SCOPE)
+ endif()
+ else()
+ check_flag(SSE1 -msse)
+ endif()
+ else()
+ set(SSE1_SUPPORTED
+ 0
+ PARENT_SCOPE)
+ endif()
+
+ check_include_file(emmintrin.h HAVE_EMMINTRIN_H) # SSE2
+ if(HAVE_EMMINTRIN_H)
+ if(MSVC)
+ if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+ check_flag(SSE2 /arch:SSE2)
+ else()
+ set(SSE2_SUPPORTED
+ 1
+ PARENT_SCOPE)
+ endif()
+ else()
+ check_flag(SSE2 -msse2)
+ endif()
+ else()
+ set(SSE2_SUPPORTED
+ 0
+ PARENT_SCOPE)
+ endif()
+
+ check_include_file(smmintrin.h HAVE_SMMINTRIN_H) # SSE4.1
+ if(HAVE_SMMINTRIN_H)
+ if(MSVC)
+ if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+ check_flag(SSE4_1 /arch:SSE2) # SSE2 and above
+ else()
+ set(SSE4_1_SUPPORTED
+ 1
+ PARENT_SCOPE)
+ endif()
+ else()
+ check_flag(SSE4_1 -msse4.1)
+ endif()
+ else()
+ set(SSE4_1_SUPPORTED
+ 0
+ PARENT_SCOPE)
+ endif()
+
+ check_include_file(immintrin.h HAVE_IMMINTRIN_H) # AVX
+ if(HAVE_IMMINTRIN_H)
+ if(MSVC)
+ check_flag(AVX /arch:AVX)
+ else()
+ check_flag(AVX -mavx)
+ endif()
+ else()
+ set(AVX_SUPPORTED
+ 0
+ PARENT_SCOPE)
+ endif()
+
+ if(SSE1_SUPPORTED OR SSE2_SUPPORTED OR SSE4_1_SUPPORTED OR AVX_SUPPORTED)
+ set(COMPILER_SUPPORT_SIMD 1 PARENT_SCOPE)
+ else()
+ message(STATUS "No SIMD support in compiler")
+ endif()
+endfunction()
+
+function(opus_detect_neon COMPILER_SUPPORT_NEON)
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm|aarch64)")
+ message(STATUS "Check NEON support by compiler")
+ check_include_file(arm_neon.h HAVE_ARM_NEON_H)
+ if(HAVE_ARM_NEON_H)
+ set(COMPILER_SUPPORT_NEON ${HAVE_ARM_NEON_H} PARENT_SCOPE)
+ endif()
+ endif()
+endfunction()
+
+function(opus_supports_cpu_detection RUNTIME_CPU_CAPABILITY_DETECTION)
+ if(MSVC)
+ check_include_file(intrin.h HAVE_INTRIN_H)
+ else()
+ check_include_file(cpuid.h HAVE_CPUID_H)
+ endif()
+ if(HAVE_INTRIN_H OR HAVE_CPUID_H)
+ set(RUNTIME_CPU_CAPABILITY_DETECTION 1 PARENT_SCOPE)
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm|aarch64)")
+ # ARM cpu detection is implemented for Windows and anything
+ # using a Linux kernel (such as Android).
+ if (CMAKE_SYSTEM_NAME MATCHES "(Windows|Linux|Android)")
+ set(RUNTIME_CPU_CAPABILITY_DETECTION 1 PARENT_SCOPE)
+ endif ()
+ else()
+ set(RUNTIME_CPU_CAPABILITY_DETECTION 0 PARENT_SCOPE)
+ endif()
+endfunction()
+
+function(add_sources_group target group)
+ target_sources(${target} PRIVATE ${ARGN})
+ source_group(${group} FILES ${ARGN})
+endfunction()
+
+function(get_opus_sources SOURCE_GROUP MAKE_FILE SOURCES)
+ # read file, each item in list is one group
+ file(STRINGS ${MAKE_FILE} opus_sources)
+
+ # add wildcard for regex match
+ string(CONCAT SOURCE_GROUP ${SOURCE_GROUP} ".*$")
+
+ # find group
+ foreach(val IN LISTS opus_sources)
+ if(val MATCHES ${SOURCE_GROUP})
+ list(LENGTH val list_length)
+ if(${list_length} EQUAL 1)
+ # for tests split by '=' and clean up the rest into a list
+ string(FIND ${val} "=" index)
+ math(EXPR index "${index} + 1")
+ string(SUBSTRING ${val}
+ ${index}
+ -1
+ sources)
+ string(REPLACE " "
+ ";"
+ sources
+ ${sources})
+ else()
+ # discard the group
+ list(REMOVE_AT val 0)
+ set(sources ${val})
+ endif()
+ break()
+ endif()
+ endforeach()
+
+ list(LENGTH sources list_length)
+ if(${list_length} LESS 1)
+ message(
+ FATAL_ERROR
+ "No files parsed succesfully from ${SOURCE_GROUP} in ${MAKE_FILE}")
+ endif()
+
+ # remove trailing whitespaces
+ set(list_var "")
+ foreach(source ${sources})
+ string(STRIP "${source}" source)
+ list(APPEND list_var "${source}")
+ endforeach()
+
+ set(${SOURCES} ${list_var} PARENT_SCOPE)
+endfunction()
diff --git a/cmake/OpusSources.cmake b/cmake/OpusSources.cmake
new file mode 100644
index 00000000..d8c6cdf4
--- /dev/null
+++ b/cmake/OpusSources.cmake
@@ -0,0 +1,41 @@
+include(OpusFunctions)
+
+get_opus_sources(SILK_HEAD silk_headers.mk silk_headers)
+get_opus_sources(SILK_SOURCES silk_sources.mk silk_sources)
+get_opus_sources(SILK_SOURCES_FLOAT silk_sources.mk silk_sources_float)
+get_opus_sources(SILK_SOURCES_FIXED silk_sources.mk silk_sources_fixed)
+get_opus_sources(SILK_SOURCES_SSE4_1 silk_sources.mk silk_sources_sse4_1)
+get_opus_sources(SILK_SOURCES_FIXED_SSE4_1 silk_sources.mk
+ silk_sources_fixed_sse4_1)
+get_opus_sources(SILK_SOURCES_ARM_NEON_INTR silk_sources.mk
+ silk_sources_arm_neon_intr)
+get_opus_sources(SILK_SOURCES_FIXED_ARM_NEON_INTR silk_sources.mk
+ silk_sources_fixed_arm_neon_intr)
+
+get_opus_sources(OPUS_HEAD opus_headers.mk opus_headers)
+get_opus_sources(OPUS_SOURCES opus_sources.mk opus_sources)
+get_opus_sources(OPUS_SOURCES_FLOAT opus_sources.mk opus_sources_float)
+
+get_opus_sources(CELT_HEAD celt_headers.mk celt_headers)
+get_opus_sources(CELT_SOURCES celt_sources.mk celt_sources)
+get_opus_sources(CELT_SOURCES_SSE celt_sources.mk celt_sources_sse)
+get_opus_sources(CELT_SOURCES_SSE2 celt_sources.mk celt_sources_sse2)
+get_opus_sources(CELT_SOURCES_SSE4_1 celt_sources.mk celt_sources_sse4_1)
+get_opus_sources(CELT_SOURCES_ARM celt_sources.mk celt_sources_arm)
+get_opus_sources(CELT_SOURCES_ARM_ASM celt_sources.mk celt_sources_arm_asm)
+get_opus_sources(CELT_AM_SOURCES_ARM_ASM celt_sources.mk
+ celt_am_sources_arm_asm)
+get_opus_sources(CELT_SOURCES_ARM_NEON_INTR celt_sources.mk
+ celt_sources_arm_neon_intr)
+get_opus_sources(CELT_SOURCES_ARM_NE10 celt_sources.mk celt_sources_arm_ne10)
+
+get_opus_sources(opus_demo_SOURCES Makefile.am opus_demo_sources)
+get_opus_sources(opus_custom_demo_SOURCES Makefile.am opus_custom_demo_sources)
+get_opus_sources(opus_compare_SOURCES Makefile.am opus_compare_sources)
+get_opus_sources(tests_test_opus_api_SOURCES Makefile.am test_opus_api_sources)
+get_opus_sources(tests_test_opus_encode_SOURCES Makefile.am
+ test_opus_encode_sources)
+get_opus_sources(tests_test_opus_decode_SOURCES Makefile.am
+ test_opus_decode_sources)
+get_opus_sources(tests_test_opus_padding_SOURCES Makefile.am
+ test_opus_padding_sources)
diff --git a/cmake/config.h.cmake.in b/cmake/config.h.cmake.in
new file mode 100644
index 00000000..5550842c
--- /dev/null
+++ b/cmake/config.h.cmake.in
@@ -0,0 +1 @@
+#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" \ No newline at end of file