From ca8b621b4fec65c768b58c6581f61d65cd40cc30 Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Wed, 10 Jul 2013 18:20:34 +0400 Subject: [PATCH] Refactored detecting several Apple-related technologies. Now the HAVE_* macros are set using cvconfig.h. Previously most of them already were there, but were always undefined. One, HAVE_COCOA, I had to add. This also makes the CMake code more consistent; now, WITH_* variables are always checked in cmake/*, while HAVE_* variables are checked in modules/highgui/CMakeLists.txt. --- cmake/OpenCVFindLibsGUI.cmake | 9 +++++++ cmake/OpenCVFindLibsGrfmt.cmake | 7 +++++- cmake/OpenCVFindLibsVideo.cmake | 10 ++++++++ cmake/templates/cvconfig.h.cmake | 3 +++ modules/highgui/CMakeLists.txt | 43 +++++++++++++------------------- 5 files changed, 45 insertions(+), 27 deletions(-) diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index d685d23feb..04c77d8ec5 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -65,3 +65,12 @@ if(WITH_OPENGL) endif() endif() endif(WITH_OPENGL) + +# --- Carbon & Cocoa --- +if(APPLE) + if(WITH_CARBON) + set(HAVE_CARBON YES) + elif(NOT IOS) + set(HAVE_COCOA YES) + endif() +endif() diff --git a/cmake/OpenCVFindLibsGrfmt.cmake b/cmake/OpenCVFindLibsGrfmt.cmake index 33e428b7c8..c8ebb3d8f2 100644 --- a/cmake/OpenCVFindLibsGrfmt.cmake +++ b/cmake/OpenCVFindLibsGrfmt.cmake @@ -161,4 +161,9 @@ endif() #cmake 2.8.2 bug - it fails to determine zlib version if(ZLIB_FOUND) ocv_parse_header2(ZLIB "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_VERSION) -endif() \ No newline at end of file +endif() + +# --- Apple ImageIO --- +if(WITH_IMAGEIO) + set(HAVE_IMAGEIO YES) +endif() diff --git a/cmake/OpenCVFindLibsVideo.cmake b/cmake/OpenCVFindLibsVideo.cmake index 0ca4828fe6..c9127189ef 100644 --- a/cmake/OpenCVFindLibsVideo.cmake +++ b/cmake/OpenCVFindLibsVideo.cmake @@ -228,3 +228,13 @@ if(WIN32) list(APPEND HIGHGUI_LIBRARIES winmm) endif() endif(WIN32) + +# --- Apple AV Foundation --- +if(WITH_AVFOUNDATION) + set(HAVE_AVFOUNDATION YES) +endif() + +# --- QuickTime --- +if(WITH_QUICKTIME) + set(HAVE_QUICKTIME YES) +endif() diff --git a/cmake/templates/cvconfig.h.cmake b/cmake/templates/cvconfig.h.cmake index a1b97e5d34..8aebbad60c 100644 --- a/cmake/templates/cvconfig.h.cmake +++ b/cmake/templates/cvconfig.h.cmake @@ -16,6 +16,9 @@ /* Carbon windowing environment */ #cmakedefine HAVE_CARBON +/* Cocoa API */ +#cmakedefine HAVE_COCOA + /* IEEE1394 capturing support */ #cmakedefine HAVE_DC1394 diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index 2b0a232099..c25108702d 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -108,16 +108,12 @@ elseif(HAVE_WIN32UI) list(APPEND highgui_srcs src/window_w32.cpp) elseif(HAVE_GTK) list(APPEND highgui_srcs src/window_gtk.cpp) -elseif(APPLE) - if(WITH_CARBON) - add_definitions(-DHAVE_CARBON=1) - list(APPEND highgui_srcs src/window_carbon.cpp) - list(APPEND HIGHGUI_LIBRARIES "-framework Carbon" "-framework QuickTime") - elseif(NOT IOS) - add_definitions(-DHAVE_COCOA=1) - list(APPEND highgui_srcs src/window_cocoa.mm) - list(APPEND HIGHGUI_LIBRARIES "-framework Cocoa") - endif() +elseif(HAVE_CARBON) + list(APPEND highgui_srcs src/window_carbon.cpp) + list(APPEND HIGHGUI_LIBRARIES "-framework Carbon" "-framework QuickTime") +elseif(HAVE_COCOA) + list(APPEND highgui_srcs src/window_cocoa.mm) + list(APPEND HIGHGUI_LIBRARIES "-framework Cocoa") endif() if(WIN32 AND NOT ARM) @@ -210,26 +206,21 @@ if(HAVE_GIGE_API) list(APPEND highgui_srcs src/cap_giganetix.cpp) endif(HAVE_GIGE_API) -if(WITH_IMAGEIO) - add_definitions(-DHAVE_IMAGEIO=1) - if(IOS) - list(APPEND HIGHGUI_LIBRARIES "-framework ImageIO") - endif() -endif(WITH_IMAGEIO) +if(HAVE_IMAGEIO AND IOS) + list(APPEND HIGHGUI_LIBRARIES "-framework ImageIO") +endif() -if(WITH_AVFOUNDATION) - add_definitions(-DHAVE_AVFOUNDATION=1) +if(HAVE_AVFOUNDATION) list(APPEND highgui_srcs src/cap_avfoundation.mm) list(APPEND HIGHGUI_LIBRARIES "-framework AVFoundation" "-framework QuartzCore") +endif() + +if(HAVE_QUICKTIME) + list(APPEND highgui_srcs src/cap_qt.cpp) + list(APPEND HIGHGUI_LIBRARIES "-framework Carbon" "-framework QuickTime" "-framework CoreFoundation" "-framework QuartzCore") elseif(APPLE) - add_definitions(-DHAVE_QUICKTIME=1) - if(WITH_QUICKTIME) - list(APPEND highgui_srcs src/cap_qt.cpp) - list(APPEND HIGHGUI_LIBRARIES "-framework Carbon" "-framework QuickTime" "-framework CoreFoundation" "-framework QuartzCore") - else() - list(APPEND highgui_srcs src/cap_qtkit.mm) - list(APPEND HIGHGUI_LIBRARIES "-framework QTKit" "-framework QuartzCore" "-framework AppKit") - endif() + list(APPEND highgui_srcs src/cap_qtkit.mm) + list(APPEND HIGHGUI_LIBRARIES "-framework QTKit" "-framework QuartzCore" "-framework AppKit") endif() if(IOS)