Skip to content
This repository was archived by the owner on Jan 7, 2023. It is now read-only.

enable cmake in windows #156

Open
wants to merge 1 commit into
base: topic_linux_and_window
Choose a base branch
from
Open
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
122 changes: 122 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
cmake_minimum_required (VERSION 3.1)
project (gst_mfx VERSION "2.0.2" LANGUAGES "C" "CXX" )
add_compile_options("/W1")

find_package(PkgConfig REQUIRED)

include(${CMAKE_SOURCE_DIR}/cmake/FindVC1ParserDependencies.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/FindBaseDependencies.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/FindMediaSDK.cmake)

option(MFX_DECODER "" ON)
option(MFX_VP9_DECODER "" OFF)

option(MFX_ENCODER "" ON)
option(MFX_H264_ENCODER "" ON)
option(MFX_H265_ENCODER "" OFF)
option(MFX_MPEG2_ENCODER "" OFF)
option(MFX_JPEG_ENCODER "" ON)

option(MFX_VPP "" ON)
option(MFX_SINK "" ON)
option(MFX_SINK_BIN "" ON)

option(USE_DRI3_RENDERER "" ON)
option(USE_WAYLAND_RENDERER "" ON)
option(USE_D3D11_RENDERER "" ON)

set(gst_version ${PROJECT_VERSION})
set(gst_version_major ${PROJECT_VERSION_MAJOR})
set(gst_version_minor ${PROJECT_VERSION_MINOR})
set(gst_version_micro ${PROJECT_VERSION_PATCH})
set(gst_version_nano ${PROJECT_VERSION_TWEAK})

set(glib_req ">= 2.40.0")
set(gst_req ${gst_version_major}.${gst_version_minor})
set(api_version "1.0")
set(temp_var)
MATH(EXPR temp_var "${gst_version_minor}*100+${gst_version_micro}")
set(libversion 0.${temp_var}.0)

set(prefix "" CACHE STRING "")
set(libdir "" CACHE STRING "")
set(plugins_install_dir "${prefix}/${libdir}/gstreamer-1.0")

if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
add_compile_options("/wd4244")
list(APPEND noseh_link_args "")
else()
list(APPEND noseh_link_args)
endif()

set(GETTEXT_PACKAGE "gst-mfx")
set(PACKAGE "gst_mfx")
set(PACKAGE_VERSION "${gst_version}")
set(GST_PACKAGE_NAME "GStreamer MFX")

list(APPEND gst_mfx_args)
list(APPEND gst_mfx_deps)

FindVC1(gst_mfx_deps)
FindBaseLibs(gst_mfx_deps)


set(with_pbutils OFF)
if(GSTREAMER_PBUTILS_FOUND)
set(with_pbutils ON)
endif()

FindMediaSDK()

list(APPEND gst_mfx_deps "legacy_stdio_definitions")

if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
list(APPEND gst_mfx_deps "d3d11" "gdi32" "shcore" "stdc++")
list(APPEND gst_mfx_args "-DWITH_D3D11_BACKEND")
endif()

if(GSTREAMER_GL_FOUND)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
list(APPEND gst_mfx_deps "opengl32")
list(APPEND gst_mfx_args "-DHAVE_GST_GL_LIBS")
list(APPEND gst_mfx_args "-DGST_USE_UNSTABLE_API")
endif()
endif()

set(mfx_decoder ${MFX_DECODER})
if(mfx_decoder)
list(APPEND gst_mfx_args "-DMFX_DECODER")
endif()

set(mfx_vp9_decoder ${MFX_VP9_DECODER})
if(mfx_vp9_decoder)
list(APPEND gst_mfx_args "-DMFX_VP9_DECODER")
endif()

if(MFX_VPP)
list(APPEND gst_mfx_args "-DMFX_VPP")
endif()

set(mfx_sink "${MFX_SINK}")
set(with_wayland OFF)
set(with_x11 OFF)
set(with_d3d11 OFF)
if(mfx_sink)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
if(USE_D3D11_RENDERER)
list(APPEND gst_mfx_args "-DMFX_SINK")
set(with_d3d11 ON)
else()
set(with_d3d11 OFF)
endif()
endif()
else()
endif()

set(mfx_encoder ${MFX_ENCODER})

configure_file(version.h.in version.h)

add_subdirectory (gst-libs)
add_subdirectory (gst)

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ add GL/glext.h and GL/wglext.h to the build, add `#if GST_GL_HAVE_PLATFORM_EGL .
comment out `and cc.has_header('GL/glext.h')` in meson.build. A more system-specific workaround would be to put the headers to
`C:\Program Files (x86)\Windows Kits\8.1\Include\um\gl` to avoid having to modify meson.build.

cmake build tips
----

1. download `pkg-config` and set environments as mentioned above.
2. add `#if GST_GL_HAVE_PLATFORM_EGL ... #endif` to `gstreamer-1.0\gst\gl\glprototypes\eglimage.h`
3. set `prefix` `lib` `DMFX_H265_ENCODER` and other variables which is similar to meson build.
4. compile in 64 mode.
> only support msvc in windows.

