opencv/modules/highgui/CMakeLists.txt

291 lines
10 KiB
CMake
Raw Normal View History

2017-06-20 20:19:43 +08:00
set(the_description "High-level GUI")
2021-05-01 21:13:58 +08:00
if(ANDROID)
ocv_add_module(highgui opencv_imgproc opencv_imgcodecs OPTIONAL opencv_videoio WRAP python)
else()
ocv_add_module(highgui opencv_imgproc opencv_imgcodecs OPTIONAL opencv_videoio WRAP python java)
endif()
2021-05-01 21:13:58 +08:00
include(${CMAKE_CURRENT_LIST_DIR}/cmake/plugin.cmake)
set(tgts "PRIVATE")
set(highgui_hdrs
${CMAKE_CURRENT_LIST_DIR}/src/precomp.hpp
)
set(highgui_srcs
${CMAKE_CURRENT_LIST_DIR}/src/backend.cpp
${CMAKE_CURRENT_LIST_DIR}/src/window.cpp
${CMAKE_CURRENT_LIST_DIR}/src/roiSelector.cpp
)
# ----------------------------------------------------------------------------
# CMake file for highgui. See root CMakeLists.txt
# Some parts taken from version of Hartmut Seichter, HIT Lab NZ.
# Jose Luis Blanco, 2008
# ----------------------------------------------------------------------------
2015-12-31 21:31:26 +08:00
if(DEFINED WINRT AND NOT DEFINED ENABLE_WINRT_MODE_NATIVE)
Update cap_msmf.cpp Add support for WinRT in the MF capture framework by removing the disallowed calls to enumerate devices and create a sample grabber sink and adding framework for the MediaCapture interface and a custom sink which interfaces with the sample grabber callback interface. The change requires discussion for making it completely functional as redundancy is required given that if the source is a video file, the old code pathways must be used. Otherwise all IMFMediaSession, IMFMediaSource, and IMFActivate code must use a MediaCapture code path and all sink code must use the CMediaSink custom sink. Support for the custom sink is extended to non-WinRT not for compatibility as Windows Vista client is a minimum regardless, but because it offers more flexibility, could be faster and is able to be used as an optionally different code path during sink creation based on a future configuration parameter. My discussion and proposal to finish this change: Devices are so easily enumerated through WinRT Windows.Devices namespace that wrapping the calls in a library is quite a chore for little benefit though to get the various modes and formats could still be a worthwhile project. For now conditional compilation to remove videodevices and any offending non-video file related activity in videodevice. In my opinion, this is a different , far less fundamental and important change which can possibly be done as a future project and also much more easily implemented in C++/CX. ImageGrabber has the IMFSampleGrabberSinkCallback replaced with a base class (SharedSampleGrabber) which also be is base class for ImageGrabberRT. This change is necessary as the custom sink does not require a thread to pump events which is done through MediaCapture already. IMFSampleGrabberSinkCallback is the common element between both models and that piece can be shared. Initializing the new ImageGrabberRT is as simple as passing an already initialized MediaCapture object and any video format/encoding parameters. The concurrency event is necessary to wait for completion and is the way the underlying, IAsyncAction wrappers in the task library work as well. Native WIN32 event objects would be an option if HAVE_CONCURRENCY is not defined. I could even imagine doing it with sleep/thread yield and InterlockedCompareExchange yet I am not enthusiastic about that approach either. Since there is a specific compiler HAVE_ for concurrency, I do not like pulling it in though I think for WinRT it is safe to say we will always have it available though should probably conditionally compile with the Interlocked option as WIN32 events would require HAVE_WIN32. It looks like C++/CX cannot be used for the IMediaExtension sink (which should not be a problem) as using COM objects requires WRL and though deriving from IMediaExtension can be done, there is little purpose without COM. Objects from C++/CX can be swapped to interact with objects from native C++ as Inspectable* can reinterpret_cast to the ref object IInspectable^ and vice-versa. A solution to the COM class with C++/CX would be great so we could have dual support. Also without #define for every WRL object in use, the code will get quite muddy given that the */^ would need to be ifdef'd everywhere. Update cap_msmf.cpp Fixed bugs and completed the change. I believe the new classes need to be moved to a header file as the file has become to large and more classes need to be added for handling all the asynchronous problems (one wrapping IAsyncAction in a task and another for making a task out of IAsyncAction). Unfortunately, blocking on the UI thread is not an option in WinRT so a synchronous architecture is considered "illegal" by Microsoft's standards even if implementable (C++/CX ppltasks library throws errors if you try it). Worse, either by design or a bug in the MF MediaCapture class with Custom Sinks causes a crash if stop/start previewing without reinitializing (spPreferredPreviewMediaType is fatally nulled). After decompiling Windows.Media.dll, I worked around this in my own projects by using an activate-able custom sink ID which strangely assigns 1 to this pointer allowing it to be reinitialized in what can only be described as a hack by Microsoft. This would add additional overhead to the project to implement especially for static libraries as it requires IDL/DLL exporting followed by manifest declaration. Better to document that it is not supported. Furthermore, an additional class for IMFAttributes should be implemented to make clean architecture for passing around attributes as opposed to directly calling non-COM interface calls on the objects and making use of SetProperties which would also be a set up for an object that uses the RuntimeClass activation ID. The remaining changes are not difficult and will be complete soon along with debug tracing messages. Update cap_msmf.cpp Create cap_msmf.h Update cap_msmf.cpp Update cap_msmf.h Update cap_msmf.cpp Update cap_msmf.h Update and rename cap_msmf.h to cap_msmf.hpp Update cap_msmf.cpp Update CMakeLists.txt Update cap_msmf.hpp Update cap_msmf.cpp Update cap_msmf.cpp Update cap_msmf.cpp Update cap_msmf.hpp Update cap_msmf.hpp Update cap_msmf.cpp Successful test - samples are grabbed Update cap_msmf.cpp Update cap_msmf.hpp Update cap_msmf.cpp Update cap_msmf.hpp Update cap_msmf.hpp Update cap_msmf.cpp Update cap_msmf.hpp Update cap_msmf.cpp Update cap_msmf.hpp Update cap_msmf.cpp Update cap_msmf.hpp Create ppltasks_winrt.h Update cap_msmf.hpp Update cap_msmf.hpp Update cap_msmf.cpp Update ppltasks_winrt.h Library updated and cleaned up with comments, marshaling, exceptions and linker settings Update ppltasks_winrt.h Fixed trailing whitespace
2013-12-14 16:53:30 +08:00
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW")
endif()
2014-07-04 22:48:15 +08:00
if(APPLE)
ocv_include_directories(${ZLIB_INCLUDE_DIRS})
2014-07-04 22:48:15 +08:00
list(APPEND HIGHGUI_LIBRARIES ${ZLIB_LIBRARIES})
endif()
2018-02-02 19:19:29 +08:00
if(HAVE_WEBP)
add_definitions(-DHAVE_WEBP)
endif()
2014-08-01 22:11:20 +08:00
file(GLOB highgui_ext_hdrs
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/*.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.h")
# Removing WinRT API headers by default
list(REMOVE_ITEM highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/highgui_winrt.hpp")
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "")
if(HAVE_QT5)
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "QT5")
2021-05-01 21:13:58 +08:00
add_definitions(-DHAVE_QT)
2017-10-10 03:12:52 +08:00
# "Automoc" doesn't work properly with opencv_world build, use QT5_WRAP_CPP() directly
#set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
2014-08-01 22:11:20 +08:00
QT5_ADD_RESOURCES(_RCC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.qrc)
QT5_WRAP_CPP(_MOC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.h)
2014-08-01 22:11:20 +08:00
list(APPEND highgui_srcs
${CMAKE_CURRENT_LIST_DIR}/src/window_QT.cpp
${CMAKE_CURRENT_LIST_DIR}/src/window_QT.h
${_MOC_OUTFILES}
2014-08-01 22:11:20 +08:00
${_RCC_OUTFILES})
foreach(dt5_dep Core Gui Widgets Test Concurrent)
add_definitions(${Qt5${dt5_dep}_DEFINITIONS})
include_directories(${Qt5${dt5_dep}_INCLUDE_DIRS})
list(APPEND HIGHGUI_LIBRARIES ${Qt5${dt5_dep}_LIBRARIES})
endforeach()
if(HAVE_QT_OPENGL)
2021-05-01 21:13:58 +08:00
add_definitions(-DHAVE_QT_OPENGL)
add_definitions(${Qt5OpenGL_DEFINITIONS})
include_directories(${Qt5OpenGL_INCLUDE_DIRS})
list(APPEND HIGHGUI_LIBRARIES ${Qt5OpenGL_LIBRARIES})
endif()
elseif(HAVE_QT)
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "QT4")
2021-05-01 21:13:58 +08:00
add_definitions(-DHAVE_QT)
if(HAVE_QT_OPENGL)
add_definitions(-DHAVE_QT_OPENGL)
set(QT_USE_QTOPENGL TRUE)
endif()
include(${QT_USE_FILE})
2014-08-01 22:11:20 +08:00
QT4_ADD_RESOURCES(_RCC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.qrc)
QT4_WRAP_CPP(_MOC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.h)
list(APPEND HIGHGUI_LIBRARIES ${QT_LIBRARIES})
2014-08-01 22:11:20 +08:00
list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.cpp ${_MOC_OUTFILES} ${_RCC_OUTFILES})
2016-09-07 23:02:36 +08:00
ocv_check_flag_support(CXX -Wno-missing-declarations _have_flag "")
2012-06-27 05:05:15 +08:00
if(${_have_flag})
set_source_files_properties(${_RCC_OUTFILES} PROPERTIES COMPILE_FLAGS -Wno-missing-declarations)
2012-06-08 01:21:29 +08:00
endif()
elseif(WINRT)
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "WINRT")
if(NOT WINRT_8_0)
# Dependencies used by the implementation referenced
# below are not available on WinRT 8.0.
# Enabling it for WiRT 8.1+ only.
# WinRT 8.1+ detected. Adding WinRT API header.
message(STATUS " ${name}: WinRT detected. Adding WinRT API header")
list(APPEND highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/highgui_winrt.hpp")
list(APPEND highgui_srcs
${CMAKE_CURRENT_LIST_DIR}/src/window_winrt.cpp
${CMAKE_CURRENT_LIST_DIR}/src/window_winrt_bridge.cpp)
list(APPEND highgui_hdrs
${CMAKE_CURRENT_LIST_DIR}/src/window_winrt_bridge.hpp)
endif()
# libraries below are neither available nor required
# on ARM devices and/or Windows Phone
if(WINRT_PHONE OR (OpenCV_ARCH STREQUAL "ARM"))
list(REMOVE_ITEM HIGHGUI_LIBRARIES "comctl32" "gdi32" "ole32" "setupapi")
if(WINRT_PHONE)
message(STATUS " ${name}: Windows Phone detected")
elseif(OpenCV_ARCH STREQUAL "ARM")
message(STATUS " ${name}: ARM detected")
if(WINRT_STORE)
list(REMOVE_ITEM HIGHGUI_LIBRARIES "ws2_32")
message(STATUS " ${name}: Removing 'ws2_32.lib'")
endif()
endif()
message(STATUS " ${name}: Removing 'comctl32.lib, gdi32.lib, ole32.lib, setupapi.lib'")
message(STATUS " ${name}: Leaving '${HIGHGUI_LIBRARIES}'")
endif()
elseif(HAVE_WIN32UI)
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "WIN32UI")
2014-08-01 22:11:20 +08:00
list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_w32.cpp)
if(OpenCV_ARCH STREQUAL "ARM64")
list(APPEND HIGHGUI_LIBRARIES "comdlg32" "advapi32")
endif()
elseif(HAVE_COCOA)
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "COCOA")
2021-05-01 21:13:58 +08:00
add_definitions(-DHAVE_COCOA)
2014-08-01 22:11:20 +08:00
list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_cocoa.mm)
list(APPEND HIGHGUI_LIBRARIES "-framework Cocoa")
endif()
2012-05-25 04:10:13 +08:00
2021-05-01 21:13:58 +08:00
if(TARGET ocv.3rdparty.gtk3 OR TARGET ocv.3rdparty.gtk2)
if(TARGET ocv.3rdparty.gtk3 AND NOT WITH_GTK_2_X)
set(__gtk_dependency "ocv.3rdparty.gtk3")
else()
set(__gtk_dependency "ocv.3rdparty.gtk2")
endif()
if(
NOT HIGHGUI_PLUGIN_LIST STREQUAL "all"
AND NOT "gtk" IN_LIST HIGHGUI_PLUGIN_LIST
AND NOT "gtk2" IN_LIST HIGHGUI_PLUGIN_LIST
AND NOT "gtk3" IN_LIST HIGHGUI_PLUGIN_LIST
AND NOT OPENCV_HIGHGUI_BUILTIN_BACKEND
2021-05-01 21:13:58 +08:00
)
if(__gtk_dependency STREQUAL "ocv.3rdparty.gtk3")
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "GTK3")
elseif(__gtk_dependency STREQUAL "ocv.3rdparty.gtk2")
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "GTK2")
else()
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "GTK")
endif()
2021-05-01 21:13:58 +08:00
list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_gtk.cpp)
list(APPEND tgts ${__gtk_dependency})
if(TARGET ocv.3rdparty.gthread)
list(APPEND tgts ocv.3rdparty.gthread)
endif()
if(TARGET ocv.3rdparty.gtkglext
AND __gtk_dependency STREQUAL "ocv.3rdparty.gtk2"
2021-05-01 21:13:58 +08:00
AND NOT OPENCV_GTK_DISABLE_GTKGLEXT
)
list(APPEND tgts ocv.3rdparty.gtkglext)
if(TARGET ocv.3rdparty.gtk_opengl
AND __gtk_dependency STREQUAL "ocv.3rdparty.gtk2"
AND NOT OPENCV_GTK_DISABLE_OPENGL
)
list(APPEND tgts ocv.3rdparty.gtk_opengl)
endif()
2021-05-01 21:13:58 +08:00
endif()
elseif("gtk" IN_LIST HIGHGUI_PLUGIN_LIST)
ocv_create_builtin_highgui_plugin(opencv_highgui_gtk ${__gtk_dependency} "window_gtk.cpp")
if(TARGET ocv.3rdparty.gthread)
ocv_target_link_libraries(opencv_highgui_gtk ocv.3rdparty.gthread)
endif()
if(TARGET ocv.3rdparty.gtkglext)
ocv_target_link_libraries(opencv_highgui_gtk ocv.3rdparty.gtkglext)
endif()
else()
if(TARGET ocv.3rdparty.gtk3 AND ("gtk3" IN_LIST HIGHGUI_PLUGIN_LIST OR HIGHGUI_PLUGIN_LIST STREQUAL "all"))
ocv_create_builtin_highgui_plugin(opencv_highgui_gtk3 ocv.3rdparty.gtk3 "window_gtk.cpp")
if(TARGET ocv.3rdparty.gthread)
ocv_target_link_libraries(opencv_highgui_gtk3 ocv.3rdparty.gthread)
endif()
if(TARGET ocv.3rdparty.gtkglext)
ocv_target_link_libraries(opencv_highgui_gtk3 ocv.3rdparty.gtkglext)
endif()
endif()
if(TARGET ocv.3rdparty.gtk2 AND ("gtk2" IN_LIST HIGHGUI_PLUGIN_LIST OR HIGHGUI_PLUGIN_LIST STREQUAL "all"))
ocv_create_builtin_highgui_plugin(opencv_highgui_gtk2 ocv.3rdparty.gtk2 "window_gtk.cpp")
if(TARGET ocv.3rdparty.gthread)
ocv_target_link_libraries(opencv_highgui_gtk2 ocv.3rdparty.gthread)
endif()
if(TARGET ocv.3rdparty.gtkglext)
ocv_target_link_libraries(opencv_highgui_gtk2 ocv.3rdparty.gtkglext)
endif()
endif()
endif()
endif()
if(NOT OPENCV_HIGHGUI_BUILTIN_BACKEND)
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "NONE")
endif()
message(STATUS "highgui: using builtin backend: ${OPENCV_HIGHGUI_BUILTIN_BACKEND}") # FIXIT: propagate to root CMake
if(TRUE)
# these variables are set by 'ocv_append_build_options(HIGHGUI ...)'
2012-05-21 16:53:38 +08:00
foreach(P ${HIGHGUI_INCLUDE_DIRS})
ocv_include_directories(${P})
endforeach()
foreach(P ${HIGHGUI_LIBRARY_DIRS})
link_directories(${P})
endforeach()
endif()
2021-05-01 21:13:58 +08:00
if(tgts STREQUAL "PRIVATE")
set(tgts "")
endif()
# install used dependencies only
if(NOT BUILD_SHARED_LIBS
AND NOT (CMAKE_VERSION VERSION_LESS "3.13.0") # upgrade CMake: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/2152
)
foreach(tgt in ${tgts})
if(tgt MATCHES "^ocv\.3rdparty\.")
install(TARGETS ${tgt} EXPORT OpenCVModules)
endif()
endforeach()
endif()
source_group("Src" FILES ${highgui_srcs} ${highgui_hdrs})
source_group("Include" FILES ${highgui_ext_hdrs})
2014-07-04 22:48:15 +08:00
ocv_set_module_sources(HEADERS ${highgui_ext_hdrs} SOURCES ${highgui_srcs} ${highgui_hdrs})
ocv_module_include_directories()
2011-04-27 00:10:26 +08:00
2014-07-04 22:48:15 +08:00
ocv_create_module(${HIGHGUI_LIBRARIES})
2014-08-01 22:11:20 +08:00
macro(ocv_highgui_configure_target)
if(APPLE)
add_apple_compiler_options(${the_module})
endif()
if(MSVC)
2012-02-06 21:29:48 +08:00
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG")
2011-06-17 02:00:41 +08:00
endif()
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations)
2014-08-01 22:11:20 +08:00
endmacro()
if(NOT BUILD_opencv_world)
ocv_highgui_configure_target()
endif()
2012-03-19 19:21:01 +08:00
2021-05-01 21:13:58 +08:00
ocv_add_accuracy_tests(${tgts})
#ocv_add_perf_tests(${tgts})
if(HIGHGUI_ENABLE_PLUGINS)
ocv_target_compile_definitions(${the_module} PRIVATE ENABLE_PLUGINS)
if(TARGET opencv_test_highgui)
ocv_target_compile_definitions(opencv_test_highgui PRIVATE ENABLE_PLUGINS)
endif()
endif()
ocv_target_link_libraries(${the_module} LINK_PRIVATE ${tgts})
# generate module configuration
set(CONFIG_STR "// Auto-generated file
#define OPENCV_HIGHGUI_BUILTIN_BACKEND_STR \"${OPENCV_HIGHGUI_BUILTIN_BACKEND}\"
")
if(OPENCV_HIGHGUI_BUILTIN_BACKEND STREQUAL "NONE")
set(CONFIG_STR "${CONFIG_STR}
#define OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND 1
")
endif()
ocv_update_file("${CMAKE_CURRENT_BINARY_DIR}/opencv_highgui_config.hpp" "${CONFIG_STR}")