From d2d6eba16a8ff2057384abd2c0ff70ac6862513a Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sat, 13 Feb 2021 00:35:18 +0000 Subject: [PATCH] cmake: fix add_apple_compiler_options() calls and OBJCXX handling --- cmake/OpenCVUtils.cmake | 10 ++++++++-- modules/highgui/CMakeLists.txt | 2 +- modules/imgcodecs/CMakeLists.txt | 2 +- modules/videoio/CMakeLists.txt | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 735fa10a4c..d03dc9c551 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -564,7 +564,11 @@ macro(ocv_check_flag_support lang flag varname base_options) elseif("_${lang}_" MATCHES "_C_") set(_lang C) elseif("_${lang}_" MATCHES "_OBJCXX_") - set(_lang OBJCXX) + if(DEFINED CMAKE_OBJCXX_COMPILER) # CMake 3.16+ and enable_language(OBJCXX) call are required + set(_lang OBJCXX) + else() + set(_lang CXX) + endif() else() set(_lang ${lang}) endif() @@ -573,7 +577,9 @@ macro(ocv_check_flag_support lang flag varname base_options) string(REGEX REPLACE "^(/|-)" "HAVE_${_lang}_" ${varname} "${${varname}}") string(REGEX REPLACE " -|-|=| |\\.|," "_" ${varname} "${${varname}}") - ocv_check_compiler_flag("${_lang}" "${base_options} ${flag}" ${${varname}} ${ARGN}) + if(DEFINED CMAKE_${_lang}_COMPILER) + ocv_check_compiler_flag("${_lang}" "${base_options} ${flag}" ${${varname}} ${ARGN}) + endif() endmacro() macro(ocv_check_runtime_flag flag result) diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index bd7c8980be..296f4cab2b 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -151,7 +151,7 @@ ocv_create_module(${HIGHGUI_LIBRARIES}) macro(ocv_highgui_configure_target) if(APPLE) - add_apple_compiler_options(the_module) + add_apple_compiler_options(${the_module}) endif() if(MSVC) diff --git a/modules/imgcodecs/CMakeLists.txt b/modules/imgcodecs/CMakeLists.txt index 1b832eaa3a..2498b5ae83 100644 --- a/modules/imgcodecs/CMakeLists.txt +++ b/modules/imgcodecs/CMakeLists.txt @@ -131,7 +131,7 @@ ocv_create_module(${GRFMT_LIBS} ${IMGCODECS_LIBRARIES}) macro(ocv_imgcodecs_configure_target) if(APPLE) - add_apple_compiler_options(the_module) + add_apple_compiler_options(${the_module}) endif() if(MSVC) diff --git a/modules/videoio/CMakeLists.txt b/modules/videoio/CMakeLists.txt index 3dac3e816c..cc0c5eb1c5 100644 --- a/modules/videoio/CMakeLists.txt +++ b/modules/videoio/CMakeLists.txt @@ -253,7 +253,7 @@ ocv_create_module(${VIDEOIO_LIBRARIES}) macro(ocv_videoio_configure_target) if(APPLE) - add_apple_compiler_options(the_module) + add_apple_compiler_options(${the_module}) endif() if(MSVC)