diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index dd41f822b9..20b38ec804 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -171,28 +171,54 @@ function(ocv_target_include_directories target) ";${ARGN};" MATCHES "/usr/include;") return() # workaround for GCC 6.x bug endif() + set(__params "") + set(__system_params "") + set(__var_name __params) foreach(dir ${ARGN}) - get_filename_component(__abs_dir "${dir}" ABSOLUTE) - ocv_is_opencv_directory(__is_opencv_dir "${dir}") - if(__is_opencv_dir) - list(APPEND __params "${__abs_dir}") + if("${dir}" STREQUAL "SYSTEM") + set(__var_name __system_params) else() - list(APPEND __params "${dir}") + get_filename_component(__abs_dir "${dir}" ABSOLUTE) + ocv_is_opencv_directory(__is_opencv_dir "${dir}") + if(__is_opencv_dir) + list(APPEND ${__var_name} "${__abs_dir}") + else() + list(APPEND ${__var_name} "${dir}") + endif() endif() endforeach() if(HAVE_CUDA OR CMAKE_VERSION VERSION_LESS 2.8.11) include_directories(${__params}) + include_directories(SYSTEM ${__system_params}) else() if(TARGET ${target}) - target_include_directories(${target} PRIVATE ${__params}) - if(OPENCV_DEPENDANT_TARGETS_${target}) - foreach(t ${OPENCV_DEPENDANT_TARGETS_${target}}) - target_include_directories(${t} PRIVATE ${__params}) - endforeach() + if(__params) + target_include_directories(${target} PRIVATE ${__params}) + if(OPENCV_DEPENDANT_TARGETS_${target}) + foreach(t ${OPENCV_DEPENDANT_TARGETS_${target}}) + target_include_directories(${t} PRIVATE ${__params}) + endforeach() + endif() + endif() + if(__system_params) + target_include_directories(${target} SYSTEM PRIVATE ${__system_params}) + if(OPENCV_DEPENDANT_TARGETS_${target}) + foreach(t ${OPENCV_DEPENDANT_TARGETS_${target}}) + target_include_directories(${t} SYSTEM PRIVATE ${__system_params}) + endforeach() + endif() endif() else() - set(__new_inc "${OCV_TARGET_INCLUDE_DIRS_${target}};${__params}") - set(OCV_TARGET_INCLUDE_DIRS_${target} "${__new_inc}" CACHE INTERNAL "") + if(__params) + set(__new_inc ${OCV_TARGET_INCLUDE_DIRS_${target}}) + list(APPEND __new_inc ${__params}) + set(OCV_TARGET_INCLUDE_DIRS_${target} "${__new_inc}" CACHE INTERNAL "") + endif() + if(__system_params) + set(__new_inc ${OCV_TARGET_INCLUDE_SYSTEM_DIRS_${target}}) + list(APPEND __new_inc ${__system_params}) + set(OCV_TARGET_INCLUDE_SYSTEM_DIRS_${target} "${__new_inc}" CACHE INTERNAL "") + endif() endif() endif() endfunction() @@ -1078,6 +1104,16 @@ function(_ocv_append_target_includes target) endif() unset(OCV_TARGET_INCLUDE_DIRS_${target} CACHE) endif() + + if(DEFINED OCV_TARGET_INCLUDE_SYSTEM_DIRS_${target}) + target_include_directories(${target} SYSTEM PRIVATE ${OCV_TARGET_INCLUDE_SYSTEM_DIRS_${target}}) + if(OPENCV_DEPENDANT_TARGETS_${target}) + foreach(t ${OPENCV_DEPENDANT_TARGETS_${target}}) + target_include_directories(${t} SYSTEM PRIVATE ${OCV_TARGET_INCLUDE_SYSTEM_DIRS_${target}}) + endforeach() + endif() + unset(OCV_TARGET_INCLUDE_SYSTEM_DIRS_${target} CACHE) + endif() endfunction() function(ocv_add_executable target)