Replace FindFFmpeg, Update CmakeLists.txt

This commit is contained in:
Stanislav Ershov 2017-11-27 13:14:26 +03:00
parent 7c37a0f4af
commit a2785b8a62
5 changed files with 167 additions and 149 deletions

View File

@ -1,15 +1,19 @@
cmake_minimum_required(VERSION 3.10)
project(telegram-desktop)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
else()
find_package(OpenSSL REQUIRED)
endif()
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cotire/CMake;${PROJECT_SOURCE_DIR}/modules/")
include(cotire)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS OFF)
set_property(GLOBAL PROPERTY CXX_STANDARD 14)
set_property(GLOBAL PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(GLOBAL PROPERTY CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
@ -24,14 +28,15 @@ find_package(LibZip REQUIRED)
find_package(LibLZMA REQUIRED)
find_package(FFmpeg REQUIRED)
find_package(Iconv REQUIRED)
#@todo Turn into find_package(Opus REQUIRED)
find_library(OPUS_LIB opus)
find_path(OPUS_INCLUDE_DIR opus.h PATHS /usr/local/include/opus)
find_path(OPUS_INCLUDE_DIR opus/opus.h)
if (NOT FFMPEG_SWSCALE_FOUND)
if (NOT SWSCALE_FOUND)
message(FATAL_ERROR "FFmpeg swscale is required")
endif()
if (NOT FFMPEG_SWRESAMPLE_FOUND)
if (NOT SWRESAMPLE_FOUND)
message(FATAL_ERROR "FFmpeg swresample is required")
endif()
if (NOT OPUS_LIB)

View File

@ -454,7 +454,6 @@ set(APP_SRC
SourceFiles/overviewwidget.cpp
SourceFiles/passcodewidget.cpp
SourceFiles/qt_functions.cpp
SourceFiles/qt_static_plugins.cpp
SourceFiles/settings.cpp
SourceFiles/shortcuts.cpp
SourceFiles/structs.cpp
@ -557,10 +556,15 @@ add_subdirectory(ThirdParty/libtgvoip)
# Shut up for testbuilding, remove me
include_directories(/usr/local/opt/openal-soft/include)
add_definitions(-Wno-switch)
if(NOT WIN32)
add_definitions(-Wno-switch)
endif()
# End remove me
if (WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -DWIN32 -D_WINDOWS -DUNICODE -DWIN64 -DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP)
list(APPEND APP_SRC Resources/winrc/Telegram.rc)
endif()
add_definitions(-DTDESKTOP_DISABLE_CRASH_REPORTS)
@ -588,7 +592,6 @@ if (APPLE)
endif()
add_executable(Telegram WIN32 MACOSX_BUNDLE
SourceFiles/stdafx.cpp
${APP_SRC}
${PLAT_SRC}
${THIRD_PARTY_SRC}
@ -598,7 +601,11 @@ add_executable(Telegram WIN32 MACOSX_BUNDLE
)
# Disable a single annoying warning about c++17
target_compile_options(Telegram PRIVATE -Wno-c++1z-extensions)
if(NOT WIN32)
target_compile_options(Telegram PRIVATE -Wno-c++1z-extensions)
else()
target_compile_options(Telegram PRIVATE /std:c++14)
endif()
target_link_libraries(Telegram
Qt5::Core
@ -609,7 +616,10 @@ target_link_libraries(Telegram
${ZLIB_LIBRARIES}
${OPENAL_LIBRARY}
${FFMPEG_LIBRARIES}
${SWRESAMPLE_LIBRARIES}
${SWSCALE_LIBRARIES}
${ICONV_LIBRARIES}
${OPENSSL_LIBRARIES}
${OPUS_LIB}
${CONAN_LIBS}
) # crashpad::crashpad_client)
@ -641,6 +651,10 @@ if (APPLE)
)
endif()
if(WIN32)
target_link_libraries(Telegram winmm imm32 ws2_32 kernel32 user32 gdi32 winspool comdlg32 advapi32 shell32 ole32 oleaut32 uuid odbc32 odbccp32 Shlwapi Iphlpapi Gdiplus Strmiids)
endif()
set_target_properties(Telegram
PROPERTIES
COTIRE_CXX_PREFIX_HEADER_INIT SourceFiles/stdafx.h

View File

@ -9,7 +9,7 @@
#include "MediaStreamItf.h"
#include "opus.h"
#include <opus/opus.h>
#include "threading.h"
#include "BlockingQueue.h"
#include "BufferPool.h"

View File

@ -9,7 +9,7 @@
#include "MediaStreamItf.h"
#include "opus.h"
#include <opus/opus.h>
#include "threading.h"
#include "BlockingQueue.h"
#include "BufferPool.h"

View File

@ -1,154 +1,153 @@
# - Try to find FFMPEG
# from https://github.com/snikulov/cmake-modules/blob/master/FindFFmpeg.cmake
#
# vim: ts=2 sw=2
# - Try to find the required ffmpeg components(default: AVFORMAT, AVUTIL, AVCODEC)
#
# Once done this will define
# FFMPEG_FOUND - System has the all required components.
# FFMPEG_INCLUDE_DIRS - Include directory necessary for using the required components headers.
# FFMPEG_LIBRARIES - Link these to use the required ffmpeg components.
# FFMPEG_DEFINITIONS - Compiler switches required for using the required ffmpeg components.
#
# FFMPEG_FOUND - system has FFMPEG
# FFMPEG_INCLUDE_DIR - the include directories
# FFMPEG_LIBRARY_DIR - the directory containing the libraries
# FFMPEG_LIBRARIES - link these to use FFMPEG
# FFMPEG_SWSCALE_FOUND - FFMPEG also has SWSCALE
# FFMPEG_SWRESAMPLE_FOUND - FFMPEG also has SWRESAMPLE
# For each of the components it will additionally set.
# - AVCODEC
# - AVDEVICE
# - AVFORMAT
# - AVFILTER
# - AVUTIL
# - POSTPROC
# - SWSCALE
# the following variables will be defined
# <component>_FOUND - System has <component>
# <component>_INCLUDE_DIRS - Include directory necessary for using the <component> headers
# <component>_LIBRARIES - Link these to use <component>
# <component>_DEFINITIONS - Compiler switches required for using <component>
# <component>_VERSION - The components version
#
# Copyright (c) 2006, Matthias Kretz, <kretz@kde.org>
# Copyright (c) 2008, Alexander Neundorf, <neundorf@kde.org>
# Copyright (c) 2011, Michael Jansen, <kde@michael-jansen.biz>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
SET( FFMPEG_HEADERS avformat.h avcodec.h avutil.h avdevice.h )
SET( FFMPEG_PATH_SUFFIXES libavformat libavcodec libavutil libavdevice )
SET( FFMPEG_SWS_HEADERS swscale.h )
SET( FFMPEG_SWS_PATH_SUFFIXES libswscale )
SET( FFMPEG_SWR_HEADERS swresample.h )
SET( FFMPEG_SWR_PATH_SUFFIXES libswresample )
SET( FFMPEG_PP_HEADERS postproc.h )
SET( FFMPEG_PP_PATH_SUFFIXES libpostproc )
include(FindPackageHandleStandardArgs)
if( $ENV{FFMPEGDIR} )
SET( FFMPEG_LIBRARIES avformat-52.lib avcodec-51.lib avutil-49.lib avdevice-52.lib )
SET( FFMPEG_SWS_LIBRARIES swscale-0.lib )
SET( FFMPEG_PP_LIBRARIES postproc-0.lib )
SET( FFMPEG_LIBRARY_DIR $ENV{FFMPEGDIR}/lib )
SET( FFMPEG_INCLUDE_PATHS $ENV{FFMPEGDIR}/include )
# The default components were taken from a survey over other FindFFMPEG.cmake files
if (NOT FFmpeg_FIND_COMPONENTS)
set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL)
endif ()
# check to see if we can find swscale
SET( TMP_ TMP-NOTFOUND )
FIND_PATH( TMP_ ${FFMPEG_SWS_LIBRARIES} ${FFMPEG_PP_LIBRARIES}
PATHS ${FFMPEG_LIBRARY_DIR} )
IF ( TMP_ )
SET( SWSCALE_FOUND TRUE )
ENDIF( TMP_ )
else( $ENV{FFMPEGDIR} )
SET( FFMPEG_LIBRARIES avformat avcodec avutil avdevice )
SET( FFMPEG_SWS_LIBRARIES swscale )
SET( FFMPEG_SWR_LIBRARIES swresample )
SET( FFMPEG_PP_LIBRARIES postproc )
INCLUDE(FindPkgConfig)
if ( PKG_CONFIG_FOUND )
pkg_check_modules( AVFORMAT libavformat )
pkg_check_modules( AVCODEC libavcodec )
pkg_check_modules( AVUTIL libavutil )
pkg_check_modules( AVDEVICE libavdevice )
pkg_check_modules( SWSCALE libswscale )
pkg_check_modules( SWRESAMPLE libswresample )
pkg_check_modules( POSTPROC libpostproc )
endif ( PKG_CONFIG_FOUND )
#
### Macro: set_component_found
#
# Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present.
#
macro(set_component_found _component )
if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS)
# message(STATUS " - ${_component} found.")
set(${_component}_FOUND TRUE)
else ()
# message(STATUS " - ${_component} not found.")
endif ()
endmacro()
SET( FFMPEG_LIBRARY_DIR ${AVFORMAT_LIBRARY_DIRS}
${AVCODEC_LIBRARY_DIRS}
${AVUTIL_LIBRARY_DIRS}
${AVDEVICE_LIBRARY_DIRS} )
SET( FFMPEG_INCLUDE_PATHS ${AVFORMAT_INCLUDE_DIRS}
${AVCODEC_INCLUDE_DIRS}
${AVUTIL_INCLUDE_DIRS}
${AVDEVICE_INCLUDE_DIRS} )
endif( $ENV{FFMPEGDIR} )
#
### Macro: find_component
#
# Checks for the given component by invoking pkgconfig and then looking up the libraries and
# include directories.
#
macro(find_component _component _pkgconfig _library _header)
SET( FFMPEG_SWSCALE_FOUND ${SWSCALE_FOUND} )
if (NOT WIN32)
# use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(PC_${_component} ${_pkgconfig})
endif ()
endif (NOT WIN32)
# add in swscale if found
IF ( SWSCALE_FOUND )
SET( FFMPEG_LIBRARY_DIR ${FFMPEG_LIBRARY_DIR}
${SWSCALE_LIBRARY_DIRS} )
SET( FFMPEG_INCLUDE_PATHS ${FFMPEG_INCLUDE_PATHS}
${SWSCALE_INCLUDE_DIRS} )
SET( FFMPEG_HEADERS ${FFMPEG_HEADERS}
${FFMPEG_SWS_HEADERS} )
SET( FFMPEG_PATH_SUFFIXES ${FFMPEG_PATH_SUFFIXES}
${FFMPEG_SWS_PATH_SUFFIXES} )
SET( FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES}
${FFMPEG_SWS_LIBRARIES} )
ENDIF ( SWSCALE_FOUND )
find_path(${_component}_INCLUDE_DIRS ${_header}
HINTS
${PC_LIB${_component}_INCLUDEDIR}
${PC_LIB${_component}_INCLUDE_DIRS}
PATH_SUFFIXES
ffmpeg
)
SET( FFMPEG_SWRESAMPLE_FOUND ${SWRESAMPLE_FOUND} )
find_library(${_component}_LIBRARIES NAMES ${_library}
HINTS
${PC_LIB${_component}_LIBDIR}
${PC_LIB${_component}_LIBRARY_DIRS}
)
# add in swresample if found
IF ( SWRESAMPLE_FOUND )
SET( FFMPEG_LIBRARY_DIR ${FFMPEG_LIBRARY_DIR}
${SWRESAMPLE_LIBRARY_DIRS} )
SET( FFMPEG_INCLUDE_PATHS ${FFMPEG_INCLUDE_PATHS}
${SWRESAMPLE_INCLUDE_DIRS} )
SET( FFMPEG_HEADERS ${FFMPEG_HEADERS}
${FFMPEG_SWR_HEADERS} )
SET( FFMPEG_PATH_SUFFIXES ${FFMPEG_PATH_SUFFIXES}
${FFMPEG_SWR_PATH_SUFFIXES} )
SET( FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES}
${FFMPEG_SWR_LIBRARIES} )
ENDIF ( SWRESAMPLE_FOUND )
set(${_component}_DEFINITIONS ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS.")
set(${_component}_VERSION ${PC_${_component}_VERSION} CACHE STRING "The ${_component} version number.")
# add in postproc if found
IF ( POSTPROC_FOUND )
SET( FFMPEG_LIBRARY_DIR ${FFMPEG_LIBRARY_DIR}
${POSTPROC_LIBRARY_DIRS} )
SET( FFMPEG_INCLUDE_PATHS ${FFMPEG_INCLUDE_PATHS}
${POSTPROC_INCLUDE_DIRS} )
SET( FFMPEG_HEADERS ${FFMPEG_HEADERS}
${FFMPEG_PP_HEADERS} )
SET( FFMPEG_PATH_SUFFIXES ${FFMPEG_PATH_SUFFIXES}
${FFMPEG_PP_PATH_SUFFIXES} )
SET( FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES}
${FFMPEG_PP_LIBRARIES} )
ENDIF ( POSTPROC_FOUND )
set_component_found(${_component})
# find includes
SET( INC_SUCCESS 0 )
SET( TMP_ TMP-NOTFOUND )
SET( FFMPEG_INCLUDE_DIR ${FFMPEG_INCLUDE_PATHS} )
FOREACH( INC_ ${FFMPEG_HEADERS} )
message( "checking: " ${INC_} )
mark_as_advanced(
${_component}_INCLUDE_DIRS
${_component}_LIBRARIES
${_component}_DEFINITIONS
${_component}_VERSION)
FIND_PATH( TMP_ ${INC_}
PATHS ${FFMPEG_INCLUDE_PATHS}
PATH_SUFFIXES ${FFMPEG_PATH_SUFFIXES} )
IF ( TMP_ )
message( "found: " ${TMP_} )
MATH( EXPR INC_SUCCESS ${INC_SUCCESS}+1 )
SET( FFMPEG_INCLUDE_DIR ${FFMPEG_INCLUDE_DIR} ${TMP_} )
ENDIF ( TMP_ )
SET( TMP_ TMP-NOTFOUND )
ENDFOREACH( INC_ )
endmacro()
# clear out duplicates
IF (FFMPEG_INCLUDE_DIR)
LIST( REMOVE_DUPLICATES FFMPEG_INCLUDE_DIR )
ENDIF (FFMPEG_INCLUDE_DIR)
IF (FFMPEG_LIBRARY_DIR)
LIST( REMOVE_DUPLICATES FFMPEG_LIBRARY_DIR )
ENDIF (FFMPEG_LIBRARY_DIR)
# Check for cached results. If there are skip the costly part.
if (NOT FFMPEG_LIBRARIES)
# find the full paths of the libraries
SET( TMP_ TMP-NOTFOUND )
IF ( NOT WIN32 )
FOREACH( LIB_ ${FFMPEG_LIBRARIES} )
FIND_LIBRARY( TMP_ NAMES ${LIB_} PATHS ${FFMPEG_LIBRARY_DIR} )
IF ( TMP_ )
SET( FFMPEG_LIBRARIES_FULL ${FFMPEG_LIBRARIES_FULL} ${TMP_} )
ENDIF ( TMP_ )
SET( TMP_ TMP-NOTFOUND )
ENDFOREACH( LIB_ )
SET ( FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES_FULL} )
ENDIF( NOT WIN32 )
# Check for all possible component.
find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
find_component(AVUTIL libavutil avutil libavutil/avutil.h)
find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h)
find_component(SWSCALE libswscale swscale libswscale/swscale.h)
find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
find_component(SWRESAMPLE libswresample swresample libswresample/swresample.h)
LIST( LENGTH FFMPEG_HEADERS LIST_SIZE_ )
# Check if the required components were found and add their stuff to the FFMPEG_* vars.
foreach (_component ${FFmpeg_FIND_COMPONENTS})
if (${_component}_FOUND)
# message(STATUS "Required component ${_component} present.")
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES})
set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS})
list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS})
else ()
# message(STATUS "Required component ${_component} missing.")
endif ()
endforeach ()
SET( FFMPEG_FOUND FALSE )
SET( FFMPEG_POSTPROC_FOUND FALSE )
IF ( ${INC_SUCCESS} EQUAL ${LIST_SIZE_} )
SET( FFMPEG_FOUND TRUE )
SET( FFMPEG_POSTPROC_FOUND ${POSTPROC_FOUND} )
ENDIF ( ${INC_SUCCESS} EQUAL ${LIST_SIZE_} )
# Build the include path with duplicates removed.
if (FFMPEG_INCLUDE_DIRS)
list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
endif ()
# cache the vars.
set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE)
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE)
set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE)
mark_as_advanced(FFMPEG_INCLUDE_DIRS
FFMPEG_LIBRARIES
FFMPEG_DEFINITIONS)
endif ()
# Now set the noncached _FOUND vars for the components.
foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE SWRESAMPLE)
set_component_found(${_component})
endforeach ()
# Compile the list of required vars
set(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS)
foreach (_component ${FFmpeg_FIND_COMPONENTS})
list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS)
endforeach ()
# Give a nice error message if some of the required vars are missing.
find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS})