Skip to content

Commit

Permalink
cmake: build qml plugin. fix cmake install dir
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
wang-bin committed Mar 10, 2017
1 parent 9dd9dba commit dfb3425
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 13 deletions.
39 changes: 30 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR)
set(PROJECT_VERSION 1.11.0)
set(SO_VERSION 1.11)
set(SO_VERSION 1)

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if(POLICY CMP0063) # visibility. since 3.3
cmake_policy(SET CMP0063 NEW)
endif()
set(CMAKE_CXX_VISIBILITY_PRESET hidden) #use with -fdata-sections -ffunction-sections to reduce target size
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)


option(BUILD_EXAMPLES "Build examples" ON)
option(BUILD_TESTS "Build tests" ON)
Expand All @@ -26,6 +36,11 @@ execute_process(
OUTPUT_VARIABLE QT_INSTALL_BINS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${qmake} -query QT_INSTALL_QML
OUTPUT_VARIABLE QT_INSTALL_QML
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${qmake} -query QT_INSTALL_PREFIX
OUTPUT_VARIABLE QT_INSTALL_PREFIX
Expand All @@ -47,21 +62,24 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) # for .moc
set(CMAKE_AUTOMOC ON)

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${QT_INSTALL_PREFIX} CACHE PATH "default install path" FORCE)
set(QTAV_INSTALL_HEADERS ${QT_INSTALL_HEADERS} CACHE PATH "")
set(QTAV_INSTALL_LIBS ${QT_INSTALL_LIBS} CACHE PATH "")
set(QTAV_INSTALL_BINS ${QT_INSTALL_BINS} CACHE PATH "")
set(QTAV_INSTALL_HEADERS ${CMAKE_INSTALL_PREFIX}/include)
set(QTAV_INSTALL_LIBS ${CMAKE_INSTALL_PREFIX}/lib)
set(QTAV_INSTALL_BINS ${CMAKE_INSTALL_PREFIX}/bin)
set(QTAV_INSTALL_QML ${CMAKE_INSTALL_PREFIX}/qml)
else()
set(QTAV_INSTALL_HEADERS ${CMAKE_INSTALL_PREFIX}/include CACHE PATH "")
set(QTAV_INSTALL_LIBS ${CMAKE_INSTALL_PREFIX}/lib CACHE PATH "")
set(QTAV_INSTALL_BINS ${CMAKE_INSTALL_PREFIX}/bin CACHE PATH "")
set(CMAKE_INSTALL_PREFIX ${QT_INSTALL_PREFIX} CACHE PATH "default install path" FORCE)
set(QTAV_INSTALL_HEADERS ${QT_INSTALL_HEADERS})
set(QTAV_INSTALL_LIBS ${QT_INSTALL_LIBS})
set(QTAV_INSTALL_BINS ${QT_INSTALL_BINS})
set(QTAV_INSTALL_QML ${QT_INSTALL_QML})
endif()

message(STATUS "Qt version: ${Qt5Core_VERSION_STRING}")
message(STATUS "Qt prefix: ${QT_INSTALL_PREFIX}")
message(STATUS "QtAV headers prefix: ${QTAV_INSTALL_HEADERS}")
message(STATUS "QtAV libs prefix: ${QTAV_INSTALL_LIBS}")
message(STATUS "QtAV bins prefix: ${QTAV_INSTALL_BINS}")
message(STATUS "QtAV qml prefix: ${QTAV_INSTALL_QML}")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Expand All @@ -79,7 +97,10 @@ find_package(Qt5Widgets)
if(Qt5Widgets_FOUND)
add_subdirectory(widgets)
endif()

find_package(Qt5 COMPONENTS Qml Quick)
if(Qt5Qml_FOUND AND Qt5Quick_FOUND)
add_subdirectory(qml)
endif()

if(BUILD_EXAMPLES)
add_subdirectory(examples)
Expand Down
7 changes: 7 additions & 0 deletions cmake/FindQtAV.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# - Try to find the QtAV library
#
# Once done this will define
#
# QTAV_FOUND - system has libqtav
# QTAV_INCLUDE_DIRS - the libqtav include directory
# QTAV_LIBRARIES - Link these to use libqtav

find_package(Qt5 QUIET REQUIRED NO_MODULE COMPONENTS Core)

Expand Down
12 changes: 12 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ SOURCE_GROUP("Resources" FILES ${PLAYER_QRC})
qt5_add_resources(PLAYER_RES ${PLAYER_QRC})
set_source_files_properties(${PLAYER_RES} PROPERTIES GENERATED ON)

if(Qt5Quick_FOUND)
set(QMLPLAYER_QRC QMLPlayer/qmlplayer.qrc)
qt5_add_resources(QMLPLAYER_RES ${QMLPLAYER_QRC})
set_source_files_properties(${QMLPLAYER_RES} PROPERTIES GENERATED ON)
add_executable(QMLPlayer
QMLPlayer/main.cpp
QMLPlayer/qtquick2applicationviewer/qtquick2applicationviewer.cpp
QMLPlayer/qtquick2applicationviewer/qtquick2applicationviewer.h
${QMLPLAYER_RES})
target_include_directories(QMLPlayer PRIVATE QMLPlayer/qtquick2applicationviewer)
target_link_libraries(QMLPlayer Qt5::Quick common)
endif()
if(Qt5Widgets_FOUND)
add_executable(Player ${PLAYER_SRC} ${PLAYER_HEADERS} ${PLAYER_RES})
target_link_libraries(Player QtAVWidgets common)
Expand Down
79 changes: 79 additions & 0 deletions qml/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
set(MODULE QmlAV)
set(EXTRA_DEFS -DBUILD_QMLAV_LIB)

