diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 96321f9294..b32465ead2 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -242,6 +242,24 @@ macro(ocv_warnings_disable) endif(NOT ENABLE_NOISY_WARNINGS) endmacro() +macro(add_apple_compiler_options the_module) + ocv_check_flag_support(OBJCXX "-fobjc-exceptions" HAVE_OBJC_EXCEPTIONS) + if(HAVE_OBJC_EXCEPTIONS) + foreach(source ${OPENCV_MODULE_${the_module}_SOURCES}) + if("${source}" MATCHES "\\.mm$") + get_source_file_property(flags "${source}" COMPILE_FLAGS) + if(flags) + set(flags "${_flags} -fobjc-exceptions") + else() + set(flags "-fobjc-exceptions") + endif() + + set_source_files_properties("${source}" PROPERTIES COMPILE_FLAGS "${flags}") + endif() + endforeach() + endif() +endmacro() + # Provides an option that the user can optionally select. # Can accept condition to control when option is available for user. # Usage: diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index de8c27ba33..174a620020 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -98,21 +98,7 @@ ocv_create_module(${HIGHGUI_LIBRARIES}) macro(ocv_highgui_configure_target) if(APPLE) - ocv_check_flag_support(OBJCXX "-fobjc-exceptions" HAVE_OBJC_EXCEPTIONS) - if(HAVE_OBJC_EXCEPTIONS) - foreach(source ${OPENCV_MODULE_${the_module}_SOURCES}) - if("${source}" MATCHES "\\.mm$") - get_source_file_property(flags "${source}" COMPILE_FLAGS) - if(flags) - set(flags "${_flags} -fobjc-exceptions") - else() - set(flags "-fobjc-exceptions") - endif() - - set_source_files_properties("${source}" PROPERTIES COMPILE_FLAGS "${flags}") - endif() - endforeach() - endif() + add_apple_compiler_options(the_module) endif() if(BUILD_SHARED_LIBS) diff --git a/modules/imgcodecs/CMakeLists.txt b/modules/imgcodecs/CMakeLists.txt index 67054053cd..3d0110ef48 100644 --- a/modules/imgcodecs/CMakeLists.txt +++ b/modules/imgcodecs/CMakeLists.txt @@ -106,21 +106,7 @@ ocv_create_module(${GRFMT_LIBS} ${IMGCODECS_LIBRARIES}) macro(ocv_imgcodecs_configure_target) if(APPLE) - ocv_check_flag_support(OBJCXX "-fobjc-exceptions" HAVE_OBJC_EXCEPTIONS) - if(HAVE_OBJC_EXCEPTIONS) - foreach(source ${OPENCV_MODULE_${the_module}_SOURCES}) - if("${source}" MATCHES "\\.mm$") - get_source_file_property(flags "${source}" COMPILE_FLAGS) - if(flags) - set(flags "${_flags} -fobjc-exceptions") - else() - set(flags "-fobjc-exceptions") - endif() - - set_source_files_properties("${source}" PROPERTIES COMPILE_FLAGS "${flags}") - endif() - endforeach() - endif() + add_apple_compiler_options(the_module) endif() if(BUILD_SHARED_LIBS) diff --git a/modules/videoio/CMakeLists.txt b/modules/videoio/CMakeLists.txt index 7c8f6a058f..1635e2022f 100644 --- a/modules/videoio/CMakeLists.txt +++ b/modules/videoio/CMakeLists.txt @@ -189,21 +189,7 @@ ocv_create_module(${VIDEOIO_LIBRARIES}) macro(ocv_videoio_configure_target) if(APPLE) - ocv_check_flag_support(OBJCXX "-fobjc-exceptions" HAVE_OBJC_EXCEPTIONS) - if(HAVE_OBJC_EXCEPTIONS) - foreach(source ${OPENCV_MODULE_${the_module}_SOURCES}) - if("${source}" MATCHES "\\.mm$") - get_source_file_property(flags "${source}" COMPILE_FLAGS) - if(flags) - set(flags "${_flags} -fobjc-exceptions") - else() - set(flags "-fobjc-exceptions") - endif() - - set_source_files_properties("${source}" PROPERTIES COMPILE_FLAGS "${flags}") - endif() - endforeach() - endif() + add_apple_compiler_options(the_module) endif() if(BUILD_SHARED_LIBS)