fix Debian 8 Jessie and Ubuntu 14 Trusty compat

Fix some porting issues to make everything work on Debian 8 "Jessie"
and Ubuntu 14 "Trusty":

- set cmake minimum version to 2.8.12, this is the Ubuntu 14 version

- combine C and C++ flags and add all of them using
  ADD_COMPILE_OPTIONS() without using generator expressions, which is a
  cmake 3.2 or so feature

- add -fpermissive to force some non-const type casts to compile on
  older versions of gcc

- add -std=c++11 for gcc to enable support on older versions of gcc

- check that the compiler supports -fstack-protector-strong before
  adding it, older versions of gcc do not

- fix the debian section of ./installdeps to include libpng-dev instead
  of libpng16-dev and add gettext for msginit etc.

- fix compat checks in src/common/ffmpeg.cpp and src/wx/cmdevents.cpp to
  check for libavcodec >= 56 instead of > 56, the Debian Jessie version
  is exactly version 56 . With the one exception of
  AV_CODEC_FLAG_GLOBAL_HEADER which is defined in later versions.
This commit is contained in:
Rafael Kitover 2017-01-29 10:14:34 -08:00
parent fdc389c280
commit 34e408ccb7
5 changed files with 38 additions and 32 deletions

View File

@ -1,7 +1,7 @@
# The project's name is VBA-M it uses C and C++ code
PROJECT(VBA-M C CXX)
cmake_minimum_required( VERSION 3.3.2 )
cmake_minimum_required( VERSION 2.8.12 )
IF(CMAKE_BUILD_TYPE STREQUAL "")
SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build Type" FORCE)
@ -286,57 +286,61 @@ IF(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
ENDIF(ENABLE_LTO)
# common optimization flags
SET(MY_C_AND_CXX_OPT_FLAGS -O2 -mtune=generic -fomit-frame-pointer ${LTO_FLAG})
SET(MY_C_OPT_FLAGS -O2 -mtune=generic -fomit-frame-pointer ${LTO_FLAG})
# common debug flags
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(MY_C_AND_CXX_DBG_FLAGS -ggdb3 -Og)
SET(MY_C_DBG_FLAGS -ggdb3 -Og)
ELSE()
SET(MY_C_AND_CXX_DBG_FLAGS -g)
SET(MY_C_DBG_FLAGS -g)
ENDIF()
# common flags
SET(MY_C_AND_CXX_FLAGS -pipe -fPIC -Wformat -Wformat-security -fstack-protector-strong --param ssp-buffer-size=4 -fexceptions -D_FORTIFY_SOURCE=2 -feliminate-unused-debug-types)
SET(MY_C_FLAGS -pipe -fPIC -fpermissive -Wformat -Wformat-security -fexceptions -D_FORTIFY_SOURCE=2 -feliminate-unused-debug-types)
SET(MY_C_FLAGS ${MY_C_FLAGS} ${MY_C_AND_CXX_FLAGS})
SET(MY_CXX_FLAGS ${MY_CXX_FLAGS} ${MY_C_AND_CXX_FLAGS})
# check if SSP flags are supported
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG(-fstack-protector-strong F_STACK_PROTECTOR_STRONG_FLAG)
IF(F_STACK_PROTECTOR_STRONG_FLAG)
SET(MY_C_FLAGS ${MY_C_FLAGS} -fstack-protector-strong)
CHECK_CXX_COMPILER_FLAG("--param ssp-buffer-size=4" SSP_BUFFER_SIZE_FLAG)
IF(SSP_BUFFER_SIZE_FLAG)
SET(MY_C_FLAGS ${MY_C_FLAGS} --param ssp-buffer-size=4)
ENDIF()
ENDIF()
# clang doesn't like -std=c++11 for non-C++ sources
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(MY_C_FLAGS ${MY_C_FLAGS} -std=c++11)
ENDIF()
IF(MINGW)
SET(MY_C_FLAGS ${MY_C_FLAGS} -static-libgcc)
SET(MY_CXX_FLAGS ${MY_CXX_FLAGS} -static-libgcc -static-libstdc++)
SET(MY_C_FLAGS ${MY_C_FLAGS} -static-libgcc -static-libstdc++)
ENDIF(MINGW)
IF(CMAKE_BUILD_TYPE STREQUAL Debug)
SET(MY_C_FLAGS ${MY_C_FLAGS} ${MY_C_AND_CXX_DBG_FLAGS} -Wall -Wextra)
SET(MY_CXX_FLAGS ${MY_CXX_FLAGS} ${MY_C_AND_CXX_DBG_FLAGS} -Wall -Wextra)
SET(MY_C_FLAGS ${MY_C_FLAGS} ${MY_C_DBG_FLAGS} -Wall -Wextra)
ELSE()
SET(MY_C_FLAGS ${MY_C_FLAGS} ${MY_C_AND_CXX_OPT_FLAGS} -Wno-error)
SET(MY_CXX_FLAGS ${MY_CXX_FLAGS} ${MY_C_AND_CXX_OPT_FLAGS} -Wno-error)
SET(MY_C_FLAGS ${MY_C_FLAGS} ${MY_C_OPT_FLAGS} -Wno-error)
ENDIF()
FOREACH(C_COMPILE_FLAG ${MY_C_FLAGS})
ADD_COMPILE_OPTIONS($<$<COMPILE_LANGUAGE:C>:${C_COMPILE_FLAG}>)
ENDFOREACH()
FOREACH(CXX_COMPILE_FLAG ${MY_CXX_FLAGS})
ADD_COMPILE_OPTIONS($<$<COMPILE_LANGUAGE:CXX>:${CXX_COMPILE_FLAG}>)
ADD_COMPILE_OPTIONS(${C_COMPILE_FLAG})
ENDFOREACH()
# make a string of compile options to add to link flags
UNSET(C_COMPILE_FLAGS_STR)
UNSET(CXX_COMPILE_FLAGS_STR)
FOREACH(ARG ${MY_C_FLAGS})
SET(C_COMPILE_FLAGS_STR "${C_COMPILE_FLAGS_STR} ${ARG}")
ENDFOREACH()
FOREACH(ARG ${MY_CXX_FLAGS})
SET(CXX_COMPILE_FLAGS_STR "${CXX_COMPILE_FLAGS_STR} ${ARG}")
ENDFOREACH()
# need all flags for linking, because of -flto etc.
SET(CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} ${C_COMPILE_FLAGS_STR}")
SET(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${CXX_COMPILE_FLAGS_STR}")
SET(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${C_COMPILE_FLAGS_STR}")
# for the gcc -fstack-protector* flags we need libssp
# we also have to use the gcc- binutils for LTO to work

View File

@ -199,7 +199,7 @@ debian_installdeps() {
if [ -z "$target" ]; then
check sudo apt-get -qq update
check sudo apt-get -qy install build-essential g++ nasm cmake zlib1g-dev libgl1-mesa-dev libavcodec-dev libavformat-dev libswscale-dev libavutil-dev libgettextpo-dev libjpeg-dev libpng16-dev libtiff5-dev libsdl2-dev libsfml-dev libopenal-dev libwxgtk3.0-dev
check sudo apt-get -qy install build-essential g++ nasm cmake gettext zlib1g-dev libgl1-mesa-dev libavcodec-dev libavformat-dev libswscale-dev libavutil-dev libgettextpo-dev libjpeg-dev libpng-dev libtiff5-dev libsdl2-dev libsfml-dev libopenal-dev libwxgtk3.0-dev
else
case "$target" in
mingw-w64-i686)

View File

@ -58,12 +58,14 @@ static void avformat_free_context(AVFormatContext *ctx)
#ifndef PixelFormat
#define PixelFormat AVPixelFormat
#endif
#if LIBAVCODEC_VERSION_MAJOR > 56
#if LIBAVCODEC_VERSION_MAJOR >= 56
#define CODEC_ID_NONE AV_CODEC_ID_NONE
#define CODEC_ID_PCM_S16LE AV_CODEC_ID_PCM_S16LE
#define CODEC_ID_PCM_S16BE AV_CODEC_ID_PCM_S16BE
#define CODEC_ID_PCM_U16LE AV_CODEC_ID_PCM_U16LE
#define CODEC_ID_PCM_U16BE AV_CODEC_ID_PCM_U16BE
#endif
#if LIBAVCODEC_VERSION_MAJOR > 56
#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
#endif
#if LIBAVUTIL_VERSION_MAJOR > 54
@ -408,7 +410,7 @@ MediaRet MediaRecorder::AddFrame(const uint8_t *vid)
AVCodecContext *ctx = vid_st->codec;
AVPacket pkt;
#if LIBAVCODEC_VERSION_MAJOR > 56
#if LIBAVCODEC_VERSION_MAJOR >= 56
int ret, got_packet = 0;
#endif
@ -448,7 +450,7 @@ MediaRet MediaRecorder::AddFrame(const uint8_t *vid)
pkt.data = f->data[0];
pkt.size = linesize * ctx->height;
} else {
#if LIBAVCODEC_VERSION_MAJOR > 56
#if LIBAVCODEC_VERSION_MAJOR >= 56
pkt.data = video_buf;
pkt.size = VIDEO_BUF_LEN;
f->format = ctx->pix_fmt;
@ -486,7 +488,7 @@ MediaRet MediaRecorder::AddFrame(const uint8_t *vid)
return MRET_OK;
}
#if LIBAVCODEC_VERSION_MAJOR > 56
#if LIBAVCODEC_VERSION_MAJOR >= 56
/* FFmpeg depricated avcodec_encode_audio.
* It was removed completely in 3.0.
* This will at least get audio recording *working*
@ -560,7 +562,7 @@ MediaRet MediaRecorder::AddFrame(const uint16_t *aud)
}
while(len + in_audio_buf2 >= frame_len) {
av_init_packet(&pkt);
#if LIBAVCODEC_VERSION_MAJOR > 56
#if LIBAVCODEC_VERSION_MAJOR >= 56
MediaRecorderEncodeAudio(ctx, &pkt, audio_buf, frame_len,
#else
pkt.size = avcodec_encode_audio(ctx, audio_buf, frame_len,

View File

@ -113,7 +113,7 @@ SET(CMAKE_REQUIRED_DEFINITIONS ${CURRENT_CMAKE_REQUIRED_DEFINITIONS})
# end of wx OpenGL check
FOREACH(CXX_COMPILE_FLAG ${wxWidgets_CXX_FLAGS})
ADD_COMPILE_OPTIONS($<$<COMPILE_LANGUAGE:CXX>:${CXX_COMPILE_FLAG}>)
ADD_COMPILE_OPTIONS(${CXX_COMPILE_FLAG})
ENDFOREACH()
#EXECUTE_PROCESS(COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --cxxflags)

View File

@ -20,7 +20,7 @@ extern "C" {
}
// For compatibility with 3.0+ ffmpeg
#include <libavcodec/version.h>
#if LIBAVCODEC_VERSION_MAJOR > 56
#if LIBAVCODEC_VERSION_MAJOR >= 56
#define CODEC_ID_NONE AV_CODEC_ID_NONE
#endif
#endif