Usage
-----
Expand Down
120 changes: 120 additions & 0 deletions cmake/FindBaseDependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
function(FindGlib libs)
pkg_check_modules(GLIB-2.0 REQUIRED glib-2.0)
pkg_check_modules(GOBJECT-2.0 REQUIRED gobject-2.0)
pkg_check_modules(GIO-2.0 REQUIRED gio-2.0)
pkg_check_modules(GMODULE-2.0 REQUIRED gmodule-2.0)

set(GLIB_LIBS "")
if(GLIB-2.0_FOUND)
list(APPEND GST_LIBS ${GLIB-2.0_LIBRARIES})
include_directories (${GLIB-2.0_INCLUDE_DIRS})
endif()

if(GOBJECT-2.0_FOUND)
list(APPEND GST_LIBS ${GOBJECT-2.0_LIBRARIES})
include_directories (${GOBJECT-2.0_INCLUDE_DIRS})
endif()

if(GIO-2.0_FOUND)
list(APPEND GST_LIBS ${GIO-2.0_LIBRARIES})
include_directories (${GIO-2.0_INCLUDE_DIRS})
endif()

if(GMODULE-2.0_FOUND)
list(APPEND GST_LIBS ${GMODULE-2.0_LIBRARIES})
include_directories (${GMODULE-2.0_INCLUDE_DIRS})
endif()

set(${libs} ${GLIB_LIBS} PARENT_SCOPE)
endfunction(FindGlib)

function(FindGstreamer libs)
pkg_check_modules (GSTREAMER REQUIRED gstreamer-1.0>=1.6)
pkg_check_modules (GSTREAMER_VIDEO REQUIRED gstreamer-video-1.0>=1.6)
pkg_check_modules (GSTREAMER_ALLOCATORS REQUIRED gstreamer-allocators-1.0>=1.6)
pkg_check_modules (GSTREAMER_GL gstreamer-gl-1.0)
pkg_check_modules (GSTREAMER_PBUTILS gstreamer-pbutils-1.0)

set(GST_LIBS "")
if(GSTREAMER_FOUND)
list(APPEND GST_LIBS ${GSTREAMER_LIBRARIES})
include_directories (${GSTREAMER_INCLUDE_DIRS})
pkg_get_variable(plugin_libdir gstreamer-1.0 "pluginsdir")
link_directories(${GSTREAMER_LIBRARY_DIRS} ${plugin_libdir})
endif()

if(GSTREAMER_VIDEO_FOUND)
list(APPEND GST_LIBS ${GSTREAMER_VIDEO_LIBRARIES})
include_directories (${GSTREAMER_VIDEO_INCLUDE_DIRS})
endif()

if(GSTREAMER_ALLOCATORS_FOUND)
list(APPEND GST_LIBS ${GSTREAMER_ALLOCATORS_LIBRARIES})
include_directories (${GSTREAMER_ALLOCATORS_INCLUDE_DIRS})
endif()

if(GSTREAMER_PBUTILS_FOUND)
list(APPEND GST_LIBS ${GSTREAMER_PBUTILS_LIBRARIES})
include_directories (${GSTREAMER_PBUTILS_INCLUDE_DIRS})
endif()


if(GSTREAMER_GL_FOUND)
list(APPEND GST_LIBS ${GSTREAMER_GL_LIBRARIES})
include_directories (${GSTREAMER_GL_INCLUDE_DIRS})
add_definitions(-DHAVE_GST_GL_LIBS)
endif()
set(${libs} ${GST_LIBS} PARENT_SCOPE)



endfunction(FindGstreamer)

function(FindVideoDriver libs)
pkg_check_modules(LIBVA REQUIRED libva)
pkg_check_modules(LIBDRM REQUIRED libdrm)
pkg_check_modules(LIBDRM_INTEL REQUIRED libdrm_intel)
pkg_check_modules(LIBVA_DRM REQUIRED libva-drm)
pkg_check_modules(LIBUDEV REQUIRED libudev)

set(VIDEO_DRIVER "")
if(LIBVA_FOUND)
list(APPEND VIDEO_DRIVER ${LIBVA_LIBRARIES})
include_directories (${LIBVA_INCLUDE_DIRS})
endif()

if(LIBDRM_FOUND)
list(APPEND VIDEO_DRIVER ${LIBDRM_LIBRARIES})
include_directories (${LIBDRM_INCLUDE_DIRS})
endif()

