Skip to content

CMake support #10

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

Closed
wants to merge 9 commits into from
Closed
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
35 changes: 6 additions & 29 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,30 +1,7 @@
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################

build/

/source/ffmpeg-cpp/.vs/ffmpeg-cpp/v15
/source/ffmpeg-cpp/ffmpeg-cpp/obj
/source/ffmpeg-cpp/demo/obj
/source/ffmpeg-cpp/x64/Debug
/source/ffmpeg-cpp/obj/Debug
/source/ffmpeg-cpp/demo/samples/out.mp4
/ffmpeg/include
/ffmpeg/lib
/ffmpeg/bin
/bin
/lib

/source/ffmpeg-cpp/decode_audio/obj
/source/ffmpeg-cpp/encode_audio/obj
/source/ffmpeg-cpp/encode_video/obj
/source/ffmpeg-cpp/decode_video/obj
/source/ffmpeg-cpp/filtering_video/obj
/include

/source/ffmpeg-cpp/remuxing/obj
/source/ffmpeg-cpp/difference/obj/x64/Debug
/source/ffmpeg-cpp/difference/obj
/source/ffmpeg-cpp/print_info/obj/x64
/source/ffmpeg-cpp/filtering_audio/obj/x64
/source/ffmpeg-cpp/simple_interface/x64/Debug
/source/ffmpeg-cpp/simple_interface_demo/obj/x64
vendor/**/*
!vendor/ffmpeg/download.ps1
!vendor/ffmpeg/readme.*
!vendor/**/.gitkeep
80 changes: 80 additions & 0 deletions CMake/FindFFMPEG.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# FindFFMPEG.cmake
#
#

macro(_ffmpeg_find varname component header)
find_path(${varname}_INCLUDE_DIR
NAMES
"${component}/${header}"
"lib${component}/${header}"
HINTS
"${FFMPEG_DIR}/include"
"$ENV{FFMPEG_DIR}/include"
"$ENV{ProgramFiles}/ffmpeg/include"
"$ENV{ProgramFiles}/FFmpeg/include"
)

if("${${varname}_INCLUDE_DIR}" STREQUAL "${varname}_INCLUDE_DIR-NOTFOUND")
message(WARNING "${component} include directories not found")
set(${varname}_INCLUDE_DIR "")
endif()

find_library(${varname}_LIBRARY
NAMES
"${component}"
"lib${component}"
HINTS
"${FFMPEG_DIR}/lib"
"$ENV{FFMPEG_DIR}/lib"
"$ENV{ProgramFiles}/ffmpeg/lib"
"$ENV{ProgramFiles}/FFmpeg/lib"
)
set(${varname}_FOUND ON)

if("${${varname}_LIBRARY}" STREQUAL "${varname}_LIBRARY-NOTFOUND")
message(WARNING "${component} not found!")
set(${varname}_FOUND OFF)
set(${varname}_LIBRARY "")
else()
message(STATUS "Found ${component} - ${${varname}_LIBRARY}")
endif()


endmacro(_ffmpeg_find)


_ffmpeg_find(FFMPEG_AVFORMAT avformat avformat.h)
_ffmpeg_find(FFMPEG_AVDEVICE avdevice avdevice.h)
_ffmpeg_find(FFMPEG_AVCODEC avcodec avcodec.h)
_ffmpeg_find(FFMPEG_AVUTIL avutil avutil.h)
_ffmpeg_find(FFMPEG_AVFILTER avfilter avfilter.h)
_ffmpeg_find(FFMPEG_SWRESAMPLE swresample swresample.h)
_ffmpeg_find(FFMPEG_SWSCALE swscale swscale.h)
_ffmpeg_find(FFMPEG_POSTPROC postproc postprocess.h)

list(APPEND FFMPEG_LIBRARIES
${FFMPEG_AVFORMAT_LIBRARY}
${FFMPEG_AVDEVICE_LIBRARY}
${FFMPEG_AVCODEC_LIBRARY}
${FFMPEG_AVUTIL_LIBRARY}
${FFMPEG_AVFILTER_LIBRARY}
${FFMPEG_SWRESAMPLE_LIBRARY}
${FFMPEG_SWSCALE_LIBRARY}
${FFMPEG_POSTPROC_LIBRARY}
)

