Skip to content

CMake: get AvTranscoder versions from headers #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@ cmake_minimum_required(VERSION 2.8.11)

project(AvTranscoder)

# Set AvTranscoder versions
set(AVTRANSCODER_VERSION_MAJOR "0")
set(AVTRANSCODER_VERSION_MINOR "5")
set(AVTRANSCODER_VERSION_MICRO "10")
set(AVTRANSCODER_VERSION ${AVTRANSCODER_VERSION_MAJOR}.${AVTRANSCODER_VERSION_MINOR}.${AVTRANSCODER_VERSION_MICRO})

# Define AvTranscoder versions
add_definitions(-DAVTRANSCODER_VERSION_MAJOR=${AVTRANSCODER_VERSION_MAJOR})
add_definitions(-DAVTRANSCODER_VERSION_MINOR=${AVTRANSCODER_VERSION_MINOR})
add_definitions(-DAVTRANSCODER_VERSION_MICRO=${AVTRANSCODER_VERSION_MICRO})

# Define AvTranscoder default path to profiles
add_definitions(-DAVTRANSCODER_DEFAULT_AVPROFILES="${CMAKE_INSTALL_PREFIX}/share/avprofiles")

Expand All @@ -37,8 +26,10 @@ if(AVTRANSCODER_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
endif()

# Build library
add_subdirectory(src)

# Build apps
if(AVTRANSCODER_DISABLE_APPS)
message("Apps disabled, will not build applications.")
else()
Expand Down
21 changes: 21 additions & 0 deletions cmake/AvTranscoderMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,24 @@
set(AVTRANSCODER_APP_PATH "${PROJECT_SOURCE_DIR}/app")
set(AVTRANSCODER_SRC_PATH "${PROJECT_SOURCE_DIR}/src")
file(GLOB_RECURSE AVTRANSCODER_SRC_FILES "AvTranscoder/*.cpp" "AvTranscoder/*.hpp")

# Get AvTranscoder versions
# AVTRANSCODER_VERSION_MAJOR
# AVTRANSCODER_VERSION_MINOR
# AVTRANSCODER_VERSION_MICRO
# AVTRANSCODER_VERSION
file(STRINGS "${AVTRANSCODER_SRC_PATH}/AvTranscoder/common.hpp" _avtranscoder_VERSION_HPP_CONTENTS REGEX "#define AVTRANSCODER_VERSION_")
foreach(v MAJOR MINOR MICRO)
if("${_avtranscoder_VERSION_HPP_CONTENTS}" MATCHES "#define AVTRANSCODER_VERSION_${v} ([0-9]+)")
set(AVTRANSCODER_VERSION_${v} "${CMAKE_MATCH_1}")
else()
set(AVTRANSCODER_RETRIEVE_VERSION_FAILED 1)
endif()
endforeach()
unset(_avtranscoder_VERSION_HPP_CONTENTS)

set(AVTRANSCODER_VERSION "${AVTRANSCODER_VERSION_MAJOR}.${AVTRANSCODER_VERSION_MINOR}.${AVTRANSCODER_VERSION_MICRO}")

if(AVTRANSCODER_RETRIEVE_VERSION_FAILED)
message(SEND_ERROR "Failed to retrieve AvTranscoder version: ${AVTRANSCODER_VERSION}")
endif()
4 changes: 4 additions & 0 deletions src/AvTranscoder/common.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef _AV_TRANSCODER_COMMON_HPP_
#define _AV_TRANSCODER_COMMON_HPP_

#define AVTRANSCODER_VERSION_MAJOR 0
#define AVTRANSCODER_VERSION_MINOR 5
#define AVTRANSCODER_VERSION_MICRO 10

#include <AvTranscoder/system.hpp>

extern "C" {
Expand Down
11 changes: 6 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(AvTranscoderMacros)

# find package ffmpeg/libav
find_package(FFmpeg COMPONENTS avcodec avformat avutil swscale swresample avresample)
# AvTranscoder versions
message(STATUS "AvTranscoder version is ${AVTRANSCODER_VERSION}")

# Check if FFmpeg or libav dependency
# Find package ffmpeg/libav
find_package(FFmpeg COMPONENTS avcodec avformat avutil swscale swresample avresample)
if(swresample_FOUND)
add_definitions(-DAVTRANSCODER_FFMPEG_DEPENDENCY)
message("Build avTranscoder with dependency to ffmpeg.")
message(STATUS "Build avTranscoder with dependency to ffmpeg.")
elseif(avresample_FOUND)
add_definitions(-DAVTRANSCODER_LIBAV_DEPENDENCY)
message("Build avTranscoder with dependency to libav.")
message(STATUS "Build avTranscoder with dependency to libav.")
else()
message(SEND_ERROR "Can't define if you depend on ffmpeg or libav.")
endif()
Expand Down