From f67041edb28126e1f4f00b7a362c95a50fbbbcf1 Mon Sep 17 00:00:00 2001 From: "Lu, Gaoyong" Date: Fri, 25 Jan 2019 09:59:51 +0800 Subject: [PATCH] enable cmake in windows --- CMakeLists.txt | 122 ++++++++++++++++++++++++++ README.md | 8 ++ cmake/FindBaseDependencies.cmake | 120 +++++++++++++++++++++++++ cmake/FindMediaSDK.cmake | 22 +++++ cmake/FindVC1ParserDependencies.cmake | 17 ++++ cmake/cmake_uninstall.cmake.in | 22 +++++ gst-libs/CMakeLists.txt | 1 + gst-libs/mfx/CMakeLists.txt | 84 ++++++++++++++++++ gst/CMakeLists.txt | 1 + gst/mfx/CMakeLists.txt | 65 ++++++++++++++ 10 files changed, 462 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/FindBaseDependencies.cmake create mode 100644 cmake/FindMediaSDK.cmake create mode 100644 cmake/FindVC1ParserDependencies.cmake create mode 100644 cmake/cmake_uninstall.cmake.in create mode 100644 gst-libs/CMakeLists.txt create mode 100644 gst-libs/mfx/CMakeLists.txt create mode 100644 gst/CMakeLists.txt create mode 100644 gst/mfx/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..acd904f0 --- /dev/null +++ b/CMakeLists.txt @@ -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) + diff --git a/README.md b/README.md index bd65cbfe..0e161c3a 100644 --- a/README.md +++ b/README.md @@ -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 ----- diff --git a/cmake/FindBaseDependencies.cmake b/cmake/FindBaseDependencies.cmake new file mode 100644 index 00000000..d2402fe8 --- /dev/null +++ b/cmake/FindBaseDependencies.cmake @@ -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) diff --git a/cmake/FindMediaSDK.cmake b/cmake/FindMediaSDK.cmake new file mode 100644 index 00000000..a9ce080c --- /dev/null +++ b/cmake/FindMediaSDK.cmake @@ -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) diff --git a/cmake/FindVC1ParserDependencies.cmake b/cmake/FindVC1ParserDependencies.cmake new file mode 100644 index 00000000..97ac45f3 --- /dev/null +++ b/cmake/FindVC1ParserDependencies.cmake @@ -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) diff --git a/cmake/cmake_uninstall.cmake.in b/cmake/cmake_uninstall.cmake.in new file mode 100644 index 00000000..5c1b6707 --- /dev/null +++ b/cmake/cmake_uninstall.cmake.in @@ -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) \ No newline at end of file diff --git a/gst-libs/CMakeLists.txt b/gst-libs/CMakeLists.txt new file mode 100644 index 00000000..9aea6dc6 --- /dev/null +++ b/gst-libs/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory (mfx) \ No newline at end of file diff --git a/gst-libs/mfx/CMakeLists.txt b/gst-libs/mfx/CMakeLists.txt new file mode 100644 index 00000000..3250d847 --- /dev/null +++ b/gst-libs/mfx/CMakeLists.txt @@ -0,0 +1,84 @@ +set(sources +"gstmfxcontext.c" +"gstmfxfilter.c" +"gstmfxprofile.c" +"gstmfxsurfacepool.c" +"gstmfxsurface.c" +"gstmfxtaskaggregator.c" +"gstmfxtask.c" +"gstmfxvalue.c" +"gstmfxwindow.c" +"video-format.c" +"gstmfxcompositefilter.c" +"gstmfxsurfacecomposition.c" +) + +if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) + list(APPEND gst_mfx_deps "dxgi" "dxguid") + list(APPEND sources + "gstmfxallocator_d3d11.c" + "gstmfxsurface_d3d11.c" + "gstmfxd3d11device.c" + ) +else() + list(APPEND sources + "gstmfxdisplay.c" + "gstmfxprimebufferproxy.c" + "gstmfxsurface_vaapi.c" + "gstmfxallocator_vaapi.c" + "gstmfxutils_vaapi.c" + ) +endif() + +if(mfx_decoder) + list(APPEND sources "gstmfxdecoder.c") +endif() + +if(with_wayland) + list(APPEND sources + "gstmfxdecoder.c" + "wayland/gstmfxdisplay_wayland.c" + "wayland/gstmfxwindow_wayland.c" + "wayland/wayland-drm-protocol.c" + "wayland/scaler-protocol.c" + ) +endif() + +if(with_x11) + list(APPEND sources + "x11/gstmfxdisplay_x11.c" + "x11/gstmfxutils_x11.c" + "x11/gstmfxwindow_x11.c" +) +endif() + +if(with_d3d11) + list(APPEND sources "d3d11/gstmfxwindow_d3d11.c") +endif() + +if(mfx_encoder) + list(APPEND sources "gstmfxencoder.c") + list(APPEND sources "common/gstbitwriter.c") + if (MFX_H264_ENCODER) + list(APPEND gst_mfx_args "-DMFX_H264_ENCODER") + list(APPEND sources "gstmfxencoder_h264.c") + endif() + if (MFX_H265_ENCODER) + list(APPEND gst_mfx_args "-DMFX_H265_ENCODER") + list(APPEND sources "gstmfxencoder_h265.c") + endif() + if (MFX_MPEG2_ENCODER) + list(APPEND gst_mfx_args "-DMFX_MPEG2_ENCODER") + list(APPEND sources "gstmfxencoder_mpeg2.c") + endif() + if (MFX_JPEG_ENCODER) + list(APPEND gst_mfx_args "-DMFX_JPEG_ENCODER") + list(APPEND sources "gstmfxencoder_jpeg.c") + endif() +endif() + +include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}) +add_compile_options(${gst_mfx_args}) + +ADD_LIBRARY(gstmfx-${api_version} STATIC ${sources}) +target_link_libraries(gstmfx-${api_version} ${gst_mfx_deps}) diff --git a/gst/CMakeLists.txt b/gst/CMakeLists.txt new file mode 100644 index 00000000..9aea6dc6 --- /dev/null +++ b/gst/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory (mfx) \ No newline at end of file diff --git a/gst/mfx/CMakeLists.txt b/gst/mfx/CMakeLists.txt new file mode 100644 index 00000000..c4be1e32 --- /dev/null +++ b/gst/mfx/CMakeLists.txt @@ -0,0 +1,65 @@ +set(sources + "gstmfx.c" + "gstmfxpluginbase.c" + "gstmfxpluginutil.c" + "gstmfxvideobufferpool.c" + "gstmfxvideocontext.c" + "gstmfxvideomemory.c" + "gstmfxvideometa.c" + ) + +if(mfx_encoder) + list(APPEND sources "gstmfxdec.c") +endif() + +if(mfx_sink) + list(APPEND sources "gstmfxsink.c") +endif() + +set(mfx_vpp ${MFX_VPP}) +if(mfx_vpp) + list(APPEND sources "gstmfxpostproc.c") +endif() + +if(mfx_sink AND mfx_vpp AND with_pbutils) + if(MFX_SINK_BIN) + list(APPEND sources "gstmfxsinkbin.c") + list(APPEND gst_mfx_args "-DMFX_SINK_BIN") + endif() +endif() + +if(mfx_encoder) + list(APPEND sources "gstmfxenc.c") + if(MFX_H264_ENCODER) + list(APPEND sources "gstmfxenc_h264.c") + list(APPEND gst_mfx_args "-DMFX_H264_ENCODER") + endif() + + if(MFX_H265_ENCODER) + list(APPEND sources "gstmfxenc_h265.c") + list(APPEND gst_mfx_args "-DMFX_H265_ENCODER") + endif() + + if(MFX_MPEG2_ENCODER) + list(APPEND sources "gstmfxenc_mpeg2.c") + list(APPEND gst_mfx_args "-DMFX_MPEG2_ENCODER") + endif() + + if(MFX_JPEG_ENCODER) + list(APPEND sources "gstmfxenc_jpeg.c") + list(APPEND gst_mfx_args "-DMFX_JPEG_ENCODER") + endif() +endif() + + +include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}) +include_directories(${CMAKE_SOURCE_DIR}/gst-libs/mfx) +include_directories(${CMAKE_SOURCE_DIR}) + +add_compile_options(${gst_mfx_args}) + +ADD_LIBRARY(gstmfx SHARED ${sources}) + +target_link_libraries(gstmfx ${gst_mfx_deps} libmfx gstmfx-${api_version}) +#message(${plugins_install_dir}) +install(TARGETS gstmfx DESTINATION ${plugins_install_dir}) \ No newline at end of file