Skip to content

Commit

Permalink
cmake: support find_package(QtAV) wang-bin#795
Browse files Browse the repository at this point in the history
Currently only FindQtAV.cmake works, i.e. "Module" mode. In "Config"
mode, QTAV_INCLUDE_DIRS and QTAV_LIBRARIES are empty. To use
FindQtAV.cmake, you have to append it's dir to CMAKE_MODULE_PATH

try simpleplayer example after qtav make install

TODO: module mode. auto insert dependencies
  • Loading branch information
wang-bin committed Jan 26, 2017
1 parent fbbe37b commit bc60860
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 87 deletions.
24 changes: 19 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 1,26 @@
cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR)
set(PROJECT_VERSION 1.11.0)
set(SO_VERSION 1.11)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")


option(BUILD_EXAMPLES "Build examples" ON)
option(BUILD_TESTS "Build tests" ON)
option(BUILD_QT5OPENGL "Build with Qt5 OpenGL module" ON)

list(APPEND CMAKE_FIND_ROOT_PATH ${QTDIR})
list(APPEND CMAKE_PREFIX_PATH ${QTDIR})
set(QTCONFIGROOT ${QTDIR}/lib/cmake/Qt5)

find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)

get_target_property(qmake Qt5::qmake LOCATION)
execute_process(
COMMAND ${qmake} -query QT_INSTALL_HEADERS
OUTPUT_VARIABLE QT_INSTALL_HEADERS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${qmake} -query QT_INSTALL_LIBS
OUTPUT_VARIABLE QT_INSTALL_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "Qt version: ${Qt5Core_VERSION_STRING}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${QT5_CFLAGS}")

Expand All @@ -36,12 42,20 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

#set(CMAKE_DEBUG_POSTFIX d)

install(FILES
cmake/FindQtAV.cmake
DESTINATION ${QT_INSTALL_LIBS}/cmake
)

add_subdirectory(src)
find_package(Qt5Widgets)
if(Qt5Widgets_FOUND)
add_subdirectory(widgets)
endif()


if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
Expand Down
49 changes: 49 additions & 0 deletions cmake/FindQtAV.cmake
Original file line number Diff line number Diff line change
@@ -0,0 1,49 @@

find_package(Qt5 QUIET REQUIRED NO_MODULE COMPONENTS Core)

get_target_property(qmake Qt5::qmake LOCATION)
execute_process(
COMMAND ${qmake} -query QT_INSTALL_HEADERS
OUTPUT_VARIABLE QT_INSTALL_HEADERS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${qmake} -query QT_INSTALL_LIBS
OUTPUT_VARIABLE QT_INSTALL_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE
)

find_path(QTAV_INCLUDE_DIR NAMES QtAV.h
HINTS ${QT_INSTALL_HEADERS}
PATH_SUFFIXES QtAV
)
find_library(QTAV_LIBRARY NAMES QtAV QtAV1
HINTS ${QT_INSTALL_LIBS}
)

find_path(QTAVWIDGETS_INCLUDE_DIR NAMES QtAVWidgets.h
HINTS ${QT_INSTALL_HEADERS}
PATH_SUFFIXES QtAVWidgets
)
find_library(QTAVWIDGETS_LIBRARY NAMES QtAVWidgets QtAVWidgets1
HINTS ${QT_INSTALL_LIBS}
)

set(QTAV_INCLUDE_DIRS ${QTAV_INCLUDE_DIR} ${QTAV_INCLUDE_DIR}/..)
set(QTAV_LIBRARIES ${QTAV_LIBRARY})
if(NOT QTAVWIDGETS_INCLUDE_DIR MATCHES "QTAVWIDGETS_INCLUDE_DIR-NOTFOUND")
set(QTAVWIDGETS_INCLUDE_DIRS ${QTAVWIDGETS_INCLUDE_DIR} ${QTAVWIDGETS_INCLUDE_DIR}/.. ${QTAV_INCLUDE_DIRS})
endif()
if(NOT QTAV_LIBRARIES MATCHES "QTAV_LIBRARIES-NOTFOUND")
set(QTAVWIDGETS_LIBRARIES ${QTAVWIDGETS_LIBRARY} ${QTAV_LIBRARY})
endif()

find_package(PackageHandleStandardArgs REQUIRED)
find_package_handle_standard_args(QtAV REQUIRED_VARS QTAV_LIBRARIES QTAV_INCLUDE_DIRS)
mark_as_advanced(QTAV_INCLUDE_DIRS QTAV_LIBRARIES QTAVWIDGETS_INCLUDE_DIRS QTAVWIDGETS_LIBRARIES)

