2020-01-24 20:54:39 +08:00
|
|
|
|
project(ZLMediaKit)
|
2018-03-21 16:01:41 +08:00
|
|
|
|
cmake_minimum_required(VERSION 3.1.3)
|
2018-03-21 15:13:33 +08:00
|
|
|
|
#使能c++11
|
2018-03-21 16:01:41 +08:00
|
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
2017-05-02 18:10:47 +08:00
|
|
|
|
#加载自定义模块
|
2019-09-11 09:21:10 +08:00
|
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
2019-08-19 14:59:56 +08:00
|
|
|
|
|
|
|
|
|
#set(CMAKE_BUILD_TYPE "Release")
|
|
|
|
|
|
|
|
|
|
if(${CMAKE_BUILD_TYPE} MATCHES "Release")
|
|
|
|
|
message(STATUS "Release版本")
|
|
|
|
|
set(BuildType "Release")
|
|
|
|
|
else()
|
|
|
|
|
set(BuildType "Debug")
|
|
|
|
|
message(STATUS "Debug版本")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
#设置bin和lib库目录
|
2019-09-11 09:21:10 +08:00
|
|
|
|
set(RELEASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/release)
|
2019-08-19 14:59:56 +08:00
|
|
|
|
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
|
|
|
|
SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/linux/${BuildType})
|
|
|
|
|
SET(EXECUTABLE_OUTPUT_PATH ${RELEASE_DIR}/linux/${BuildType})
|
2019-12-18 10:37:23 +08:00
|
|
|
|
add_compile_options(-fPIC)
|
2019-08-19 14:59:56 +08:00
|
|
|
|
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
|
2019-08-19 15:46:42 +08:00
|
|
|
|
SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/windows/${BuildType})
|
|
|
|
|
SET(EXECUTABLE_OUTPUT_PATH ${RELEASE_DIR}/windows/${BuildType})
|
2019-08-19 14:59:56 +08:00
|
|
|
|
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
|
|
|
|
SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/mac/${BuildType})
|
|
|
|
|
SET(EXECUTABLE_OUTPUT_PATH ${RELEASE_DIR}/mac/${BuildType})
|
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
|
LINK_DIRECTORIES(${LIBRARY_OUTPUT_PATH})
|
|
|
|
|
|
2018-03-21 15:13:33 +08:00
|
|
|
|
#设置工程源码根目录
|
2019-09-11 09:21:10 +08:00
|
|
|
|
set(ToolKit_Root ${CMAKE_CURRENT_SOURCE_DIR}/3rdpart/ZLToolKit/src)
|
|
|
|
|
set(MediaKit_Root ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
2019-12-05 19:53:55 +08:00
|
|
|
|
set(MediaServer_Root ${CMAKE_CURRENT_SOURCE_DIR}/3rdpart/media-server)
|
|
|
|
|
|
2018-03-21 15:13:33 +08:00
|
|
|
|
#设置头文件目录
|
|
|
|
|
INCLUDE_DIRECTORIES(${ToolKit_Root})
|
|
|
|
|
INCLUDE_DIRECTORIES(${MediaKit_Root})
|
2020-05-30 11:49:36 +08:00
|
|
|
|
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/3rdpart)
|
2017-08-09 18:39:30 +08:00
|
|
|
|
|
2020-07-02 16:58:21 +08:00
|
|
|
|
option(ENABLE_HLS "Enable HLS" true)
|
|
|
|
|
option(ENABLE_OPENSSL "Enable OpenSSL" true)
|
|
|
|
|
option(ENABLE_MYSQL "Enable MySQL" false)
|
|
|
|
|
option(ENABLE_FAAC "Enable FAAC" false)
|
|
|
|
|
option(ENABLE_X264 "Enable x264" false)
|
|
|
|
|
option(ENABLE_MP4 "Enable MP4" true)
|
|
|
|
|
option(ENABLE_RTPPROXY "Enable RTPPROXY" true)
|
2019-08-01 11:44:16 +08:00
|
|
|
|
|
2019-12-05 19:53:55 +08:00
|
|
|
|
set(LINK_LIB_LIST zlmediakit zltoolkit)
|
2017-05-02 18:10:47 +08:00
|
|
|
|
|
|
|
|
|
#查找openssl是否安装
|
2017-05-11 22:10:12 +08:00
|
|
|
|
find_package(OpenSSL QUIET)
|
2019-08-01 11:47:30 +08:00
|
|
|
|
if (OPENSSL_FOUND AND ENABLE_OPENSSL)
|
2019-04-04 11:30:57 +08:00
|
|
|
|
message(STATUS "found library:${OPENSSL_LIBRARIES},ENABLE_OPENSSL defined")
|
2019-08-01 11:47:30 +08:00
|
|
|
|
include_directories(${OPENSSL_INCLUDE_DIR})
|
2017-12-01 11:42:49 +08:00
|
|
|
|
add_definitions(-DENABLE_OPENSSL)
|
2019-08-01 11:47:30 +08:00
|
|
|
|
list(APPEND LINK_LIB_LIST ${OPENSSL_LIBRARIES})
|
2020-06-12 18:17:49 +08:00
|
|
|
|
else()
|
|
|
|
|
message(WARNING "openssl未找到,rtmp将不支持flash播放器,https/wss/rtsps/rtmps也将失效")
|
2019-04-04 11:30:57 +08:00
|
|
|
|
endif ()
|
2017-05-02 18:10:47 +08:00
|
|
|
|
|
|
|
|
|
#查找mysql是否安装
|
|
|
|
|
find_package(MYSQL QUIET)
|
2019-04-04 11:30:57 +08:00
|
|
|
|
if (MYSQL_FOUND AND ENABLE_MYSQL)
|
|
|
|
|
message(STATUS "found library:${MYSQL_LIBRARIES},ENABLE_MYSQL defined")
|
2017-12-01 11:42:49 +08:00
|
|
|
|
include_directories(${MYSQL_INCLUDE_DIR})
|
2019-05-24 17:50:46 +08:00
|
|
|
|
include_directories(${MYSQL_INCLUDE_DIR}/mysql)
|
2017-12-01 11:42:49 +08:00
|
|
|
|
add_definitions(-DENABLE_MYSQL)
|
|
|
|
|
list(APPEND LINK_LIB_LIST ${MYSQL_LIBRARIES})
|
2019-04-04 11:30:57 +08:00
|
|
|
|
endif ()
|
2017-05-02 18:10:47 +08:00
|
|
|
|
|
|
|
|
|
#查找x264是否安装
|
|
|
|
|
find_package(X264 QUIET)
|
2019-04-04 11:30:57 +08:00
|
|
|
|
if (X264_FOUND AND ENABLE_X264)
|
|
|
|
|
message(STATUS "found library:${X264_LIBRARIES},ENABLE_X264 defined")
|
2017-12-01 11:42:49 +08:00
|
|
|
|
include_directories(${X264_INCLUDE_DIRS})
|
|
|
|
|
add_definitions(-DENABLE_X264)
|
|
|
|
|
list(APPEND LINK_LIB_LIST ${X264_LIBRARIES})
|
2018-03-21 15:13:33 +08:00
|
|
|
|
endif ()
|
2017-05-02 18:10:47 +08:00
|
|
|
|
|
|
|
|
|
#查找faac是否安装
|
|
|
|
|
find_package(FAAC QUIET)
|
2019-04-04 11:30:57 +08:00
|
|
|
|
if (FAAC_FOUND AND ENABLE_FAAC)
|
|
|
|
|
message(STATUS "found library:${FAAC_LIBRARIES},ENABLE_FAAC defined")
|
2017-12-01 11:42:49 +08:00
|
|
|
|
include_directories(${FAAC_INCLUDE_DIR})
|
|
|
|
|
add_definitions(-DENABLE_FAAC)
|
|
|
|
|
list(APPEND LINK_LIB_LIST ${FAAC_LIBRARIES})
|
2018-03-21 15:13:33 +08:00
|
|
|
|
endif ()
|
2017-05-03 00:05:30 +08:00
|
|
|
|
|
2019-12-06 11:54:10 +08:00
|
|
|
|
if(${CMAKE_BUILD_TYPE} MATCHES "Release")
|
|
|
|
|
#查找jemalloc是否安装
|
|
|
|
|
find_package(JEMALLOC QUIET)
|
|
|
|
|
if(JEMALLOC_FOUND)
|
|
|
|
|
message(STATUS "found library:\"${JEMALLOC_LIBRARIES}\"")
|
|
|
|
|
include_directories(${JEMALLOC_INCLUDE_DIR})
|
|
|
|
|
list(APPEND LINK_LIB_LIST ${JEMALLOC_LIBRARIES})
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
2019-05-31 12:14:51 +08:00
|
|
|
|
|
2019-08-19 15:46:42 +08:00
|
|
|
|
set(VS_FALGS "/wd4819 /wd4996 /wd4018 /wd4267 /wd4244 /wd4101 /wd4828 /wd4309 /wd4573" )
|
2019-12-05 19:53:55 +08:00
|
|
|
|
|
|
|
|
|
#添加mpeg用于支持ts生成
|
2019-04-04 11:30:57 +08:00
|
|
|
|
if(ENABLE_HLS)
|
2019-12-05 19:53:55 +08:00
|
|
|
|
message(STATUS "ENABLE_HLS defined")
|
|
|
|
|
add_definitions(-DENABLE_HLS)
|
|
|
|
|
|
2020-06-12 18:17:49 +08:00
|
|
|
|
include_directories(${MediaServer_Root}/libmpeg/include)
|
2019-04-04 11:30:57 +08:00
|
|
|
|
aux_source_directory(${MediaServer_Root}/libmpeg/include src_mpeg)
|
|
|
|
|
aux_source_directory(${MediaServer_Root}/libmpeg/source src_mpeg)
|
2019-12-05 19:53:55 +08:00
|
|
|
|
|
2019-04-04 11:30:57 +08:00
|
|
|
|
add_library(mpeg STATIC ${src_mpeg})
|
2019-12-05 19:53:55 +08:00
|
|
|
|
list(APPEND LINK_LIB_LIST mpeg)
|
|
|
|
|
|
2019-05-31 12:14:51 +08:00
|
|
|
|
if(WIN32)
|
|
|
|
|
set_target_properties(mpeg PROPERTIES COMPILE_FLAGS ${VS_FALGS} )
|
|
|
|
|
endif(WIN32)
|
2019-04-04 11:30:57 +08:00
|
|
|
|
endif()
|
2019-04-01 12:57:33 +08:00
|
|
|
|
|
2019-12-05 19:53:55 +08:00
|
|
|
|
#添加mov、flv库用于MP4录制
|
2020-04-03 20:45:58 +08:00
|
|
|
|
if(ENABLE_MP4)
|
|
|
|
|
message(STATUS "ENABLE_MP4 defined")
|
|
|
|
|
add_definitions(-DENABLE_MP4)
|
2019-12-05 19:53:55 +08:00
|
|
|
|
|
2020-06-12 18:17:49 +08:00
|
|
|
|
include_directories(${MediaServer_Root}/libmov/include)
|
|
|
|
|
include_directories(${MediaServer_Root}/libflv/include)
|
|
|
|
|
|
2019-07-30 19:26:38 +08:00
|
|
|
|
aux_source_directory(${MediaServer_Root}/libmov/include src_mov)
|
|
|
|
|
aux_source_directory(${MediaServer_Root}/libmov/source src_mov)
|
2019-12-05 19:53:55 +08:00
|
|
|
|
|
2019-07-30 19:26:38 +08:00
|
|
|
|
aux_source_directory(${MediaServer_Root}/libflv/include src_flv)
|
|
|
|
|
aux_source_directory(${MediaServer_Root}/libflv/source src_flv)
|
2019-12-05 19:53:55 +08:00
|
|
|
|
|
|
|
|
|
add_library(mov STATIC ${src_mov})
|
2019-07-30 19:26:38 +08:00
|
|
|
|
add_library(flv STATIC ${src_flv})
|
2019-12-05 19:53:55 +08:00
|
|
|
|
list(APPEND LINK_LIB_LIST mov flv)
|
|
|
|
|
|
2019-07-30 19:26:38 +08:00
|
|
|
|
if(WIN32)
|
|
|
|
|
set_target_properties(mov flv PROPERTIES COMPILE_FLAGS ${VS_FALGS} )
|
|
|
|
|
endif(WIN32)
|
|
|
|
|
endif()
|
|
|
|
|
|
2019-12-06 13:39:55 +08:00
|
|
|
|
#添加rtp库用于rtp转ps/ts
|
2020-01-24 20:54:39 +08:00
|
|
|
|
if(ENABLE_RTPPROXY AND ENABLE_HLS)
|
2019-12-06 13:39:55 +08:00
|
|
|
|
message(STATUS "ENABLE_RTPPROXY defined")
|
2020-06-12 18:17:49 +08:00
|
|
|
|
include_directories(${MediaServer_Root}/librtp/include)
|
|
|
|
|
|
2019-12-06 11:54:10 +08:00
|
|
|
|
aux_source_directory(${MediaServer_Root}/librtp/include src_rtp)
|
|
|
|
|
aux_source_directory(${MediaServer_Root}/librtp/source src_rtp)
|
|
|
|
|
aux_source_directory(${MediaServer_Root}/librtp/payload src_rtp)
|
|
|
|
|
add_library(rtp STATIC ${src_rtp})
|
|
|
|
|
add_definitions(-DENABLE_RTPPROXY)
|
|
|
|
|
list(APPEND LINK_LIB_LIST rtp)
|
2019-10-10 17:28:38 +08:00
|
|
|
|
endif()
|
2019-07-30 19:26:38 +08:00
|
|
|
|
|
2019-12-06 11:54:10 +08:00
|
|
|
|
#收集源代码
|
|
|
|
|
file(GLOB ToolKit_src_list ${ToolKit_Root}/*/*.cpp ${ToolKit_Root}/*/*.h ${ToolKit_Root}/*/*.c)
|
2019-12-17 09:24:35 +08:00
|
|
|
|
if(IOS)
|
|
|
|
|
list(APPEND ToolKit_src_list ${ToolKit_Root}/Network/Socket_ios.mm)
|
|
|
|
|
endif()
|
|
|
|
|
|
2019-12-06 11:54:10 +08:00
|
|
|
|
file(GLOB MediaKit_src_list ${MediaKit_Root}/*/*.cpp ${MediaKit_Root}/*/*.h ${MediaKit_Root}/*/*.c)
|
2019-12-05 19:53:55 +08:00
|
|
|
|
|
2019-12-06 11:54:10 +08:00
|
|
|
|
#去除win32的适配代码
|
|
|
|
|
if (NOT WIN32)
|
|
|
|
|
list(REMOVE_ITEM ToolKit_src_list ${ToolKit_Root}/win32/getopt.c)
|
|
|
|
|
else()
|
|
|
|
|
#防止Windows.h包含Winsock.h
|
2019-12-06 13:53:28 +08:00
|
|
|
|
add_definitions(-DWIN32_LEAN_AND_MEAN -DMP4V2_NO_STDINT_DEFS -DOS_WINDOWS)
|
2019-12-06 11:54:10 +08:00
|
|
|
|
endif ()
|
2019-12-05 19:53:55 +08:00
|
|
|
|
|
|
|
|
|
#添加库
|
|
|
|
|
add_library(zltoolkit STATIC ${ToolKit_src_list})
|
|
|
|
|
add_library(zlmediakit STATIC ${MediaKit_src_list})
|
|
|
|
|
|
2018-03-21 16:16:04 +08:00
|
|
|
|
if (WIN32)
|
2018-03-21 15:13:33 +08:00
|
|
|
|
list(APPEND LINK_LIB_LIST WS2_32 Iphlpapi shlwapi)
|
2019-05-31 12:14:51 +08:00
|
|
|
|
set_target_properties(zltoolkit PROPERTIES COMPILE_FLAGS ${VS_FALGS} )
|
|
|
|
|
set_target_properties(zlmediakit PROPERTIES COMPILE_FLAGS ${VS_FALGS} )
|
2018-03-27 00:40:22 +08:00
|
|
|
|
elseif(NOT ANDROID OR IOS)
|
2018-03-21 16:16:04 +08:00
|
|
|
|
list(APPEND LINK_LIB_LIST pthread)
|
2018-03-21 15:13:33 +08:00
|
|
|
|
endif ()
|
|
|
|
|
|
2019-12-27 12:15:38 +08:00
|
|
|
|
#复制文件过来
|
|
|
|
|
execute_process(COMMAND cp -r ${CMAKE_CURRENT_SOURCE_DIR}/www ${EXECUTABLE_OUTPUT_PATH}/)
|
|
|
|
|
execute_process(COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/conf/config.ini ${EXECUTABLE_OUTPUT_PATH}/)
|
|
|
|
|
|
2019-12-17 18:45:31 +08:00
|
|
|
|
#添加c库
|
|
|
|
|
add_subdirectory(api)
|
|
|
|
|
|
2019-12-17 09:24:35 +08:00
|
|
|
|
if (NOT IOS)
|
|
|
|
|
#测试程序
|
|
|
|
|
add_subdirectory(tests)
|
|
|
|
|
#主服务器
|
|
|
|
|
add_subdirectory(server)
|
|
|
|
|
endif ()
|