Skip to content

Commit 5a791e6

Browse files
alalekvpisarev
authored andcommitted
cmake: update reporting of excluded dispatching files (opencv#10711)
* cmake: add ocv_get_smart_file_name() macro * cmake: avoid adding files for unavailable dispatch modes
1 parent 61e76e7 commit 5a791e6

File tree

6 files changed

+101
-25
lines changed

6 files changed

+101
-25
lines changed

cmake/OpenCVCompilerOptimizations.cmake

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,8 @@ macro(ocv_compiler_optimization_process_sources SOURCES_VAR_NAME LIBS_VAR_NAME T
580580
list(APPEND __result "${fname}")
581581
#continue()
582582
elseif(CV_DISABLE_OPTIMIZATION OR NOT CV_ENABLE_INTRINSICS)
583-
message(STATUS "Excluding from source files list (optimization is disabled): ${fname}")
583+
ocv_get_smart_file_name(fname_ "${fname}")
584+
message(STATUS "Excluding from source files list (optimization is disabled): ${fname_}")
584585
#continue()
585586
else()
586587
get_source_file_property(__definitions "${fname}" COMPILE_DEFINITIONS)
@@ -622,7 +623,8 @@ macro(ocv_compiler_optimization_process_sources SOURCES_VAR_NAME LIBS_VAR_NAME T
622623
endif()
623624
endforeach()
624625
if(NOT __opt_found)
625-
message(STATUS "Excluding from source files list: ${fname}")
626+
ocv_get_smart_file_name(fname_ "${fname}")
627+
message(STATUS "Excluding from source files list: ${fname_}")
626628
endif()
627629
endif()
628630
else()
@@ -702,15 +704,18 @@ macro(ocv_compiler_optimization_fill_cpu_config)
702704
#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_${OPT}
703705
# define CV_TRY_${OPT} 1
704706
# define CV_CPU_HAS_SUPPORT_${OPT} 1
705-
# define CV_CPU_CALL_${OPT}(fn, args) return (opt_${OPT}::fn args)
707+
# define CV_CPU_CALL_${OPT}(fn, args) return (cpu_baseline::fn args)
708+
# define CV_CPU_CALL_${OPT}_(fn, args) return (opt_${OPT}::fn args)
706709
#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_${OPT}
707710
# define CV_TRY_${OPT} 1
708711
# define CV_CPU_HAS_SUPPORT_${OPT} (cv::checkHardwareSupport(CV_CPU_${OPT}))
709712
# define CV_CPU_CALL_${OPT}(fn, args) if (CV_CPU_HAS_SUPPORT_${OPT}) return (opt_${OPT}::fn args)
713+
# define CV_CPU_CALL_${OPT}_(fn, args) if (CV_CPU_HAS_SUPPORT_${OPT}) return (opt_${OPT}::fn args)
710714
#else
711715
# define CV_TRY_${OPT} 0
712716
# define CV_CPU_HAS_SUPPORT_${OPT} 0
713717
# define CV_CPU_CALL_${OPT}(fn, args)
718+
# define CV_CPU_CALL_${OPT}_(fn, args)
714719
#endif
715720
#define __CV_CPU_DISPATCH_CHAIN_${OPT}(fn, args, mode, ...) CV_CPU_CALL_${OPT}(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__))
716721
")
@@ -761,7 +766,10 @@ macro(ocv_add_dispatched_file filename)
761766
else()
762767
file(WRITE "${__file}" "${__codestr}")
763768
endif()
764-
list(APPEND OPENCV_MODULE_${the_module}_SOURCES_DISPATCHED "${__file}")
769+
770+
if(";${CPU_DISPATCH};" MATCHES "${OPT}" OR __CPU_DISPATCH_INCLUDE_ALL)
771+
list(APPEND OPENCV_MODULE_${the_module}_SOURCES_DISPATCHED "${__file}")
772+
endif()
765773

766774
set(__declarations_str "${__declarations_str}
767775
#define CV_CPU_DISPATCH_MODE ${OPT}
@@ -786,6 +794,14 @@ macro(ocv_add_dispatched_file filename)
786794
endif()
787795
endmacro()
788796

797+
# Workaround to support code which always require all code paths
798+
macro(ocv_add_dispatched_file_force_all)
799+
set(__CPU_DISPATCH_INCLUDE_ALL 1)
800+
ocv_add_dispatched_file(${ARGN})
801+
unset(__CPU_DISPATCH_INCLUDE_ALL)
802+
endmacro()
803+
804+
789805
if(CV_DISABLE_OPTIMIZATION OR CV_ICC)
790806
ocv_update(CV_ENABLE_UNROLLED 0)
791807
else()

cmake/OpenCVUtils.cmake

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ endmacro()
118118

119119

120120
# check if "sub" (file or dir) is below "dir"
121-
function(is_subdir res dir sub )
121+
function(ocv_is_subdir res dir sub )
122122
get_filename_component(dir "${dir}" ABSOLUTE)
123123
get_filename_component(sub "${sub}" ABSOLUTE)
124124
file(TO_CMAKE_PATH "${dir}" dir)
@@ -140,7 +140,7 @@ endfunction()
140140
function(ocv_is_opencv_directory result_var dir)
141141
set(result FALSE)
142142
foreach(parent ${OpenCV_SOURCE_DIR} ${OpenCV_BINARY_DIR} ${OPENCV_EXTRA_MODULES_PATH})
143-
is_subdir(result "${parent}" "${dir}")
143+
ocv_is_subdir(result "${parent}" "${dir}")
144144
if(result)
145145
break()
146146
endif()
@@ -1461,6 +1461,21 @@ macro(ocv_copyfiles_add_target target list_var comment_str)
14611461
add_custom_target(${target} DEPENDS "${OPENCV_DEPHELPER}/${target}")
14621462
endmacro()
14631463

1464+
macro(ocv_get_smart_file_name output_var fpath)
1465+
ocv_is_subdir(__subir "${OpenCV_BINARY_DIR}" "${fpath}")
1466+
if(__subir)
1467+
file(RELATIVE_PATH ${output_var} "${OpenCV_BINARY_DIR}" "${fpath}")
1468+
set(${output_var} "<BUILD>/${${output_var}}")
1469+
else()
1470+
ocv_is_subdir(__subir "${OpenCV_SOURCE_DIR}" "${fpath}")
1471+
if(__subir)
1472+
file(RELATIVE_PATH ${output_var} "${OpenCV_SOURCE_DIR}" "${fpath}")
1473+
else()
1474+
set(${output_var} "${fpath}")
1475+
endif()
1476+
endif()
1477+
unset(__subir)
1478+
endmacro()
14641479

14651480
# Needed by install(DIRECTORY ...)
14661481
if(NOT CMAKE_VERSION VERSION_LESS 3.1)

0 commit comments

Comments
 (0)