message("QtAV_FOUND = ${QTAV_FOUND}")
message("QTAV_INCLUDE_DIRS = ${QTAV_INCLUDE_DIRS}")
message("QTAV_LIBRARIES = ${QTAV_LIBRARIES}")
message("QTAVWIDGETS_INCLUDE_DIRS = ${QTAVWIDGETS_INCLUDE_DIRS}")
message("QTAVWIDGETS_LIBRARIES = ${QTAVWIDGETS_LIBRARIES}")
8 changes: 8 additions & 0 deletions examples/simpleplayer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 1,8 @@
cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR)
find_package(QtAV REQUIRED)
find_package(Qt5Widgets REQUIRED)
set(CMAKE_AUTOMOC ON)

add_executable(simpleplayer main.cpp playerwindow.cpp playerwindow.h)
target_include_directories(simpleplayer PRIVATE ${QTAVWIDGETS_INCLUDE_DIRS})
target_link_libraries(simpleplayer ${QTAVWIDGETS_LIBRARIES} Qt5::Widgets)
116 changes: 37 additions & 79 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 188,6 @@ set(DYNAMIC_GL 0)
set(OPENGL 0) #desktop opengl
set(OPENGLES 0) #glesv2
#get_target_property(QtGui_location Qt5::Gui LOCATION) #dll path
get_target_property(qmake Qt5::qmake LOCATION) #dll path
execute_process(
COMMAND ${qmake} -query QT_INSTALL_HEADERS
OUTPUT_VARIABLE QT_INSTALL_HEADERS
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(Qt5Gui_OPENGL_IMPLEMENTATION STREQUAL GL) # windows always set to GL
set(OPENGL 1)
Expand All @@ -217,77 211,9 @@ if(NOT OPENGL AND NOT OPENGLES AND NOT DYNAMIC_GL)
set(HAVE_OPENGL 0)
endif()

set(SDK_HEADERS
QtAV/QtAV
QtAV/QtAV.h
QtAV/dptr.h
QtAV/QtAV_Global.h
QtAV/AudioResampler.h
QtAV/AudioDecoder.h
QtAV/AudioEncoder.h
QtAV/AudioFormat.h
QtAV/AudioFrame.h
QtAV/AudioOutput.h
QtAV/AVDecoder.h
QtAV/AVEncoder.h
QtAV/AVDemuxer.h
QtAV/AVMuxer.h
QtAV/Filter.h
QtAV/FilterContext.h
QtAV/GLSLFilter.h
QtAV/LibAVFilter.h
QtAV/EncodeFilter.h
QtAV/Frame.h
QtAV/FrameReader.h
QtAV/QPainterRenderer.h
QtAV/Packet.h
QtAV/AVError.h
QtAV/AVPlayer.h
QtAV/AVTranscoder.h
QtAV/VideoCapture.h
QtAV/VideoRenderer.h
QtAV/VideoOutput.h
QtAV/MediaIO.h
QtAV/AVOutput.h
QtAV/AVClock.h
QtAV/VideoDecoder.h
QtAV/VideoEncoder.h
QtAV/VideoFormat.h
QtAV/VideoFrame.h
QtAV/VideoFrameExtractor.h
QtAV/FactoryDefine.h
QtAV/Statistics.h
QtAV/SubImage.h
QtAV/Subtitle.h
QtAV/SubtitleFilter.h
QtAV/SurfaceInterop.h
QtAV/OpenGLVideo.h
QtAV/OpenGLRendererBase.h
QtAV/VideoShader.h
QtAV/VideoShaderObject.h
QtAV/version.h
)
set(SDK_PRIVATE_HEADERS
QtAV/private/factory.h
QtAV/private/mkid.h
QtAV/private/prepost.h
QtAV/private/singleton.h
QtAV/private/PlayerSubtitle.h
QtAV/private/SubtitleProcessor.h
QtAV/private/AVCompat.h
QtAV/private/AudioOutputBackend.h
QtAV/private/AudioResampler_p.h
QtAV/private/AVDecoder_p.h
QtAV/private/AVEncoder_p.h
QtAV/private/MediaIO_p.h
QtAV/private/AVOutput_p.h
QtAV/private/Filter_p.h
QtAV/private/Frame_p.h
QtAV/private/VideoShader_p.h
QtAV/private/VideoRenderer_p.h
QtAV/private/QPainterRenderer_p.h
QtAV/private/OpenGLRendererBase_p.h
)
file(GLOB SDK_HEADERS QtAV/*.h)
list(APPEND SDK_HEADERS QtAV/QtAV)
file(GLOB SDK_PRIVATE_HEADERS QtAV/private/*.h)

list(APPEND SOURCES
AVCompat.cpp
Expand Down Expand Up @@ -510,6 436,11 @@ target_link_libraries(${MODULE}
set_target_properties(${MODULE} PROPERTIES
MACOSX_RPATH ON
FRAMEWORK ON
# MACOSX_FRAMEWORK_INFO_PLIST qtav-Info.plist
#PUBLIC_HEADER ${SDK_HEADERS}
#PRIVATE_HEADER ${SDK_PRIVATE_HEADERS}
XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"

VERSION ${PROJECT_VERSION}
SOVERSION ${SO_VERSION}
OUTPUT_NAME ${MODULE}
Expand All @@ -522,8 453,35 @@ set_target_properties(${MODULE} PROPERTIES
#http://doc.qt.io/qt-5/cmake-manual.html
set(CMAKE_INCLUDE_CURRENT_DIR ON) # for .moc
target_include_directories(${MODULE}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/QtAV
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})

install(FILES
${SDK_HEADERS}
DESTINATION ${QT_INSTALL_HEADERS}/${MODULE}
)
install(FILES
${SDK_PRIVATE_HEADERS}
DESTINATION ${QT_INSTALL_HEADERS}/${MODULE}/private
)
install(TARGETS ${MODULE}
EXPORT ${MODULE}-targets
#PUBLIC_HEADER DESTINATION ${QT_INSTALL_HEADERS}/${MODULE} # list is too long
#PRIVATE_HEADER DESTINATION ${QT_INSTALL_HEADERS}/${MODULE}/private
RUNTIME DESTINATION ${QT_INSTALL_LIBS}/bin
LIBRARY DESTINATION ${QT_INSTALL_LIBS}/lib
ARCHIVE DESTINATION ${QT_INSTALL_LIBS}/lib
FRAMEWORK DESTINATION ${QT_INSTALL_LIBS}
)

# FIXME: why QTAV_INCLUDE_DIRS is empty?
install(EXPORT ${MODULE}-targets
DESTINATION ${QT_INSTALL_LIBS}/cmake/${MODULE}
FILE ${MODULE}-config.cmake
)

33 changes: 30 additions & 3 deletions widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 20,8 @@ set(SDK_HEADERS
QtAVWidgets/VideoPreviewWidget.h
QtAVWidgets/WidgetRenderer.h
)
file(GLOB SDK_PRIVATE_HEADERS QtAVWidgets/*.h)

set(SOURCES
global.cpp
GraphicsItemRenderer.cpp
Expand Down Expand Up @@ -65,8 67,33 @@ set_target_properties(${MODULE} PROPERTIES
#http://doc.qt.io/qt-5/cmake-manual.html
set(CMAKE_INCLUDE_CURRENT_DIR ON) # for .moc
target_include_directories(${MODULE}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/QtAVWidgets
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})
target_compile_definitions(${MODULE} PRIVATE ${EXTRA_DEFS})


install(FILES
${SDK_HEADERS}
DESTINATION ${QT_INSTALL_HEADERS}/${MODULE}
)
install(FILES
${SDK_PRIVATE_HEADERS}
DESTINATION ${QT_INSTALL_HEADERS}/${MODULE}/private
)
install(TARGETS ${MODULE}
EXPORT ${MODULE}-targets
#PUBLIC_HEADER DESTINATION ${QT_INSTALL_HEADERS}/${MODULE}
#PRIVATE_HEADER DESTINATION ${QT_INSTALL_HEADERS}/${MODULE}/private
RUNTIME DESTINATION ${QT_INSTALL_LIBS}/bin
LIBRARY DESTINATION ${QT_INSTALL_LIBS}/lib
ARCHIVE DESTINATION ${QT_INSTALL_LIBS}/lib
FRAMEWORK DESTINATION ${QT_INSTALL_LIBS}
)
install(EXPORT ${MODULE}-targets
DESTINATION ${QT_INSTALL_LIBS}/cmake/${MODULE}
FILE ${MODULE}-config.cmake
)

0 comments on commit bc60860

Please sign in to comment.