#URI = QtAV #uri used in QtAVQmlPlugin::registerTypes(uri)
#qtAtLeast(5, 3): QMAKE_MOC_OPTIONS += -Muri=$$URI # not sure what moc does
set(HEADERS
QmlAV/Export.h
QmlAV/MediaMetaData.h
QmlAV/SGVideoNode.h
QmlAV/QQuickItemRenderer.h
QmlAV/QuickFilter.h
QmlAV/QmlAVPlayer.h
QmlAV/QuickSubtitle.h
QmlAV/QuickSubtitleItem.h
QmlAV/QuickVideoPreview.h
)
set(SOURCES
plugin.cpp
QQuickItemRenderer.cpp
SGVideoNode.cpp
QmlAVPlayer.cpp
QuickFilter.cpp
QuickSubtitle.cpp
MediaMetaData.cpp
QuickSubtitleItem.cpp
QuickVideoPreview.cpp
)
if(NOT Qt5Qml_VERSION VERSION_LESS 5.2.0)
list(APPEND HEADERS QmlAV/QuickFBORenderer.h)
list(APPEND SOURCES QuickFBORenderer.cpp)
endif()
# add HEADERS for moc
add_library(${MODULE} SHARED ${SOURCES} ${RESOURCES_SOURCES} ${HEADERS})
target_link_libraries(${MODULE}
LINK_PRIVATE ${EXTRA_LIBS}
LINK_PUBLIC QtAV Qt5::Qml Qt5::Quick
)
set_target_properties(${MODULE} PROPERTIES
OUTPUT_NAME ${MODULE}
CLEAN_DIRECT_OUTPUT 1
#LINK_SEARCH_START_STATIC 1
MACOSX_RPATH ON
FRAMEWORK OFF
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/QtAV
)

#http://stackoverflow.com/questions/19866424/cmake-and-qt5-automoc-error
#http://doc.qt.io/qt-5/cmake-manual.html
set(CMAKE_INCLUDE_CURRENT_DIR ON) # for .moc
target_include_directories(${MODULE}
PUBLIC $<INSTALL_INTERFACE:include>
PUBLIC $<INSTALL_INTERFACE:include/${MODULE}>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${MODULE}>
PRIVATE ${EXTRA_INCLUDE}
)
target_compile_definitions(${MODULE} PRIVATE ${EXTRA_DEFS})
set(QML_FILES qmldir Video.qml plugins.qmltypes)
add_custom_command(TARGET ${MODULE} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/bin/QtAV
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${QML_FILES} ${CMAKE_BINARY_DIR}/bin/QtAV
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

install(TARGETS ${MODULE}
EXPORT ${MODULE}-targets
RUNTIME DESTINATION ${QTAV_INSTALL_QML}/QtAV
LIBRARY DESTINATION ${QTAV_INSTALL_QML}/QtAV
ARCHIVE DESTINATION ${QTAV_INSTALL_QML}/QtAV
FRAMEWORK DESTINATION ${QTAV_INSTALL_LIBS}
)
install(EXPORT ${MODULE}-targets
DESTINATION ${QTAV_INSTALL_LIBS}/cmake/${MODULE}
FILE ${MODULE}-config.cmake
)
install(
FILES ${QML_FILES}
DESTINATION ${QTAV_INSTALL_QML}/QtAV
)
5 changes: 3 additions & 2 deletions qml/QuickFBORenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2017 Wang Bin <[email protected]>
* This file is part of QtAV (from 2015)
Expand Down Expand Up @@ -31,7 +31,8 @@
#include <QtGui/QOpenGLFramebufferObject>
#include <QtQuick/QQuickWindow>
// for dynamicgl. qglfunctions before qt5.3 does not have portable gl functions
#ifdef QT_OPENGL_DYNAMIC
// use qt gl func if possible to avoid linking to opengl directly
#if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)
#include <QtGui/QOpenGLFunctions>
#define DYGL(glFunc) QOpenGLContext::currentContext()->functions()->glFunc
#else
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ install(TARGETS ${MODULE}
RUNTIME DESTINATION ${QTAV_INSTALL_BINS}
LIBRARY DESTINATION ${QTAV_INSTALL_LIBS}
ARCHIVE DESTINATION ${QTAV_INSTALL_LIBS}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX}
FRAMEWORK DESTINATION ${QTAV_INSTALL_LIBS}
)

# FIXME: why QTAV_INCLUDE_DIRS is empty?
Expand Down
2 changes: 1 addition & 1 deletion widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ install(TARGETS ${MODULE}
RUNTIME DESTINATION ${QTAV_INSTALL_BINS}
LIBRARY DESTINATION ${QTAV_INSTALL_LIBS}
ARCHIVE DESTINATION ${QTAV_INSTALL_LIBS}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX}
FRAMEWORK DESTINATION ${QTAV_INSTALL_LIBS}
)
install(EXPORT ${MODULE}-targets
DESTINATION ${QTAV_INSTALL_LIBS}/cmake/${MODULE}
Expand Down

0 comments on commit dfb3425

Please sign in to comment.