ZLMediaKit/CMakeLists.txt

532 lines
18 KiB
CMake
Raw Normal View History

2022-07-25 00:22:30 +08:00
# MIT License
#
# Copyright (c) 2016-2022 The ZLMediaKit project authors. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
2018-03-21 16:01:41 +08:00
cmake_minimum_required(VERSION 3.1.3)
2022-07-25 00:22:30 +08:00
# 加载自定义模块
# Load custom modules
2022-07-25 00:22:30 +08:00
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
2022-07-25 00:22:30 +08:00
project(ZLMediaKit LANGUAGES C CXX)
# 使能 C++11
# Enable C++11
2018-03-21 16:01:41 +08:00
set(CMAKE_CXX_STANDARD 11)
2019-08-19 14:59:56 +08:00
2023-12-10 11:13:26 +08:00
# 主程序链接符号可以给外部动态库调用
add_link_options("LINKER:-export_dynamic")
2022-07-25 00:22:30 +08:00
option(ENABLE_API "Enable C API SDK" ON)
option(ENABLE_API_STATIC_LIB "Enable mk_api static lib" OFF)
option(ENABLE_ASAN "Enable Address Sanitize" OFF)
option(ENABLE_CXX_API "Enable C++ API SDK" OFF)
option(ENABLE_FAAC "Enable FAAC" OFF)
option(ENABLE_FFMPEG "Enable FFmpeg" OFF)
option(ENABLE_HLS "Enable HLS" ON)
option(ENABLE_JEMALLOC_STATIC "Enable static linking to the jemalloc library" OFF)
option(ENABLE_JEMALLOC_DUMP "Enable jemalloc to dump malloc statistics" OFF)
2022-07-25 00:22:30 +08:00
option(ENABLE_MEM_DEBUG "Enable Memory Debug" OFF)
option(ENABLE_MP4 "Enable MP4" ON)
option(ENABLE_MSVC_MT "Enable MSVC Mt/Mtd lib" ON)
option(ENABLE_MYSQL "Enable MySQL" OFF)
option(ENABLE_OPENSSL "Enable OpenSSL" ON)
option(ENABLE_PLAYER "Enable Player" ON)
option(ENABLE_RTPPROXY "Enable RTPPROXY" ON)
option(ENABLE_SERVER "Enable Server" ON)
option(ENABLE_SERVER_LIB "Enable server as android static library" OFF)
option(ENABLE_SRT "Enable SRT" ON)
option(ENABLE_TESTS "Enable Tests" ON)
2022-12-30 13:51:37 +08:00
option(ENABLE_SCTP "Enable SCTP" ON)
2022-07-25 00:22:30 +08:00
option(ENABLE_WEBRTC "Enable WebRTC" ON)
option(ENABLE_X264 "Enable x264" OFF)
2022-11-13 00:38:56 +08:00
option(ENABLE_WEPOLL "Enable wepoll" ON)
2023-03-12 00:06:39 +08:00
option(DISABLE_REPORT "Disable report to report.zlmediakit.com" off)
option(USE_SOLUTION_FOLDERS "Enable solution dir supported" ON)
2022-07-25 00:22:30 +08:00
##############################################################################
# 设置socket默认缓冲区大小为256k.如果设置为0则不设置socket的默认缓冲区大小,使用系统内核默认值(设置为0仅对linux有效)
# Set the default buffer size of the socket to 256k. If set to 0, the default buffer size of the socket will not be set,
# and the system kernel default value will be used (setting to 0 is only valid for linux)
set(SOCKET_DEFAULT_BUF_SIZE 262144 CACHE STRING "Default buffer size for socket" FORCE)
2022-07-25 00:22:30 +08:00
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE "Debug")
endif()
2022-07-25 00:22:30 +08:00
message(STATUS "编译类型: ${CMAKE_BUILD_TYPE}")
# 方便排查编译问题, 需要 FORCE CACHE, 否则需要命令行设置才生效
# To facilitate the troubleshooting of compilation problems, you need to FORCE CACHE, otherwise you need to set it on the command line to take effect
2022-07-25 00:22:30 +08:00
set(CMAKE_VERBOSE_MAKEFILE ON CACHE INTERNAL "" FORCE)
2022-07-28 00:25:50 +08:00
# TODO: include 当前目录会导致 server 编译出错, 待排除
set(CMAKE_INCLUDE_CURRENT_DIR OFF)
2022-07-25 00:22:30 +08:00
# 安装路径
# Install path
2022-07-25 00:22:30 +08:00
if(NOT CMAKE_INSTALL_PREFIX)
if(UNIX)
set(INSTALL_PATH_LIB lib${LIB_SUFFIX})
set(INSTALL_PATH_INCLUDE include)
set(INSTALL_PATH_RUNTIME bin)
elseif(WIN32)
# Windows 下安装到了用户主目录下?
# Install to the user's home directory under Windows?
2022-07-25 00:22:30 +08:00
set(INSTALL_PATH_LIB $ENV{HOME}/${CMAKE_PROJECT_NAME}/lib)
set(INSTALL_PATH_INCLUDE $ENV{HOME}/${CMAKE_PROJECT_NAME}/include)
else()
message(WARNING "该平台(${CMAKE_SYSTEM_NAME})下暂未设置安装路径")
endif()
else()
set(INSTALL_PATH_LIB ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
set(INSTALL_PATH_INCLUDE ${CMAKE_INSTALL_PREFIX}/include)
set(INSTALL_PATH_RUNTIME ${CMAKE_INSTALL_PREFIX}/bin)
endif()
2021-02-21 21:28:17 +08:00
2022-07-25 00:22:30 +08:00
string(TOLOWER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME_LOWER)
# 设置输出目录, 包括 bin, lib 以及其他文件
# Windows 也不再区分 32/64
# Set the output directory, including bin, lib and other files
# Windows no longer distinguishes 32/64
2022-07-25 00:22:30 +08:00
set(OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/release/${SYSTEM_NAME_LOWER}/${CMAKE_BUILD_TYPE})
set(LIBRARY_OUTPUT_PATH ${OUTPUT_DIR})
set(EXECUTABLE_OUTPUT_PATH ${OUTPUT_DIR})
# 添加 git 版本信息
# Add git version information
2022-11-06 00:38:14 +08:00
set(COMMIT_HASH "Git_Unkown_commit")
set(COMMIT_TIME "Git_Unkown_time")
set(BRANCH_NAME "Git_Unkown_branch")
set(BUILD_TIME "")
2022-11-06 00:38:14 +08:00
string(TIMESTAMP BUILD_TIME "%Y-%m-%dT%H:%M:%S")
find_package(Git QUIET)
2022-07-25 00:22:30 +08:00
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short=7 HEAD
OUTPUT_VARIABLE COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
execute_process(
COMMAND ${GIT_EXECUTABLE} symbolic-ref --short -q HEAD
OUTPUT_VARIABLE BRANCH_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
2022-11-06 00:38:14 +08:00
execute_process(
COMMAND ${GIT_EXECUTABLE} log --format=format:%aI -1
OUTPUT_VARIABLE COMMIT_TIME
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
2022-07-25 00:22:30 +08:00
endif()
configure_file(
2022-07-25 00:22:30 +08:00
${CMAKE_CURRENT_SOURCE_DIR}/version.h.ini
2022-07-26 13:09:25 +08:00
${CMAKE_CURRENT_BINARY_DIR}/version.h
2022-07-25 00:22:30 +08:00
@ONLY)
2022-11-06 00:38:14 +08:00
message(STATUS "Git version is ${BRANCH_NAME} ${COMMIT_HASH}/${COMMIT_TIME} ${BUILD_TIME}")
2022-07-25 00:22:30 +08:00
##############################################################################
2022-05-25 14:50:26 +08:00
2022-07-25 00:22:30 +08:00
# 方便修改全局变量
# Convenient to modify global variables
2022-07-25 00:22:30 +08:00
function(update_cached name value)
set("${name}" "${value}" CACHE INTERNAL "*** Internal ***" FORCE)
endfunction()
2022-05-25 14:50:26 +08:00
2022-07-25 00:22:30 +08:00
function(update_cached_list name)
set(_tmp_list "${${name}}")
list(APPEND _tmp_list "${ARGN}")
list(REMOVE_DUPLICATES _tmp_list)
update_cached(${name} "${_tmp_list}")
endfunction()
2022-05-25 14:50:26 +08:00
2022-07-25 00:22:30 +08:00
# TODO:
function(set_file_group prefix)
message(STATUS "set_file_group " ${prefix} " " ${ARGC})
foreach(FILE IN LISTS ARGN 1)
# Get the directory of the source file
get_filename_component(PARENT_DIR "${FILE}" DIRECTORY)
2022-05-25 14:50:26 +08:00
2022-07-25 00:22:30 +08:00
# Remove common directory prefix to make the group
string(REPLACE "${prefix}" "" GROUP "${PARENT_DIR}")
2022-05-25 14:50:26 +08:00
2022-07-25 00:22:30 +08:00
# Make sure we are using windows slashes
string(REPLACE "/" "\\" GROUP "${GROUP}")
2022-05-25 14:50:26 +08:00
2022-07-25 00:22:30 +08:00
source_group("${GROUP}" FILES "${FILE}")
endforeach()
endfunction()
2022-05-25 14:50:26 +08:00
2022-07-25 00:22:30 +08:00
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif()
if(UNIX)
# UNIX/Linux/Darwin
set(COMPILE_OPTIONS_DEFAULT
"-fPIC"
"-Wall;-Wextra"
"-Wno-unused-function;-Wno-unused-parameter;-Wno-unused-variable"
"-Wno-error=extra;-Wno-error=missing-field-initializers;-Wno-error=type-limits")
elseif(WIN32)
2022-07-28 00:25:50 +08:00
if (MSVC)
2022-11-03 10:51:49 +08:00
set(COMPILE_OPTIONS_DEFAULT
# TODO: /wd4819 应该是不会生效
"/wd4566;/wd4819"
# warning C4530: C++ exception handler used, but unwind semantics are not enabled.
"/EHsc")
2022-07-28 00:25:50 +08:00
# disable Windows logo
list(APPEND COMPILE_OPTIONS_DEFAULT "/nologo")
list(APPEND CMAKE_STATIC_LINKER_FLAGS "/nologo")
endif()
2022-07-25 00:22:30 +08:00
endif()
2022-07-29 19:37:51 +08:00
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
include_directories(SYSTEM "/opt/homebrew/include")
endif()
endif()
2022-07-25 00:22:30 +08:00
# mediakit 以及各个 runtime 依赖
# mediakit and various runtime dependencies
2023-07-15 18:47:05 +08:00
update_cached(MK_LINK_LIBRARIES "")
update_cached(MK_COMPILE_DEFINITIONS ENABLE_VERSION)
2022-07-25 00:22:30 +08:00
2023-03-12 00:06:39 +08:00
if (DISABLE_REPORT)
update_cached_list(MK_COMPILE_DEFINITIONS DISABLE_REPORT)
endif ()
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
include(CheckCXXSourceCompiles)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/cmake/checks/atomic_check.cpp atomic_check_cpp)
check_cxx_source_compiles("${atomic_check_cpp}" HAVE_CXX_ATOMICS_WITHOUT_LIB)
if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
# cmake --help-policy CMP0075
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
check_cxx_source_compiles("${atomic_check_cpp}" HAVE_CXX_ATOMICS_WITH_LIB)
if(NOT HAVE_CXX_ATOMICS_WITH_LIB)
message(WARNING "Compiler doesn't support std::atomic<long long>")
else()
update_cached_list(MK_LINK_LIBRARIES atomic)
endif()
endif()
endif()
2022-07-25 00:22:30 +08:00
# 多个模块依赖 ffmpeg 相关库, 统一查找
# Multiple modules depend on ffmpeg related libraries, unified search
2022-07-25 00:22:30 +08:00
if(ENABLE_FFMPEG)
find_package(PkgConfig QUIET)
# 查找 ffmpeg/libutil 是否安装
# find ffmpeg/libutil installed
2022-07-25 00:22:30 +08:00
if(PKG_CONFIG_FOUND)
pkg_check_modules(AVUTIL QUIET IMPORTED_TARGET libavutil)
if(AVUTIL_FOUND)
update_cached_list(MK_LINK_LIBRARIES PkgConfig::AVUTIL)
message(STATUS "found library: ${AVUTIL_LIBRARIES}")
endif()
endif()
# 查找 ffmpeg/libavcodec 是否安装
# find ffmpeg/libavcodec installed
2022-07-25 00:22:30 +08:00
if(PKG_CONFIG_FOUND)
pkg_check_modules(AVCODEC QUIET IMPORTED_TARGET libavcodec)
if(AVCODEC_FOUND)
update_cached_list(MK_LINK_LIBRARIES PkgConfig::AVCODEC)
message(STATUS "found library: ${AVCODEC_LIBRARIES}")
endif()
endif()
# 查找 ffmpeg/libswscale 是否安装
# find ffmpeg/libswscale installed
2022-07-25 00:22:30 +08:00
if(PKG_CONFIG_FOUND)
pkg_check_modules(SWSCALE QUIET IMPORTED_TARGET libswscale)
if(SWSCALE_FOUND)
update_cached_list(MK_LINK_LIBRARIES PkgConfig::SWSCALE)
message(STATUS "found library: ${SWSCALE_LIBRARIES}")
endif()
endif()
# 查找 ffmpeg/libswresample 是否安装
# find ffmpeg/libswresample installed
2022-07-25 00:22:30 +08:00
if(PKG_CONFIG_FOUND)
pkg_check_modules(SWRESAMPLE QUIET IMPORTED_TARGET libswresample)
if(SWRESAMPLE_FOUND)
update_cached_list(MK_LINK_LIBRARIES PkgConfig::SWRESAMPLE)
message(STATUS "found library: ${SWRESAMPLE_LIBRARIES}")
endif()
endif()
# 查找 ffmpeg/libutil 是否安装
# find ffmpeg/libutil installed
2022-07-25 00:22:30 +08:00
if(NOT AVUTIL_FOUND)
find_package(AVUTIL QUIET)
if(AVUTIL_FOUND)
include_directories(SYSTEM ${AVUTIL_INCLUDE_DIR})
update_cached_list(MK_LINK_LIBRARIES ${AVUTIL_LIBRARIES})
message(STATUS "found library: ${AVUTIL_LIBRARIES}")
2022-05-25 14:50:26 +08:00
endif ()
2022-07-25 00:22:30 +08:00
endif ()
# 查找 ffmpeg/libavcodec 是否安装
# find ffmpeg/libavcodec installed
2022-07-25 00:22:30 +08:00
if(NOT AVCODEC_FOUND)
find_package(AVCODEC QUIET)
if(AVCODEC_FOUND)
include_directories(SYSTEM ${AVCODEC_INCLUDE_DIR})
update_cached_list(MK_LINK_LIBRARIES ${AVCODEC_LIBRARIES})
message(STATUS "found library: ${AVCODEC_LIBRARIES}")
endif()
endif()
# 查找 ffmpeg/libswscale 是否安装
# find ffmpeg/libswscale installed
2022-07-25 00:22:30 +08:00
if(NOT SWSCALE_FOUND)
find_package(SWSCALE QUIET)
if(SWSCALE_FOUND)
include_directories(SYSTEM ${SWSCALE_INCLUDE_DIR})
update_cached_list(MK_LINK_LIBRARIES ${SWSCALE_LIBRARIES})
message(STATUS "found library: ${SWSCALE_LIBRARIES}")
endif()
endif()
# 查找 ffmpeg/libswresample 是否安装
# find ffmpeg/libswresample installed
2022-07-25 00:22:30 +08:00
if(NOT SWRESAMPLE_FOUND)
find_package(SWRESAMPLE QUIET)
if(SWRESAMPLE_FOUND)
include_directories(SYSTEM ${SWRESAMPLE_INCLUDE_DIRS})
update_cached_list(MK_LINK_LIBRARIES ${SWRESAMPLE_LIBRARIES})
message(STATUS "found library: ${SWRESAMPLE_LIBRARIES}")
endif()
endif()
if(AVUTIL_FOUND AND AVCODEC_FOUND AND SWSCALE_FOUND AND SWRESAMPLE_FOUND)
update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_FFMPEG)
update_cached_list(MK_LINK_LIBRARIES ${CMAKE_DL_LIBS})
else()
set(ENABLE_FFMPEG OFF)
message(WARNING "ffmpeg related functions not found")
2022-07-25 00:22:30 +08:00
endif()
endif()
2022-05-25 14:50:26 +08:00
2022-07-25 00:22:30 +08:00
if(ENABLE_MEM_DEBUG)
2022-09-19 21:02:51 +08:00
update_cached_list(MK_LINK_LIBRARIES
2022-07-25 00:22:30 +08:00
"-Wl,-wrap,free;-Wl,-wrap,malloc;-Wl,-wrap,realloc;-Wl,-wrap,calloc")
update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_MEM_DEBUG)
message(STATUS "Memory debugging enabled")
2022-07-25 00:22:30 +08:00
endif()
2022-05-25 14:50:26 +08:00
2022-07-25 00:22:30 +08:00
if(ENABLE_ASAN)
list(APPEND COMPILE_OPTIONS_DEFAULT
"-fsanitize=address;-fno-omit-frame-pointer")
2022-09-19 21:00:48 +08:00
# https://github.com/google/sanitizers/wiki/AddressSanitizer#using-addresssanitizer
# > In order to use AddressSanitizer you will need to
# > compile and link your program using clang with the -fsanitize=address switch.
update_cached_list(MK_LINK_LIBRARIES "-fsanitize=address")
message(STATUS "Address Sanitize enabled")
2022-07-25 00:22:30 +08:00
endif()
# 下载jemalloc后静态编译
# Static compilation after downloading jemalloc
2022-07-25 00:22:30 +08:00
set(DEP_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdpart/external-${CMAKE_SYSTEM_NAME})
2022-06-29 10:59:44 +08:00
if(ENABLE_JEMALLOC_STATIC)
2022-07-25 00:22:30 +08:00
if(NOT EXISTS ${DEP_ROOT_DIR})
file(MAKE_DIRECTORY ${DEP_ROOT_DIR})
endif()
if (ENABLE_JEMALLOC_DUMP)
set(ENABLE_JEMALLOC_STAT ON)
else ()
set(ENABLE_JEMALLOC_STAT OFF)
endif ()
2022-07-25 00:22:30 +08:00
include(Jemalloc)
include_directories(SYSTEM ${DEP_ROOT_DIR}/${JEMALLOC_NAME}/include/jemalloc)
link_directories(${DEP_ROOT_DIR}/${JEMALLOC_NAME}/lib)
# 用于影响后续查找过程
# Used to affect subsequent lookup process
2022-07-25 00:22:30 +08:00
set(JEMALLOC_ROOT_DIR "${DEP_ROOT_DIR}/${JEMALLOC_NAME}")
endif()
# 默认链接 jemalloc 库避免内存碎片
# Link the jemalloc library by default to avoid memory fragmentation
2022-05-25 14:50:26 +08:00
find_package(JEMALLOC QUIET)
2022-07-25 00:22:30 +08:00
if(JEMALLOC_FOUND)
message(STATUS "found library: ${JEMALLOC_LIBRARIES}")
include_directories(${JEMALLOC_INCLUDE_DIR})
update_cached_list(MK_LINK_LIBRARIES ${JEMALLOC_LIBRARIES})
add_definitions(-DUSE_JEMALLOC)
message(STATUS "jemalloc will be used to avoid memory fragmentation")
if (ENABLE_JEMALLOC_DUMP)
add_definitions(-DENABLE_JEMALLOC_DUMP)
message(STATUS "jemalloc will save memory usage statistics when the program exits")
endif ()
2022-07-25 00:22:30 +08:00
endif()
2021-02-21 21:38:24 +08:00
2022-07-25 00:22:30 +08:00
# 查找 openssl 是否安装
# find openssl installed
2022-06-19 15:54:30 +08:00
find_package(OpenSSL QUIET)
2022-07-25 00:22:30 +08:00
if(OPENSSL_FOUND AND ENABLE_OPENSSL)
message(STATUS "found library: ${OPENSSL_LIBRARIES}, ENABLE_OPENSSL defined")
include_directories(${OPENSSL_INCLUDE_DIR})
update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_OPENSSL)
update_cached_list(MK_LINK_LIBRARIES ${OPENSSL_LIBRARIES})
if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND OPENSSL_USE_STATIC_LIBS)
update_cached_list(MK_LINK_LIBRARIES ${CMAKE_DL_LIBS})
endif()
else()
set(ENABLE_OPENSSL OFF)
2022-08-01 16:12:52 +08:00
set(ENABLE_WEBRTC OFF)
message(WARNING "openssl 未找到, rtmp 将不支持 flash 播放器, https/wss/rtsps/rtmps/webrtc 也将失效")
2022-07-25 00:22:30 +08:00
endif()
2017-05-02 18:10:47 +08:00
2022-07-25 00:22:30 +08:00
# 查找 mysql 是否安装
# find mysql installed
2017-05-02 18:10:47 +08:00
find_package(MYSQL QUIET)
2022-07-25 00:22:30 +08:00
if(MYSQL_FOUND AND ENABLE_MYSQL)
message(STATUS "found library: ${MYSQL_LIBRARIES}, ENABLE_MYSQL defined")
include_directories(SYSTEM
${MYSQL_INCLUDE_DIR}
${MYSQL_INCLUDE_DIR}/mysql)
update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_MYSQL)
update_cached_list(MK_LINK_LIBRARIES ${MYSQL_LIBRARIES})
endif()
# 查找 x264 是否安装
# find x264 installed
2017-05-02 18:10:47 +08:00
find_package(X264 QUIET)
2022-07-25 00:22:30 +08:00
if(X264_FOUND AND ENABLE_X264)
message(STATUS "found library: ${X264_LIBRARIES}, ENABLE_X264 defined")
include_directories(SYSTEM ${X264_INCLUDE_DIRS})
2022-07-25 00:22:30 +08:00
update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_X264)
update_cached_list(MK_LINK_LIBRARIES ${X264_LIBRARIES})
endif()
2019-12-05 19:53:55 +08:00
2022-07-25 00:22:30 +08:00
# 查找 faac 是否安装
# find faac installed
2022-07-25 00:22:30 +08:00
find_package(FAAC QUIET)
if(FAAC_FOUND AND ENABLE_FAAC)
message(STATUS "found library:${FAAC_LIBRARIES}, ENABLE_FAAC defined")
include_directories(SYSTEM ${FAAC_INCLUDE_DIR})
update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_FAAC)
update_cached_list(MK_LINK_LIBRARIES ${FAAC_LIBRARIES})
endif()
2020-06-12 18:17:49 +08:00
2022-07-25 00:22:30 +08:00
if(WIN32)
update_cached_list(MK_LINK_LIBRARIES WS2_32 Iphlpapi shlwapi)
elseif(NOT ANDROID OR IOS)
update_cached_list(MK_LINK_LIBRARIES pthread)
endif()
2019-12-05 19:53:55 +08:00
2022-07-25 00:22:30 +08:00
# ----------------------------------------------------------------------------
# Solution folders:
# ----------------------------------------------------------------------------
if(USE_SOLUTION_FOLDERS)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets")
endif()
2019-12-05 19:53:55 +08:00
2022-07-25 00:22:30 +08:00
if(MSVC AND ENABLE_MSVC_MT)
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE)
# TODO: 通常应该不需要替换
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
endif()
2022-07-25 00:22:30 +08:00
##############################################################################
2019-12-05 19:53:55 +08:00
2022-07-25 00:22:30 +08:00
# for version.h
include_directories(${CMAKE_CURRENT_BINARY_DIR})
# for assert.h
2022-09-25 12:12:23 +08:00
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdpart)
2022-07-25 00:22:30 +08:00
add_subdirectory(3rdpart)
2022-06-03 13:25:32 +08:00
2022-07-25 00:22:30 +08:00
add_subdirectory(src)
2023-12-10 10:21:40 +08:00
add_subdirectory(ext-codec)
2022-07-25 00:22:30 +08:00
if(ENABLE_SRT)
add_subdirectory(srt)
2021-08-12 16:07:31 +08:00
endif()
2021-06-29 17:44:35 +08:00
2022-07-25 00:22:30 +08:00
if(ENABLE_WEBRTC)
add_subdirectory(webrtc)
endif()
2021-08-12 16:07:31 +08:00
2022-07-25 00:22:30 +08:00
if(ENABLE_API)
add_subdirectory(api)
endif()
2021-08-12 16:07:31 +08:00
2022-08-01 16:12:52 +08:00
##############################################################################
2022-07-25 13:54:24 +08:00
2022-08-01 16:12:52 +08:00
if(ENABLE_PLAYER AND ENABLE_FFMPEG)
add_subdirectory(player)
endif()
2022-06-19 01:12:14 +08:00
2022-08-01 16:12:52 +08:00
#MediaServer主程序
#MediaServer main program
if(ENABLE_SERVER)
add_subdirectory(server)
endif()
2022-08-01 16:12:52 +08:00
# Android 会 add_subdirectory 并依赖该变量
# Android will add_subdirectory and depend on this variable
if(ENABLE_SERVER_LIB AND NOT CMAKE_PARENT_LIST_FILE STREQUAL CMAKE_CURRENT_LIST_FILE)
2022-08-01 16:12:52 +08:00
set(MK_LINK_LIBRARIES ${MK_LINK_LIBRARIES} PARENT_SCOPE)
2022-07-25 00:22:30 +08:00
endif()
2022-08-01 16:12:52 +08:00
# IOS 不编译可执行程序
# IOS does not compile executable programs
if(IOS)
return()
endif()
2022-08-01 16:12:52 +08:00
#cpp测试demo程序
#cpp test demo program
2022-08-01 16:12:52 +08:00
if (ENABLE_TESTS)
add_subdirectory(tests)
endif ()
# 拷贝www文件夹、配置文件、默认证书
# Copy www folder, configuration file, default certificate
2022-08-01 16:12:52 +08:00
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/www" DESTINATION ${EXECUTABLE_OUTPUT_PATH})
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/conf/config.ini" DESTINATION ${EXECUTABLE_OUTPUT_PATH})
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/default.pem" DESTINATION ${EXECUTABLE_OUTPUT_PATH})