list(APPEND FFMPEG_INCLUDE_DIRS
${FFMPEG_AVFORMAT_INCLUDE_DIR}
${FFMPEG_AVDEVICE_INCLUDE_DIR}
${FFMPEG_AVCODEC_INCLUDE_DIR}
${FFMPEG_AVUTIL_INCLUDE_DIR}
${FFMPEG_AVFILTER_INCLUDE_DIR}
${FFMPEG_SWRESAMPLE_INCLUDE_DIR}
${FFMPEG_SWSCALE_INCLUDE_DIR}
${FFMPEG_POSTPROC_INCLUDE_DIR}
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FFMPEG
REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS
)
26 changes: 26 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.8)

# Don't configure in project root
if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
message(FATAL_ERROR "Please don't make configuration in-source.")
endif()

project(ffmpeg-cpp VERSION 1.0.0.0)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")

# If FFMPEG_DIR is not specified assume it's in /vendor/ffmpeg
if("${FFMPEG_DIR}" STREQUAL "")
set(FFMPEG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/vendor/ffmpeg")
endif()

find_package(FFMPEG REQUIRED)

# Orginize targets by folder structure
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Set C++ standard
set (CMAKE_CXX_STANDARD 11)

add_subdirectory("source")
add_subdirectory("examples")
36 changes: 36 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Variable to set examples output directory
set(EXAMPLE_BIN_DIR "${CMAKE_CURRENT_BINARY_DIR}")

set(examples
remuxing print_info filtering_video filtering_audio encode_video
encode_audio difference demo decode_video decode_audio
)

add_subdirectory("decode_audio")
add_subdirectory("decode_video")
add_subdirectory("demo")
add_subdirectory("difference")
add_subdirectory("encode_audio")
add_subdirectory("encode_video")
add_subdirectory("filtering_audio")
add_subdirectory("filtering_video")
add_subdirectory("print_info")
add_subdirectory("remuxing")

add_custom_target(samples ALL)
macro(copy_samples dir)
add_custom_command(
TARGET samples POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/samples" "${dir}/samples"
)
endmacro(copy_samples)

copy_samples("${EXAMPLE_BIN_DIR}")

if(MSVC)
set_target_properties(
${examples}
PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${EXAMPLE_BIN_DIR}"
)
endif()
11 changes: 11 additions & 0 deletions examples/decode_audio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_executable(decode_audio
decode_audio.cpp
)

target_link_libraries(decode_audio ffmpeg-cpp)

set_target_properties(decode_audio
PROPERTIES
FOLDER examples
RUNTIME_OUTPUT_DIRECTORY ${EXAMPLE_BIN_DIR}
)
11 changes: 11 additions & 0 deletions examples/decode_video/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_executable(decode_video
decode_video.cpp
)

target_link_libraries(decode_video ffmpeg-cpp)

set_target_properties(decode_video
PROPERTIES
FOLDER examples
RUNTIME_OUTPUT_DIRECTORY ${EXAMPLE_BIN_DIR}
)
15 changes: 15 additions & 0 deletions examples/demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
add_executable(demo
demo.cpp
GeneratedAudioSource.cpp
GeneratedAudioSource.h
GeneratedVideoSource.cpp
GeneratedVideoSource.h
)

target_link_libraries(demo ffmpeg-cpp)

set_target_properties(demo
PROPERTIES
FOLDER examples
RUNTIME_OUTPUT_DIRECTORY ${EXAMPLE_BIN_DIR}
)
File renamed without changes.
11 changes: 11 additions & 0 deletions examples/difference/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_executable(difference
difference.cpp
)

target_link_libraries(difference ffmpeg-cpp)

set_target_properties(difference
PROPERTIES
FOLDER examples
RUNTIME_OUTPUT_DIRECTORY ${EXAMPLE_BIN_DIR}
)
11 changes: 11 additions & 0 deletions examples/encode_audio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_executable(encode_audio
encode_audio.cpp
)

target_link_libraries(encode_audio ffmpeg-cpp)

set_target_properties(encode_audio
PROPERTIES
FOLDER examples
RUNTIME_OUTPUT_DIRECTORY ${EXAMPLE_BIN_DIR}
)
11 changes: 11 additions & 0 deletions examples/encode_video/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_executable(encode_video
encode_video.cpp
)

target_link_libraries(encode_video ffmpeg-cpp)

set_target_properties(encode_video
PROPERTIES
FOLDER examples
RUNTIME_OUTPUT_DIRECTORY ${EXAMPLE_BIN_DIR}
)
11 changes: 11 additions & 0 deletions examples/filtering_audio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_executable(filtering_audio
filtering_audio.cpp
)

target_link_libraries(filtering_audio ffmpeg-cpp)

set_target_properties(filtering_audio
PROPERTIES
FOLDER examples
RUNTIME_OUTPUT_DIRECTORY ${EXAMPLE_BIN_DIR}
)
11 changes: 11 additions & 0 deletions examples/filtering_video/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_executable(filtering_video
filtering_video.cpp
)

target_link_libraries(filtering_video ffmpeg-cpp)

set_target_properties(filtering_video
PROPERTIES
FOLDER examples
RUNTIME_OUTPUT_DIRECTORY ${EXAMPLE_BIN_DIR}
)
11 changes: 11 additions & 0 deletions examples/print_info/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_executable(print_info
print_info.cpp
)

target_link_libraries(print_info ffmpeg-cpp)

set_target_properties(print_info
PROPERTIES
FOLDER examples
RUNTIME_OUTPUT_DIRECTORY ${EXAMPLE_BIN_DIR}
)
11 changes: 11 additions & 0 deletions examples/remuxing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_executable(remuxing
remuxing.cpp
)

target_link_libraries(remuxing ffmpeg-cpp)

set_target_properties(remuxing
PROPERTIES
FOLDER examples
RUNTIME_OUTPUT_DIRECTORY ${EXAMPLE_BIN_DIR}
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
41 changes: 41 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@


# Get all header files
set(_include_dir "${PROJECT_SOURCE_DIR}/include/ffmpeg-cpp")
file(GLOB_RECURSE _headers
"${_include_dir}/*.h"
)

# Get all of the sources from subdirectories
set(_src "")
include("${CMAKE_CURRENT_LIST_DIR}/sources.cmake")

# Group every source file by folder structure
foreach(_source IN ITEMS ${_src})
get_filename_component(_source_path "${_source}" PATH)
if(IS_ABSOLUTE ${_source})
file(RELATIVE_PATH _source_path "${CMAKE_CURRENT_SOURCE_DIR}" "${_source_path}")
endif()
string(REPLACE "/" "\\" _group_path "${_source_path}")
source_group("${_group_path}" FILES "${_source}")
endforeach()


add_library(ffmpeg-cpp STATIC
${_headers}
${_src}
)

target_include_directories(ffmpeg-cpp
PUBLIC
$<BUILD_INTERFACE:${_include_dir}>
$<INSTALL_INTERFACE:"include/ffmpeg-cpp">
${FFMPEG_INCLUDE_DIRS}
PRIVATE
${_include_dir}
)

target_link_libraries(ffmpeg-cpp
PUBLIC
${FFMPEG_LIBRARIES}
)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "AudioCodec.h"
#include "Codecs/AudioCodec.h"
#include "FFmpegException.h"

using namespace std;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Codec.h"
#include "Codecs/Codec.h"
#include "FFmpegException.h"
#include "CodecDeducer.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "H264NVEncCodec.h"
#include "Codecs/H264NVEncCodec.h"

namespace ffmpegcpp
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "H265NVEncCodec.h"
#include "Codecs/H265NVEncCodec.h"

namespace ffmpegcpp
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "JPGCodec.h"
#include "Codecs/JPGCodec.h"

namespace ffmpegcpp
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "PNGCodec.h"
#include "Codecs/PNGCodec.h"

namespace ffmpegcpp
{
Expand Down
Loading