if(LIBDRM_INTEL_FOUND)
list(APPEND VIDEO_DRIVER ${LIBDRM_INTEL_LIBRARIES})
include_directories (${LIBDRM_INTEL_INCLUDE_DIRS})
endif()

if(LIBVA_DRM_FOUND)
list(APPEND VIDEO_DRIVER ${LIBVA_DRM_LIBRARIES})
include_directories (${LIBVA_DRM_INCLUDE_DIRS})
endif()

if(LIBUDEV_FOUND)
list(APPEND VIDEO_DRIVER ${LIBUDEV_LIBRARIES})
include_directories (${LIBUDEV_INCLUDE_DIRS})
endif()
set(${libs} ${VIDEO_DRIVER} PARENT_SCOPE)
endfunction(FindVideoDriver)

function(FindBaseLibs libs)

set(glib_libs "")
set(gst_libs "")
set(drv_libs "")
FindGlib(glib_libs)
FindGstreamer(gst_libs)
# message("${glib_libs}")
# message("${gst_libs}")
#FindVideoDriver(drv_libs)
#set(${libs} ${gst_libs} ${drv_libs} PARENT_SCOPE)
set(${libs} ${${libs}} ${gst_libs} ${drv_libs} PARENT_SCOPE)
endfunction(FindBaseLibs)
22 changes: 22 additions & 0 deletions cmake/FindMediaSDK.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function(FindMediaSDK)
pkg_check_modules(MFX QUIET mfx)
set(MFX_LIBS "")
if(MFX_FOUND)
message(STATUS "MFX_LIBRARY_DIRS: ${MFX_LIBDIR}")
include_directories (${MFX_INCLUDE_DIRS})
else()
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
if(DEFINED ENV{INTELMEDIASDKROOT})
set(MFX_HOME $ENV{INTELMEDIASDKROOT})
endif()
endif()

set(MFX_INCLUDES "${MFX_HOME}/include")
set(MFX_LIBRARY "${MFX_HOME}/lib/x64/libmfx.lib")
message(STATUS "MediaSDK include directory: ${MFX_INCLUDES}")
message(STATUS "MediaSDK library directory: ${MFX_LIBRARY}")
include_directories(${MFX_INCLUDES})
endif()
add_library(libmfx STATIC IMPORTED)
set_property(TARGET libmfx PROPERTY IMPORTED_LOCATION ${MFX_LIBRARY})
endfunction(FindMediaSDK)
17 changes: 17 additions & 0 deletions cmake/FindVC1ParserDependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function(FindVC1 libs)
set(PARSER_LIB "")
pkg_check_modules(GSTREAMER_CODECPARSERS gstreamer-codecparsers-1.0)
pkg_check_modules(GSTREAMER_PBUTILS gstreamer-pbutils-1.0)
if((NOT GSTREAMER_CODECPARSERS_FOUND) OR (NOT GSTREAMER_PBUTILS_FOUND))
set(MFX_VC1_PARSER 0 PARENT_SCOPE)
endif()
if(GSTREAMER_CODECPARSERS_FOUND)
list(APPEND PARSER_LIB ${GSTREAMER_CODECPARSERS_LIBRARIES})
include_directories (${GSTREAMER_CODECPARSERS_INCLUDE_DIRS})
endif()
if(GSTREAMER_PBUTILS_FOUND)
list(APPEND PARSER_LIB ${GSTREAMER_PBUTILS_LIBRARIES})
include_directories (${GSTREAMER_PBUTILS_INCLUDE_DIRS})
endif()
set(${libs} ${${libs}} ${PARSER_LIB} PARENT_SCOPE)
endfunction(FindVC1)
22 changes: 22 additions & 0 deletions cmake/cmake_uninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
IF(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_BINARY_DIR@/install_manifest.txt\"")
ENDIF(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")

FILE(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
STRING(REGEX REPLACE "\n" ";" files "${files}")
FOREACH(file ${files})
MESSAGE(STATUS "Uninstalling \"${file}\"")
IF(EXISTS "${file}")
EXEC_PROGRAM(
"@CMAKE_COMMAND@" ARGS "-E remove \"${file}\""
OUTPUT_VARIABLE rm_out
RETURN_VALUE rm_retval
)
IF("${rm_retval}" STREQUAL 0)
ELSE("${rm_retval}" STREQUAL 0)
MESSAGE(FATAL_ERROR "Problem when removing \"${file}\"")
ENDIF("${rm_retval}" STREQUAL 0)
ELSE(EXISTS "${file}")
MESSAGE(STATUS "File \"${file}\" does not exist.")
ENDIF(EXISTS "${file}")
ENDFOREACH(file)
1 change: 1 addition & 0 deletions gst-libs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory (mfx)
Loading